summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-12-08 11:26:28 -0800
committerGitHub <noreply@github.com>2017-12-08 11:26:28 -0800
commit1d0fa771b97a39ce487a202db4785c78a4c5ba29 (patch)
tree7796a1dc2530b2c9634e567cfde792e8635c23b6
parent9c51f2b51ecc57dfad1478bbc6932ec2795b1374 (diff)
downloadbinaryen-1d0fa771b97a39ce487a202db4785c78a4c5ba29.tar.gz
binaryen-1d0fa771b97a39ce487a202db4785c78a4c5ba29.tar.bz2
binaryen-1d0fa771b97a39ce487a202db4785c78a4c5ba29.zip
allow exporting an import (#1326)
-rw-r--r--src/wasm/wasm-validator.cpp15
-rw-r--r--test/export-import.wast8
-rw-r--r--test/export-import.wast.from-wast9
-rw-r--r--test/export-import.wast.fromBinary10
-rw-r--r--test/export-import.wast.fromBinary.noDebugInfo10
5 files changed, 43 insertions, 9 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index ef70cc9e7..df88a5f32 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -926,16 +926,13 @@ static void validateExports(Module& module, ValidationInfo& info) {
for (auto& exp : module.exports) {
Name name = exp->value;
if (exp->kind == ExternalKind::Function) {
- bool found = false;
- for (auto& func : module.functions) {
- if (func->name == name) {
- found = true;
- break;
- }
- }
- info.shouldBeTrue(found, name, "module function exports must be found");
+ Import* imp;
+ info.shouldBeTrue(module.getFunctionOrNull(name) ||
+ ((imp = module.getImportOrNull(name)) && imp->kind == ExternalKind::Function), name, "module function exports must be found");
} else if (exp->kind == ExternalKind::Global) {
- info.shouldBeTrue(module.getGlobalOrNull(name), name, "module global exports must be found");
+ Import* imp;
+ info.shouldBeTrue(module.getGlobalOrNull(name) ||
+ ((imp = module.getImportOrNull(name)) && imp->kind == ExternalKind::Global), name, "module global exports must be found");
} else if (exp->kind == ExternalKind::Table) {
info.shouldBeTrue(name == Name("0") || name == module.table.name, name, "module table exports must be found");
} else if (exp->kind == ExternalKind::Memory) {
diff --git a/test/export-import.wast b/test/export-import.wast
new file mode 100644
index 000000000..5dc2185c6
--- /dev/null
+++ b/test/export-import.wast
@@ -0,0 +1,8 @@
+(module
+ (type $v (func))
+ (import "env" "test1" (func $test1))
+ (import "env" "test2" (global $test2 i32))
+ (export "test1" (func $test1))
+ (export "test2" (global $test2))
+)
+
diff --git a/test/export-import.wast.from-wast b/test/export-import.wast.from-wast
new file mode 100644
index 000000000..3675ae243
--- /dev/null
+++ b/test/export-import.wast.from-wast
@@ -0,0 +1,9 @@
+(module
+ (type $v (func))
+ (type $FUNCSIG$v (func))
+ (import "env" "test1" (func $test1))
+ (import "env" "test2" (global $test2 i32))
+ (memory $0 0)
+ (export "test1" (func $test1))
+ (export "test2" (global $test2))
+)
diff --git a/test/export-import.wast.fromBinary b/test/export-import.wast.fromBinary
new file mode 100644
index 000000000..468498a94
--- /dev/null
+++ b/test/export-import.wast.fromBinary
@@ -0,0 +1,10 @@
+(module
+ (type $0 (func))
+ (type $1 (func))
+ (import "env" "test2" (global $import$1 i32))
+ (import "env" "test1" (func $test1))
+ (memory $0 0)
+ (export "test1" (func $test1))
+ (export "test2" (global $import$1))
+)
+
diff --git a/test/export-import.wast.fromBinary.noDebugInfo b/test/export-import.wast.fromBinary.noDebugInfo
new file mode 100644
index 000000000..562a51cc6
--- /dev/null
+++ b/test/export-import.wast.fromBinary.noDebugInfo
@@ -0,0 +1,10 @@
+(module
+ (type $0 (func))
+ (type $1 (func))
+ (import "env" "test2" (global $import$1 i32))
+ (import "env" "test1" (func $import$0))
+ (memory $0 0)
+ (export "test1" (func $import$0))
+ (export "test2" (global $import$1))
+)
+