ROSE  0.11.98.0
Unparser/Aarch32.h
1 #ifndef ROSE_BinaryAnalysis_Unparser_Aarch32_H
2 #define ROSE_BinaryAnalysis_Unparser_Aarch32_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_ASM_AARCH32
5 
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/Unparser/Base.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 namespace Unparser {
12 
13 std::string unparseAarch32Mnemonic(SgAsmAarch32Instruction*);
14 std::string unparseAarch32Expression(SgAsmExpression*, const LabelMap*, RegisterDictionaryPtr);
15 
16 struct Aarch32Settings: public Settings {};
17 
21 class Aarch32: public Base {
22  Aarch32Settings settings_;
23 
24 protected:
25  explicit Aarch32(const Aarch32Settings &settings)
26  : settings_(settings) {}
27 
28 public:
29  ~Aarch32() {}
30 
31  static Ptr instance(const Aarch32Settings &settings = Aarch32Settings()) {
32  return Ptr(new Aarch32(settings));
33  }
34 
35  Ptr copy() const override {
36  return instance(settings());
37  }
38 
39  const Aarch32Settings& settings() const override { return settings_; }
40  Aarch32Settings& settings() override { return settings_; }
41 
42 protected:
43  void emitInstructionMnemonic(std::ostream&, SgAsmInstruction*, State&) const override;
44  void emitOperandBody(std::ostream&, SgAsmExpression*, State&) const override;
45 
46 protected:
47  void outputExpr(std::ostream&, SgAsmExpression*, State &) const;
48  void outputRegister(std::ostream&, SgAsmRegisterReferenceExpression*, State&) const;
49 
50 private:
51  // Precedence for the sake of emitting expressions. Higher return value is higher precedence.
52  static int operatorPrecedence(SgAsmExpression*);
53 
54  // Parentheses for emitting expressions with inverted precedences
55  struct Parens {
56  std::string left, right;
57  Parens() {}
58  Parens(const std::string &left, const std::string &right)
59  : left(left), right(right) {}
60  };
61 
62  // What parens to use when the operator has rootPrec and the left or right operand is as specified.
63  static Parens parensForPrecedence(int rootPrec, SgAsmExpression*);
64 };
65 
66 } // namespace
67 } // namespace
68 } // namespace
69 
70 #endif
71 #endif
Base class for references to a machine register.
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.
Base class for machine instructions.
Main namespace for the ROSE library.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
Base class for expressions.
Binary analysis.