@@ -447,9 +447,9 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
447447
448448 void prepare () {
449449 // we need function types for all our functions
450- for (auto * func : wasm->functions ) {
450+ for (auto & func : wasm->functions ) {
451451 if (func->type .isNull ()) {
452- func->type = ensureFunctionType (getSig (func), wasm)->name ;
452+ func->type = ensureFunctionType (getSig (func. get () ), wasm)->name ;
453453 }
454454 }
455455 }
@@ -523,7 +523,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
523523 if (debug) std::cerr << " == writeSignatures" << std::endl;
524524 auto start = startSection (BinaryConsts::Section::Signatures);
525525 o << U32LEB (wasm->functionTypes .size ());
526- for (auto * type : wasm->functionTypes ) {
526+ for (auto & type : wasm->functionTypes ) {
527527 if (debug) std::cerr << " write one" << std::endl;
528528 o << int8_t (BinaryConsts::TypeForms::Basic);
529529 o << U32LEB (type->params .size ());
@@ -553,7 +553,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
553553 if (debug) std::cerr << " == writeImports" << std::endl;
554554 auto start = startSection (BinaryConsts::Section::ImportTable);
555555 o << U32LEB (wasm->imports .size ());
556- for (auto * import : wasm->imports ) {
556+ for (auto & import : wasm->imports ) {
557557 if (debug) std::cerr << " write one" << std::endl;
558558 o << U32LEB (getFunctionTypeIndex (import ->type ->name ));
559559 writeInlineString (import ->module .str );
@@ -606,7 +606,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
606606 if (debug) std::cerr << " == writeFunctionSignatures" << std::endl;
607607 auto start = startSection (BinaryConsts::Section::FunctionSignatures);
608608 o << U32LEB (wasm->functions .size ());
609- for (auto * curr : wasm->functions ) {
609+ for (auto & curr : wasm->functions ) {
610610 if (debug) std::cerr << " write one" << std::endl;
611611 o << U32LEB (getFunctionTypeIndex (curr->type ));
612612 }
@@ -623,7 +623,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
623623 if (debug) std::cerr << " write one at" << o.size () << std::endl;
624624 size_t sizePos = writeU32LEBPlaceholder ();
625625 size_t start = o.size ();
626- Function* function = wasm->functions [i] ;
626+ Function* function = wasm->getFunction (i) ;
627627 mappedLocals.clear ();
628628 numLocalsByType.clear ();
629629 if (debug) std::cerr << " writing" << function->name << std::endl;
@@ -654,7 +654,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
654654 if (debug) std::cerr << " == writeexports" << std::endl;
655655 auto start = startSection (BinaryConsts::Section::ExportTable);
656656 o << U32LEB (wasm->exports .size ());
657- for (auto * curr : wasm->exports ) {
657+ for (auto & curr : wasm->exports ) {
658658 if (debug) std::cerr << " write one" << std::endl;
659659 o << U32LEB (getFunctionIndex (curr->value ));
660660 writeInlineString (curr->name .str );
@@ -720,7 +720,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
720720 if (debug) std::cerr << " == writeNames" << std::endl;
721721 auto start = startSection (BinaryConsts::Section::Names);
722722 o << U32LEB (wasm->functions .size ());
723- for (auto * curr : wasm->functions ) {
723+ for (auto & curr : wasm->functions ) {
724724 writeInlineString (curr->name .str );
725725 o << U32LEB (0 ); // TODO: locals
726726 }
@@ -1354,7 +1354,7 @@ class WasmBinaryBuilder {
13541354 if (debug) std::cerr << " num: " << numTypes << std::endl;
13551355 for (size_t i = 0 ; i < numTypes; i++) {
13561356 if (debug) std::cerr << " read one" << std::endl;
1357- auto curr = allocator. alloc < FunctionType>() ;
1357+ auto curr = new FunctionType;
13581358 auto form = getInt8 ();
13591359 assert (form == BinaryConsts::TypeForms::Basic);
13601360 size_t numParams = getU32LEB ();
@@ -1379,11 +1379,11 @@ class WasmBinaryBuilder {
13791379 if (debug) std::cerr << " num: " << num << std::endl;
13801380 for (size_t i = 0 ; i < num; i++) {
13811381 if (debug) std::cerr << " read one" << std::endl;
1382- auto curr = allocator. alloc < Import>() ;
1382+ auto curr = new Import;
13831383 curr->name = Name (std::string (" import$" ) + std::to_string (i));
13841384 auto index = getU32LEB ();
13851385 assert (index < wasm.functionTypes .size ());
1386- curr->type = wasm.functionTypes [ index] ;
1386+ curr->type = wasm.getFunctionType ( index) ;
13871387 assert (curr->type ->name .is ());
13881388 curr->module = getInlineString ();
13891389 curr->base = getInlineString ();
@@ -1400,8 +1400,7 @@ class WasmBinaryBuilder {
14001400 for (size_t i = 0 ; i < num; i++) {
14011401 if (debug) std::cerr << " read one" << std::endl;
14021402 auto index = getU32LEB ();
1403- assert (index < wasm.functionTypes .size ());
1404- functionTypes.push_back (wasm.functionTypes [index]);
1403+ functionTypes.push_back (wasm.getFunctionType (index));
14051404 }
14061405 }
14071406
@@ -1481,7 +1480,7 @@ class WasmBinaryBuilder {
14811480 if (debug) std::cerr << " num: " << num << std::endl;
14821481 for (size_t i = 0 ; i < num; i++) {
14831482 if (debug) std::cerr << " read one" << std::endl;
1484- auto curr = allocator. alloc < Export>() ;
1483+ auto curr = new Export;
14851484 auto index = getU32LEB ();
14861485 assert (index < functionTypes.size ());
14871486 curr->name = getInlineString ();
@@ -1774,7 +1773,7 @@ class WasmBinaryBuilder {
17741773 void visitCallIndirect (CallIndirect *curr) {
17751774 if (debug) std::cerr << " zz node: CallIndirect" << std::endl;
17761775 auto arity = getU32LEB ();
1777- curr->fullType = wasm.functionTypes [ getU32LEB ()] ;
1776+ curr->fullType = wasm.getFunctionType ( getU32LEB ()) ;
17781777 auto num = curr->fullType ->params .size ();
17791778 assert (num == arity);
17801779 curr->operands .resize (num);
0 commit comments