ROSE  0.11.2.0
Reference.h
1 #ifndef ROSE_Partitioner2_Reference_H
2 #define ROSE_Partitioner2_Reference_H
3 
4 #include <rosePublicConfig.h>
5 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
6 
7 #include <Partitioner2/BasicBlock.h>
8 #include <Partitioner2/Function.h>
9 #include <set>
10 
11 namespace Rose {
12 namespace BinaryAnalysis {
13 namespace Partitioner2 {
14 
16 // Reference
18 
25 class Reference {
26  Function::Ptr function_;
27  BasicBlock::Ptr bblock_;
28  SgAsmInstruction *insn_;
30 public:
32  enum Granularity {
40  };
41 
47  explicit Reference(const Function::Ptr &function, const BasicBlock::Ptr &bblock=BasicBlock::Ptr(),
49  : function_(function), bblock_(bblock), insn_(insn), address_(address) {}
50 
51 
52  explicit Reference(const BasicBlock::Ptr &bblock, SgAsmInstruction *insn=NULL,
54  : bblock_(bblock), insn_(insn), address_(address) {}
55 
57  : insn_(insn), address_(address) {}
58 
59  explicit Reference(rose_addr_t address)
60  : insn_(NULL), address_(address) {}
61 
63  : insn_(NULL) {}
71  if (address_)
72  return ADDRESS;
73  if (insn_)
74  return INSTRUCTION;
75  if (bblock_)
76  return BASIC_BLOCK;
77  if (function_)
78  return FUNCTION;
79  return EMPTY;
80  }
81 
85  bool isEmpty() const {
86  return granularity()==EMPTY;
87  }
88 
92  bool hasFunction() const {
93  return function_!=NULL;
94  }
95 
97  Function::Ptr function() const {
98  return function_;
99  }
100 
104  bool hasBasicBlock() const {
105  return bblock_!=NULL;
106  }
107 
110  return bblock_;
111  }
112 
116  bool hasInstruction() const {
117  return insn_ != NULL;
118  }
119 
122  return insn_;
123  }
124 
129  bool hasExplicitAddress() const {
130  return address_;
131  }
132 
137  rose_addr_t address() const;
138 
142  bool operator==(const Reference &other) const;
143 
150  bool operator<(const Reference &other) const;
151 };
152 
154 typedef std::set<Reference> ReferenceSet;
155 
158 
159 } // namespace
160 } // namespace
161 } // namespace
162 
163 #endif
164 #endif
bool hasBasicBlock() const
Predicate for having a basic block.
Definition: Reference.h:104
bool isEmpty() const
Predicate for emptiness.
Definition: Reference.h:85
SgAsmInstruction * instruction() const
Optional instruction pointer.
Definition: Reference.h:121
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:47
Reference points to a basic block but not an instruction or a stored address.
Definition: Reference.h:36
Reference to a function, basic block, instruction, or address.
Definition: Reference.h:25
Base class for machine instructions.
Reference points to nothing and has no address.
Definition: Reference.h:33
Function::Ptr function() const
Optional function pointer.
Definition: Reference.h:97
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:59
Reference points to nothing but has an address.
Definition: Reference.h:34
rose_addr_t address() const
Address.
std::set< Reference > ReferenceSet
Set of references.
Definition: Reference.h:154
bool hasInstruction() const
Predicate for having an instruction.
Definition: Reference.h:116
Reference points to an instruction but no stored address.
Definition: Reference.h:35
Sawyer::Container::Map< Reference, ReferenceSet > CrossReferences
Cross references.
Definition: Reference.h:157
bool hasExplicitAddress() const
Predicate for having a stored address.
Definition: Reference.h:129
BasicBlock::Ptr basicBlock() const
Optional basic block pointer.
Definition: Reference.h:109
bool operator<(const Reference &other) const
Compare two references.
Granularity granularity() const
Reference granularity.
Definition: Reference.h:70
Reference(SgAsmInstruction *insn, const Sawyer::Optional< rose_addr_t > &address=Sawyer::Nothing())
Constructor.
Definition: Reference.h:56
Reference points to a function but not a basic block or instruction, and has no stored address...
Definition: Reference.h:38
bool hasFunction() const
Predicate for having a function.
Definition: Reference.h:92
Represents no value.
Definition: Optional.h:32
Container associating values with keys.
Definition: Sawyer/Map.h:66
Reference(const BasicBlock::Ptr &bblock, SgAsmInstruction *insn=NULL, const Sawyer::Optional< rose_addr_t > &address=Sawyer::Nothing())
Constructor.
Definition: Reference.h:52