summaryrefslogtreecommitdiff
path: root/test/wasm_backend/indirect_call_only.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/wasm_backend/indirect_call_only.cpp')
-rw-r--r--test/wasm_backend/indirect_call_only.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/wasm_backend/indirect_call_only.cpp b/test/wasm_backend/indirect_call_only.cpp
new file mode 100644
index 000000000..ef52a4ad1
--- /dev/null
+++ b/test/wasm_backend/indirect_call_only.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);
+ }
+}
+