Line data Source code
1 : // Copyright 2007-2008 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_DISASM_H_
6 : #define V8_DISASM_H_
7 :
8 : #include "src/utils.h"
9 :
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 2749033 : class NameConverter {
18 : public:
19 0 : 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;
26 :
27 : protected:
28 : v8::internal::EmbeddedVector<char, 128> tmp_buffer_;
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_
|