diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-05-31 14:46:58 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-05-31 14:46:58 -0700 |
commit | 6c1baf1971adaf9f8a393943d4ba31d280e04e77 (patch) | |
tree | 10975f2fd6d3ba387f3395da7b9fa9bc212a6ce2 | |
parent | fa7573de6c3b17f831217e30745ea1092935eb54 (diff) | |
download | binaryen-6c1baf1971adaf9f8a393943d4ba31d280e04e77.tar.gz binaryen-6c1baf1971adaf9f8a393943d4ba31d280e04e77.tar.bz2 binaryen-6c1baf1971adaf9f8a393943d4ba31d280e04e77.zip |
handle duplicate exports in asm2wasm
-rw-r--r-- | src/asm2wasm.h | 15 | ||||
-rw-r--r-- | test/unit.asm.js | 9 | ||||
-rw-r--r-- | test/unit.fromasm | 1 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 1 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 7 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 7 |
6 files changed, 35 insertions, 5 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 2c78df2c0..4231fcc9a 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -660,6 +660,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { // exports Ref object = curr[1]; Ref contents = object[1]; + std::map<Name, Export*> exported; for (unsigned k = 0; k < contents->size(); k++) { Ref pair = contents[k]; IString key = pair[0]->getIString(); @@ -675,10 +676,16 @@ void Asm2WasmBuilder::processAsm(Ref ast) { getTempRet0 = value; } assert(wasm.checkFunction(value)); - auto export_ = new Export; - export_->name = key; - export_->value = value; - wasm.addExport(export_); + if (exported.count(key) > 0) { + // asm.js allows duplicate exports, but not wasm. use the last, like asm.js + exported[key]->value = value; + } else { + auto* export_ = new Export; + export_->name = key; + export_->value = value; + wasm.addExport(export_); + exported[key] = export_; + } } } } diff --git a/test/unit.asm.js b/test/unit.asm.js index 8fb28b990..5b958a111 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -227,6 +227,13 @@ function asm(global, env, buffer) { return 0; } + function forgetMe() { + 123.456; + } + function exportMe() { + -3.14159; + } + function z() { } function w() { @@ -236,6 +243,6 @@ function asm(global, env, buffer) { var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ]; var FUNCTION_TABLE_c = [ z, cneg ]; - return { big_negative: big_negative }; + return { big_negative: big_negative, pick: forgetMe, pick: exportMe }; } diff --git a/test/unit.fromasm b/test/unit.fromasm index 288b3af3b..7ee15cd05 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -11,6 +11,7 @@ (import $f64-to-int "asm2wasm" "f64-to-int" (param f64) (result i32)) (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) + (export "pick" $big_negative) (table $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 303a0cabf..293fc490a 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -9,6 +9,7 @@ (import $h "env" "h" (param i32)) (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) + (export "pick" $big_negative) (table $big_negative $big_negative $big_negative $big_negative $big_negative $big_negative $importedDoubles $big_negative $big_negative $cneg) (func $big_negative (nop) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 70f8d286b..2f7665622 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -9,6 +9,7 @@ (import $h "env" "h" (param i32)) (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) + (export "pick" $exportMe) (table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) @@ -686,6 +687,12 @@ (i32.const 0) ) ) + (func $forgetMe + (f64.const 123.456) + ) + (func $exportMe + (f64.const -3.14159) + ) (func $z (nop) ) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index 07311b00e..19c13f29f 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -11,6 +11,7 @@ (import $f64-to-int "asm2wasm" "f64-to-int" (param f64) (result i32)) (import $f64-rem "asm2wasm" "f64-rem" (param f64 f64) (result f64)) (export "big_negative" $big_negative) + (export "pick" $exportMe) (table $z $big_negative $z $z $w $w $importedDoubles $w $z $cneg) (func $big_negative (local $temp f64) @@ -690,6 +691,12 @@ (i32.const 0) ) ) + (func $forgetMe + (f64.const 123.456) + ) + (func $exportMe + (f64.const -3.14159) + ) (func $z (nop) ) |