aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-10-08 19:18:43 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-10-08 19:18:43 +0200
commit5e04a9626e2986fc40825d15cb09a274223381e9 (patch)
treea52a96fa585247145cb521b9c6f7fe7946ba7997 /tests
parent63a2cced4238af7d171e0b8807d887c435b4656b (diff)
downloadAGH-engineering-thesis-5e04a9626e2986fc40825d15cb09a274223381e9.tar.gz
AGH-engineering-thesis-5e04a9626e2986fc40825d15cb09a274223381e9.zip
translate webasm block of instructions + put instruction names as comments in generated code
Diffstat (limited to 'tests')
-rw-r--r--tests/wasm_compile_arithm/words_to_verify.mem8
l---------tests/wasm_compile_block/Makefile1
-rw-r--r--tests/wasm_compile_block/instructions.wat121
l---------tests/wasm_compile_block/test.v1
-rw-r--r--tests/wasm_compile_block/words_to_verify.mem7
-rw-r--r--tests/wasm_compile_br_if/words_to_verify.mem6
-rw-r--r--tests/wasm_compile_function_call/words_to_verify.mem3
-rw-r--r--tests/wasm_compile_if_else/words_to_verify.mem4
-rw-r--r--tests/wasm_compile_loop/words_to_verify.mem2
-rw-r--r--tests/wasm_compile_simple_module/test.v6
-rw-r--r--tests/wasm_compile_simple_module/words_to_verify.mem2
11 files changed, 146 insertions, 15 deletions
diff --git a/tests/wasm_compile_arithm/words_to_verify.mem b/tests/wasm_compile_arithm/words_to_verify.mem
index d3f3c4e..078cd6d 100644
--- a/tests/wasm_compile_arithm/words_to_verify.mem
+++ b/tests/wasm_compile_arithm/words_to_verify.mem
@@ -1,7 +1,7 @@
// address value
0FFFFC 23
- 200 FFEFE021
- 204 16D3B7
- 208 ED8
- 20C 3C773E7C
+ 400 FFEFE021
+ 404 16D3B7
+ 408 ED8
+ 40C 3C773E7C
diff --git a/tests/wasm_compile_block/Makefile b/tests/wasm_compile_block/Makefile
new file mode 120000
index 0000000..e451c8b
--- /dev/null
+++ b/tests/wasm_compile_block/Makefile
@@ -0,0 +1 @@
+../wasm_compile_simple_module/Makefile \ No newline at end of file
diff --git a/tests/wasm_compile_block/instructions.wat b/tests/wasm_compile_block/instructions.wat
new file mode 100644
index 0000000..11b179d
--- /dev/null
+++ b/tests/wasm_compile_block/instructions.wat
@@ -0,0 +1,121 @@
+;; The idea is - we have 4 blocks, one inside another. We enter subsequent
+;; blocks (how many we enter, depends on $blockfun's first arg) and then we
+;; start leaving them. We "normally" (e.g. without br) exit some blocks (number
+;; depending on $blockfun's 2nd arg) and then we break out of the outermost one
+;; with the use of br_if.
+;; When making this "path" through blocks, we also construct a result value.
+;; The result value is initially 0 and upon each "normal" exit from a block,
+;; one bit is being set to 1 in the result. Which bit is set, depends on the
+;; block being left. Block 1 sets bit 0, block 2 sets bit 1, etc.
+;; So, the entire function actually computes an integer with bits a1-a2 through
+;; a1 set, with a1 and a2 being arguments to the function.
+;; To keep things simple, we limit this to 4 block and 4 bits, that can be set
+
+(module
+ (memory 0 1)
+ (func $blockfun
+ (param $blocks_to_enter i32)
+ (param $ones_to_set i32)
+ (result i32)
+
+ i32.const 0 ;; initial result value
+
+ get_local $blocks_to_enter
+ i32.const 0
+ i32.eq
+ br_if 0 ;; if number of blocks to enter is 0 - just return
+
+ block $b1 (param i32) (result i32)
+ get_local $blocks_to_enter
+ i32.const 1
+ i32.sub
+ set_local $blocks_to_enter
+
+ get_local $blocks_to_enter
+ if (param i32) (result i32)
+ block $b2 (param i32) (result i32)
+ get_local $blocks_to_enter
+ i32.const 1
+ i32.sub
+ set_local $blocks_to_enter
+
+ get_local $blocks_to_enter
+ if (param i32) (result i32)
+ block $b3 (param i32) (result i32)
+ get_local $blocks_to_enter
+ i32.const 1
+ i32.sub
+ set_local $blocks_to_enter
+
+ get_local $blocks_to_enter
+ if (param i32) (result i32)
+ block $b4 (param i32) (result i32)
+ get_local $ones_to_set
+ i32.const 0
+ i32.eq
+ br_if $b1
+
+ get_local $ones_to_set
+ i32.const 1
+ i32.sub
+ set_local $ones_to_set
+
+ i32.const 8 ;; block $b4 adds (1 << 3) to the result
+ i32.add
+ end
+ end
+
+ get_local $ones_to_set
+ i32.const 0
+ i32.eq
+ br_if $b1
+
+ get_local $ones_to_set
+ i32.const 1
+ i32.sub
+ set_local $ones_to_set
+
+ i32.const 4 ;; block $b3 adds (1 << 2) to the result
+ i32.add
+ end
+ end
+
+ get_local $ones_to_set
+ i32.const 0
+ i32.eq
+ br_if $b1
+
+ get_local $ones_to_set
+ i32.const 1
+ i32.sub
+ set_local $ones_to_set
+
+ i32.const 2 ;; block $b2 adds (1 << 1) to the result
+ i32.add
+ end
+ end
+
+ get_local $ones_to_set
+ i32.const 0
+ i32.eq
+ br_if $b1
+
+ get_local $ones_to_set
+ i32.const 1
+ i32.sub
+ set_local $ones_to_set
+
+ i32.const 1 ;; block $b1 adds (1 << 0) to the result
+ i32.add
+ end)
+ (func $main
+ (i32.store offset=0x0 align=2 (i32.const 0x0)
+ (call $blockfun (i32.const 4) (i32.const 2)))
+ (i32.store offset=0x0 align=2 (i32.const 0x4)
+ (call $blockfun (i32.const 3) (i32.const 2)))
+ (i32.store offset=0x0 align=2 (i32.const 0x8)
+ (call $blockfun (i32.const 2) (i32.const 0)))
+ (i32.store offset=0x0 align=2 (i32.const 0xC)
+ (call $blockfun (i32.const 4) (i32.const 4)))
+ )
+ (export "main" (func $main)))
diff --git a/tests/wasm_compile_block/test.v b/tests/wasm_compile_block/test.v
new file mode 120000
index 0000000..f0235d8
--- /dev/null
+++ b/tests/wasm_compile_block/test.v
@@ -0,0 +1 @@
+../wasm_compile_simple_module/test.v \ No newline at end of file
diff --git a/tests/wasm_compile_block/words_to_verify.mem b/tests/wasm_compile_block/words_to_verify.mem
new file mode 100644
index 0000000..c450cd6
--- /dev/null
+++ b/tests/wasm_compile_block/words_to_verify.mem
@@ -0,0 +1,7 @@
+// address value
+ 0FFFFC 23
+
+ 400 C
+ 404 6
+ 408 0
+ 40C F
diff --git a/tests/wasm_compile_br_if/words_to_verify.mem b/tests/wasm_compile_br_if/words_to_verify.mem
index aac1103..e7a45dc 100644
--- a/tests/wasm_compile_br_if/words_to_verify.mem
+++ b/tests/wasm_compile_br_if/words_to_verify.mem
@@ -1,6 +1,6 @@
// address value
0FFFFC 23
- 200 00000000
- 204 FFFFFFFF
- 208 FFFFFFFF
+ 400 00000000
+ 404 FFFFFFFF
+ 408 FFFFFFFF
diff --git a/tests/wasm_compile_function_call/words_to_verify.mem b/tests/wasm_compile_function_call/words_to_verify.mem
index bd24e95..a66822c 100644
--- a/tests/wasm_compile_function_call/words_to_verify.mem
+++ b/tests/wasm_compile_function_call/words_to_verify.mem
@@ -1,3 +1,4 @@
// address value
0FFFFC 23
- 23C 1E // Address is 0x200 + 0x25 + 0x17
+
+ 43C 1E // Address is 0x400 + 0x25 + 0x17
diff --git a/tests/wasm_compile_if_else/words_to_verify.mem b/tests/wasm_compile_if_else/words_to_verify.mem
index 75a6c84..22c6442 100644
--- a/tests/wasm_compile_if_else/words_to_verify.mem
+++ b/tests/wasm_compile_if_else/words_to_verify.mem
@@ -1,5 +1,5 @@
// address value
0FFFFC 23
- 200 00000000
- 204 FFFFFFFF
+ 400 00000000
+ 404 FFFFFFFF
diff --git a/tests/wasm_compile_loop/words_to_verify.mem b/tests/wasm_compile_loop/words_to_verify.mem
index ef41c69..43dba15 100644
--- a/tests/wasm_compile_loop/words_to_verify.mem
+++ b/tests/wasm_compile_loop/words_to_verify.mem
@@ -1,4 +1,4 @@
// address value
0FFFFC 23
- 200 00000037
+ 400 00000037
diff --git a/tests/wasm_compile_simple_module/test.v b/tests/wasm_compile_simple_module/test.v
index 5e28ba1..9a25ad9 100644
--- a/tests/wasm_compile_simple_module/test.v
+++ b/tests/wasm_compile_simple_module/test.v
@@ -159,7 +159,7 @@ module wasm_compile_test();
CLK <= 0;
RST <= 1;
- for (i = 0; i < 10000; i++) begin
+ for (i = 0; i < 20000; i++) begin
#1;
CLK <= ~CLK;
@@ -194,9 +194,9 @@ module wasm_compile_test();
$finish;
end // if (M_finished)
- end // for (i = 0; i < 10000; i++)
+ end // for (i = 0; i < 20000; i++)
- $display("error: cpu hasn't finished its operations in 5000 ticks");
+ $display("error: cpu hasn't finished its operations in 10000 ticks");
$finish;
end // initial begin
endmodule // stack_machine_test
diff --git a/tests/wasm_compile_simple_module/words_to_verify.mem b/tests/wasm_compile_simple_module/words_to_verify.mem
index d6a16c1..07046c4 100644
--- a/tests/wasm_compile_simple_module/words_to_verify.mem
+++ b/tests/wasm_compile_simple_module/words_to_verify.mem
@@ -1,3 +1,3 @@
// address value
0FFFFC 23
- 23C 1E // Address is 0x200 + 0x1F + 0x1D
+ 43C 1E // Address is 0x400 + 0x1F + 0x1D