Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright 2007-2008 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_DISASM_H_ |
| 6 | #define V8_DISASM_H_ |
| 7 | |
| 8 | namespace disasm { |
| 9 | |
| 10 | typedef unsigned char byte; |
| 11 | |
| 12 | // Interface and default implementation for converting addresses and |
| 13 | // register-numbers to text. The default implementation is machine |
| 14 | // specific. |
| 15 | class NameConverter { |
| 16 | public: |
| 17 | virtual ~NameConverter() {} |
| 18 | virtual const char* NameOfCPURegister(int reg) const; |
| 19 | virtual const char* NameOfByteCPURegister(int reg) const; |
| 20 | virtual const char* NameOfXMMRegister(int reg) const; |
| 21 | virtual const char* NameOfAddress(byte* addr) const; |
| 22 | virtual const char* NameOfConstant(byte* addr) const; |
| 23 | virtual const char* NameInCode(byte* addr) const; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 24 | |
| 25 | protected: |
| 26 | v8::internal::EmbeddedVector<char, 128> tmp_buffer_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | |
| 30 | // A generic Disassembler interface |
| 31 | class Disassembler { |
| 32 | public: |
| 33 | // Caller deallocates converter. |
| 34 | explicit Disassembler(const NameConverter& converter); |
| 35 | |
| 36 | virtual ~Disassembler(); |
| 37 | |
| 38 | // Writes one disassembled instruction into 'buffer' (0-terminated). |
| 39 | // Returns the length of the disassembled machine instruction in bytes. |
| 40 | int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction); |
| 41 | |
| 42 | // Returns -1 if instruction does not mark the beginning of a constant pool, |
| 43 | // or the number of entries in the constant pool beginning here. |
| 44 | int ConstantPoolSizeAt(byte* instruction); |
| 45 | |
| 46 | // Write disassembly into specified file 'f' using specified NameConverter |
| 47 | // (see constructor). |
| 48 | static void Disassemble(FILE* f, byte* begin, byte* end); |
| 49 | private: |
| 50 | const NameConverter& converter_; |
| 51 | |
| 52 | DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler); |
| 53 | }; |
| 54 | |
| 55 | } // namespace disasm |
| 56 | |
| 57 | #endif // V8_DISASM_H_ |