ROSE  0.11.31.0
BinaryUnparserAarch64.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 <BinaryUnparserBase.h>
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 namespace Unparser {
11 
12 struct Aarch64Settings: public Settings {};
13 
17 class Aarch64: public Base {
18  Aarch64Settings settings_;
19 
20 protected:
21  explicit Aarch64(const Aarch64Settings &settings)
22  : settings_(settings) {}
23 
24 public:
25  ~Aarch64() {}
26 
27  static Ptr instance(const Aarch64Settings &settings = Aarch64Settings()) {
28  return Ptr(new Aarch64(settings));
29  }
30 
31  Ptr copy() const ROSE_OVERRIDE {
32  return instance(settings());
33  }
34 
35  const Aarch64Settings& settings() const ROSE_OVERRIDE { return settings_; }
36  Aarch64Settings& settings() ROSE_OVERRIDE { return settings_; }
37 
38 protected:
39  void emitInstructionMnemonic(std::ostream&, SgAsmInstruction*, State&) const ROSE_OVERRIDE;
40  void emitOperandBody(std::ostream&, SgAsmExpression*, State&) const ROSE_OVERRIDE;
41 
42 protected:
43  static std::string unparseArmCondition(Aarch64InstructionCondition);
44  void outputExpr(std::ostream&, SgAsmExpression*, State&) const;
45  void outputRegister(std::ostream&, SgAsmRegisterReferenceExpression*, State&) const;
46 
47 private:
48  // Precedence for the sake of emitting expressions. Higher return value is higher precedence.
49  static int operatorPrecedence(SgAsmExpression*);
50 
51  // Parentheses for emitting expressions with inverted precedences
52  struct Parens {
53  std::string left, right;
54  Parens() {}
55  Parens(const std::string &left, const std::string &right)
56  : left(left), right(right) {}
57  };
58 
59  // What parens to use when the operator has rootPrec and the left or right operand is as specified.
60  static Parens parensForPrecedence(int rootPrec, SgAsmExpression*);
61 };
62 
63 } // namespace
64 } // namespace
65 } // namespace
66 
67 #endif
68 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
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.
STL namespace.
Main namespace for the ROSE library.
Base class for expressions.