Commit af9e4c33 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Replace WasmName by Vector<const char>

R=titzer@chromium.org

Review URL: https://codereview.chromium.org/1910213004

Cr-Commit-Position: refs/heads/master@{#35796}
parent c32b2020
...@@ -2680,8 +2680,8 @@ static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, ...@@ -2680,8 +2680,8 @@ static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
if (isolate->logger()->is_logging_code_events() || if (isolate->logger()->is_logging_code_events() ||
isolate->cpu_profiler()->is_profiling()) { isolate->cpu_profiler()->is_profiling()) {
ScopedVector<char> buffer(128); ScopedVector<char> buffer(128);
SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length, SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length(),
func_name.name); func_name.start());
Handle<String> name_str = Handle<String> name_str =
isolate->factory()->NewStringFromAsciiChecked(buffer.start()); isolate->factory()->NewStringFromAsciiChecked(buffer.start());
Handle<String> script_str = Handle<String> script_str =
...@@ -2896,7 +2896,7 @@ std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction( ...@@ -2896,7 +2896,7 @@ std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
wasm::WasmName name = wasm::WasmName name =
module_env->module->GetName(function.name_offset, function.name_length); module_env->module->GetName(function.name_offset, function.name_length);
SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:",
function.func_index, name.length, name.name); function.func_index, name.length(), name.start());
thrower.Failed(buffer.start(), result); thrower.Failed(buffer.start(), result);
return std::make_pair(nullptr, nullptr); return std::make_pair(nullptr, nullptr);
} }
...@@ -2955,10 +2955,8 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, ...@@ -2955,10 +2955,8 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
#else #else
FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
#endif #endif
Vector<const char> func_name = Vector<const char> func_name = module_env->module->GetNameOrNull(
module_env->module function.name_offset, function.name_length);
->GetNameOrNull(function.name_offset, function.name_length)
.toVec();
Vector<char> buffer; Vector<char> buffer;
if (func_name.is_empty()) { if (func_name.is_empty()) {
if (debugging) { if (debugging) {
......
...@@ -103,7 +103,7 @@ std::ostream& operator<<(std::ostream& os, const WasmFunctionName& pair) { ...@@ -103,7 +103,7 @@ std::ostream& operator<<(std::ostream& os, const WasmFunctionName& pair) {
if (pair.module_) { if (pair.module_) {
WasmName name = pair.module_->GetName(pair.function_->name_offset, WasmName name = pair.module_->GetName(pair.function_->name_offset,
pair.function_->name_length); pair.function_->name_length);
os.write(name.name, name.length); os.write(name.start(), name.length());
} else { } else {
os << "+" << pair.function_->func_index; os << "+" << pair.function_->func_index;
} }
...@@ -337,13 +337,13 @@ static MaybeHandle<JSFunction> ReportFFIError(ErrorThrower& thrower, ...@@ -337,13 +337,13 @@ static MaybeHandle<JSFunction> ReportFFIError(ErrorThrower& thrower,
const char* error, uint32_t index, const char* error, uint32_t index,
wasm::WasmName module_name, wasm::WasmName module_name,
wasm::WasmName function_name) { wasm::WasmName function_name) {
if (function_name.name) { if (function_name.start()) {
thrower.Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", thrower.Error("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s",
index, module_name.length, module_name.name, index, module_name.length(), module_name.start(),
function_name.length, function_name.name, error); function_name.length(), function_name.start(), error);
} else { } else {
thrower.Error("Import #%d module=\"%.*s\" error: %s", index, thrower.Error("Import #%d module=\"%.*s\" error: %s", index,
module_name.length, module_name.name, error); module_name.length(), module_name.start(), error);
} }
thrower.Error("Import "); thrower.Error("Import ");
return MaybeHandle<JSFunction>(); return MaybeHandle<JSFunction>();
...@@ -358,8 +358,7 @@ static MaybeHandle<JSFunction> LookupFunction( ...@@ -358,8 +358,7 @@ static MaybeHandle<JSFunction> LookupFunction(
} }
// Look up the module first. // Look up the module first.
Handle<String> name = factory->InternalizeUtf8String( Handle<String> name = factory->InternalizeUtf8String(module_name);
Vector<const char>(module_name.name, module_name.length));
MaybeHandle<Object> result = Object::GetProperty(ffi, name); MaybeHandle<Object> result = Object::GetProperty(ffi, name);
if (result.is_null()) { if (result.is_null()) {
return ReportFFIError(thrower, "module not found", index, module_name, return ReportFFIError(thrower, "module not found", index, module_name,
...@@ -374,10 +373,9 @@ static MaybeHandle<JSFunction> LookupFunction( ...@@ -374,10 +373,9 @@ static MaybeHandle<JSFunction> LookupFunction(
} }
Handle<Object> function; Handle<Object> function;
if (function_name.name) { if (function_name.start()) {
// Look up the function in the module. // Look up the function in the module.
Handle<String> name = factory->InternalizeUtf8String( Handle<String> name = factory->InternalizeUtf8String(function_name);
Vector<const char>(function_name.name, function_name.length));
MaybeHandle<Object> result = Object::GetProperty(module, name); MaybeHandle<Object> result = Object::GetProperty(module, name);
if (result.is_null()) { if (result.is_null()) {
return ReportFFIError(thrower, "function not found", index, module_name, return ReportFFIError(thrower, "function not found", index, module_name,
...@@ -502,8 +500,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -502,8 +500,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
WasmName str = GetName(func.name_offset, func.name_length); WasmName str = GetName(func.name_offset, func.name_length);
WasmName str_null = {nullptr, 0}; WasmName str_null = {nullptr, 0};
Handle<String> name = factory->InternalizeUtf8String( Handle<String> name = factory->InternalizeUtf8String(str);
Vector<const char>(str.name, str.length));
Handle<Code> code = Handle<Code>::null(); Handle<Code> code = Handle<Code>::null();
Handle<JSFunction> function = Handle<JSFunction>::null(); Handle<JSFunction> function = Handle<JSFunction>::null();
if (func.external) { if (func.external) {
...@@ -519,8 +516,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -519,8 +516,8 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
code = code =
compiler::CompileWasmFunction(thrower, isolate, &module_env, func); compiler::CompileWasmFunction(thrower, isolate, &module_env, func);
if (code.is_null()) { if (code.is_null()) {
thrower.Error("Compilation of #%d:%.*s failed.", index, str.length, thrower.Error("Compilation of #%d:%.*s failed.", index, str.length(),
str.name); str.start());
return MaybeHandle<JSObject>(); return MaybeHandle<JSObject>();
} }
if (func.exported) { if (func.exported) {
...@@ -564,8 +561,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -564,8 +561,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
for (const WasmExport& exp : export_table) { for (const WasmExport& exp : export_table) {
if (thrower.error()) break; if (thrower.error()) break;
WasmName str = GetName(exp.name_offset, exp.name_length); WasmName str = GetName(exp.name_offset, exp.name_length);
Handle<String> name = factory->InternalizeUtf8String( Handle<String> name = factory->InternalizeUtf8String(str);
Vector<const char>(str.name, str.length));
Handle<Code> code = linker.GetFunctionCode(exp.func_index); Handle<Code> code = linker.GetFunctionCode(exp.func_index);
Handle<JSFunction> function = compiler::CompileJSToWasmWrapper( Handle<JSFunction> function = compiler::CompileJSToWasmWrapper(
isolate, &module_env, name, code, instance.js_object, isolate, &module_env, name, code, instance.js_object,
......
...@@ -193,14 +193,18 @@ struct WasmModule { ...@@ -193,14 +193,18 @@ struct WasmModule {
WasmName GetName(uint32_t offset, uint32_t length) const { WasmName GetName(uint32_t offset, uint32_t length) const {
if (length == 0) return {"<?>", 3}; // no name. if (length == 0) return {"<?>", 3}; // no name.
CHECK(BoundsCheck(offset, offset + length)); CHECK(BoundsCheck(offset, offset + length));
return {reinterpret_cast<const char*>(module_start + offset), length}; DCHECK_GE(static_cast<int>(length), 0);
return {reinterpret_cast<const char*>(module_start + offset),
static_cast<int>(length)};
} }
// Get a string stored in the module bytes representing a name. // Get a string stored in the module bytes representing a name.
WasmName GetNameOrNull(uint32_t offset, uint32_t length) const { WasmName GetNameOrNull(uint32_t offset, uint32_t length) const {
if (length == 0) return {NULL, 0}; // no name. if (length == 0) return {NULL, 0}; // no name.
CHECK(BoundsCheck(offset, offset + length)); CHECK(BoundsCheck(offset, offset + length));
return {reinterpret_cast<const char*>(module_start + offset), length}; DCHECK_GE(static_cast<int>(length), 0);
return {reinterpret_cast<const char*>(module_start + offset),
static_cast<int>(length)};
} }
// Checks the given offset range is contained within the module bytes. // Checks the given offset range is contained within the module bytes.
......
...@@ -49,14 +49,7 @@ const LocalType kAstEnd = MachineRepresentation::kTagged; ...@@ -49,14 +49,7 @@ const LocalType kAstEnd = MachineRepresentation::kTagged;
typedef Signature<LocalType> FunctionSig; typedef Signature<LocalType> FunctionSig;
std::ostream& operator<<(std::ostream& os, const FunctionSig& function); std::ostream& operator<<(std::ostream& os, const FunctionSig& function);
struct WasmName { typedef Vector<const char> WasmName;
const char* name;
uint32_t length;
// TODO(clemensh): Remove whole WasmName, replace by Vector<const char>
inline Vector<const char> toVec() const {
return Vector<const char>(name, length);
}
};
// TODO(titzer): Renumber all the opcodes to fill in holes. // TODO(titzer): Renumber all the opcodes to fill in holes.
......
...@@ -179,8 +179,8 @@ class TestingModule : public ModuleEnv { ...@@ -179,8 +179,8 @@ class TestingModule : public ModuleEnv {
*v8::Local<v8::Function>::Cast(CompileRun(source)))); *v8::Local<v8::Function>::Cast(CompileRun(source))));
uint32_t index = AddFunction(sig, Handle<Code>::null()); uint32_t index = AddFunction(sig, Handle<Code>::null());
Isolate* isolate = module->shared_isolate; Isolate* isolate = module->shared_isolate;
WasmName module_name = {"test", 4}; WasmName module_name = ArrayVector("test");
WasmName function_name = {nullptr, 0}; WasmName function_name;
Handle<Code> code = CompileWasmToJSWrapper(isolate, this, jsfunc, sig, Handle<Code> code = CompileWasmToJSWrapper(isolate, this, jsfunc, sig,
module_name, function_name); module_name, function_name);
instance->function_code[index] = code; instance->function_code[index] = code;
......
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