Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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_ARM64_DISASM_ARM64_H |
| 6 | #define V8_ARM64_DISASM_ARM64_H |
| 7 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/arm64/decoder-arm64.h" |
| 9 | #include "src/arm64/instructions-arm64.h" |
| 10 | #include "src/globals.h" |
| 11 | #include "src/utils.h" |
| 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
| 16 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 17 | class DisassemblingDecoder : public DecoderVisitor { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 18 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | DisassemblingDecoder(); |
| 20 | DisassemblingDecoder(char* text_buffer, int buffer_size); |
| 21 | virtual ~DisassemblingDecoder(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | void Format(Instruction* instr, const char* mnemonic, const char* format); |
| 33 | void Substitute(Instruction* instr, const char* string); |
| 34 | int SubstituteField(Instruction* instr, const char* format); |
| 35 | int SubstituteRegisterField(Instruction* instr, const char* format); |
| 36 | int SubstituteImmediateField(Instruction* instr, const char* format); |
| 37 | int SubstituteLiteralField(Instruction* instr, const char* format); |
| 38 | int SubstituteBitfieldImmediateField(Instruction* instr, const char* format); |
| 39 | int SubstituteShiftField(Instruction* instr, const char* format); |
| 40 | int SubstituteExtendField(Instruction* instr, const char* format); |
| 41 | int SubstituteConditionField(Instruction* instr, const char* format); |
| 42 | int SubstitutePCRelAddressField(Instruction* instr, const char* format); |
| 43 | int SubstituteBranchTargetField(Instruction* instr, const char* format); |
| 44 | int SubstituteLSRegOffsetField(Instruction* instr, const char* format); |
| 45 | int SubstitutePrefetchField(Instruction* instr, const char* format); |
| 46 | int SubstituteBarrierField(Instruction* instr, const char* format); |
| 47 | |
| 48 | bool RdIsZROrSP(Instruction* instr) const { |
| 49 | return (instr->Rd() == kZeroRegCode); |
| 50 | } |
| 51 | |
| 52 | bool RnIsZROrSP(Instruction* instr) const { |
| 53 | return (instr->Rn() == kZeroRegCode); |
| 54 | } |
| 55 | |
| 56 | bool RmIsZROrSP(Instruction* instr) const { |
| 57 | return (instr->Rm() == kZeroRegCode); |
| 58 | } |
| 59 | |
| 60 | bool RaIsZROrSP(Instruction* instr) const { |
| 61 | return (instr->Ra() == kZeroRegCode); |
| 62 | } |
| 63 | |
| 64 | bool IsMovzMovnImm(unsigned reg_size, uint64_t value); |
| 65 | |
| 66 | void ResetOutput(); |
| 67 | void AppendToOutput(const char* string, ...); |
| 68 | |
| 69 | char* buffer_; |
| 70 | uint32_t buffer_pos_; |
| 71 | uint32_t buffer_size_; |
| 72 | bool own_buffer_; |
| 73 | }; |
| 74 | |
| 75 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 76 | class PrintDisassembler : public DisassemblingDecoder { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 77 | public: |
| 78 | explicit PrintDisassembler(FILE* stream) : stream_(stream) { } |
| 79 | ~PrintDisassembler() { } |
| 80 | |
| 81 | virtual void ProcessOutput(Instruction* instr); |
| 82 | |
| 83 | private: |
| 84 | FILE *stream_; |
| 85 | }; |
| 86 | |
| 87 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | } // namespace internal |
| 89 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | |
| 91 | #endif // V8_ARM64_DISASM_ARM64_H |