aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/wamr/Makefile11
-rw-r--r--lib/wamr/test/fibonacci.c26
-rw-r--r--lib/wamr/test/main.c14
3 files changed, 50 insertions, 1 deletions
diff --git a/lib/wamr/Makefile b/lib/wamr/Makefile
index de1462b..5946e8d 100644
--- a/lib/wamr/Makefile
+++ b/lib/wamr/Makefile
@@ -32,7 +32,6 @@ CFLAGS = -DBH_FREE=wasm_runtime_free \
-DWASM_ENABLE_BULK_MEMORY=1 \
-DWASM_ENABLE_FAST_INTERP=1 \
-DWASM_ENABLE_INTERP=1 \
- -DWASM_ENABLE_LIBC_EMCC=1 \
-Icore/iwasm/common \
-Icore/iwasm/include \
-Icore/iwasm/interpreter \
@@ -56,3 +55,13 @@ $(LIB): $(OBJ)
.PHONY: clean
clean:
rm -f $(LIB) $(OBJ)
+
+.PHONY: check
+check: test/test.exe test/fibonacci.wasm
+ (cd $(dir $<); ./$(notdir $<))
+
+test/test.exe: test/main.c $(LIB)
+ $(CC) -o $@ $< -Icore/iwasm/include -L. -lwamr
+
+test/fibonacci.wasm: test/fibonacci.c
+ clang -target wasm32 -nostdlib -Wl,--no-entry -Wl,--export=fibonacci -Wl,--allow-undefined -o $@ $<
diff --git a/lib/wamr/test/fibonacci.c b/lib/wamr/test/fibonacci.c
new file mode 100644
index 0000000..ce67a7e
--- /dev/null
+++ b/lib/wamr/test/fibonacci.c
@@ -0,0 +1,26 @@
+#include <stdint.h>
+
+extern void lognumber(int32_t n);
+
+extern int32_t fibonacci(int32_t i) {
+ if (i < 0) {
+ return -1;
+ }
+
+ uint32_t last = 0;
+ uint32_t result = 1;
+ for (; i > 0; i--) {
+ uint32_t current = result;
+ lognumber((int32_t)current);
+
+ result += last;
+ last = current;
+
+ if (result > INT32_MAX) {
+ // overflow
+ return -1;
+ }
+ }
+
+ return (int32_t)result;
+}
diff --git a/lib/wamr/test/main.c b/lib/wamr/test/main.c
new file mode 100644
index 0000000..2ae4912
--- /dev/null
+++ b/lib/wamr/test/main.c
@@ -0,0 +1,14 @@
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "wasm_export.h"
+
+int main(int argc, char *argv[argc + 1]) {
+ FILE *f = fopen("fibonacci.wasm", "w");
+ assert(f);
+
+ wasm_runtime_init();
+
+ return EXIT_SUCCESS;
+}