ROSE  0.11.96.0
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/Unparser/Base.h>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 namespace Unparser {
11 
12 std::string unparseAarch64Mnemonic(SgAsmAarch64Instruction*);
13 std::string unparseAarch64Expression(SgAsmExpression*, const LabelMap*, const RegisterDictionary*);
14 
15 struct Aarch64Settings: public Settings {};
16 
20 class Aarch64: public Base {
21  Aarch64Settings settings_;
22 
23 protected:
24  explicit Aarch64(const Aarch64Settings &settings)
25  : settings_(settings) {}
26 
27 public:
28  ~Aarch64() {}
29 
30  static Ptr instance(const Aarch64Settings &settings = Aarch64Settings()) {
31  return Ptr(new Aarch64(settings));
32  }
33 
34  Ptr copy() const override {
35  return instance(settings());
36  }
37 
38  const Aarch64Settings& settings() const override { return settings_; }
39  Aarch64Settings& settings() override { return settings_; }
40 
41 protected:
42  void emitInstructionMnemonic(std::ostream&, SgAsmInstruction*, State&) const override;
43  void emitOperandBody(std::ostream&, SgAsmExpression*, State&) const override;
44 
45 protected:
46  static std::string unparseArmCondition(Aarch64InstructionCondition);
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
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:162
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.
Base class for expressions.