[wasm] Handle non-asm-js case in WasmCompiledModule::GetAsmJsSourcePosition.

This hides more implementation details and simplifies callers.

R=ahaas@chromium.org

Bug: 
Change-Id: I4809611c55b810a3b0674713e12f3f17401e6c9c
Reviewed-on: https://chromium-review.googlesource.com/620713
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Ben Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47434}
This commit is contained in:
Ben L. Titzer 2017-08-18 16:08:23 +02:00 committed by Commit Bot
parent a3ef2489f2
commit 15fe64c0e5
5 changed files with 29 additions and 33 deletions

View File

@ -1229,16 +1229,11 @@ WASM_SUMMARY_DISPATCH(int, byte_offset)
#undef WASM_SUMMARY_DISPATCH
int FrameSummary::WasmFrameSummary::SourcePosition() const {
int offset = byte_offset();
Handle<WasmCompiledModule> compiled_module(wasm_instance()->compiled_module(),
isolate());
if (compiled_module->is_asm_js()) {
offset = WasmCompiledModule::GetAsmJsSourcePosition(
compiled_module, function_index(), offset, at_to_number_conversion());
} else {
offset += compiled_module->GetFunctionOffset(function_index());
}
return offset;
return WasmCompiledModule::GetSourcePosition(compiled_module,
function_index(), byte_offset(),
at_to_number_conversion());
}
Handle<Script> FrameSummary::WasmFrameSummary::script() const {

View File

@ -1625,21 +1625,14 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
int func_index = elements->WasmFunctionIndex(i)->value();
int code_offset = elements->Offset(i)->value();
// TODO(wasm): Clean this up (bug 5007).
int pos = code_offset < 0
? (-1 - code_offset)
: elements->Code(i)->SourcePosition(code_offset);
if (elements->IsAsmJsWasmFrame(i)) {
// For asm.js frames, make an additional translation step to get the
// asm.js source position.
bool at_to_number_conversion =
elements->Flags(i)->value() & FrameArray::kAsmJsAtNumberConversion;
pos = WasmCompiledModule::GetAsmJsSourcePosition(
compiled_module, func_index, pos, at_to_number_conversion);
} else {
// For pure wasm, make the function-local position module-relative by
// adding the function offset.
pos += compiled_module->GetFunctionOffset(func_index);
}
int byte_offset = code_offset < 0
? (-1 - code_offset)
: elements->Code(i)->SourcePosition(code_offset);
bool is_at_number_conversion =
elements->IsAsmJsWasmFrame(i) &&
elements->Flags(i)->value() & FrameArray::kAsmJsAtNumberConversion;
byte pos = WasmCompiledModule::GetSourcePosition(
compiled_module, func_index, byte_offset, is_at_number_conversion);
Handle<Script> script(compiled_module->script());
*target = MessageLocation(script, pos, pos + 1);

View File

@ -757,7 +757,7 @@ int AsmJsWasmStackFrame::GetPosition() const {
Handle<WasmCompiledModule> compiled_module(
WasmInstanceObject::cast(*wasm_instance_)->compiled_module(), isolate_);
DCHECK_LE(0, byte_offset);
return WasmCompiledModule::GetAsmJsSourcePosition(
return WasmCompiledModule::GetSourcePosition(
compiled_module, wasm_func_index_, static_cast<uint32_t>(byte_offset),
is_at_number_conversion_);
}

View File

@ -1232,16 +1232,24 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable(
} // namespace
int WasmCompiledModule::GetAsmJsSourcePosition(
int WasmCompiledModule::GetSourcePosition(
Handle<WasmCompiledModule> compiled_module, uint32_t func_index,
uint32_t byte_offset, bool is_at_number_conversion) {
Isolate* isolate = compiled_module->GetIsolate();
const WasmModule* module = compiled_module->module();
if (!module->is_asm_js()) {
// for non-asm.js modules, we just add the function's start offset
// to make a module-relative position.
return byte_offset + compiled_module->GetFunctionOffset(func_index);
}
// asm.js modules have an additional offset table that must be searched.
Handle<ByteArray> offset_table =
GetDecodedAsmJsOffsetTable(compiled_module, isolate);
DCHECK_LT(func_index, compiled_module->module()->functions.size());
uint32_t func_code_offset =
compiled_module->module()->functions[func_index].code.offset();
DCHECK_LT(func_index, module->functions.size());
uint32_t func_code_offset = module->functions[func_index].code.offset();
uint32_t total_offset = func_code_offset + byte_offset;
// Binary search for the total byte offset.

View File

@ -512,11 +512,11 @@ class WasmCompiledModule : public FixedArray {
// Returns true if the position is valid inside this module, false otherwise.
bool GetPositionInfo(uint32_t position, Script::PositionInfo* info);
// Get the asm.js source position from a byte offset.
// Must only be called if the associated wasm object was created from asm.js.
static int GetAsmJsSourcePosition(Handle<WasmCompiledModule> compiled_module,
uint32_t func_index, uint32_t byte_offset,
bool is_at_number_conversion);
// Get the source position from a given function index and byte offset,
// for either asm.js or pure WASM modules.
static int GetSourcePosition(Handle<WasmCompiledModule> compiled_module,
uint32_t func_index, uint32_t byte_offset,
bool is_at_number_conversion);
// Compute the disassembly of a wasm function.
// Returns the disassembly string and a list of <byte_offset, line, column>