• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_DIAGNOSTICS_ARM64_DISASM_ARM64_H_
6 #define V8_DIAGNOSTICS_ARM64_DISASM_ARM64_H_
7 
8 #include "src/codegen/arm64/assembler-arm64.h"
9 #include "src/codegen/arm64/decoder-arm64.h"
10 #include "src/codegen/arm64/instructions-arm64.h"
11 #include "src/common/globals.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 class V8_EXPORT_PRIVATE DisassemblingDecoder : public DecoderVisitor {
17  public:
18   DisassemblingDecoder();
19   DisassemblingDecoder(char* text_buffer, int buffer_size);
20   virtual ~DisassemblingDecoder();
21   char* GetOutput();
22 
23 // Declare all Visitor functions.
24 #define DECLARE(A) void Visit##A(Instruction* instr);
25   VISITOR_LIST(DECLARE)
26 #undef DECLARE
27 
28  protected:
29   virtual void ProcessOutput(Instruction* instr);
30 
31   // Default output functions.  The functions below implement a default way of
32   // printing elements in the disassembly. A sub-class can override these to
33   // customize the disassembly output.
34 
35   // Prints the name of a register.
36   virtual void AppendRegisterNameToOutput(const CPURegister& reg);
37 
38   void Format(Instruction* instr, const char* mnemonic, const char* format);
39   void Substitute(Instruction* instr, const char* string);
40   int SubstituteField(Instruction* instr, const char* format);
41   int SubstituteRegisterField(Instruction* instr, const char* format);
42   int SubstituteImmediateField(Instruction* instr, const char* format);
43   int SubstituteLiteralField(Instruction* instr, const char* format);
44   int SubstituteBitfieldImmediateField(Instruction* instr, const char* format);
45   int SubstituteShiftField(Instruction* instr, const char* format);
46   int SubstituteExtendField(Instruction* instr, const char* format);
47   int SubstituteConditionField(Instruction* instr, const char* format);
48   int SubstitutePCRelAddressField(Instruction* instr, const char* format);
49   int SubstituteBranchTargetField(Instruction* instr, const char* format);
50   int SubstituteLSRegOffsetField(Instruction* instr, const char* format);
51   int SubstitutePrefetchField(Instruction* instr, const char* format);
52   int SubstituteBarrierField(Instruction* instr, const char* format);
53 
RdIsZROrSP(Instruction * instr)54   bool RdIsZROrSP(Instruction* instr) const {
55     return (instr->Rd() == kZeroRegCode);
56   }
57 
RnIsZROrSP(Instruction * instr)58   bool RnIsZROrSP(Instruction* instr) const {
59     return (instr->Rn() == kZeroRegCode);
60   }
61 
RmIsZROrSP(Instruction * instr)62   bool RmIsZROrSP(Instruction* instr) const {
63     return (instr->Rm() == kZeroRegCode);
64   }
65 
RaIsZROrSP(Instruction * instr)66   bool RaIsZROrSP(Instruction* instr) const {
67     return (instr->Ra() == kZeroRegCode);
68   }
69 
70   bool IsMovzMovnImm(unsigned reg_size, uint64_t value);
71 
72   void ResetOutput();
73   void AppendToOutput(const char* string, ...);
74 
75   char* buffer_;
76   uint32_t buffer_pos_;
77   uint32_t buffer_size_;
78   bool own_buffer_;
79 };
80 
81 class V8_EXPORT_PRIVATE PrintDisassembler : public DisassemblingDecoder {
82  public:
PrintDisassembler(FILE * stream)83   explicit PrintDisassembler(FILE* stream) : stream_(stream) {}
~PrintDisassembler()84   ~PrintDisassembler() {}
85 
86   virtual void ProcessOutput(Instruction* instr);
87 
88  private:
89   FILE* stream_;
90 };
91 
92 }  // namespace internal
93 }  // namespace v8
94 
95 #endif  // V8_DIAGNOSTICS_ARM64_DISASM_ARM64_H_
96