blob: f7f2d4120281897ea0fd7f15841ab13c23b0b778 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2007-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_DISASM_H_
29#define V8_DISASM_H_
30
31namespace disasm {
32
33typedef unsigned char byte;
34
35// Interface and default implementation for converting addresses and
36// register-numbers to text. The default implementation is machine
37// specific.
38class NameConverter {
39 public:
40 virtual ~NameConverter() {}
41 virtual const char* NameOfCPURegister(int reg) const;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000042 virtual const char* NameOfByteCPURegister(int reg) const;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000043 virtual const char* NameOfXMMRegister(int reg) const;
44 virtual const char* NameOfAddress(byte* addr) const;
45 virtual const char* NameOfConstant(byte* addr) const;
46 virtual const char* NameInCode(byte* addr) const;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000047
48 protected:
49 v8::internal::EmbeddedVector<char, 128> tmp_buffer_;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000050};
51
52
53// A generic Disassembler interface
54class Disassembler {
55 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000056 // Caller deallocates converter.
57 explicit Disassembler(const NameConverter& converter);
58
59 virtual ~Disassembler();
60
61 // Writes one disassembled instruction into 'buffer' (0-terminated).
62 // Returns the length of the disassembled machine instruction in bytes.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +000063 int InstructionDecode(v8::internal::Vector<char> buffer, byte* instruction);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000064
kasper.lund7276f142008-07-30 08:49:36 +000065 // Returns -1 if instruction does not mark the beginning of a constant pool,
66 // or the number of entries in the constant pool beginning here.
67 int ConstantPoolSizeAt(byte* instruction);
68
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000069 // Write disassembly into specified file 'f' using specified NameConverter
70 // (see constructor).
71 static void Disassemble(FILE* f, byte* begin, byte* end);
72 private:
73 const NameConverter& converter_;
ager@chromium.org3bf7b912008-11-17 09:09:45 +000074
75 DISALLOW_IMPLICIT_CONSTRUCTORS(Disassembler);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000076};
77
78} // namespace disasm
79
80#endif // V8_DISASM_H_