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 #include "src/utils/utils.h" 13 14 namespace v8 { 15 namespace internal { 16 17 class V8_EXPORT_PRIVATE DisassemblingDecoder : public DecoderVisitor { 18 public: 19 DisassemblingDecoder(); 20 DisassemblingDecoder(char* text_buffer, int buffer_size); 21 virtual ~DisassemblingDecoder(); 22 char* GetOutput(); 23 24 // Declare all Visitor functions. 25 #define DECLARE(A) void Visit##A(Instruction* instr); 26 VISITOR_LIST(DECLARE) 27 #undef DECLARE 28 29 protected: 30 virtual void ProcessOutput(Instruction* instr); 31 32 // Default output functions. The functions below implement a default way of 33 // printing elements in the disassembly. A sub-class can override these to 34 // customize the disassembly output. 35 36 // Prints the name of a register. 37 virtual void AppendRegisterNameToOutput(const CPURegister& reg); 38 39 void Format(Instruction* instr, const char* mnemonic, const char* format); 40 void Substitute(Instruction* instr, const char* string); 41 int SubstituteField(Instruction* instr, const char* format); 42 int SubstituteRegisterField(Instruction* instr, const char* format); 43 int SubstituteImmediateField(Instruction* instr, const char* format); 44 int SubstituteLiteralField(Instruction* instr, const char* format); 45 int SubstituteBitfieldImmediateField(Instruction* instr, const char* format); 46 int SubstituteShiftField(Instruction* instr, const char* format); 47 int SubstituteExtendField(Instruction* instr, const char* format); 48 int SubstituteConditionField(Instruction* instr, const char* format); 49 int SubstitutePCRelAddressField(Instruction* instr, const char* format); 50 int SubstituteBranchTargetField(Instruction* instr, const char* format); 51 int SubstituteLSRegOffsetField(Instruction* instr, const char* format); 52 int SubstitutePrefetchField(Instruction* instr, const char* format); 53 int SubstituteBarrierField(Instruction* instr, const char* format); 54 RdIsZROrSP(Instruction * instr)55 bool RdIsZROrSP(Instruction* instr) const { 56 return (instr->Rd() == kZeroRegCode); 57 } 58 RnIsZROrSP(Instruction * instr)59 bool RnIsZROrSP(Instruction* instr) const { 60 return (instr->Rn() == kZeroRegCode); 61 } 62 RmIsZROrSP(Instruction * instr)63 bool RmIsZROrSP(Instruction* instr) const { 64 return (instr->Rm() == kZeroRegCode); 65 } 66 RaIsZROrSP(Instruction * instr)67 bool RaIsZROrSP(Instruction* instr) const { 68 return (instr->Ra() == kZeroRegCode); 69 } 70 71 bool IsMovzMovnImm(unsigned reg_size, uint64_t value); 72 73 void ResetOutput(); 74 void AppendToOutput(const char* string, ...); 75 76 char* buffer_; 77 uint32_t buffer_pos_; 78 uint32_t buffer_size_; 79 bool own_buffer_; 80 }; 81 82 class V8_EXPORT_PRIVATE PrintDisassembler : public DisassemblingDecoder { 83 public: PrintDisassembler(FILE * stream)84 explicit PrintDisassembler(FILE* stream) : stream_(stream) {} ~PrintDisassembler()85 ~PrintDisassembler() {} 86 87 virtual void ProcessOutput(Instruction* instr); 88 89 private: 90 FILE* stream_; 91 }; 92 93 } // namespace internal 94 } // namespace v8 95 96 #endif // V8_DIAGNOSTICS_ARM64_DISASM_ARM64_H_ 97