ROSE  0.11.98.0
Unparser/Aarch64.h
1 #ifndef ROSE_BinaryAnalysis_Unparser_Aarch64_H
2 #define ROSE_BinaryAnalysis_Unparser_Aarch64_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_ASM_AARCH64
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 unparseAarch64Mnemonic(SgAsmAarch64Instruction*);
14 std::string unparseAarch64Expression(SgAsmExpression*, const LabelMap*, RegisterDictionaryPtr);
15 
16 struct Aarch64Settings: public Settings {};
17 
21 class Aarch64: public Base {
22  Aarch64Settings settings_;
23 
24 protected:
25  explicit Aarch64(const Aarch64Settings &settings)
26  : settings_(settings) {}
27 
28 public:
29  ~Aarch64() {}
30 
31  static Ptr instance(const Aarch64Settings &settings = Aarch64Settings()) {
32  return Ptr(new Aarch64(settings));
33  }
34 
35  Ptr copy() const override {
36  return instance(settings());
37  }
38 
39  const Aarch64Settings& settings() const override { return settings_; }
40  Aarch64Settings& 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  static std::string unparseArmCondition(Aarch64InstructionCondition);
48  void outputExpr(std::ostream&, SgAsmExpression*, State&) const;
49  void outputRegister(std::ostream&, SgAsmRegisterReferenceExpression*, State&) const;
50 
51 private:
52  // Precedence for the sake of emitting expressions. Higher return value is higher precedence.
53  static int operatorPrecedence(SgAsmExpression*);
54 
55  // Parentheses for emitting expressions with inverted precedences
56  struct Parens {
57  std::string left, right;
58  Parens() {}
59  Parens(const std::string &left, const std::string &right)
60  : left(left), right(right) {}
61  };
62 
63  // What parens to use when the operator has rootPrec and the left or right operand is as specified.
64  static Parens parensForPrecedence(int rootPrec, SgAsmExpression*);
65 };
66 
67 } // namespace
68 } // namespace
69 } // namespace
70 
71 #endif
72 #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.