From 5e04a9626e2986fc40825d15cb09a274223381e9 Mon Sep 17 00:00:00 2001 From: Wojciech Kosior Date: Thu, 8 Oct 2020 19:18:43 +0200 Subject: translate webasm block of instructions + put instruction names as comments in generated code --- tests/wasm_compile_arithm/words_to_verify.mem | 8 +- tests/wasm_compile_block/Makefile | 1 + tests/wasm_compile_block/instructions.wat | 121 +++++++++++++++++++++ tests/wasm_compile_block/test.v | 1 + tests/wasm_compile_block/words_to_verify.mem | 7 ++ tests/wasm_compile_br_if/words_to_verify.mem | 6 +- .../wasm_compile_function_call/words_to_verify.mem | 3 +- tests/wasm_compile_if_else/words_to_verify.mem | 4 +- tests/wasm_compile_loop/words_to_verify.mem | 2 +- tests/wasm_compile_simple_module/test.v | 6 +- .../wasm_compile_simple_module/words_to_verify.mem | 2 +- 11 files changed, 146 insertions(+), 15 deletions(-) create mode 120000 tests/wasm_compile_block/Makefile create mode 100644 tests/wasm_compile_block/instructions.wat create mode 120000 tests/wasm_compile_block/test.v create mode 100644 tests/wasm_compile_block/words_to_verify.mem (limited to 'tests') 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 -- cgit v1.2.3