Commit 54e9f3e6 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] In the FunctionBody, replace {base} by {offset}

For correct error positions, the FunctionBody struct stored a {base}
pointer to the beginning of the wasm module bytes, in addition to the
{start} and {end} pointer of the function body within the module bytes.
For streaming compilation, we do not have all module bytes in a single
chunk of memory. Therefore this CL changes the FunctionBody such that it
does not store the base pointer but the offset of the function body
within the module. I did the same change already some time ago for the
{Decoder}.

R=clemensh@chromium.org, mtrofin@chromium.org

Change-Id: I5138fbe270d0f5166a7dcc5cb8f3fe78a298bff6
Reviewed-on: https://chromium-review.googlesource.com/544863Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46170}
parent 2c260da3
......@@ -3949,7 +3949,7 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate,
: WasmCompilationUnit(
isolate, &module_env->module_env,
wasm::FunctionBody{
function->sig, module_env->wire_bytes.start(),
function->sig, function->code.offset(),
module_env->wire_bytes.start() + function->code.offset(),
module_env->wire_bytes.start() + function->code.end_offset()},
module_env->wire_bytes.GetNameOrNull(function), function->func_index,
......
......@@ -158,8 +158,8 @@ struct Control {
class WasmDecoder : public Decoder {
public:
WasmDecoder(const WasmModule* module, FunctionSig* sig, const byte* start,
const byte* end)
: Decoder(start, end),
const byte* end, uint32_t buffer_offset = 0)
: Decoder(start, end, buffer_offset),
module_(module),
sig_(sig),
local_types_(nullptr) {}
......@@ -656,18 +656,17 @@ class WasmFullDecoder : public WasmDecoder {
}
bool TraceFailed() {
TRACE("wasm-error module+%-6d func+%d: %s\n\n",
baserel(start_ + error_offset_), error_offset_, error_msg_.c_str());
TRACE("wasm-error module+%-6d func+%d: %s\n\n", error_offset_,
GetBufferRelativeOffset(error_offset_), error_msg_.c_str());
return false;
}
private:
WasmFullDecoder(Zone* zone, const wasm::WasmModule* module,
TFBuilder* builder, const FunctionBody& body)
: WasmDecoder(module, body.sig, body.start, body.end),
: WasmDecoder(module, body.sig, body.start, body.end, body.offset),
zone_(zone),
builder_(builder),
base_(body.base),
local_type_vec_(zone),
stack_(zone),
control_(zone),
......@@ -680,7 +679,6 @@ class WasmFullDecoder : public WasmDecoder {
Zone* zone_;
TFBuilder* builder_;
const byte* base_;
SsaEnv* ssa_env_;
......@@ -763,9 +761,9 @@ class WasmFullDecoder : public WasmDecoder {
// Decodes the body of a function.
void DecodeFunctionBody() {
TRACE("wasm-decode %p...%p (module+%d, %d bytes) %s\n",
reinterpret_cast<const void*>(start_),
reinterpret_cast<const void*>(end_), baserel(pc_),
TRACE("wasm-decode %p...%p (module+%u, %d bytes) %s\n",
reinterpret_cast<const void*>(start()),
reinterpret_cast<const void*>(end()), pc_offset(),
static_cast<int>(end_ - start_), builder_ ? "graph building" : "");
{
......@@ -1711,10 +1709,6 @@ class WasmFullDecoder : public WasmDecoder {
return val;
}
int baserel(const byte* ptr) {
return base_ ? static_cast<int>(ptr - base_) : 0;
}
int startrel(const byte* ptr) { return static_cast<int>(ptr - start_); }
void BreakTo(unsigned depth) {
......
......@@ -30,14 +30,14 @@ struct WasmModule; // forward declaration of module interface.
// A wrapper around the signature and bytes of a function.
struct FunctionBody {
FunctionSig* sig; // function signature
const byte* base; // base of the module bytes, for error reporting
uint32_t offset; // offset in the module bytes, for error reporting
const byte* start; // start of the function body
const byte* end; // end of the function body
};
static inline FunctionBody FunctionBodyForTesting(const byte* start,
const byte* end) {
return {nullptr, start, start, end};
return {nullptr, 0, start, end};
}
// A {DecodeResult} only stores the failure / success status, but no data. Thus
......@@ -60,14 +60,14 @@ void PrintRawWasmCode(const byte* start, const byte* end);
inline DecodeResult VerifyWasmCode(AccountingAllocator* allocator,
const WasmModule* module, FunctionSig* sig,
const byte* start, const byte* end) {
FunctionBody body = {sig, nullptr, start, end};
FunctionBody body = {sig, 0, start, end};
return VerifyWasmCode(allocator, module, body);
}
inline DecodeResult BuildTFGraph(AccountingAllocator* allocator,
TFBuilder* builder, FunctionSig* sig,
const byte* start, const byte* end) {
FunctionBody body = {sig, nullptr, start, end};
FunctionBody body = {sig, 0, start, end};
return BuildTFGraph(allocator, builder, body);
}
......
......@@ -328,7 +328,7 @@ void ModuleCompiler::ValidateSequentially(ModuleBytesEnv* module_env,
if (func.imported) continue;
const byte* base = module_env->wire_bytes.start();
FunctionBody body{func.sig, base, base + func.code.offset(),
FunctionBody body{func.sig, func.code.offset(), base + func.code.offset(),
base + func.code.end_offset()};
DecodeResult result = VerifyWasmCode(isolate_->allocator(),
module_env->module_env.module, body);
......
......@@ -945,7 +945,7 @@ class ModuleDecoder : public Decoder {
os << "Verifying wasm function " << func_name << std::endl;
}
FunctionBody body = {
function->sig, start_,
function->sig, function->code.offset(),
start_ + GetBufferRelativeOffset(function->code.offset()),
start_ + GetBufferRelativeOffset(function->code.end_offset())};
DecodeResult result = VerifyWasmCode(
......
......@@ -986,7 +986,7 @@ void LazyCompilationOrchestrator::CompileFunction(
&sig_tables);
uint8_t* module_start = compiled_module->module_bytes()->GetChars();
const WasmFunction* func = &module_env.module->functions[func_index];
wasm::FunctionBody body{func->sig, module_start,
wasm::FunctionBody body{func->sig, func->code.offset(),
module_start + func->code.offset(),
module_start + func->code.end_offset()};
// TODO(wasm): Refactor this to only get the name if it is really needed for
......
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