ROSE  0.9.9.139
Reference.h
1 #ifndef ROSE_Partitioner2_Reference_H
2 #define ROSE_Partitioner2_Reference_H
3 
4 #include <Partitioner2/BasicBlock.h>
5 #include <Partitioner2/Function.h>
6 #include <set>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 namespace Partitioner2 {
11 
13 // Reference
15 
22 class Reference {
23  Function::Ptr function_;
24  BasicBlock::Ptr bblock_;
25  SgAsmInstruction *insn_;
27 public:
29  enum Granularity {
37  };
38 
44  explicit Reference(const Function::Ptr &function, const BasicBlock::Ptr &bblock=BasicBlock::Ptr(),
46  : function_(function), bblock_(bblock), insn_(insn), address_(address) {}
47 
48 
49  explicit Reference(const BasicBlock::Ptr &bblock, SgAsmInstruction *insn=NULL,
51  : bblock_(bblock), insn_(insn), address_(address) {}
52 
54  : insn_(insn), address_(address) {}
55 
56  explicit Reference(rose_addr_t address)
57  : insn_(NULL), address_(address) {}
58 
60  : insn_(NULL) {}
68  if (address_)
69  return ADDRESS;
70  if (insn_)
71  return INSTRUCTION;
72  if (bblock_)
73  return BASIC_BLOCK;
74  if (function_)
75  return FUNCTION;
76  return EMPTY;
77  }
78 
82  bool isEmpty() const {
83  return granularity()==EMPTY;
84  }
85 
89  bool hasFunction() const {
90  return function_!=NULL;
91  }
92 
94  Function::Ptr function() const {
95  return function_;
96  }
97 
101  bool hasBasicBlock() const {
102  return bblock_!=NULL;
103  }
104 
107  return bblock_;
108  }
109 
113  bool hasInstruction() const {
114  return insn_ != NULL;
115  }
116 
119  return insn_;
120  }
121 
126  bool hasExplicitAddress() const {
127  return address_;
128  }
129 
134  rose_addr_t address() const;
135 
139  bool operator==(const Reference &other) const;
140 
147  bool operator<(const Reference &other) const;
148 };
149 
151 typedef std::set<Reference> ReferenceSet;
152 
155 
156 } // namespace
157 } // namespace
158 } // namespace
159 
160 #endif
bool hasBasicBlock() const
Predicate for having a basic block.
Definition: Reference.h:101
bool isEmpty() const
Predicate for emptiness.
Definition: Reference.h:82
SgAsmInstruction * instruction() const
Optional instruction pointer.
Definition: Reference.h:118
Reference(const Function::Ptr &function, const BasicBlock::Ptr &bblock=BasicBlock::Ptr(), SgAsmInstruction *insn=NULL, const Sawyer::Optional< rose_addr_t > &address=Sawyer::Nothing())
Constructor.
Definition: Reference.h:44
Reference points to a basic block but not an instruction or a stored address.
Definition: Reference.h:33
Reference to a function, basic block, instruction, or address.
Definition: Reference.h:22
Base class for machine instructions.
Reference points to nothing and has no address.
Definition: Reference.h:30
Function::Ptr function() const
Optional function pointer.
Definition: Reference.h:94
bool operator==(const Reference &other) const
Whether two references are equal.
Main namespace for the ROSE library.
Reference(rose_addr_t address)
Constructor.
Definition: Reference.h:56
Reference points to nothing but has an address.
Definition: Reference.h:31
rose_addr_t address() const
Address.
std::set< Reference > ReferenceSet
Set of references.
Definition: Reference.h:151
bool hasInstruction() const
Predicate for having an instruction.
Definition: Reference.h:113
Reference points to an instruction but no stored address.
Definition: Reference.h:32
Sawyer::Container::Map< Reference, ReferenceSet > CrossReferences
Cross references.
Definition: Reference.h:154
bool hasExplicitAddress() const
Predicate for having a stored address.
Definition: Reference.h:126
BasicBlock::Ptr basicBlock() const
Optional basic block pointer.
Definition: Reference.h:106
bool operator<(const Reference &other) const
Compare two references.
Granularity granularity() const
Reference granularity.
Definition: Reference.h:67
Reference(SgAsmInstruction *insn, const Sawyer::Optional< rose_addr_t > &address=Sawyer::Nothing())
Constructor.
Definition: Reference.h:53
Reference points to a function but not a basic block or instruction, and has no stored address...
Definition: Reference.h:35
bool hasFunction() const
Predicate for having a function.
Definition: Reference.h:89
Represents no value.
Definition: Optional.h:32
Container associating values with keys.
Definition: Sawyer/Map.h:64
Reference(const BasicBlock::Ptr &bblock, SgAsmInstruction *insn=NULL, const Sawyer::Optional< rose_addr_t > &address=Sawyer::Nothing())
Constructor.
Definition: Reference.h:49