blob: 89b7fc261565a680495c4854c3cb8cf3282090ff [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2007-2008 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_DISASM_H_
6#define V8_DISASM_H_
7
8namespace disasm {
9
10typedef 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.
15class 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 Block44f0eee2011-05-26 01:26:41 +010024
25 protected:
26 v8::internal::EmbeddedVector<char, 128> tmp_buffer_;
Steve Blocka7e24c12009-10-30 11:49:00 +000027};
28
29
30// A generic Disassembler interface
31class 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_