summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck.py3
-rw-r--r--test/wasm_backend/indirect_call.cpp50
-rw-r--r--test/wasm_backend/indirect_call.txt23
3 files changed, 75 insertions, 1 deletions
diff --git a/check.py b/check.py
index 32406227a..7525d24fb 100755
--- a/check.py
+++ b/check.py
@@ -307,7 +307,8 @@ if has_emcc:
print '\n[ checking emcc WASM_BACKEND testcases... ]\n'
- for c in ['hello_world.cpp', 'hello_num.cpp', 'globals.cpp']:
+ for c in sorted(os.listdir(os.path.join('test', 'wasm_backend'))):
+ if not c.endswith('cpp'): continue
print '..', c
base = c.replace('.cpp', '').replace('.c', '')
expected = open(os.path.join('test', 'wasm_backend', base + '.txt')).read()
diff --git a/test/wasm_backend/indirect_call.cpp b/test/wasm_backend/indirect_call.cpp
new file mode 100644
index 000000000..75c459199
--- /dev/null
+++ b/test/wasm_backend/indirect_call.cpp
@@ -0,0 +1,50 @@
+#include <emscripten.h>
+
+void print(const char *prefix, int v) {
+ int *x = (int*)8; // XXX this order is wrong!
+ *x = (int)prefix;
+ int *y = (int*)16;
+ *y = v;
+ EM_ASM({
+ Module.print("print: " + Pointer_stringify(HEAP32[8>>2]) + " : " + HEAP32[16>>2]);
+ });
+}
+
+void something() {
+ print("something", 12);
+}
+
+void more() {
+ print("more", -1);
+}
+
+void other(int x) {
+ print("other", x + 40);
+}
+
+void yet(int x) {
+ print("yet", x + 99);
+}
+
+typedef void (*v)();
+typedef void (*vi)(int);
+
+int main(int argc, char **argv) {
+ print("argc", argc);
+ v f1[4] = { something, more, something, more };
+ print("addr of something", (int)&something);
+ print("addr of more", (int)&more);
+ for (int i = 0; i < 4 && i < argc*4; i++) {
+ print("i", i);
+ v curr = f1[i];
+ print("curr address to call", (int)curr);
+ curr();
+ }
+ vi f2[4] = { other, yet, other, yet };
+ for (int i = 0; i < 4 && i < argc*4; i++) {
+ vi curr = f2[i];
+ print("curr", (int)curr);
+ curr(i);
+ }
+}
+
diff --git a/test/wasm_backend/indirect_call.txt b/test/wasm_backend/indirect_call.txt
new file mode 100644
index 000000000..8d60cc1ff
--- /dev/null
+++ b/test/wasm_backend/indirect_call.txt
@@ -0,0 +1,23 @@
+print: argc : 1
+print: addr of something : 0
+print: addr of more : 1
+print: i : 0
+print: curr address to call : 0
+print: something : 12
+print: i : 1
+print: curr address to call : 1
+print: more : -1
+print: i : 2
+print: curr address to call : 0
+print: something : 12
+print: i : 3
+print: curr address to call : 1
+print: more : -1
+print: curr : 2
+print: other : 40
+print: curr : 3
+print: yet : 100
+print: curr : 2
+print: other : 42
+print: curr : 3
+print: yet : 102