diff options
Diffstat (limited to 'test/binaryen.js')
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 11 | ||||
-rw-r--r-- | test/binaryen.js/reloc.js | 26 | ||||
-rw-r--r-- | test/binaryen.js/reloc.js.txt | 13 |
3 files changed, 45 insertions, 5 deletions
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 1bf0b3b54..87a6bc97c 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -5471,17 +5471,18 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} BinaryenFunctionGetVar(functions[0], 0); BinaryenFunctionGetVar(functions[0], 1); BinaryenFunctionGetBody(functions[0]); + expressions[777] = BinaryenConst(the_module, BinaryenLiteralInt32(0)); { const char* funcNames[] = { "kitchen()sinker" }; - BinaryenSetFunctionTable(the_module, 1, 4294967295, funcNames, 1); + BinaryenSetFunctionTable(the_module, 1, 4294967295, funcNames, 1, expressions[777]); } - expressions[777] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); + expressions[778] = BinaryenConst(the_module, BinaryenLiteralInt32(10)); { const char segment0[] = { 104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100 }; const char segment1[] = { 73, 32, 97, 109, 32, 112, 97, 115, 115, 105, 118, 101 }; const char* segments[] = { segment0, segment1 }; int8_t segmentPassive[] = { 0, 1 }; - BinaryenExpressionRef segmentOffsets[] = { expressions[777], expressions[0] }; + BinaryenExpressionRef segmentOffsets[] = { expressions[778], expressions[0] }; BinaryenIndex segmentSizes[] = { 12, 12 }; BinaryenSetMemory(the_module, 1, 256, "mem", segments, segmentPassive, segmentOffsets, segmentSizes, 2, 1); } @@ -5489,10 +5490,10 @@ getExpressionInfo(f64.const)={"id":14,"type":4,"value":9.5} BinaryenType paramTypes[] = { 0 }; functionTypes[3] = BinaryenAddFunctionType(the_module, "v", 0, paramTypes, 0); } - expressions[778] = BinaryenNop(the_module); + expressions[779] = BinaryenNop(the_module); { BinaryenType varTypes[] = { 0 }; - functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[778]); + functions[1] = BinaryenAddFunction(the_module, "starter", functionTypes[3], varTypes, 0, expressions[779]); } BinaryenSetStart(the_module, functions[1]); { diff --git a/test/binaryen.js/reloc.js b/test/binaryen.js/reloc.js new file mode 100644 index 000000000..68c29228d --- /dev/null +++ b/test/binaryen.js/reloc.js @@ -0,0 +1,26 @@ +function assert(x) { + if (!x) throw 'error!'; +} + +var module = new Binaryen.Module(); + +// memory with offset + +module.addGlobalImport("memory_base", "env", "memory_base", Binaryen.i32, false); +module.setMemory(1, -1, null, [ + { + offset: module.global.get("memory_base", Binaryen.i32), + data: "data data".split('').map(function(x) { return x.charCodeAt(0) }) + } +]); + +// table with offset + +var signature = module.addFunctionType("v", Binaryen.none, []); +var func = module.addFunction("func", signature, [], module.nop()); + +module.addGlobalImport("table_base", "env", "table_base", Binaryen.i32, false); +module.setFunctionTable(1, -1, [ "func", "func" ], module.global.get("table_base", Binaryen.i32)); + +assert(module.validate()); +console.log(module.emitText()); diff --git a/test/binaryen.js/reloc.js.txt b/test/binaryen.js/reloc.js.txt new file mode 100644 index 000000000..901499f98 --- /dev/null +++ b/test/binaryen.js/reloc.js.txt @@ -0,0 +1,13 @@ +(module + (type $v (func)) + (import "env" "memory_base" (global $memory_base i32)) + (import "env" "table_base" (global $table_base i32)) + (memory $0 1) + (data (global.get $memory_base) "data data") + (table $0 1 funcref) + (elem (global.get $table_base) $func $func) + (func $func (; 0 ;) (type $v) + (nop) + ) +) + |