ROSE  0.11.31.0
NullSemantics2.h
1 #ifndef Rose_NullSemantics2_H
2 #define Rose_NullSemantics2_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include "BaseSemantics2.h"
7 
8 namespace Rose {
9 namespace BinaryAnalysis { // documented elsewhere
10 namespace InstructionSemantics2 { // documented elsewhere
11 
12 
17 namespace NullSemantics {
18 
20 // Semantic values
22 
25 
28 
30  // Real constructors.
31 protected:
32  explicit SValue(size_t nbits): BaseSemantics::SValue(nbits) {}
33 
35  // Static allocating constructors
36 public:
38  static SValuePtr instance() {
39  return SValuePtr(new SValue(1));
40  }
41 
43  static SValuePtr instance(size_t nbits) {
44  return SValuePtr(new SValue(nbits));
45  }
46 
48  static SValuePtr instance(size_t nbits, uint64_t number) {
49  return SValuePtr(new SValue(nbits)); // the number is not important in this domain
50  }
51 
53  static SValuePtr instance(const SValuePtr &other) {
54  return SValuePtr(new SValue(*other));
55  }
56 
58  // Virtual constructors
59 public:
60  virtual BaseSemantics::SValuePtr bottom_(size_t nBits) const ROSE_OVERRIDE {
61  return instance(nBits);
62  }
63  virtual BaseSemantics::SValuePtr undefined_(size_t nBits) const ROSE_OVERRIDE {
64  return instance(nBits);
65  }
66  virtual BaseSemantics::SValuePtr unspecified_(size_t nBits) const ROSE_OVERRIDE {
67  return instance(nBits);
68  }
69  virtual BaseSemantics::SValuePtr number_(size_t nBits, uint64_t number) const ROSE_OVERRIDE {
70  return instance(nBits, number);
71  }
72  virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const ROSE_OVERRIDE {
73  SValuePtr retval(new SValue(*this));
74  if (new_width!=0 && new_width!=retval->nBits())
75  retval->set_width(new_width);
76  return retval;
77  }
80  const SmtSolverPtr&) const ROSE_OVERRIDE {
81  return Sawyer::Nothing();
82  }
83 
85  // Dynamic pointer casting
86 public:
88  static SValuePtr promote(const BaseSemantics::SValuePtr &v) {
89  SValuePtr retval = v.dynamicCast<SValue>();
90  ASSERT_not_null(retval);
91  return retval;
92  }
93 
95  // Implementations of functions inherited
96 public:
97  virtual bool isBottom() const ROSE_OVERRIDE {
98  return false;
99  }
100 
101  virtual void print(std::ostream &stream, BaseSemantics::Formatter&) const ROSE_OVERRIDE {
102  stream <<"VOID[" <<nBits() <<"]";
103  }
104 
105  virtual void hash(Combinatorics::Hasher &hasher) const override {
106  hasher.insert(0); // hash depends on number of SValues hashed, but not any content
107  }
108 
110  // Override legacy members. These now are called by the camelCase names in the base class. Eventually we'll switch the
111  // camelCase names to be the virtual functions and get rid of the snake_case names, so be sure to specify "override" in
112  // your own code so you know when we make the switch.
113 public:
114  // See isConcrete
115  virtual bool is_number() const ROSE_OVERRIDE {
116  return false;
117  }
118 
119  // See toUnsigned and toSigned
120  virtual uint64_t get_number() const ROSE_OVERRIDE {
121  ASSERT_not_reachable("not a number");
122  uint64_t retval;
123  return retval;
124  }
125 
126  // See mayEqual
127  virtual bool may_equal(const BaseSemantics::SValuePtr &other,
128  const SmtSolverPtr &solver = SmtSolverPtr()) const ROSE_OVERRIDE {
129  return true;
130  }
131 
132  // See mustEqual
133  virtual bool must_equal(const BaseSemantics::SValuePtr &other,
134  const SmtSolverPtr &solver = SmtSolverPtr()) const ROSE_OVERRIDE {
135  return this == getRawPointer(other); // must be equal if they're both the same object
136  }
137 
138 };
139 
140 
142 // Register state
144 
146 typedef boost::shared_ptr<class RegisterState> RegisterStatePtr;
147 
151 class RegisterState: public BaseSemantics::RegisterState {
152 protected:
153  RegisterState(const RegisterState &other)
154  : BaseSemantics::RegisterState(other) {}
155 
156  RegisterState(const BaseSemantics::SValuePtr &protoval, const RegisterDictionary *regdict)
157  : BaseSemantics::RegisterState(protoval, regdict) {}
158 
159 public:
160  static RegisterStatePtr instance(const BaseSemantics::SValuePtr &protoval, const RegisterDictionary *regdict) {
161  return RegisterStatePtr(new RegisterState(protoval, regdict));
162  }
163 
164  virtual BaseSemantics::RegisterStatePtr create(const BaseSemantics::SValuePtr &protoval,
165  const RegisterDictionary *regdict) const ROSE_OVERRIDE {
166  return instance(protoval, regdict);
167  }
168 
169  virtual BaseSemantics::RegisterStatePtr clone() const ROSE_OVERRIDE {
170  return RegisterStatePtr(new RegisterState(*this));
171  }
172 
173  static RegisterStatePtr promote(const BaseSemantics::RegisterStatePtr &from) {
174  RegisterStatePtr retval = boost::dynamic_pointer_cast<RegisterState>(from);
175  ASSERT_not_null(retval);
176  return retval;
177  }
178 
179  virtual bool merge(const BaseSemantics::RegisterStatePtr &other_, BaseSemantics::RiscOperators*) ROSE_OVERRIDE {
180  return false;
181  }
182 
183  virtual void clear() ROSE_OVERRIDE {}
184  virtual void zero() ROSE_OVERRIDE {}
185 
187  readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt,
188  BaseSemantics::RiscOperators *ops) ROSE_OVERRIDE {
189  return protoval()->undefined_(reg.nBits());
190  }
191 
193  peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt,
194  BaseSemantics::RiscOperators *ops) ROSE_OVERRIDE {
195  return protoval()->undefined_(reg.nBits());
196  }
197 
198  virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &value,
199  BaseSemantics::RiscOperators *ops) ROSE_OVERRIDE {}
200 
201  virtual void hash(Combinatorics::Hasher&, BaseSemantics::RiscOperators*) const override {}
202 
203  virtual void print(std::ostream&, BaseSemantics::Formatter&) const ROSE_OVERRIDE {}
204 };
205 
206 
208 // Memory state
210 
212 typedef boost::shared_ptr<class MemoryState> MemoryStatePtr;
213 
217 class MemoryState: public BaseSemantics::MemoryState {
218 protected:
219  MemoryState(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval)
220  : BaseSemantics::MemoryState(addrProtoval, valProtoval) {}
221 
222  MemoryState(const MemoryStatePtr &other)
223  : BaseSemantics::MemoryState(other) {}
224 
225 public:
226  static MemoryStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval) {
227  return MemoryStatePtr(new MemoryState(addrProtoval, valProtoval));
228  }
229 
230 public:
231  virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::SValuePtr &addrProtoval,
232  const BaseSemantics::SValuePtr &valProtoval) const ROSE_OVERRIDE {
233  return instance(addrProtoval, valProtoval);
234  }
235 
236  virtual BaseSemantics::MemoryStatePtr clone() const ROSE_OVERRIDE {
237  return MemoryStatePtr(new MemoryState(*this));
238  }
239 
240 public:
241  static MemoryStatePtr promote(const BaseSemantics::MemoryStatePtr &x) {
242  MemoryStatePtr retval = boost::dynamic_pointer_cast<MemoryState>(x);
243  ASSERT_not_null(x);
244  return retval;
245  }
246 
247 public:
248  virtual void clear() ROSE_OVERRIDE {}
249 
250  virtual BaseSemantics::SValuePtr readMemory(const BaseSemantics::SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
252  BaseSemantics::RiscOperators *valOps) ROSE_OVERRIDE {
253  return dflt->copy();
254  }
255 
256  virtual void writeMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &value,
257  BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) ROSE_OVERRIDE {}
258 
259  virtual BaseSemantics::SValuePtr peekMemory(const BaseSemantics::SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
261  BaseSemantics::RiscOperators *valOps) ROSE_OVERRIDE {
262  return dflt->copy();
263  }
264 
265  virtual void hash(Combinatorics::Hasher&, BaseSemantics::RiscOperators *addrOps,
266  BaseSemantics::RiscOperators *valOps) const override {}
267 
268  virtual void print(std::ostream&, BaseSemantics::Formatter&) const ROSE_OVERRIDE {}
269 
270  virtual bool merge(const BaseSemantics::MemoryStatePtr &other, BaseSemantics::RiscOperators *addrOps,
271  BaseSemantics::RiscOperators *valOps) ROSE_OVERRIDE {
272  return false;
273  }
274 };
275 
276 
278 // Complete state
280 
281 typedef BaseSemantics::State State;
282 typedef BaseSemantics::StatePtr StatePtr;
283 
284 
286 // RISC operators
288 
290 typedef boost::shared_ptr<class RiscOperators> RiscOperatorsPtr;
291 
294 
296  // Real constructors
297 protected:
299  : BaseSemantics::RiscOperators(protoval, solver) {
300  name("Null");
301  }
302  explicit RiscOperators(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver = SmtSolverPtr())
304  name("Null");
305  }
306 
308  // Static allocating constructors
309 public:
312  static RiscOperatorsPtr instance(const RegisterDictionary *regdict);
313 
315  static RiscOperatorsPtr instance(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver = SmtSolverPtr()) {
316  return RiscOperatorsPtr(new RiscOperators(protoval, solver));
317  }
318 
320  static RiscOperatorsPtr instance(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver = SmtSolverPtr()) {
321  return RiscOperatorsPtr(new RiscOperators(state, solver));
322  }
323 
325  // Virtual constructors
326 public:
328  const SmtSolverPtr &solver = SmtSolverPtr()) const ROSE_OVERRIDE {
329  return instance(protoval, solver);
330  }
331 
333  const SmtSolverPtr &solver = SmtSolverPtr()) const ROSE_OVERRIDE {
334  return instance(state, solver);
335  }
336 
338  // Risc operators inherited
339 public:
340  virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &a_,
341  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
342 
344  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
345 
346  virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &a_,
347  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
348 
349  virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE;
350 
351  virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &a_,
352  size_t begin_bit, size_t end_bit) ROSE_OVERRIDE;
353 
354  virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &a_,
355  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
356 
357  virtual BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE;
358 
359  virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE;
360 
361  virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &a_,
362  const BaseSemantics::SValuePtr &sa_) ROSE_OVERRIDE;
363 
364  virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &a_,
365  const BaseSemantics::SValuePtr &sa_) ROSE_OVERRIDE;
366 
367  virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &a_,
368  const BaseSemantics::SValuePtr &sa_) ROSE_OVERRIDE;
369 
370  virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &a_,
371  const BaseSemantics::SValuePtr &sa_) ROSE_OVERRIDE;
372 
373  virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &a_,
374  const BaseSemantics::SValuePtr &sa_) ROSE_OVERRIDE;
375 
376  virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE;
377 
378  virtual BaseSemantics::SValuePtr ite(const BaseSemantics::SValuePtr &sel_,
379  const BaseSemantics::SValuePtr &a_,
380  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
381 
382  virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) ROSE_OVERRIDE;
383 
385  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
386 
388  const BaseSemantics::SValuePtr &b_,
389  const BaseSemantics::SValuePtr &c_,
390  BaseSemantics::SValuePtr &carry_out/*out*/) ROSE_OVERRIDE;
391 
392  virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE;
393 
395  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
396 
398  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
399 
401  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
402 
404  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
405 
407  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
408 
410  const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE;
411 
413  const BaseSemantics::SValuePtr &addr,
414  const BaseSemantics::SValuePtr &dflt,
415  const BaseSemantics::SValuePtr &cond) ROSE_OVERRIDE;
416 
418  const BaseSemantics::SValuePtr &addr,
419  const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE;
420 
421  virtual void writeMemory(RegisterDescriptor segreg,
422  const BaseSemantics::SValuePtr &addr,
423  const BaseSemantics::SValuePtr &data,
424  const BaseSemantics::SValuePtr &cond) ROSE_OVERRIDE;
425 };
426 
427 } // namespace
428 } // namespace
429 } // namespace
430 } // namespace
431 
432 #endif
433 #endif
virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const ROSE_OVERRIDE
Create a new value from an existing value, changing the width if new_width is non-zero.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
virtual uint64_t get_number() const ROSE_OVERRIDE
Virtual API.
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) ROSE_OVERRIDE
Read memory without side effects.
static RiscOperatorsPtr instance(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr())
Constructor.
size_t nBits() const
Property: Size in bits.
virtual void hash(Combinatorics::Hasher &hasher) const override
Hash this semantic value.
virtual BaseSemantics::SValuePtr undefined_(size_t nBits) const ROSE_OVERRIDE
Create a new undefined semantic value.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
virtual bool is_number() const ROSE_OVERRIDE
Virtual API.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &other, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const ROSE_OVERRIDE
Possibly create a new value by merging two existing values.
void insert(const std::string &x)
Insert data into the digest.
static SValuePtr instance()
Instantiate a new prototypical values.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Calculates modulo with signed values.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to null RISC operations.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
Holds a value or nothing.
Definition: Optional.h:49
virtual SValuePtr protoval() const
Property: Prototypical semantic value.
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer to null register state.
Main namespace for the ROSE library.
static RiscOperatorsPtr instance(const RegisterDictionary *regdict)
Instantiate a new RiscOperators object and configures it to use semantic values and states that are d...
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) ROSE_OVERRIDE
Two's complement.
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
virtual BaseSemantics::SValuePtr addWithCarries(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, const BaseSemantics::SValuePtr &c_, BaseSemantics::SValuePtr &carry_out) ROSE_OVERRIDE
Used for printing RISC operators with formatting.
boost::shared_ptr< class RegisterState > RegisterStatePtr
Shared-ownership pointer to null register state.
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) ROSE_OVERRIDE
Writes a value to memory.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Multiply two unsigned values.
virtual BaseSemantics::SValuePtr unspecified_(size_t nBits) const ROSE_OVERRIDE
Create a new unspecified semantic value.
Describes (part of) a physical CPU register.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual API.
static RiscOperatorsPtr instance(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Static allocating constructor.
NullSemantics operators always return a new undefined value.
static SValuePtr instance(size_t nbits)
Instantiate a new undefined value.
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Multiplies two signed values.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const ROSE_OVERRIDE
Virtual API.
virtual void print(std::ostream &stream, BaseSemantics::Formatter &) const ROSE_OVERRIDE
Print a value to a stream using default format.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Divides two unsigned values.
virtual BaseSemantics::SValuePtr number_(size_t nBits, uint64_t number) const ROSE_OVERRIDE
Create a new concrete semantic value.
SharedPointer< U > dynamicCast() const
Dynamic cast.
Base class for most instruction semantics RISC operators.
static SValuePtr instance(size_t nbits, uint64_t number)
Instantiate a new concrete value.
static SValuePtr instance(const SValuePtr &other)
Instantiate a new copy of an existing value.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Calculates modulo with unsigned values.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) ROSE_OVERRIDE
Divides two signed values.
virtual bool isBottom() const ROSE_OVERRIDE
Determines whether a value is a data-flow bottom.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to a null semantic value.
static SValuePtr promote(const BaseSemantics::SValuePtr &v)
Promote a base value to a NullSemantics value.
Defines registers available for a particular architecture.
Definition: Registers.h:38
virtual SmtSolverPtr solver() const
Property: Satisfiability module theory (SMT) solver.
Represents no value.
Definition: Optional.h:32
virtual const std::string & name() const
Property: Name used for debugging.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) ROSE_OVERRIDE
Reads a value from memory.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
std::shared_ptr< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
virtual BaseSemantics::SValuePtr bottom_(size_t nBits) const ROSE_OVERRIDE
Data-flow bottom value.