summaryrefslogtreecommitdiff
path: root/test/binaryen.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-06-13 21:04:50 -0700
committerGitHub <noreply@github.com>2017-06-13 21:04:50 -0700
commit8aa91ecb38cc7beaec1f56982e25bb2833cbab39 (patch)
treeb78372abf8fa7740ae65541ec9ae3fcb27c5fb1e /test/binaryen.js
parentb5b40c9ab0c35ed74e97a6491e15651382091b2e (diff)
downloadbinaryen-8aa91ecb38cc7beaec1f56982e25bb2833cbab39.tar.gz
binaryen-8aa91ecb38cc7beaec1f56982e25bb2833cbab39.tar.bz2
binaryen-8aa91ecb38cc7beaec1f56982e25bb2833cbab39.zip
S-expression parsing in C API and binaryen.js (#1050)
* add C API and binaryen.js support for parsing s-expressions * update js builds and tests
Diffstat (limited to 'test/binaryen.js')
-rw-r--r--test/binaryen.js/kitchen-sink.js25
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt30
2 files changed, 49 insertions, 6 deletions
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index 773757ff0..3d0615378 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -494,6 +494,30 @@ function test_tracing() {
Binaryen.setAPITracing(0);
}
+function test_parsing() {
+ var text;
+
+ // create a module and write it to text
+ module = new Binaryen.Module();
+ var iii = module.addFunctionType("iii", Binaryen.i32, [ Binaryen.i32, Binaryen.i32 ]);
+ var x = module.getLocal(0, Binaryen.i32),
+ y = module.getLocal(1, Binaryen.i32);
+ var add = module.i32.add(x, y);
+ var adder = module.addFunction("adder", iii, [], add);
+ text = module.emitText();
+ module.dispose();
+ module = null;
+ print('test_parsing text:\n' + text);
+
+ text = text.replace('adder', 'ADD_ER');
+
+ var module2 = Binaryen.parseText(text);
+ assert(module2.validate());
+ console.log("module loaded from text form:");
+ console.log(module2.emitText());
+ module2.dispose();
+}
+
function main() {
test_types();
test_core();
@@ -502,6 +526,7 @@ function main() {
test_interpret();
test_nonvalid();
test_tracing();
+ test_parsing();
}
main();
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index c70888508..02109919f 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -1028,9 +1028,6 @@ raw:
optimized:
(module
- (type $v (func))
- (type $vi (func (param i32)))
- (type $i (func (result i32)))
(memory $0 0)
)
@@ -2910,9 +2907,6 @@ raw:
optimized:
BinaryenModulePrint(the_module);
(module
- (type $v (func))
- (type $vi (func (param i32)))
- (type $i (func (result i32)))
(memory $0 0)
)
@@ -2923,3 +2917,27 @@ optimized:
relooperBlocks.clear();
return 0;
}
+test_parsing text:
+(module
+ (type $iii (func (param i32 i32) (result i32)))
+ (memory $0 0)
+ (func $adder (type $iii) (param $0 i32) (param $1 i32) (result i32)
+ (i32.add
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+)
+
+module loaded from text form:
+(module
+ (type $iii (func (param i32 i32) (result i32)))
+ (memory $0 0)
+ (func $ADD_ER (type $iii) (param $0 i32) (param $1 i32) (result i32)
+ (i32.add
+ (get_local $0)
+ (get_local $1)
+ )
+ )
+)
+