1717#include < algorithm>
1818#include < fstream>
1919
20- #include " ir/module-utils.h"
2120#include " support/bits.h"
2221#include " wasm-binary.h"
2322#include " wasm-stack.h"
@@ -34,11 +33,6 @@ void WasmBinaryWriter::prepare() {
3433 // https://github.com/WebAssembly/spec/pull/301 might want this:
3534 // assert(!func->type.isNull());
3635 }
37- ModuleUtils::BinaryIndexes indexes (*wasm);
38- mappedFunctions = std::move (indexes.functionIndexes );
39- mappedGlobals = std::move (indexes.globalIndexes );
40- mappedEvents = std::move (indexes.eventIndexes );
41-
4236 importInfo = wasm::make_unique<ImportInfo>(*wasm);
4337}
4438
@@ -458,18 +452,18 @@ void WasmBinaryWriter::writeDataSegments() {
458452}
459453
460454uint32_t WasmBinaryWriter::getFunctionIndex (Name name) {
461- assert (mappedFunctions .count (name));
462- return mappedFunctions [name];
455+ assert (indexes. functionIndexes .count (name));
456+ return indexes. functionIndexes [name];
463457}
464458
465459uint32_t WasmBinaryWriter::getGlobalIndex (Name name) {
466- assert (mappedGlobals .count (name));
467- return mappedGlobals [name];
460+ assert (indexes. globalIndexes .count (name));
461+ return indexes. globalIndexes [name];
468462}
469463
470464uint32_t WasmBinaryWriter::getEventIndex (Name name) {
471- assert (mappedEvents .count (name));
472- return mappedEvents [name];
465+ assert (indexes. eventIndexes .count (name));
466+ return indexes. eventIndexes [name];
473467}
474468
475469void WasmBinaryWriter::writeFunctionTableDeclaration () {
@@ -534,22 +528,18 @@ void WasmBinaryWriter::writeEvents() {
534528}
535529
536530void WasmBinaryWriter::writeNames () {
537- bool hasContents = false ;
538- if (wasm->functions .size () > 0 ) {
539- hasContents = true ;
540- getFunctionIndex (wasm->functions [0 ]->name ); // generate mappedFunctions
541- }
542- if (!hasContents) {
531+ if (wasm->functions .empty ()) {
543532 return ;
544533 }
534+
545535 if (debug) {
546536 std::cerr << " == writeNames" << std::endl;
547537 }
548538 auto start = startSection (BinaryConsts::Section::User);
549539 writeInlineString (BinaryConsts::UserSections::Name);
550540 auto substart =
551541 startSubsection (BinaryConsts::UserSections::Subsection::NameFunction);
552- o << U32LEB (mappedFunctions .size ());
542+ o << U32LEB (indexes. functionIndexes .size ());
553543 Index emitted = 0 ;
554544 auto add = [&](Function* curr) {
555545 o << U32LEB (emitted);
@@ -558,7 +548,7 @@ void WasmBinaryWriter::writeNames() {
558548 };
559549 ModuleUtils::iterImportedFunctions (*wasm, add);
560550 ModuleUtils::iterDefinedFunctions (*wasm, add);
561- assert (emitted == mappedFunctions .size ());
551+ assert (emitted == indexes. functionIndexes .size ());
562552 finishSubsection (substart);
563553 /* TODO: locals */
564554 finishSection (start);
0 commit comments