ROSE  0.9.10.103
DispatcherPowerpc.h
1 // Semantics for 32-bit Motorola-IBM PowerPC microprocessors using ROSE instruction semantics API2
2 // This code was derived from $ROSE/projects/assemblyToSourceAst/powerpcInstructionSemantics.h,
3 // which is mostly a copy of $ROSE/projects/SemanticSignatureVectors/powerpcInstructionSemantics.h
4 //
5 // The ROSE style guide indicates that PowerPC, when used as part of a symbol in ROSE source code,
6 // should be capitalized as "Powerpc" (e.g., "DispatcherPowerpc", the same rule that consistently
7 // capitializes x86 as "DispatcherX86").
8 
9 #ifndef ROSE_DispatcherPpc_H
10 #define ROSE_DispatcherPpc_H
11 
12 #include "BaseSemantics2.h"
13 
14 #include <boost/serialization/access.hpp>
15 #include <boost/serialization/base_object.hpp>
16 #include <boost/serialization/export.hpp>
17 #include <boost/serialization/split_member.hpp>
18 
19 namespace Rose {
20 namespace BinaryAnalysis {
21 namespace InstructionSemantics2 {
22 
24 typedef boost::shared_ptr<class DispatcherPowerpc> DispatcherPowerpcPtr;
25 
27 public:
29 
36 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
37 private:
38  friend class boost::serialization::access;
39 
40  template<class S>
41  void save(S &s, const unsigned /*version*/) const {
42  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
43  }
44 
45  template<class S>
46  void load(S &s, const unsigned /*version*/) {
47  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Super);
48  regcache_init();
49  iproc_init();
50  memory_init();
51  }
52 
53  BOOST_SERIALIZATION_SPLIT_MEMBER();
54 #endif
55 
56 protected:
57  // prototypical constructor
58  DispatcherPowerpc(): BaseSemantics::Dispatcher(32, RegisterDictionary::dictionary_powerpc()) {}
59 
60  DispatcherPowerpc(const BaseSemantics::RiscOperatorsPtr &ops, size_t addrWidth, const RegisterDictionary *regs)
61  : BaseSemantics::Dispatcher(ops, addrWidth, regs ? regs : RegisterDictionary::dictionary_powerpc()) {
62  ASSERT_require(32==addrWidth);
63  regcache_init();
64  iproc_init();
65  memory_init();
66  }
67 
69  void iproc_init();
70 
72  void regcache_init();
73 
75  void memory_init();
76 
77 public:
80  static DispatcherPowerpcPtr instance() {
82  }
83 
85  static DispatcherPowerpcPtr instance(const BaseSemantics::RiscOperatorsPtr &ops, size_t addrWidth,
86  const RegisterDictionary *regs=NULL) {
87  return DispatcherPowerpcPtr(new DispatcherPowerpc(ops, addrWidth, regs));
88  }
89 
92  const RegisterDictionary *regs=NULL) const ROSE_OVERRIDE {
93  if (0==addrWidth)
94  addrWidth = addressWidth();
95  if (!regs)
96  regs = get_register_dictionary();
97  return instance(ops, addrWidth, regs);
98  }
99 
101  static DispatcherPowerpcPtr promote(const BaseSemantics::DispatcherPtr &d) {
102  DispatcherPowerpcPtr retval = boost::dynamic_pointer_cast<DispatcherPowerpc>(d);
103  assert(retval!=NULL);
104  return retval;
105  }
106 
107  virtual void set_register_dictionary(const RegisterDictionary *regdict) ROSE_OVERRIDE;
108 
109  virtual RegisterDescriptor instructionPointerRegister() const ROSE_OVERRIDE;
110 
111  virtual RegisterDescriptor stackPointerRegister() const ROSE_OVERRIDE;
112 
113  virtual int iproc_key(SgAsmInstruction *insn_) const ROSE_OVERRIDE {
114  SgAsmPowerpcInstruction *insn = isSgAsmPowerpcInstruction(insn_);
115  assert(insn!=NULL);
116  return insn->get_kind();
117  }
118 
120  virtual void record(const BaseSemantics::SValuePtr &result);
121 };
122 
123 } // namespace
124 } // namespace
125 } // namespace
126 
127 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
129 #endif
130 
131 #endif
virtual RegisterDescriptor stackPointerRegister() const ROSE_OVERRIDE
Returns the stack pointer register.
Base class for machine instructions.
Main namespace for the ROSE library.
Describes (part of) a physical CPU register.
void regcache_init()
Load the cached register descriptors.
virtual const RegisterDictionary * get_register_dictionary() const
Access the register dictionary.
void memory_init()
Make sure memory is set up correctly.
virtual void set_register_dictionary(const RegisterDictionary *regdict) ROSE_OVERRIDE
Access the register dictionary.
boost::shared_ptr< class Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
virtual RegisterDescriptor instructionPointerRegister() const ROSE_OVERRIDE
Returns the instruction pointer register.
Base classes for instruction semantics.
virtual BaseSemantics::DispatcherPtr create(const BaseSemantics::RiscOperatorsPtr &ops, size_t addrWidth=0, const RegisterDictionary *regs=NULL) const ROSE_OVERRIDE
Virtual constructor.
size_t addressWidth() const
Property: Width of memory addresses.
boost::shared_ptr< class RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
boost::shared_ptr< class DispatcherPowerpc > DispatcherPowerpcPtr
Shared-ownership pointer to a PowerPC instruction dispatcher.
virtual int iproc_key(SgAsmInstruction *insn_) const ROSE_OVERRIDE
Given an instruction, return the InsnProcessor key that can be used as an index into the iproc_table...
PowerpcInstructionKind get_kind() const
Property: Instruction kind.
Represents one PowerPC machine instruction.
Defines registers available for a particular architecture.
Definition: Registers.h:32
void iproc_init()
Loads the iproc table with instruction processing functors.
const RegisterDictionary * regdict
See set_register_dictionary().
virtual void record(const BaseSemantics::SValuePtr &result)
Write status flags for result.
static DispatcherPowerpcPtr instance()
Construct a prototypical dispatcher.
static DispatcherPowerpcPtr instance(const BaseSemantics::RiscOperatorsPtr &ops, size_t addrWidth, const RegisterDictionary *regs=NULL)
Constructor.
static DispatcherPowerpcPtr promote(const BaseSemantics::DispatcherPtr &d)
Dynamic cast to a DispatcherPowerpcPtr with assertion.