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