GTIRB  v2.1.0
GrammaTech Intermediate Representation for Binaries: C++ API
ProxyBlock.hpp
Go to the documentation of this file.
1 //===- ProxyBlock.hpp -------------------------------------------*- C++ -*-===//
2 //
3 // Copyright (C) 2020 GrammaTech, Inc.
4 //
5 // This code is licensed under the MIT license. See the LICENSE file in the
6 // project root for license terms.
7 //
8 // This project is sponsored by the Office of Naval Research, One Liberty
9 // Center, 875 N. Randolph Street, Arlington, VA 22203 under contract #
10 // N68335-17-C-0700. The content of the information does not necessarily
11 // reflect the position or policy of the Government and no official
12 // endorsement should be inferred.
13 //
14 //===----------------------------------------------------------------------===//
15 #ifndef GTIRB_PROX_BLOCK_H
16 #define GTIRB_PROX_BLOCK_H
17 
18 #include <gtirb/CfgNode.hpp>
19 #include <gtirb/Node.hpp>
20 
25 
26 namespace gtirb {
27 namespace proto {
28 class ProxyBlock;
29 }
30 
31 template <class T> class ErrorOr;
32 class Module;
33 
50 public:
54  static ProxyBlock* Create(Context& C) { return C.Create<ProxyBlock>(C); }
55 
57  Module* getModule() { return Parent; }
59  const Module* getModule() const { return Parent; }
60 
61  static bool classof(const Node* N) {
62  return N->getKind() == Kind::ProxyBlock;
63  }
65 
66 private:
67  ProxyBlock(Context& C) : CfgNode(C, Kind::ProxyBlock) {}
68  ProxyBlock(Context& C, const UUID& U) : CfgNode(C, Kind::ProxyBlock, U) {}
69 
70  static ProxyBlock* Create(Context& C, const UUID& U) {
71  return C.Create<ProxyBlock>(C, U);
72  }
73 
74  void setModule(Module* M) { Parent = M; }
75 
77  using MessageType = proto::ProxyBlock;
78 
84  void toProtobuf(MessageType* Message) const;
85 
92  static ErrorOr<ProxyBlock*> fromProtobuf(Context& C,
93  const MessageType& Message);
94 
95  // Present for testing purposes only.
96  void save(std::ostream& Out) const;
97 
98  // Present for testing purposes only.
99  static ProxyBlock* load(Context& C, std::istream& In);
100 
101  Module* Parent{nullptr};
102 
103  friend class Context; // Allow Context to construct proxies.
104  friend class Module; // Allow Module to call setModule, Create, etc.
105  // Allows serializaton from Module via sequenceToProtobuf.
106  template <typename T> friend typename T::MessageType toProtobuf(const T&);
107  friend class SerializationTestHarness; // Testing support.
108 };
109 
110 } // namespace gtirb
111 
112 #endif // GTIRB_PROXY_BLOCK_H
gtirb::Context::Create
NodeTy * Create(Args &&... TheArgs)
Create an object of type T.
Definition: Context.hpp:126
gtirb::Node
Represents the base of the Node class hierarchy.
Definition: Node.hpp:39
gtirb::CfgNode
Represents the base of types that can be inserted into the CFG.
Definition: CfgNode.hpp:30
gtirb::ProxyBlock::getModule
Module * getModule()
Get the Module this block belongs to.
Definition: ProxyBlock.hpp:57
gtirb::UUID
boost::uuids::uuid UUID
Represents a universally unique identifier used to identify Node objects across serialization boundar...
Definition: Context.hpp:36
gtirb::Context
The context under which GTIRB operations occur.
Definition: Context.hpp:63
Node.hpp
Class gtirb::Node.
GTIRB_EXPORT_API
#define GTIRB_EXPORT_API
This macro controls the visibility of exported symbols (i.e. classes) in shared libraries....
Definition: Export.hpp:52
gtirb
Main namespace for the GTIRB API.
Definition: Addr.hpp:28
gtirb::ProxyBlock::classof
static bool classof(const Node *N)
Definition: ProxyBlock.hpp:61
gtirb::ProxyBlock
A placeholder that serves as the endpoint (source or target) of a CFG edge.
Definition: ProxyBlock.hpp:49
CfgNode.hpp
Base class for nodes of the CFG.
gtirb::ProxyBlock::Create
static ProxyBlock * Create(Context &C)
Create an unitialized ProxyBlock object.
Definition: ProxyBlock.hpp:54
gtirb::Module
Represents a single binary (library or executable).
Definition: Module.hpp:107
gtirb::ProxyBlock::getModule
const Module * getModule() const
Get the Module this block belongs to.
Definition: ProxyBlock.hpp:59