blob: 263aa317d55ca22f780188c0c74103874a1c1245 [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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/utils.h"
9
Steve Blocka7e24c12009-10-30 11:49:00 +000010namespace disasm {
11
12typedef 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.
17class 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 Block44f0eee2011-05-26 01:26:41 +010026
27 protected:
28 v8::internal::EmbeddedVector<char, 128> tmp_buffer_;
Steve Blocka7e24c12009-10-30 11:49:00 +000029};
30
31
32// A generic Disassembler interface
33class 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_