| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
*/ |
| 4 |
// Copyright 2007-2008 the V8 project authors. All rights reserved. |
| 5 |
// Use of this source code is governed by a BSD-style license that can be |
| 6 |
// found in the LICENSE file. |
| 7 |
|
| 8 |
#ifndef jit_riscv64_disasm_Disasm_riscv64_h |
| 9 |
#define jit_riscv64_disasm_Disasm_riscv64_h |
| 10 |
|
| 11 |
#include "mozilla/Assertions.h" |
| 12 |
#include "mozilla/Types.h" |
| 13 |
|
| 14 |
#include <stdio.h> |
| 15 |
|
| 16 |
#include "jit/riscv64/constant/Constant-riscv64.h" |
| 17 |
#include "jit/riscv64/constant/util-riscv64.h" |
| 18 |
namespace js { |
| 19 |
namespace jit { |
| 20 |
namespace disasm { |
| 21 |
|
| 22 |
typedef unsigned char byte; |
| 23 |
|
| 24 |
// Interface and default implementation for converting addresses and |
| 25 |
// register-numbers to text. The default implementation is machine |
| 26 |
// specific. |
| 27 |
class NameConverter { |
| 28 |
public: |
| 29 |
virtual ~NameConverter() {} |
| 30 |
virtual const char* NameOfCPURegister(int reg) const; |
| 31 |
virtual const char* NameOfByteCPURegister(int reg) const; |
| 32 |
virtual const char* NameOfXMMRegister(int reg) const; |
| 33 |
virtual const char* NameOfAddress(byte* addr) const; |
| 34 |
virtual const char* NameOfConstant(byte* addr) const; |
| 35 |
virtual const char* NameInCode(byte* addr) const; |
| 36 |
|
| 37 |
protected: |
| 38 |
EmbeddedVector<char, 128> tmp_buffer_; |
| 39 |
}; |
| 40 |
|
| 41 |
// A generic Disassembler interface |
| 42 |
class Disassembler { |
| 43 |
public: |
| 44 |
// Caller deallocates converter. |
| 45 |
explicit Disassembler(const NameConverter& converter); |
| 46 |
|
| 47 |
virtual ~Disassembler(); |
| 48 |
|
| 49 |
// Writes one disassembled instruction into 'buffer' (0-terminated). |
| 50 |
// Returns the length of the disassembled machine instruction in bytes. |
| 51 |
int InstructionDecode(V8Vector<char> buffer, uint8_t* instruction); |
| 52 |
|
| 53 |
// Returns -1 if instruction does not mark the beginning of a constant pool, |
| 54 |
// or the number of entries in the constant pool beginning here. |
| 55 |
int ConstantPoolSizeAt(byte* instruction); |
| 56 |
|
| 57 |
// Write disassembly into specified file 'f' using specified NameConverter |
| 58 |
// (see constructor). |
| 59 |
static void Disassemble(FILE* f, uint8_t* begin, uint8_t* end); |
| 60 |
|
| 61 |
private: |
| 62 |
const NameConverter& converter_; |
| 63 |
|
| 64 |
// Disallow implicit constructors. |
| 65 |
Disassembler() = delete; |
| 66 |
Disassembler(const Disassembler&) = delete; |
| 67 |
void operator=(const Disassembler&) = delete; |
| 68 |
}; |
| 69 |
|
| 70 |
} // namespace disasm |
| 71 |
} // namespace jit |
| 72 |
} // namespace js |
| 73 |
|
| 74 |
#endif // jit_riscv64_disasm_Disasm_riscv64_h |