ROSE 2.1.0
Loading...
Searching...
No Matches
SymbolicSemantics.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_SymbolicSemantics_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_SymbolicSemantics_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/Formatter.h>
8#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/FrameState.h>
9#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellList.h>
10#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellMap.h>
11#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryState.h>
12#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/Merger.h>
13#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RegisterStateGeneric.h>
14#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RiscOperators.h>
15#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/State.h>
16#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/SValue.h>
17#include <Rose/BinaryAnalysis/SymbolicExpression.h>
18
19#include <Cxx_GrammarSerialization.h>
20
21#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
22#include <boost/serialization/access.hpp>
23#include <boost/serialization/base_object.hpp>
24#include <boost/serialization/export.hpp>
25#include <boost/serialization/set.hpp>
26#endif
27
28#include <inttypes.h>
29#include <map>
30#include <vector>
31
32namespace Rose {
33namespace BinaryAnalysis {
34namespace InstructionSemantics {
35
55namespace SymbolicSemantics {
56
63using InsnSet = std::set<SgAsmInstruction*>;
64
66// Boolean flags
68
70namespace AllowSideEffects {
71 enum Flag {NO, YES};
72}
73
74
76// Merging symbolic values
78
81
84 size_t setSizeLimit_ = 1;
85protected:
86 Merger();
87
88public:
90 typedef MergerPtr Ptr;
91
93 static Ptr instance();
94
96 static Ptr instance(size_t);
97
109 size_t setSizeLimit() const { return setSizeLimit_; }
110 void setSizeLimit(size_t n) { setSizeLimit_ = n; }
112};
113
114
115
117// Semantic values
119
122
125public:
126 SymbolicExpression::Formatter expr_formatter;
127};
128
198public:
201
203 using Ptr = SValuePtr;
204
205protected:
208
211 InsnSet defs;
212
214 // Serialization
215#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
216private:
217 friend class boost::serialization::access;
218
219 template<class S>
220 void serialize(S &s, const unsigned /*version*/) {
221 roseAstSerializationRegistration(s); // "defs" has SgAsmInstruction ASTs
222 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
223 s & BOOST_SERIALIZATION_NVP(expr);
224 s & BOOST_SERIALIZATION_NVP(defs);
225 }
226#endif
227
229 // Real constructors
230protected:
231 SValue(); // needed for serialization
232 explicit SValue(size_t nbits);
233 SValue(size_t nbits, uint64_t number);
235
237 // Static allocating constructors
238public:
241
243 static SValuePtr instance_bottom(size_t nbits);
244
246 static SValuePtr instance_undefined(size_t nbits);
247
249 static SValuePtr instance_unspecified(size_t nbits);
250
252 static SValuePtr instance_integer(size_t nbits, uint64_t value);
253
256
258 // Virtual allocating constructors
259public:
260 virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const override;
261 virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const override;
262 virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const override;
263 virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) const override;
264 virtual BaseSemantics::SValuePtr boolean_(bool value) const override;
265 virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const override;
266
269 const SmtSolverPtr&) const override;
270
272 // Dynamic pointer casts
273public:
276
278 // Override virtual methods...
279public:
280 virtual bool isBottom() const override;
281
282 virtual void print(std::ostream&, BaseSemantics::Formatter&) const override;
283
284 virtual void hash(Combinatorics::Hasher&) const override;
285
286protected: // when implementing use these names; but when calling, use the camelCase names
287 virtual bool may_equal(const BaseSemantics::SValuePtr &other,
288 const SmtSolverPtr &solver = SmtSolverPtr()) const override;
289 virtual bool must_equal(const BaseSemantics::SValuePtr &other,
290 const SmtSolverPtr &solver = SmtSolverPtr()) const override;
291
292 // It's not possible to change the size of a symbolic expression in place. That would require that we recursively change
293 // the size of the SymbolicExpression, which might be shared with many unrelated values whose size we don't want to affect.
294 virtual void set_width(size_t nbits) override;
295 virtual bool is_number() const override;
296 virtual uint64_t get_number() const override;
297 virtual std::string get_comment() const override;
298 virtual void set_comment(const std::string&) const override;
299
301 // Additional methods first declared in this class...
302public:
310 virtual SValuePtr substitute(const SValuePtr &from, const SValuePtr &to, const SmtSolverPtr &solver) const;
311
318 virtual void defined_by(SgAsmInstruction *insn, const InsnSet &set1, const InsnSet &set2, const InsnSet &set3);
319 virtual void defined_by(SgAsmInstruction *insn, const InsnSet &set1, const InsnSet &set2);
320 virtual void defined_by(SgAsmInstruction *insn, const InsnSet &set1);
321 virtual void defined_by(SgAsmInstruction *insn);
327 virtual const ExprPtr& get_expression() const;
328
331 virtual void set_expression(const ExprPtr &new_expr);
332 virtual void set_expression(const SValuePtr &source);
349 virtual const InsnSet& get_defining_instructions() const;
350
356 virtual size_t add_defining_instructions(const InsnSet &to_add);
357 virtual size_t add_defining_instructions(const SValuePtr &source);
366 virtual void set_defining_instructions(const InsnSet &new_defs);
367 virtual void set_defining_instructions(const SValuePtr &source);
370};
371
372
374// Register state
376
378typedef BaseSemantics::RegisterStateGenericPtr RegisterStatePtr;
379
380
382// Frame state
384
386typedef BaseSemantics::FrameStatePtr FrameStatePtr;
387
388
390// List-based Memory state
392
394typedef boost::shared_ptr<class MemoryListState> MemoryListStatePtr;
395
413public:
416
419
422 public:
424 protected:
425 CellCompressor() {}
426 public:
427 virtual ~CellCompressor() {}
428
430 virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
432 const BaseSemantics::CellList &cells) = 0;
433 };
434
449 public:
450 static Ptr instance();
451 virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
453 const BaseSemantics::CellList &cells) override;
454 };
455
458 public:
459 static Ptr instance();
460 virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
462 const BaseSemantics::CellList &cells) override;
463 };
464
469 CellCompressor::Ptr mccarthy_;
470 CellCompressor::Ptr simple_;
471 protected:
473 public:
474 static Ptr instance();
475 virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
477 const BaseSemantics::CellList &cells) override;
478 };
479
484 public:
485 static Ptr instance();
486 virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt,
488 const BaseSemantics::CellList &cells) override;
489 };
490
491private:
492 CellCompressor::Ptr cellCompressor_; // Callback when a memory read aliases multiple memory cells.
493
495 // Serialization
496#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
497private:
498 friend class boost::serialization::access;
499
500 template<class S>
501 void serialize(S &s, const unsigned /*version*/) {
502 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
503 }
504#endif
505
506
508 // Real constructors
509protected:
510 MemoryListState(); // for serialization
511 explicit MemoryListState(const BaseSemantics::MemoryCellPtr &protocell);
512 MemoryListState(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval);
513 MemoryListState(const MemoryListState &other);
514
516 // Static allocating constructors
517public:
520
523 static MemoryListStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval);
524
527
529 // Virtual constructors
530public:
534 const BaseSemantics::SValuePtr &valProtoval) const override;
535
537 virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::MemoryCellPtr &protocell) const override;
538
540 virtual BaseSemantics::AddressSpacePtr clone() const override;
541
543 // Dynamic pointer casts
544public:
548
550 // Methods we inherited
551public:
557 BaseSemantics::RiscOperators *valOps) override;
558
564 BaseSemantics::RiscOperators *valOps) override;
565
569 virtual void writeMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &value,
571
572protected:
573 BaseSemantics::SValuePtr readOrPeekMemory(const BaseSemantics::SValuePtr &address,
574 const BaseSemantics::SValuePtr &dflt,
577 AllowSideEffects::Flag allowSideEffects);
578
580 // Methods first declared in this class
581public:
591 // Deprecated [Robb Matzke 2021-12-15]
592 CellCompressor::Ptr get_cell_compressor() const ROSE_DEPRECATED("use cellCompressor");
593 void set_cell_compressor(const CellCompressor::Ptr&) ROSE_DEPRECATED("use cellCompressor");
594};
595
596
598// Map-based Memory state
600
602typedef boost::shared_ptr<class MemoryMapState> MemoryMapStatePtr;
603
621class MemoryMapState: public BaseSemantics::MemoryCellMap {
622public:
625
628
630 // Serialization
631#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
632private:
633 friend class boost::serialization::access;
634
635 template<class S>
636 void serialize(S &s, const unsigned /*version*/) {
637 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
638 }
639#endif
640
642 // Real constructors
643protected:
644 MemoryMapState(); // for serialization
645
646 explicit MemoryMapState(const BaseSemantics::MemoryCellPtr &protocell);
647
648 MemoryMapState(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval);
649
651 // Static allocating constructors
652public:
655
658 static MemoryMapStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval);
659
662
664 // Virtual constructors
665public:
669 const BaseSemantics::SValuePtr &valProtoval) const override;
670
673
675 virtual BaseSemantics::AddressSpacePtr clone() const override;
676
678 // Dynamic pointer casts
679public:
683
685 // Methods we override from the super class (documented in the super class)
686public:
687 virtual CellKey generateCellKey(const BaseSemantics::SValuePtr &addr_) const override;
688};
689
690
691
693// Default memory state
695
696// List-base memory was the type originally used by this domain. We must keep it that way because some analysis, including 3rd
697// party, assumes that the state is list-based. New analysis can use the map-based state by instantiating it when the symbolic
698// risc operators are constructed.
700typedef MemoryListStatePtr MemoryStatePtr;
701
703// Complete state
705
707typedef BaseSemantics::StatePtr StatePtr;
708
709
711// RISC operators
713
720
727
729typedef boost::shared_ptr<class RiscOperators> RiscOperatorsPtr;
730
751public:
754
757
758protected:
759 bool omit_cur_insn; // if true, do not include cur_insn as a definer
760 DefinersMode computingDefiners_; // whether to track definers (instruction VAs) of SValues
761 WritersMode computingMemoryWriters_; // whether to track writers (instruction VAs) to memory.
762 WritersMode computingRegisterWriters_; // whether to track writers (instruction VAs) to registers.
763 uint64_t trimThreshold_; // max size of expressions (zero means no maximimum)
764 bool reinterpretMemoryReads_; // cast data to unsigned integer when reading from memory
765 bool reinterpretRegisterReads_; // cast data to unsigned integer when reading from registers
766 size_t nTrimmed_ = 0; // number of expressions trimmed down to a new variable
767
768
770 // Serialization
771#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
772private:
773 friend class boost::serialization::access;
774
775 template<class S>
776 void serialize(S &s, const unsigned /*version*/) {
777 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
778 s & BOOST_SERIALIZATION_NVP(omit_cur_insn);
779 s & BOOST_SERIALIZATION_NVP(computingDefiners_);
780 s & BOOST_SERIALIZATION_NVP(computingMemoryWriters_);
781 s & BOOST_SERIALIZATION_NVP(computingRegisterWriters_);
782 s & BOOST_SERIALIZATION_NVP(trimThreshold_);
783 }
784#endif
785
787 // Real constructors
788protected:
789 RiscOperators(); // for serialization
790
791 explicit RiscOperators(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver);
792
793 explicit RiscOperators(const BaseSemantics::StatePtr &state, const SmtSolverPtr &solver);
794
796 // Static allocating constructors
797public:
799
803
807 const SmtSolverPtr &solver = SmtSolverPtr());
808
812
814 // Virtual constructors
815public:
817 const SmtSolverPtr &solver = SmtSolverPtr()) const override;
818
820 const SmtSolverPtr &solver = SmtSolverPtr()) const override;
821
823 // Dynamic pointer casts
824public:
828
830 // Inherited methods for constructing values.
831public:
832 virtual BaseSemantics::SValuePtr boolean_(bool b) override;
833 virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) override;
834
836 // New methods for constructing values, so we don't have to write so many SValue::promote calls in the RiscOperators
837 // implementations.
838 SValuePtr svalueExpr(const ExprPtr &expr, const InsnSet &defs=InsnSet());
839
840protected:
841 SValuePtr svalueUndefined(size_t nbits);
842 SValuePtr svalueBottom(size_t nbits);
843 SValuePtr svalueUnspecified(size_t nbits);
844 SValuePtr svalueNumber(size_t nbits, uint64_t value);
845 SValuePtr svalueBoolean(bool b);
846
848 // Configuration properties
849public:
850
868 void computingDefiners(DefinersMode m) { computingDefiners_ = m; }
869 DefinersMode computingDefiners() const { return computingDefiners_; }
890 void computingMemoryWriters(WritersMode m) { computingMemoryWriters_ = m; }
891 WritersMode computingMemoryWriters() const { return computingMemoryWriters_; }
915 void computingRegisterWriters(WritersMode m) { computingRegisterWriters_ = m; }
916 WritersMode computingRegisterWriters() const { return computingRegisterWriters_; }
919 // Used internally to control whether cur_insn should be omitted from the list of definers.
920 bool getset_omit_cur_insn(bool b) { bool retval = omit_cur_insn; omit_cur_insn=b; return retval; }
921
928 void trimThreshold(uint64_t n) { trimThreshold_ = n; }
929 uint64_t trimThreshold() const { return trimThreshold_; }
938 size_t nTrimmed() const { return nTrimmed_; }
939 void nTrimmed(size_t n) { nTrimmed_ = n; }
949 bool reinterpretMemoryReads() const { return reinterpretMemoryReads_; }
950 void reinterpretMemoryReads(bool b) { reinterpretMemoryReads_ = b; }
951 bool reinterpretRegisterReads() const { return reinterpretRegisterReads_; }
952 void reinterpretRegisterReads(bool b) { reinterpretRegisterReads_ = b; }
956 // Methods first defined at this level of the class hierarchy
957public:
1019 virtual void substitute(const SValuePtr &from, const SValuePtr &to);
1020
1026
1032
1037
1039 // Override methods from base class. These are the RISC operators that are invoked by a Dispatcher.
1040public:
1041 virtual void interrupt(int majr, int minr) override;
1043 const BaseSemantics::SValuePtr &b_) override;
1045 const BaseSemantics::SValuePtr &b_) override;
1047 const BaseSemantics::SValuePtr &b_) override;
1050 size_t begin_bit, size_t end_bit) override;
1052 const BaseSemantics::SValuePtr &b_) override;
1056 const BaseSemantics::SValuePtr &sa_) override;
1058 const BaseSemantics::SValuePtr &sa_) override;
1060 const BaseSemantics::SValuePtr &sa_) override;
1062 const BaseSemantics::SValuePtr &sa_) override;
1064 const BaseSemantics::SValuePtr &sa_) override;
1067 const BaseSemantics::SValuePtr &a_,
1068 const BaseSemantics::SValuePtr &b_,
1069 IteStatus&) override;
1070 virtual BaseSemantics::SValuePtr unsignedExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override;
1071 virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override;
1073 const BaseSemantics::SValuePtr &b_) override;
1075 const BaseSemantics::SValuePtr &b_,
1076 const BaseSemantics::SValuePtr &c_,
1077 BaseSemantics::SValuePtr &carry_out/*out*/) override;
1080 const BaseSemantics::SValuePtr &b_) override;
1082 const BaseSemantics::SValuePtr &b_) override;
1084 const BaseSemantics::SValuePtr &b_) override;
1086 const BaseSemantics::SValuePtr &b_) override;
1088 const BaseSemantics::SValuePtr &b_) override;
1090 const BaseSemantics::SValuePtr &b_) override;
1092 SgAsmFloatType *retType) override;
1095 const BaseSemantics::SValuePtr &dflt) override;
1097 const BaseSemantics::SValuePtr &dflt) override;
1098 virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a_) override;
1100 const BaseSemantics::SValuePtr &addr,
1101 const BaseSemantics::SValuePtr &dflt,
1102 const BaseSemantics::SValuePtr &cond) override;
1104 const BaseSemantics::SValuePtr &addr,
1105 const BaseSemantics::SValuePtr &dflt) override;
1106 virtual void writeMemory(RegisterDescriptor segreg,
1107 const BaseSemantics::SValuePtr &addr,
1108 const BaseSemantics::SValuePtr &data,
1109 const BaseSemantics::SValuePtr &cond) override;
1110
1111 BaseSemantics::SValuePtr readLocal(uint8_t index) override;
1112 void writeLocal(uint8_t index, const BaseSemantics::SValuePtr &value) override;
1113
1115 void pushOperand(const BaseSemantics::SValuePtr &value) override;
1116
1117public:
1118 BaseSemantics::SValuePtr readOrPeekMemory(RegisterDescriptor segreg,
1119 const BaseSemantics::SValuePtr &addr,
1120 const BaseSemantics::SValuePtr &dflt,
1121 AllowSideEffects::Flag);
1122};
1123
1124} // namespace
1125} // namespace
1126} // namespace
1127} // namespace
1128
1129#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
1134#endif
1135
1136#endif
1137#endif
Base class for most instruction semantics RISC operators.
Base class for semantics machine states.
Definition State.h:45
Functor for handling a memory read whose address matches more than one memory cell.
virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps, const BaseSemantics::CellList &cells) override
Compress the cells into a single value.
Functor for handling a memory read whose address matches more than one memory cell.
virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps, const BaseSemantics::CellList &cells) override
Compress the cells into a single value.
Functor for handling a memory read whose address matches more than one memory cell.
virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps, const BaseSemantics::CellList &cells) override
Compress the cells into a single value.
Functor for handling a memory read whose address matches more than one memory cell.
virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps, const BaseSemantics::CellList &cells) override
Compress the cells into a single value.
Functor for handling a memory read that found more than one cell that might alias the requested addre...
virtual SValuePtr operator()(const SValuePtr &address, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps, const BaseSemantics::CellList &cells)=0
Compress the cells into a single value.
virtual void writeMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &value, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Write a byte to memory.
static MemoryListStatePtr instance(const MemoryListStatePtr &other)
Instantiates a new deep copy of an existing state.
virtual BaseSemantics::SValuePtr readMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Read a byte from memory.
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval) const override
Virtual constructor.
static MemoryListStatePtr instance(const BaseSemantics::MemoryCellPtr &protocell)
Instantiates a new memory state having specified prototypical cells and value.
virtual BaseSemantics::SValuePtr peekMemory(const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, BaseSemantics::RiscOperators *addrOps, BaseSemantics::RiscOperators *valOps) override
Read a byte from memory with no side effects.
static MemoryListStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval)
Instantiates a new memory state having specified prototypical value.
static MemoryListStatePtr promote(const BaseSemantics::AddressSpacePtr &)
Recasts a base pointer to a symbolic memory state.
CellCompressor::Ptr cellCompressor() const
Callback for handling a memory read whose address matches more than one memory cell.
void cellCompressor(const CellCompressor::Ptr &)
Callback for handling a memory read whose address matches more than one memory cell.
virtual BaseSemantics::AddressSpacePtr clone() const override
Virtual copy constructor.
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::MemoryCellPtr &protocell) const override
Virtual constructor.
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval) const override
Virtual constructor.
static MemoryMapStatePtr instance(const BaseSemantics::MemoryCellPtr &protocell)
Instantiates a new memory state having specified prototypical cells and value.
virtual BaseSemantics::MemoryStatePtr create(const BaseSemantics::MemoryCellPtr &protocell) const
Virtual constructor.
virtual BaseSemantics::AddressSpacePtr clone() const override
Virtual copy constructor.
static MemoryMapStatePtr promote(const BaseSemantics::AddressSpacePtr &)
Recasts a base pointer to a symbolic memory state.
static MemoryMapStatePtr instance(const MemoryMapStatePtr &other)
Instantiates a new deep copy of an existing state.
static MemoryMapStatePtr instance(const BaseSemantics::SValuePtr &addrProtoval, const BaseSemantics::SValuePtr &valProtoval)
Instantiates a new memory state having specified prototypical value.
virtual CellKey generateCellKey(const BaseSemantics::SValuePtr &addr_) const override
Generate a cell lookup key.
MergerPtr Ptr
Shared-ownership pointer for a Merger object.
Defines RISC operators for the SymbolicSemantics domain.
static RiscOperatorsPtr instanceFromProtoval(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified prototypical values.
void computingDefiners(DefinersMode m)
Property: Track which instructions define a semantic value.
virtual BaseSemantics::SValuePtr unsignedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with unsigned values.
static SgAsmFloatType * sgIsIeee754(SgAsmType *)
Tests whether a SgAsmType is an IEEE-754 floating-point type.
void computingMemoryWriters(WritersMode m)
Property: Track which instructions write to each memory location.
size_t nTrimmed() const
Property: Number of symbolic expressions trimmed.
virtual BaseSemantics::SValuePtr signedModulo(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Calculates modulo with signed values.
virtual BaseSemantics::SValuePtr invert(const BaseSemantics::SValuePtr &a_) override
One's complement.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::StatePtr &, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr signedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two signed values.
virtual BaseSemantics::SValuePtr signExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override
Sign extends a value.
virtual BaseSemantics::SValuePtr rotateRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the right.
virtual BaseSemantics::SValuePtr boolean_(bool b) override
Returns a Boolean value.
virtual BaseSemantics::SValuePtr readRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Reads a value from a register.
virtual BaseSemantics::RiscOperatorsPtr create(const BaseSemantics::SValuePtr &protoval, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual allocating constructor.
virtual BaseSemantics::SValuePtr peekRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &dflt) override
Obtain a register value without side effects.
WritersMode computingRegisterWriters() const
Property: Track latest writer to each register.
virtual BaseSemantics::SValuePtr shiftRight(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right logically (no sign bit).
virtual BaseSemantics::SValuePtr peekMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt) override
Read memory without side effects.
virtual BaseSemantics::SValuePtr rotateLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Rotate bits to the left.
virtual BaseSemantics::SValuePtr readMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &dflt, const BaseSemantics::SValuePtr &cond) override
Reads a value from memory.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) override
Returns a number of the specified bit width.
virtual BaseSemantics::SValuePtr mostSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of most significant set bit; zero when no bits are set.
virtual BaseSemantics::SValuePtr shiftRightArithmetic(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted right arithmetically (with sign bit).
virtual BaseSemantics::SValuePtr filterResult(const BaseSemantics::SValuePtr &)
Filters results from RISC operators.
static RiscOperatorsPtr promote(const BaseSemantics::RiscOperatorsPtr &)
Run-time promotion of a base RiscOperators pointer to symbolic operators.
void nTrimmed(size_t n)
Property: Number of symbolic expressions trimmed.
void computingRegisterWriters(WritersMode m)
Property: Track latest writer to each register.
void reinterpretMemoryReads(bool b)
Property: Reinterpret data as unsigned integers when reading from memory or registers.
virtual void writeRegister(RegisterDescriptor reg, const BaseSemantics::SValuePtr &a_) override
Writes a value to a register.
virtual BaseSemantics::SValuePtr fpConvert(const BaseSemantics::SValuePtr &a, SgAsmFloatType *aType, SgAsmFloatType *retType) override
Convert from one floating-point type to another.
virtual void interrupt(int majr, int minr) override
Unconditionally raise an interrupt.
static RiscOperatorsPtr instanceFromState(const BaseSemantics::StatePtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object with specified state.
void trimThreshold(uint64_t n)
Property: Maximum size of expressions.
virtual BaseSemantics::SValuePtr unsignedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiply two unsigned values.
virtual BaseSemantics::SValuePtr unsignedDivide(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Divides two unsigned values.
virtual BaseSemantics::SValuePtr reinterpret(const BaseSemantics::SValuePtr &, SgAsmType *) override
Reinterpret an expression as a different type.
virtual void writeMemory(RegisterDescriptor segreg, const BaseSemantics::SValuePtr &addr, const BaseSemantics::SValuePtr &data, const BaseSemantics::SValuePtr &cond) override
Writes a value to memory.
virtual BaseSemantics::SValuePtr equalToZero(const BaseSemantics::SValuePtr &a_) override
Determines whether a value is equal to zero.
void pushOperand(const BaseSemantics::SValuePtr &value) override
Pushes a value to the Frame Operand Stack.
BaseSemantics::SValuePtr popOperand() override
Pops a value from the Frame Operand Stack.
virtual BaseSemantics::SValuePtr iteWithStatus(const BaseSemantics::SValuePtr &sel_, const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, IteStatus &) override
If-then-else with status.
bool reinterpretRegisterReads() const
Property: Reinterpret data as unsigned integers when reading from memory or registers.
virtual BaseSemantics::SValuePtr leastSignificantSetBit(const BaseSemantics::SValuePtr &a_) override
Returns position of least significant set bit; zero when no bits are set.
virtual BaseSemantics::SValuePtr addWithCarries(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_, const BaseSemantics::SValuePtr &c_, BaseSemantics::SValuePtr &carry_out) override
Add two values of equal size and a carry bit.
virtual BaseSemantics::SValuePtr unsignedExtend(const BaseSemantics::SValuePtr &a_, size_t new_width) override
Extend (or shrink) operand a so it is nbits wide by adding or removing high-order bits.
WritersMode computingMemoryWriters() const
Property: Track which instructions write to each memory location.
virtual void substitute(const SValuePtr &from, const SValuePtr &to)
Substitute all occurrences of from with to in the current state.
DefinersMode computingDefiners() const
Property: Track which instructions define a semantic value.
virtual BaseSemantics::SValuePtr add(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Adds two integers of equal size.
void reinterpretRegisterReads(bool b)
Property: Reinterpret data as unsigned integers when reading from memory or registers.
virtual BaseSemantics::SValuePtr negate(const BaseSemantics::SValuePtr &a_) override
Two's complement.
virtual BaseSemantics::SValuePtr xor_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise XOR of two values.
virtual BaseSemantics::SValuePtr concat(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Concatenates the bits of two values.
bool reinterpretMemoryReads() const
Property: Reinterpret data as unsigned integers when reading from memory or registers.
virtual BaseSemantics::SValuePtr shiftLeft(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &sa_) override
Returns arg shifted left.
virtual BaseSemantics::SValuePtr extract(const BaseSemantics::SValuePtr &a_, size_t begin_bit, size_t end_bit) override
Extracts bits from a value.
uint64_t trimThreshold() const
Property: Maximum size of expressions.
BaseSemantics::SValuePtr readLocal(uint8_t index) override
Reads a value from the local variable table in the current frame.
virtual BaseSemantics::SValuePtr and_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise AND of two values.
static RiscOperatorsPtr instanceFromRegisters(const RegisterDictionaryPtr &, const SmtSolverPtr &solver=SmtSolverPtr())
Instantiates a new RiscOperators object and configures it to use semantic values and states that are ...
virtual BaseSemantics::SValuePtr signedMultiply(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Multiplies two signed values.
virtual BaseSemantics::SValuePtr or_(const BaseSemantics::SValuePtr &a_, const BaseSemantics::SValuePtr &b_) override
Computes bit-wise OR of two values.
virtual SymbolicExpression::Type sgTypeToSymbolicType(SgAsmType *)
Convert a SgAsmType to a symbolic type.
Type of values manipulated by the SymbolicSemantics domain.
virtual const InsnSet & get_defining_instructions() const
Returns the set of instructions that defined this value.
virtual size_t add_defining_instructions(const InsnSet &to_add)
Adds definitions to the list of defining instructions.
static SValuePtr instance()
Instantiate a new prototypical value.
virtual bool may_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual API.
virtual void defined_by(SgAsmInstruction *insn, const InsnSet &set1, const InsnSet &set2)
Adds instructions to the list of defining instructions.
virtual BaseSemantics::SValuePtr copy(size_t new_width=0) const override
Create a new value from an existing value, changing the width if new_width is non-zero.
static SValuePtr instance_integer(size_t nbits, uint64_t value)
Instantiate a new concrete value.
virtual void set_expression(const ExprPtr &new_expr)
Changes the expression stored in the value.
static SValuePtr promote(const BaseSemantics::SValuePtr &)
Promote a base value to a SymbolicSemantics value.
virtual void defined_by(SgAsmInstruction *insn)
Adds instructions to the list of defining instructions.
static SValuePtr instance_symbolic(const SymbolicExpression::Ptr &value)
Instantiate a new symbolic value.
virtual BaseSemantics::SValuePtr bottom_(size_t nbits) const override
Data-flow bottom value.
static SValuePtr instance_undefined(size_t nbits)
Instantiate a new undefined value of specified width.
virtual Sawyer::Optional< BaseSemantics::SValuePtr > createOptionalMerge(const BaseSemantics::SValuePtr &other, const BaseSemantics::MergerPtr &, const SmtSolverPtr &) const override
Possibly create a new value by merging two existing values.
virtual void defined_by(SgAsmInstruction *insn, const InsnSet &set1, const InsnSet &set2, const InsnSet &set3)
Adds instructions to the list of defining instructions.
static SValuePtr instance_unspecified(size_t nbits)
Instantiate a new unspecified value of specified width.
virtual size_t add_defining_instructions(const SValuePtr &source)
Adds definitions to the list of defining instructions.
virtual void set_defining_instructions(SgAsmInstruction *insn)
Set defining instructions.
virtual bool must_equal(const BaseSemantics::SValuePtr &other, const SmtSolverPtr &solver=SmtSolverPtr()) const override
Virtual API.
virtual void set_width(size_t nbits) override
Virtual API.
virtual void defined_by(SgAsmInstruction *insn, const InsnSet &set1)
Adds instructions to the list of defining instructions.
virtual std::string get_comment() const override
Some subclasses support the ability to add comments to values.
virtual void set_comment(const std::string &) const override
Some subclasses support the ability to add comments to values.
virtual BaseSemantics::SValuePtr boolean_(bool value) const override
Create a new, Boolean value.
virtual size_t add_defining_instructions(SgAsmInstruction *insn)
Adds definitions to the list of defining instructions.
virtual void print(std::ostream &, BaseSemantics::Formatter &) const override
Print a value to a stream using default format.
static SValuePtr instance_bottom(size_t nbits)
Instantiate a new data-flow bottom value of specified width.
virtual uint64_t get_number() const override
Virtual API.
virtual void hash(Combinatorics::Hasher &) const override
Hash this semantic value.
virtual void set_defining_instructions(const InsnSet &new_defs)
Set defining instructions.
virtual bool isBottom() const override
Determines whether a value is a data-flow bottom.
virtual BaseSemantics::SValuePtr number_(size_t nbits, uint64_t value) const override
Create a new concrete semantic value.
virtual void set_expression(const SValuePtr &source)
Changes the expression stored in the value.
virtual const ExprPtr & get_expression() const
Returns the expression stored in this value.
virtual SValuePtr substitute(const SValuePtr &from, const SValuePtr &to, const SmtSolverPtr &solver) const
Substitute one value for another throughout a value.
virtual BaseSemantics::SValuePtr unspecified_(size_t nbits) const override
Create a new unspecified semantic value.
virtual void set_defining_instructions(const SValuePtr &source)
Set defining instructions.
virtual BaseSemantics::SValuePtr undefined_(size_t nbits) const override
Create a new undefined semantic value.
Describes (part of) a physical CPU register.
Controls formatting of expression trees when printing.
Interior node of an expression tree for instruction semantics.
Leaf node of an expression tree for instruction semantics.
Base class for symbolic expression nodes.
Holds a value or nothing.
Definition Optional.h:54
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Floating point types.
Base class for machine instructions.
Base class for binary types.
Base classes for instruction semantics.
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
std::list< MemoryCellPtr > CellList
List of memory cells.
Definition MemoryCell.h:280
boost::shared_ptr< class RegisterStateGeneric > RegisterStateGenericPtr
Shared-ownership pointer to generic register states.
boost::shared_ptr< AddressSpace > AddressSpacePtr
Shared-ownership pointer for AddressSpace objects.
boost::shared_ptr< FrameState > FrameStatePtr
Shared-ownership pointer to a frame state.
WritersMode
How to update the list of writers stored at each abstract location.
boost::shared_ptr< class MemoryMapState > MemoryMapStatePtr
Shared-ownership pointer to symbolic memory state.
boost::shared_ptr< class MemoryListState > MemoryListStatePtr
Shared-ownership pointer for symbolic list-based memory state.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer for symbolic semantic value.
DefinersMode
How to update the list of definers stored in each semantic value.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to symbolic RISC operations.
Sawyer::SharedPointer< Interior > InteriorPtr
Reference counting pointer.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
Sawyer::SharedPointer< Leaf > LeafPtr
Reference counting pointer.
std::shared_ptr< SmtSolver > SmtSolverPtr
Reference counting pointer.
The ROSE library.