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