Commit a71f40de authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm][cleanup] Rename fields and methods for function names

Just a refactoring to make clear that we are talking about function
names. Note that there are also names for locals inside functions,
which we currently don't use.

Drive-by: Remove style-guide violation by {WasmModule::names_} field.

R=mstarzinger@chromium.org

Bug: v8:7754
Change-Id: I9c47ea01893f128e1716be01032adfaf006ae28a
Reviewed-on: https://chromium-review.googlesource.com/1118271Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54105}
parent 88b53ab5
......@@ -385,7 +385,7 @@ wasm::WasmCode* LazyCompileFunction(Isolate* isolate,
{
ModuleWireBytes wire_bytes(native_module->wire_bytes());
WireBytesRef name_ref =
module_env->module->LookupName(wire_bytes, func_index);
module_env->module->LookupFunctionName(wire_bytes, func_index);
func_name = wire_bytes.GetName(name_ref);
}
......@@ -1997,7 +1997,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
MaybeHandle<String> func_name;
if (is_asm_js) {
// For modules arising from asm.js, honor the names section.
WireBytesRef func_name_ref = module_->LookupName(
WireBytesRef func_name_ref = module_->LookupFunctionName(
module_object_->native_module()->wire_bytes(),
function.func_index);
func_name = WasmModuleObject::ExtractUtf8StringFromModuleBytes(
......@@ -2182,8 +2182,8 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) {
MaybeHandle<String> func_name;
if (module_->origin == kAsmJsOrigin) {
// For modules arising from asm.js, honor the names section.
WireBytesRef func_name_ref =
module_->LookupName(native_module->wire_bytes(), func_index);
WireBytesRef func_name_ref = module_->LookupFunctionName(
native_module->wire_bytes(), func_index);
func_name = WasmModuleObject::ExtractUtf8StringFromModuleBytes(
isolate_, module_object_, func_name_ref)
.ToHandleChecked();
......
......@@ -144,7 +144,8 @@ void WasmCode::LogCode(Isolate* isolate) const {
ModuleWireBytes wire_bytes(native_module()->wire_bytes());
// TODO(herhut): Allow to log code without on-heap round-trip of the name.
ModuleEnv* module_env = GetModuleEnv(native_module()->compilation_state());
WireBytesRef name_ref = module_env->module->LookupName(wire_bytes, index());
WireBytesRef name_ref =
module_env->module->LookupFunctionName(wire_bytes, index());
WasmName name_vec = wire_bytes.GetName(name_ref);
MaybeHandle<String> maybe_name =
isolate->factory()->NewStringFromUtf8(Vector<const char>::cast(name_vec));
......
......@@ -35,51 +35,52 @@ constexpr const char* WasmException::kRuntimeIdStr;
// static
constexpr const char* WasmException::kRuntimeValuesStr;
WireBytesRef WasmModule::LookupName(const ModuleWireBytes& wire_bytes,
uint32_t function_index) const {
if (!names_) {
names_.reset(new std::unordered_map<uint32_t, WireBytesRef>());
WireBytesRef WasmModule::LookupFunctionName(const ModuleWireBytes& wire_bytes,
uint32_t function_index) const {
if (!function_names) {
function_names.reset(new std::unordered_map<uint32_t, WireBytesRef>());
wasm::DecodeFunctionNames(wire_bytes.start(), wire_bytes.end(),
names_.get());
function_names.get());
}
auto it = names_->find(function_index);
if (it == names_->end()) return WireBytesRef();
auto it = function_names->find(function_index);
if (it == function_names->end()) return WireBytesRef();
return it->second;
}
void WasmModule::AddNameForTesting(int function_index, WireBytesRef name) {
if (!names_) {
names_.reset(new std::unordered_map<uint32_t, WireBytesRef>());
void WasmModule::AddFunctionNameForTesting(int function_index,
WireBytesRef name) {
if (!function_names) {
function_names.reset(new std::unordered_map<uint32_t, WireBytesRef>());
}
names_->insert(std::make_pair(function_index, name));
function_names->insert(std::make_pair(function_index, name));
}
// Get a string stored in the module bytes representing a name.
WasmName ModuleWireBytes::GetName(WireBytesRef ref) const {
if (ref.is_empty()) return {"<?>", 3}; // no name.
CHECK(BoundsCheck(ref.offset(), ref.length()));
return Vector<const char>::cast(
return WasmName::cast(
module_bytes_.SubVector(ref.offset(), ref.end_offset()));
}
// Get a string stored in the module bytes representing a function name.
WasmName ModuleWireBytes::GetName(const WasmFunction* function,
const WasmModule* module) const {
return GetName(module->LookupName(*this, function->func_index));
return GetName(module->LookupFunctionName(*this, function->func_index));
}
// Get a string stored in the module bytes representing a name.
WasmName ModuleWireBytes::GetNameOrNull(WireBytesRef ref) const {
if (!ref.is_set()) return {nullptr, 0}; // no name.
CHECK(BoundsCheck(ref.offset(), ref.length()));
return Vector<const char>::cast(
return WasmName::cast(
module_bytes_.SubVector(ref.offset(), ref.end_offset()));
}
// Get a string stored in the module bytes representing a function name.
WasmName ModuleWireBytes::GetNameOrNull(const WasmFunction* function,
const WasmModule* module) const {
return GetNameOrNull(module->LookupName(*this, function->func_index));
return GetNameOrNull(module->LookupFunctionName(*this, function->func_index));
}
std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name) {
......
......@@ -154,14 +154,15 @@ struct V8_EXPORT_PRIVATE WasmModule {
SignatureMap signature_map; // canonicalizing map for signature indexes.
ModuleOrigin origin = kWasmOrigin; // origin of the module
mutable std::unique_ptr<std::unordered_map<uint32_t, WireBytesRef>> names_;
mutable std::unique_ptr<std::unordered_map<uint32_t, WireBytesRef>>
function_names;
WasmModule() : WasmModule(nullptr) {}
WasmModule(std::unique_ptr<Zone> owned);
WireBytesRef LookupName(const ModuleWireBytes& wire_bytes,
uint32_t function_index) const;
void AddNameForTesting(int function_index, WireBytesRef name);
WireBytesRef LookupFunctionName(const ModuleWireBytes& wire_bytes,
uint32_t function_index) const;
void AddFunctionNameForTesting(int function_index, WireBytesRef name);
};
size_t EstimateWasmModuleSize(const WasmModule* module);
......
......@@ -643,7 +643,7 @@ MaybeHandle<String> WasmModuleObject::GetFunctionNameOrNull(
Isolate* isolate, Handle<WasmModuleObject> module_object,
uint32_t func_index) {
DCHECK_LT(func_index, module_object->module()->functions.size());
wasm::WireBytesRef name = module_object->module()->LookupName(
wasm::WireBytesRef name = module_object->module()->LookupFunctionName(
wasm::ModuleWireBytes(module_object->native_module()->wire_bytes()),
func_index);
if (!name.is_set()) return {};
......@@ -663,7 +663,8 @@ Vector<const uint8_t> WasmModuleObject::GetRawFunctionName(
uint32_t func_index) {
DCHECK_GT(module()->functions.size(), func_index);
wasm::ModuleWireBytes wire_bytes(native_module()->wire_bytes());
wasm::WireBytesRef name_ref = module()->LookupName(wire_bytes, func_index);
wasm::WireBytesRef name_ref =
module()->LookupFunctionName(wire_bytes, func_index);
wasm::WasmName name = wire_bytes.GetName(name_ref);
return Vector<const uint8_t>::cast(name);
}
......
......@@ -109,7 +109,7 @@ uint32_t TestingModuleBuilder::AddFunction(FunctionSig* sig, const char* name,
test_module_->num_declared_functions);
if (name) {
Vector<const byte> name_vec = Vector<const byte>::cast(CStrVector(name));
test_module_->AddNameForTesting(
test_module_->AddFunctionNameForTesting(
index, {AddBytes(name_vec), static_cast<uint32_t>(name_vec.length())});
}
if (interpreter_) {
......@@ -410,7 +410,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
memcpy(func_wire_bytes.start(), wire_bytes.start() + function_->code.offset(),
func_wire_bytes.length());
WireBytesRef func_name_ref =
module_env.module->LookupName(wire_bytes, function_->func_index);
module_env.module->LookupFunctionName(wire_bytes, function_->func_index);
ScopedVector<char> func_name(func_name_ref.length());
memcpy(func_name.start(), wire_bytes.start() + func_name_ref.offset(),
func_name_ref.length());
......
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