[asm.js] Cleanup vector use in WasmModuleBuilder.

R=clemensh@chromium.org

Change-Id: Ifa9f0f510bc5b864ebba199603919adb6a35d3a1
Reviewed-on: https://chromium-review.googlesource.com/500267
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45190}
This commit is contained in:
Michael Starzinger 2017-05-09 11:39:09 +02:00 committed by Commit Bot
parent 17d1530d21
commit d40c6abd17
3 changed files with 12 additions and 16 deletions

View File

@ -365,8 +365,7 @@ void AsmJsParser::ValidateModule() {
module_builder_->MarkStartFunction(start); module_builder_->MarkStartFunction(start);
for (auto& global_import : global_imports_) { for (auto& global_import : global_imports_) {
uint32_t import_index = module_builder_->AddGlobalImport( uint32_t import_index = module_builder_->AddGlobalImport(
global_import.import_name.start(), global_import.import_name.length(), global_import.import_name, global_import.value_type);
global_import.value_type);
start->EmitWithI32V(kExprGetGlobal, import_index); start->EmitWithI32V(kExprGetGlobal, import_index);
start->EmitWithI32V(kExprSetGlobal, VarIndex(global_import.var_info)); start->EmitWithI32V(kExprSetGlobal, VarIndex(global_import.var_info));
} }
@ -2150,9 +2149,8 @@ AsmType* AsmJsParser::ValidateCall() {
if (it != function_info->import->cache.end()) { if (it != function_info->import->cache.end()) {
index = it->second; index = it->second;
} else { } else {
index = module_builder_->AddImport( index =
function_info->import->function_name.start(), module_builder_->AddImport(function_info->import->function_name, sig);
function_info->import->function_name.length(), sig);
function_info->import->cache[sig] = index; function_info->import->cache[sig] = index;
} }
current_function_builder_->AddAsmWasmOffset(call_pos, to_number_pos); current_function_builder_->AddAsmWasmOffset(call_pos, to_number_pos);

View File

@ -308,16 +308,16 @@ void WasmModuleBuilder::SetIndirectFunction(uint32_t indirect,
indirect_functions_[indirect] = direct; indirect_functions_[indirect] = direct;
} }
uint32_t WasmModuleBuilder::AddImport(const char* name, int name_length, uint32_t WasmModuleBuilder::AddImport(Vector<const char> name,
FunctionSig* sig) { FunctionSig* sig) {
function_imports_.push_back({AddSignature(sig), name, name_length}); function_imports_.push_back({AddSignature(sig), name.start(), name.length()});
return static_cast<uint32_t>(function_imports_.size() - 1); return static_cast<uint32_t>(function_imports_.size() - 1);
} }
uint32_t WasmModuleBuilder::AddGlobalImport(const char* name, int name_length, uint32_t WasmModuleBuilder::AddGlobalImport(Vector<const char> name,
ValueType type) { ValueType type) {
global_imports_.push_back( global_imports_.push_back(
{WasmOpcodes::ValueTypeCodeFor(type), name, name_length}); {WasmOpcodes::ValueTypeCodeFor(type), name.start(), name.length()});
return static_cast<uint32_t>(global_imports_.size() - 1); return static_cast<uint32_t>(global_imports_.size() - 1);
} }

View File

@ -260,17 +260,15 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
explicit WasmModuleBuilder(Zone* zone); explicit WasmModuleBuilder(Zone* zone);
// Building methods. // Building methods.
// TODO(mstarzinger): Refactor to take Vector<const char> instead. uint32_t AddImport(Vector<const char> name, FunctionSig* sig);
uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); void SetImportName(uint32_t index, Vector<const char> name) {
void SetImportName(uint32_t index, const char* name, int name_length) { function_imports_[index].name = name.start();
function_imports_[index].name = name; function_imports_[index].name_length = name.length();
function_imports_[index].name_length = name_length;
} }
WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr);
uint32_t AddGlobal(ValueType type, bool exported, bool mutability = true, uint32_t AddGlobal(ValueType type, bool exported, bool mutability = true,
const WasmInitExpr& init = WasmInitExpr()); const WasmInitExpr& init = WasmInitExpr());
// TODO(mstarzinger): Refactor to take Vector<const char> instead. uint32_t AddGlobalImport(Vector<const char> name, ValueType type);
uint32_t AddGlobalImport(const char* name, int name_length, ValueType type);
void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); void AddDataSegment(const byte* data, uint32_t size, uint32_t dest);
uint32_t AddSignature(FunctionSig* sig); uint32_t AddSignature(FunctionSig* sig);
uint32_t AllocateIndirectFunctions(uint32_t count); uint32_t AllocateIndirectFunctions(uint32_t count);