ROSE  0.11.145.0
TestSemantics.h
1 // Perform basic sanity checks on instruction semantics
2 #ifndef ROSE_BinaryAnalysis_InstructionSemantics_TestSemantics_H
3 #define ROSE_BinaryAnalysis_InstructionSemantics_TestSemantics_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 
7 #include <Rose/BinaryAnalysis/BasicTypes.h>
8 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics.h>
9 #include <Rose/CommandLine.h>
10 
11 namespace Rose {
12 namespace BinaryAnalysis { // documented elsewhere
13 namespace InstructionSemantics { // documented elsewhere
14 
27 template<class SValuePtr, class RegisterStatePtr, class MemoryStatePtr, class StatePtr, class RiscOperatorsPtr>
29 public:
30  typedef typename SValuePtr::Pointee SValue;
31  typedef typename RegisterStatePtr::element_type RegisterState;
32  typedef typename MemoryStatePtr::element_type MemoryState;
33  typedef typename StatePtr::element_type State;
34  typedef typename RiscOperatorsPtr::element_type RiscOperators;
35 
37  public:
38  Exception(const std::string &mesg): BaseSemantics::Exception(mesg, NULL) {}
39  };
40 
41  void require(bool assertion, const std::string &what_failed) {
42  if (!assertion)
43  throw Exception("failed assertion: "+what_failed);
44  }
45 
46  template<typename Pointer>
47  void nonnull(const Pointer &x, const std::string &what_failed) {
48  if (x==NULL)
49  throw Exception("must not be null: "+what_failed);
50  }
51 
52  // check boost smart pointers
53  template<class ToPtr, class FromPtr>
54  void check_type(const FromPtr &x, const std::string &what_failed) {
55  typedef typename ToPtr::element_type To;
56  nonnull(x, what_failed);
57  ToPtr y = boost::dynamic_pointer_cast<To>(x);
58  if (y==NULL)
59  throw Exception("wrong pointer type: "+what_failed);
60  }
61 
62  // check SValue smart pointers
63  void check_sval_type(const BaseSemantics::SValuePtr &x, const std::string &what_failed) {
64  nonnull(x, what_failed);
65  SValuePtr y = BaseSemantics::dynamic_pointer_cast<SValue>(x);
66  if (y==NULL)
67  throw Exception("wrong pointer type: "+what_failed);
68  }
69 
70  // Compile-time checks for SValue
71  class SValueSubclass: public SValue {
72  public:
73  explicit SValueSubclass(size_t nbits): SValue(nbits) {}
74  SValueSubclass(const SValueSubclass &other): SValue(other) {}
75  };
76 
77  // Compile-time checks for RegisterState
78  class RegisterStateSubclass: public RegisterState {
79  public:
80  explicit RegisterStateSubclass(const SValuePtr &protoval, const RegisterDictionaryPtr &regdict)
81  : RegisterState(protoval, regdict) {}
82  };
83 
84  // Compile-time checks for MemoryState
85  class MemoryStateSubclass: public MemoryState {
86  public:
87  explicit MemoryStateSubclass(const SValuePtr &protoval)
88  : MemoryState(protoval) {}
89  };
90 
91  // Compile-time checks for State
92  class StateSubclass: public State {
93  public:
94  StateSubclass(const RegisterStatePtr &registers, const MemoryStatePtr &memory)
95  : State(registers, memory) {}
96  StateSubclass(const StateSubclass &other)
97  : State(other) {}
98  };
99 
100  // Compile-time checks for RiscOperators
101  class RiscOperatorsSubclass: public RiscOperators {
102  public:
103  explicit RiscOperatorsSubclass(const SValuePtr &protoval, const SmtSolverPtr &solver = SmtSolverPtr())
104  : RiscOperators(protoval, solver) {}
105  explicit RiscOperatorsSubclass(const StatePtr &state, const SmtSolverPtr &solver = SmtSolverPtr())
106  : RiscOperators(state, solver) {}
107  };
108 
109  // Run-time checks
110  void test(const BaseSemantics::RiscOperatorsPtr &ops) {
111  ByteOrder::Endianness savedByteOrder = ops->currentState()->memoryState()->get_byteOrder();
112  ops->currentState()->memoryState()->set_byteOrder(ByteOrder::ORDER_LSB);
113  test(ops->protoval(), ops->currentState(), ops);
114  ops->currentState()->memoryState()->set_byteOrder(ByteOrder::ORDER_MSB);
115  test(ops->protoval(), ops->currentState(), ops);
116  ops->currentState()->memoryState()->set_byteOrder(savedByteOrder);
117  }
118 
119  void test(const BaseSemantics::SValuePtr &protoval,
120  const BaseSemantics::StatePtr &state,
121  const BaseSemantics::RiscOperatorsPtr &ops) {
122 
124  const RegisterDescriptor reg32 = regdict->findOrThrow("eip");
126 
128  // SValue
130 
131  SValuePtr v0;
132  require(v0==NULL, "default SValue constructor");
133 
134  // Dynamic pointer casts
135  check_sval_type(SValue::promote(protoval), "SValue::promote()");
136 
137  // Virtual constructor: undefined_()
138  BaseSemantics::SValuePtr v1 = protoval->undefined_(8);
139  check_sval_type(v1, "SValue::undefined_()");
140  require(v1->nBits()==8, "SValue::undefined_() width");
141 
142  // Virtual constructor: unspecified_()
143  BaseSemantics::SValuePtr v1b = protoval->unspecified_(8);
144  check_sval_type(v1b, "SValue::unspecified_()");
145  require(v1b->nBits()==8, "SValue::unspecified() width");
146 
147  // Virtual constructor: number_(). Note that we can't check that the number is actually concrete and has a value
148  // because BaseSemantics defines only the API for is_number() and get_number() and not the semantics of those
149  // methods. In fact, the NullSemantics domain doesn't make any distinction between concrete and abstract values--it
150  // treats everything as abstract.
151  BaseSemantics::SValuePtr v2 = protoval->number_(32, 123);
152  check_sval_type(v2, "SValue::number_()");
153  require(v2->nBits()==32, "SValue::number_() width");
154 
155  // Virtual constructor: boolean_()
156  BaseSemantics::SValuePtr v3 = protoval->boolean_(true);
157  check_sval_type(v3, "SValue::boolean_()");
158  require(v3->nBits()==1, "SValue::boolean_() width");
159 
160  // Virtual constructor: copy()
161  BaseSemantics::SValuePtr v4 = v3->copy();
162  check_sval_type(v4, "SValue::copy()");
163  require(v4!=v3, "SValue::copy() should have returned a new object");
164  require(v4->nBits()==1, "SValue::copy() width");
165  require(v4->isConcrete() == v3->isConcrete(), "copies should be identical");
166  if (v4->isConcrete())
167  require(v4->toUnsigned().get() == v3->toUnsigned().get(), "concrete copies should be identical");
168  std::ostringstream v3str, v4str;
169  v3str <<*v3;
170  v4str <<*v4;
171  require(v3str.str() == v4str.str(), "copies should be identical");
172 
173  // may_equal
174  require(v3->mayEqual(v3), "a value may_equal itself");
175  require(v3->mayEqual(v4), "a value may_equal a copy of itself");
176  require(v4->mayEqual(v3), "a value may_equal a copy of itself");
177 
178  // mustEqual. Note: must_equal(v3, v4) need not be true when v4 is a copy of v3, although most subclasses do this.
179  require(v3->mustEqual(v3), "a value must_equal itself");
180  require(v3->mustEqual(v4) == v4->mustEqual(v3), "must_equal should be symmetric");
181 
182 
184  // RegisterState (read/write is tested by RiscOperators)
186 
187  // Dynamic pointer cast
188  BaseSemantics::RegisterStatePtr rs1 = state->registerState();
189  check_type<RegisterStatePtr>(RegisterState::promote(rs1), "RegisterState::promote()");
190 
191  BaseSemantics::SValuePtr rs1v1 = rs1->protoval();
192  check_sval_type(rs1v1, "RegisterState::protoval()");
193 
194  // Virtual constructors
195  BaseSemantics::RegisterStatePtr rs3 = rs1->create(protoval, regdict);
196  check_type<RegisterStatePtr>(rs3, "create()");
197  require(rs3->registerDictionary()==regdict, "RegisterState::create() register dictionary");
198  require(rs3 != rs1, "RegisterState::create() must return a new object");
199  BaseSemantics::SValuePtr rs3v1 = rs3->protoval();
200  check_sval_type(rs3v1, "RegisterState::protoval() after create()");
201 
202  BaseSemantics::RegisterStatePtr rs4 = rs1->clone();
203  check_type<RegisterStatePtr>(rs4, "clone()");
204  require(rs4 != rs1, "RegisterState::clone() must return a new object");
205  require(rs4->registerDictionary()==rs1->registerDictionary(),
206  "RegisterState::clone() must use the register dictionary from the source state");
207  BaseSemantics::SValuePtr rs4v1 = rs4->protoval();
208  check_sval_type(rs4v1, "RegisterState::protoval() after clone()");
209 
211  // MemoryState (read/write is tested by RiscOperators)
213 
214  // Dynamic pointer cast
215  BaseSemantics::MemoryStatePtr ms1 = state->memoryState();
216  check_type<MemoryStatePtr>(MemoryState::promote(ms1), "MemoryState::promote()");
217 
218  BaseSemantics::SValuePtr ms1v1 = ms1->get_addr_protoval();
219  check_sval_type(ms1v1, "MemoryState::get_addr_protoval()");
220 
221  BaseSemantics::SValuePtr ms1v2 = ms1->get_val_protoval();
222  check_sval_type(ms1v2, "MemoryState::get_val_protoval()");
223 
224  // Virtual constructors
225  BaseSemantics::MemoryStatePtr ms2 = ms1->create(protoval, protoval);
226  require(ms2 != ms1, "MemoryState::create() must return a new state");
227  check_type<MemoryStatePtr>(ms2, "MemoryState::create(protoval)");
228  BaseSemantics::SValuePtr ms2v1 = ms2->get_addr_protoval();
229  check_sval_type(ms2v1, "MemoryState::get_addr_protoval() after create");
230  BaseSemantics::SValuePtr ms2v2 = ms2->get_val_protoval();
231  check_sval_type(ms2v2, "MemoryState::get_val_protoval() after create");
232 
233  BaseSemantics::MemoryStatePtr ms3 = ms1->clone();
234  require(ms3 != ms1, "MemoryState::clone must return a new state");
235  check_type<MemoryStatePtr>(ms3, "MemoryState::clone()");
236  BaseSemantics::SValuePtr ms3v1 = ms3->get_addr_protoval();
237  check_sval_type(ms3v1, "MemoryState::get_addr_protoval() after clone");
238  BaseSemantics::SValuePtr ms3v2 = ms3->get_val_protoval();
239  check_sval_type(ms3v2, "MemoryState::get_val_protoval() after clone");
240 
242  // State (read/write is tested by RiscOperators)
244 
245  // Dynamic pointer casts
246  check_type<StatePtr>(State::promote(state), "State::promote()");
247 
248  BaseSemantics::SValuePtr state_protoval = state->protoval();
249  check_sval_type(state_protoval, "State::protoval()");
250 
251  // Virtual constructors
252  BaseSemantics::StatePtr s1 = state->create(rs1, ms1);
253  require(s1 != state, "State::create() must return a new state");
254  check_type<StatePtr>(s1, "State::create(regs,mem)");
255  require(s1->registerState()==rs1, "State::create() must use supplied register state");
256  require(s1->memoryState()==ms1, "State::create() must use supplied memory state");
257 
258  BaseSemantics::StatePtr s2 = state->clone();
259  require(s2 != state, "State::clone() must return a new state");
260  check_type<StatePtr>(s2, "State::clone()");
261  require(s2->registerState() != state->registerState(),
262  "State::clone() must deep-copy the register state");
263  require(s2->memoryState() != state->memoryState(),
264  "State::clone() must deep-copy the memory state");
265 
267  // RiscOperators
269 
270  // Dynamic pointer casts
271  check_type<RiscOperatorsPtr>(RiscOperators::promote(ops), "RiscOperators::promote()");
272 
273  BaseSemantics::SValuePtr ops_protoval = ops->protoval();
274  check_sval_type(ops_protoval, "RiscOperators::protoval()");
275 
276  // Virtual constructors
277  BaseSemantics::RiscOperatorsPtr o1 = ops->create(protoval, solver);
278  require(o1 != ops, "RiscOperators::create(protoval,solver) should return a new object");
279  check_type<RiscOperatorsPtr>(o1, "RiscOperators::create(protoval,solver)");
280 
281  BaseSemantics::RiscOperatorsPtr o2 = ops->create(state, solver);
282  require(o2 != ops, "RiscOperators::create(state,solver) should return a new object");
283  check_type<RiscOperatorsPtr>(o2, "RiscOperators::create(state,solver)");
284 
285  BaseSemantics::StatePtr ops_orig_state = ops->currentState();
286  check_type<StatePtr>(ops_orig_state, "RiscOperators::currentState()");
287 
288  // We shouldn't use the supplied state because these tests modify it. So we'll make a copy of the state and use that,
289  // and then restore the original state before we return (but leave our state there fore debugging if there's an
290  // exception). This has the side effect of implicitly checking that State::clone() works because if it didn't the
291  // caller would see the mess we made here. State::clone was tested already.
292  BaseSemantics::StatePtr our_state = ops_orig_state->clone();
293  ops->currentState(our_state);
294  require(ops->currentState() == our_state, "RiscOperators::currentState failed to change state");
295 
296  for (size_t i=0; i<4; ++i) {
297  // Value-creating operators
298  BaseSemantics::SValuePtr v32a, v32b, v8, v1;
299  switch (i) {
300  case 0:
301  v32a = ops->undefined_(32);
302  v32b = ops->undefined_(32);
303  v8 = ops->undefined_(8);
304  v1 = ops->undefined_(1);
305  break;
306  case 1:
307  v32a = ops->undefined_(32);
308  v32b = ops->number_(32, 3);
309  v8 = ops->number_(8, 3);
310  v1 = ops->boolean_(false);
311  break;
312  case 2:
313  v32a = ops->number_(32, 4);
314  v32b = ops->undefined_(32);
315  v8 = ops->undefined_(8);
316  v1 = ops->undefined_(1);
317  break;
318  case 3:
319  v32a = ops->number_(32, 4);
320  v32b = ops->number_(32, 3);
321  v8 = ops->number_(8, 3);
322  v1 = ops->boolean_(true);
323  break;
324  }
325  check_sval_type(v32a, "RiscOperators value constructor");
326  require(v32a->nBits()==32, "RiscOperators value constructor width");
327  check_sval_type(v32b, "RiscOperators value constructor");
328  require(v32b->nBits()==32, "RiscOperators value constructor width");
329  check_sval_type(v8, "RiscOperators value constructor");
330  require(v8->nBits()==8, "RiscOperators value constructor width");
331  check_sval_type(v1, "RiscOperators value constructor");
332  require(v1->nBits()==1, "RiscOperators value constructor width");
333 
334  // x86-specific operators
335  BaseSemantics::SValuePtr ops_v4 = ops->filterCallTarget(v32a);
336  check_sval_type(ops_v4, "RiscOperators::filterCallTarget");
337  require(ops_v4->nBits()==32, "RiscOperators::filterCallTarget width");
338 
339  BaseSemantics::SValuePtr ops_v5 = ops->filterReturnTarget(v32a);
340  check_sval_type(ops_v5, "RiscOperators::filterReturnTarget");
341  require(ops_v5->nBits()==32, "RiscOperators::filterReturnTarget width");
342 
343  BaseSemantics::SValuePtr ops_v6 = ops->filterIndirectJumpTarget(v32a);
344  check_sval_type(ops_v6, "RiscOperators::filterIndirectJumpTarget");
345  require(ops_v6->nBits()==32, "RiscOperators::filterIndirectJumpTarget width");
346 
347  BaseSemantics::SValuePtr ops_v7 = ops->rdtsc();
348  check_sval_type(ops_v7, "RiscOperators::rdtsc");
349  require(ops_v7->nBits()==64, "RiscOperators::rdtsc width");
350 
351  BaseSemantics::SValuePtr ops_v8 = ops->and_(v32a, v32b);
352  check_sval_type(ops_v8, "RiscOperators::and_");
353  require(ops_v8->nBits()==32, "RiscOperators::and_ width");
354 
355  BaseSemantics::SValuePtr ops_v9 = ops->or_(v32a, v32b);
356  check_sval_type(ops_v9, "RiscOperators::or_");
357  require(ops_v9->nBits()==32, "RiscOperators::or_ width");
358 
359  BaseSemantics::SValuePtr ops_v10 = ops->xor_(v32a, v32b);
360  check_sval_type(ops_v10, "RiscOperators::xor_");
361  require(ops_v10->nBits()==32, "RiscOperators::xor_ width");
362 
363  BaseSemantics::SValuePtr ops_v11 = ops->invert(v32a);
364  check_sval_type(ops_v11, "RiscOperators::invert");
365  require(ops_v11->nBits()==32, "RiscOperators::invert width");
366 
367  BaseSemantics::SValuePtr ops_v12 = ops->extract(v32a, 5, 8);
368  check_sval_type(ops_v12, "RiscOperators::extract");
369  require(ops_v12->nBits()==3, "RiscOperators::extract width");
370 
371  BaseSemantics::SValuePtr ops_v13 = ops->concat(v32a, v32b);
372  check_sval_type(ops_v13, "RiscOperators::concat");
373  require(ops_v13->nBits()==64, "RiscOperators::concat width");
374 
375  BaseSemantics::SValuePtr ops_v14 = ops->leastSignificantSetBit(v32a);
376  check_sval_type(ops_v14, "RiscOperators::leastSignificantSetBit");
377  require(ops_v14->nBits()==32, "RiscOperators::leastSignificantSetBit width");
378 
379  BaseSemantics::SValuePtr ops_v15 = ops->mostSignificantSetBit(v32a);
380  check_sval_type(ops_v15, "RiscOperators::mostSignificantSetBit");
381  require(ops_v15->nBits()==32, "RiscOperators::mostSignificantSetBit width");
382 
383  BaseSemantics::SValuePtr ops_v16 = ops->rotateLeft(v32a, v8);
384  check_sval_type(ops_v16, "RiscOperators::rotateLeft");
385  require(ops_v16->nBits()==32, "RiscOperators::rotateLeft width");
386 
387  BaseSemantics::SValuePtr ops_v17 = ops->rotateRight(v32a, v8);
388  check_sval_type(ops_v17, "RiscOperators::rotateRight");
389  require(ops_v17->nBits()==32, "RiscOperators::rotateRight width");
390 
391  BaseSemantics::SValuePtr ops_v18 = ops->shiftLeft(v32a, v8);
392  check_sval_type(ops_v18, "RiscOperators::shiftLeft");
393  require(ops_v18->nBits()==32, "RiscOperators::shiftLeft width");
394 
395  BaseSemantics::SValuePtr ops_v19 = ops->shiftRight(v32a, v8);
396  check_sval_type(ops_v19, "RiscOperators::shiftRight");
397  require(ops_v19->nBits()==32, "RiscOperators::shiftRight width");
398 
399  BaseSemantics::SValuePtr ops_v20 = ops->shiftRightArithmetic(v32a, v8);
400  check_sval_type(ops_v20, "RiscOperators::shiftRightArithmetic");
401  require(ops_v20->nBits()==32, "RiscOperators::shiftRightArithmetic width");
402 
403  BaseSemantics::SValuePtr ops_v21 = ops->equalToZero(v32a);
404  check_sval_type(ops_v21, "RiscOperators::equalToZero");
405  require(ops_v21->nBits()==1, "RiscOperators::equalToZero width");
406 
407  BaseSemantics::SValuePtr ops_v22 = ops->ite(v1, v32a, v32b);
408  check_sval_type(ops_v22, "RiscOperators::ite");
409  require(ops_v22->nBits()==32, "RiscOperators::ite width");
410 
412  BaseSemantics::SValuePtr ops_v22b = ops->iteWithStatus(v1, v32a, v32b, status1);
413  check_sval_type(ops_v22b, "RiscOperators::iteWithStatus");
414  require(ops_v22b->nBits() == 32, "RiscOperators::iteWithStatus width");
415 
416  BaseSemantics::SValuePtr ops_v23 = ops->unsignedExtend(v8, 32);
417  check_sval_type(ops_v23, "RiscOperators::unsignedExtend");
418  require(ops_v23->nBits()==32, "RiscOperators::unsignedExtend width");
419 
420  BaseSemantics::SValuePtr ops_v24 = ops->unsignedExtend(v32a, 8);
421  check_sval_type(ops_v24, "RiscOperators::unsignedExtend truncate");
422  require(ops_v24->nBits()==8, "RiscOperators::unsignedExtend truncate width");
423 
424  BaseSemantics::SValuePtr ops_v25 = ops->signExtend(v8, 32);
425  check_sval_type(ops_v25, "RiscOperators::signExtend");
426  require(ops_v25->nBits()==32, "RiscOperators::signExtend width");
427 
428  BaseSemantics::SValuePtr ops_v26 = ops->add(v32a, v32b);
429  check_sval_type(ops_v26, "RiscOperators::add");
430  require(ops_v26->nBits()==32, "RiscOperators::add width");
431 
432  BaseSemantics::SValuePtr carry_out;
433  BaseSemantics::SValuePtr ops_v27 = ops->addWithCarries(v32a, v32b, v1, carry_out);
434  check_sval_type(ops_v27, "RiscOperators::addWithCarries");
435  require(ops_v27->nBits()==32, "RiscOperators::addWithCarries width");
436  check_sval_type(carry_out, "RiscOperators::addWithCarries carry_out");
437  require(carry_out->nBits()==32, "RiscOperators::addWithCarries carry_out width");
438 
439  BaseSemantics::SValuePtr ops_v28 = ops->negate(v32a);
440  check_sval_type(ops_v28, "RiscOperators::negate");
441  require(ops_v28->nBits()==32, "RiscOperators::negate width");
442 
443  try {
444  BaseSemantics::SValuePtr ops_v29 = ops->signedDivide(v32a, v8);
445  check_sval_type(ops_v29, "RiscOperators::signedDivide");
446  require(ops_v29->nBits()==32, "RiscOperators::signedDivide width");
447  } catch (const BaseSemantics::Exception&) {
448  // possible division by zero
449  }
450 
451  try {
452  BaseSemantics::SValuePtr ops_v30 = ops->signedModulo(v32a, v8);
453  check_sval_type(ops_v30, "RiscOperators::signedModulo");
454  require(ops_v30->nBits()==8, "RiscOperators::signedModulo width");
455  } catch (const BaseSemantics::Exception&) {
456  // possible division by zero
457  }
458 
459  BaseSemantics::SValuePtr ops_v31 = ops->signedMultiply(v32a, v8);
460  check_sval_type(ops_v31, "RiscOperators::signedMultiply");
461  require(ops_v31->nBits()==40, "RiscOperators::signedMultiply width");
462 
463  try {
464  BaseSemantics::SValuePtr ops_v32 = ops->unsignedDivide(v32a, v8);
465  check_sval_type(ops_v32, "RiscOperators::unsignedDivide");
466  require(ops_v32->nBits()==32, "RiscOperators::unsignedDivide width");
467  } catch (const BaseSemantics::Exception&) {
468  // possible division by zero
469  }
470 
471  try {
472  BaseSemantics::SValuePtr ops_v33 = ops->unsignedModulo(v32a, v8);
473  check_sval_type(ops_v33, "RiscOperators::unsignedModulo");
474  require(ops_v33->nBits()==8, "RiscOperators::unsignedModulo width");
475  } catch (const BaseSemantics::Exception&) {
476  // possible division by zero
477  }
478 
479  BaseSemantics::SValuePtr ops_v34 = ops->unsignedMultiply(v32a, v8);
480  check_sval_type(ops_v34, "RiscOperators::unsignedMultiply");
481  require(ops_v34->nBits()==40, "RiscOperators::unsignedMultiply width");
482 
483  BaseSemantics::SValuePtr ops_v35 = ops->readRegister(reg32);
484  check_sval_type(ops_v35, "RiscOperators::readRegister");
485  require(ops_v35->nBits()==32, "RiscOperators::readRegister width");
486 
487  // We can't really check many semantics for readMemory because each MemoryState might behave differently. For
488  // example, we can't check that reading the same address twice in a row returns the same value both times because
489  // the NullSemantics doesn't have this property.
490 
491  BaseSemantics::SValuePtr dflt8 = ops->number_(8, 0);
492  BaseSemantics::SValuePtr ops_v36 = ops->readMemory(RegisterDescriptor(), v32a, dflt8, v1);
493  check_sval_type(ops_v36, "RiscOperators::readMemory byte");
494  require(ops_v36->nBits()==8, "RiscOperators::readMemory byte width");
495 
496  BaseSemantics::SValuePtr dflt32 = ops->number_(32, 0);
497  BaseSemantics::SValuePtr ops_v37 = ops->readMemory(RegisterDescriptor(), v32a, dflt32, v1);
498  check_sval_type(ops_v37, "RiscOperators::readMemory word");
499  require(ops_v37->nBits()==32, "RiscOperators::readMemory word width");
500 
501  // Nothing to check for write memory other than that we can actually call it. The problem is that writeMemory only
502  // modifies a state and doesn't return anything we can test. The specifics of how it modifies a memory state is
503  // entirely up to the implementation, so we can't even test that writing a value to an address and then reading
504  // from that address returns the value that was written (e.g., NullSemantics doesn't have this property).
505 
506  ops->writeMemory(RegisterDescriptor(), v32a, dflt32, v1);
507 
508  }
509 
510  // Restore the original state
511  ops->currentState(ops_orig_state);
512  }
513 };
514 
515 } // namespace
516 } // namespace
517 } // namespace
518 
519 #endif
520 #endif
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
Provides functions for testing binary instruction semantics.
Definition: TestSemantics.h:28
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
Main namespace for the ROSE library.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
static Ptr instance(const std::string &name)
Allocate a new solver by name.
Describes (part of) a physical CPU register.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
static Ptr instancePentium4()
Intel Pentium 4 registers.
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
ROSE_DLL_API GenericSwitchArgs genericSwitchArgs
Global location for parsed generic command-line switches.