Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: src/wasm/wasm-module-builder.cc

Issue 2535723009: [wasm][asm.js] Allow a function to be exported more than once. (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module-builder.cc
diff --git a/src/wasm/wasm-module-builder.cc b/src/wasm/wasm-module-builder.cc
index 4bc569a68ca7d2f8045304944a02fddbe17dc673..111b90ba372ea58766a930587088ab02eefad28c 100644
--- a/src/wasm/wasm-module-builder.cc
+++ b/src/wasm/wasm-module-builder.cc
@@ -50,11 +50,10 @@ WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder)
: builder_(builder),
locals_(builder->zone()),
signature_index_(0),
- exported_(0),
func_index_(static_cast<uint32_t>(builder->functions_.size())),
body_(builder->zone()),
name_(builder->zone()),
- exported_name_(builder->zone()),
+ exported_names_(builder->zone()),
i32_temps_(builder->zone()),
i64_temps_(builder->zone()),
f32_temps_(builder->zone()),
@@ -141,12 +140,9 @@ void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) {
EmitCode(code, sizeof(code));
}
-void WasmFunctionBuilder::Export() { exported_ = true; }
-
void WasmFunctionBuilder::ExportAs(Vector<const char> name) {
- exported_ = true;
- exported_name_.resize(name.length());
- memcpy(exported_name_.data(), name.start(), name.length());
+ exported_names_.push_back(ZoneVector<char>(
+ name.start(), name.start() + name.length(), builder_->zone()));
}
void WasmFunctionBuilder::SetName(Vector<const char> name) {
@@ -172,13 +168,10 @@ void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const {
buffer.write_u32v(signature_index_);
}
-void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const {
- if (exported_) {
- const ZoneVector<char>* exported_name =
- exported_name_.size() == 0 ? &name_ : &exported_name_;
- buffer.write_size(exported_name->size());
- buffer.write(reinterpret_cast<const byte*>(exported_name->data()),
- exported_name->size());
+void WasmFunctionBuilder::WriteExports(ZoneBuffer& buffer) const {
+ for (auto name : exported_names_) {
+ buffer.write_size(name.size());
+ buffer.write(reinterpret_cast<const byte*>(name.data()), name.size());
buffer.write_u8(kExternalFunction);
buffer.write_u32v(func_index_ +
static_cast<uint32_t>(builder_->imports_.size()));
@@ -348,7 +341,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
buffer.write_size(functions_.size());
for (auto function : functions_) {
function->WriteSignature(buffer);
- if (function->exported()) exports++;
+ exports += function->exported_names_.size();
if (function->name_.size() > 0) has_names = true;
}
FixupSection(buffer, start);
@@ -451,7 +444,7 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
if (exports > 0) {
size_t start = EmitSection(kExportSectionCode, buffer);
buffer.write_u32v(exports);
- for (auto function : functions_) function->WriteExport(buffer);
+ for (auto function : functions_) function->WriteExports(buffer);
FixupSection(buffer, start);
}
@@ -524,10 +517,8 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
}
for (auto function : functions_) {
buffer.write_size(function->name_.size());
- if (function->name_.size() > 0) {
- buffer.write(reinterpret_cast<const byte*>(&function->name_[0]),
- function->name_.size());
- }
+ buffer.write(reinterpret_cast<const byte*>(function->name_.data()),
+ function->name_.size());
buffer.write_u8(0);
}
FixupSection(buffer, start);
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698