ROSE  0.11.54.0
Reference.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_Reference_H
2 #define ROSE_BinaryAnalysis_Partitioner2_Reference_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/Partitioner2/BasicBlock.h>
7 #include <Rose/BinaryAnalysis/Partitioner2/Function.h>
8 #include <set>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 namespace Partitioner2 {
13 
15 // Reference
17 
24 class Reference {
25  Function::Ptr function_;
26  BasicBlock::Ptr bblock_;
27  SgAsmInstruction *insn_;
29 public:
31  enum Granularity {
39  };
40 
46  explicit Reference(const Function::Ptr &function, const BasicBlock::Ptr &bblock=BasicBlock::Ptr(),
48  : function_(function), bblock_(bblock), insn_(insn), address_(address) {}
49 
50 
51  explicit Reference(const BasicBlock::Ptr &bblock, SgAsmInstruction *insn=NULL,
53  : bblock_(bblock), insn_(insn), address_(address) {}
54 
56  : insn_(insn), address_(address) {}
57 
58  explicit Reference(rose_addr_t address)
59  : insn_(NULL), address_(address) {}
60 
62  : insn_(NULL) {}
70  if (address_)
71  return ADDRESS;
72  if (insn_)
73  return INSTRUCTION;
74  if (bblock_)
75  return BASIC_BLOCK;
76  if (function_)
77  return FUNCTION;
78  return EMPTY;
79  }
80 
84  bool isEmpty() const {
85  return granularity()==EMPTY;
86  }
87 
91  bool hasFunction() const {
92  return function_!=NULL;
93  }
94 
96  Function::Ptr function() const {
97  return function_;
98  }
99 
103  bool hasBasicBlock() const {
104  return bblock_!=NULL;
105  }
106 
109  return bblock_;
110  }
111 
115  bool hasInstruction() const {
116  return insn_ != NULL;
117  }
118 
121  return insn_;
122  }
123 
128  bool hasExplicitAddress() const {
129  return address_;
130  }
131 
136  rose_addr_t address() const;
137 
141  bool operator==(const Reference &other) const;
142 
149  bool operator<(const Reference &other) const;
150 };
151 
153 typedef std::set<Reference> ReferenceSet;
154 
157 
158 } // namespace
159 } // namespace
160 } // namespace
161 
162 #endif
163 #endif
bool hasBasicBlock() const
Predicate for having a basic block.
Definition: Reference.h:103
bool isEmpty() const
Predicate for emptiness.
Definition: Reference.h:84
SgAsmInstruction * instruction() const
Optional instruction pointer.
Definition: Reference.h:120
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:46
Reference points to a basic block but not an instruction or a stored address.
Definition: Reference.h:35
Reference to a function, basic block, instruction, or address.
Definition: Reference.h:24
Base class for machine instructions.
Reference points to nothing and has no address.
Definition: Reference.h:32
Function::Ptr function() const
Optional function pointer.
Definition: Reference.h:96
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:58
Reference points to nothing but has an address.
Definition: Reference.h:33
rose_addr_t address() const
Address.
std::set< Reference > ReferenceSet
Set of references.
Definition: Reference.h:153
bool hasInstruction() const
Predicate for having an instruction.
Definition: Reference.h:115
Reference points to an instruction but no stored address.
Definition: Reference.h:34
Sawyer::Container::Map< Reference, ReferenceSet > CrossReferences
Cross references.
Definition: Reference.h:156
bool hasExplicitAddress() const
Predicate for having a stored address.
Definition: Reference.h:128
BasicBlock::Ptr basicBlock() const
Optional basic block pointer.
Definition: Reference.h:108
bool operator<(const Reference &other) const
Compare two references.
Granularity granularity() const
Reference granularity.
Definition: Reference.h:69
Reference(SgAsmInstruction *insn, const Sawyer::Optional< rose_addr_t > &address=Sawyer::Nothing())
Constructor.
Definition: Reference.h:55
Reference points to a function but not a basic block or instruction, and has no stored address...
Definition: Reference.h:37
bool hasFunction() const
Predicate for having a function.
Definition: Reference.h:91
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:51