Commit 6e830964 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[cleanup] Use CodeReference in Disassembler

This avoids some code duplication.

R=mstarzinger@chromium.org

Bug: v8:7570
Change-Id: Ib8f9095945e688e24351529f8e782614453f2161
Reviewed-on: https://chromium-review.googlesource.com/1023416Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52762}
parent 09027e6c
......@@ -28,12 +28,8 @@ namespace internal {
class V8NameConverter: public disasm::NameConverter {
public:
explicit V8NameConverter(Code* code)
: isolate_(code->GetIsolate()), code_(CodeReference(handle(code))) {}
V8NameConverter(Isolate* isolate, const wasm::WasmCode* code)
: isolate_(isolate), code_(CodeReference(code)) {}
explicit V8NameConverter(Isolate* isolate)
: isolate_(isolate), code_(CodeReference()) {}
explicit V8NameConverter(Isolate* isolate, CodeReference code = {})
: isolate_(isolate), code_(code) {}
virtual const char* NameOfAddress(byte* pc) const;
virtual const char* NameInCode(byte* addr) const;
const CodeReference& code() const { return code_; }
......@@ -333,14 +329,7 @@ static int DecodeIt(Isolate* isolate, std::ostream* os,
}
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, Code* code, Address current_pc) {
V8NameConverter v8NameConverter(code);
return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc);
}
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, const wasm::WasmCode* code,
Address current_pc) {
byte* end, CodeReference code, Address current_pc) {
V8NameConverter v8NameConverter(isolate, code);
return DecodeIt(isolate, os, v8NameConverter, begin, end, current_pc);
}
......@@ -348,7 +337,7 @@ int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
#else // ENABLE_DISASSEMBLER
int Disassembler::Decode(Isolate* isolate, std::ostream* os, byte* begin,
byte* end, Code* code, Address current_pc) {
byte* end, CodeReference code, Address current_pc) {
return 0;
}
......
......@@ -6,14 +6,11 @@
#define V8_DISASSEMBLER_H_
#include "src/allocation.h"
#include "src/code-reference.h"
namespace v8 {
namespace internal {
namespace wasm {
class WasmCode;
}
class Disassembler : public AllStatic {
public:
// Decode instructions in the the interval [begin, end) and print the
......@@ -21,10 +18,7 @@ class Disassembler : public AllStatic {
// instruction could be decoded.
// the code object is used for name resolution and may be null.
static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end,
Code* code = nullptr, Address current_pc = kNullAddress);
static int Decode(Isolate* isolate, std::ostream* os, byte* begin, byte* end,
const wasm::WasmCode* code,
Address current_pc = kNullAddress);
CodeReference code = {}, Address current_pc = kNullAddress);
};
} // namespace internal
......
......@@ -14629,8 +14629,16 @@ void Code::Disassemble(const char* name, std::ostream& os, Address current_pc) {
os << "Instructions (size = " << code_size << ")\n";
Address begin = InstructionStart();
Address end = begin + code_size;
Disassembler::Decode(isolate, &os, reinterpret_cast<byte*>(begin),
reinterpret_cast<byte*>(end), this, current_pc);
{
// TODO(mstarzinger): Refactor CodeReference to avoid the
// unhandlified->handlified transition.
AllowHandleAllocation allow_handles;
DisallowHeapAllocation no_gc;
HandleScope handle_scope(isolate);
Disassembler::Decode(isolate, &os, reinterpret_cast<byte*>(begin),
reinterpret_cast<byte*>(end),
CodeReference(handle(this, isolate)), current_pc);
}
if (constant_pool_offset < size) {
int constant_pool_size = safepoint_offset - constant_pool_offset;
......
......@@ -271,8 +271,8 @@ void WasmCode::Disassemble(const char* name, Isolate* isolate, std::ostream& os,
// TODO(mtrofin): rework the dependency on isolate and code in
// Disassembler::Decode.
Disassembler::Decode(isolate, &os, instructions().start(),
instructions().start() + instruction_size, this,
current_pc);
instructions().start() + instruction_size,
CodeReference(this), current_pc);
os << "\n";
if (!source_positions().is_empty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment