Skip to content

Commit 8139c9d

Browse files
authored
Add a C source for for test/lld/em_asm_O0 (#3045)
That had just a wat file, with no C. This adds a C file as best I can guess - looks pretty close - and updates all the lld tests with scripts/test/generate_lld_tests.py and ./auto_update_tests.py lld As the diff shows, the handwritten wat was very different than what emcc+lld emit now. I think we must have switches EM_ASMs to be variadic at some point? That is what they currently are, and would explain the diff. See the discussion that led to this in #3044
1 parent 825c6a8 commit 8139c9d

12 files changed

+168
-68
lines changed

test/lld/em_asm.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@
6565
(func $main (param $0 i32) (param $1 i32) (result i32)
6666
(call $__original_main)
6767
)
68-
;; custom section "producers", size 112
68+
;; custom section "producers", size 157
6969
)
7070

test/lld/em_asm_O0.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <emscripten.h>
2+
3+
int main(int argc, char **argv) {
4+
EM_ASM({ Module.print("Hello world"); });
5+
int ret = EM_ASM_INT({ return $0 + $1; }, 20, 30);
6+
EM_ASM({ Module.print("Got " + $0); }, 42);
7+
return ret;
8+
}

test/lld/em_asm_O0.wat

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,95 @@
11
(module
2-
(type $0 (func (param i32) (result i32)))
3-
(type $1 (func (param i32 i32 i32) (result i32)))
4-
(type $2 (func (param i32 i32) (result i32)))
5-
(type $3 (func (result i32)))
6-
(type $4 (func))
7-
(import "env" "_Z24emscripten_asm_const_intIJEEiPKcDpT_" (func $_Z24emscripten_asm_const_intIJEEiPKcDpT_ (param i32) (result i32)))
8-
(import "env" "_Z24emscripten_asm_const_intIJiiEEiPKcDpT_" (func $_Z24emscripten_asm_const_intIJiiEEiPKcDpT_ (param i32 i32 i32) (result i32)))
9-
(import "env" "_Z24emscripten_asm_const_intIJiEEiPKcDpT_" (func $_Z24emscripten_asm_const_intIJiEEiPKcDpT_ (param i32 i32) (result i32)))
10-
(global $global$0 (mut i32) (i32.const 66192))
11-
(global $global$1 i32 (i32.const 66192))
12-
(global $global$2 i32 (i32.const 652))
13-
(table 1 1 funcref)
2+
(type $none_=>_none (func))
3+
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
4+
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
5+
(import "env" "emscripten_asm_const_int" (func $emscripten_asm_const_int (param i32 i32 i32) (result i32)))
146
(memory $0 2)
157
(data (i32.const 568) "{ Module.print(\"Hello world\"); }\00{ return $0 + $1; }\00{ Module.print(\"Got \" + $0); }\00")
8+
(table $0 1 1 funcref)
9+
(global $global$0 (mut i32) (i32.const 66192))
10+
(global $global$1 i32 (i32.const 652))
1611
(export "memory" (memory $0))
1712
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
1813
(export "main" (func $main))
19-
(export "__heap_base" (global $global$1))
20-
(export "__data_end" (global $global$2))
21-
(func $main (; 3 ;) (type $3) (result i32)
22-
(local $t1 i32)
23-
(local $t2 i32)
14+
(export "__data_end" (global $global$1))
15+
(func $__wasm_call_ctors
16+
)
17+
(func $main (param $0 i32) (param $1 i32) (result i32)
18+
(local $2 i32)
19+
(local $3 i32)
20+
(global.set $global$0
21+
(local.tee $2
22+
(i32.sub
23+
(global.get $global$0)
24+
(i32.const 32)
25+
)
26+
)
27+
)
28+
(i32.store8 offset=31
29+
(local.get $2)
30+
(i32.const 0)
31+
)
2432
(drop
25-
(call $_Z24emscripten_asm_const_intIJEEiPKcDpT_
33+
(call $emscripten_asm_const_int
2634
(i32.const 568)
35+
(i32.add
36+
(local.get $2)
37+
(i32.const 31)
38+
)
39+
(i32.const 0)
40+
)
41+
)
42+
(i32.store8 offset=30
43+
(local.get $2)
44+
(i32.const 0)
45+
)
46+
(i32.store16 offset=28 align=1
47+
(local.get $2)
48+
(i32.const 26985)
49+
)
50+
(i64.store offset=16
51+
(local.get $2)
52+
(i64.const 128849018900)
53+
)
54+
(local.set $3
55+
(call $emscripten_asm_const_int
56+
(i32.const 601)
57+
(i32.add
58+
(local.get $2)
59+
(i32.const 28)
60+
)
61+
(i32.add
62+
(local.get $2)
63+
(i32.const 16)
64+
)
2765
)
2866
)
29-
(local.set $t1 (i32.const 621))
30-
(local.set $t2 (i32.const 601))
67+
(i32.store16 offset=26 align=1
68+
(local.get $2)
69+
(i32.const 105)
70+
)
71+
(i32.store
72+
(local.get $2)
73+
(i32.const 42)
74+
)
3175
(drop
32-
(call $_Z24emscripten_asm_const_intIJiEEiPKcDpT_
33-
(local.get $t1)
34-
(call $_Z24emscripten_asm_const_intIJiiEEiPKcDpT_
35-
(local.get $t2)
36-
(i32.const 13)
37-
(i32.const 27)
76+
(call $emscripten_asm_const_int
77+
(i32.const 621)
78+
(i32.add
79+
(local.get $2)
80+
(i32.const 26)
3881
)
82+
(local.get $2)
3983
)
4084
)
41-
(i32.const 0)
42-
)
43-
(func $__wasm_call_ctors (; 4 ;) (type $4)
85+
(global.set $global$0
86+
(i32.add
87+
(local.get $2)
88+
(i32.const 32)
89+
)
90+
)
91+
(local.get $3)
4492
)
45-
;; custom section "linking", size 3
93+
;; custom section "producers", size 157
4694
)
4795

test/lld/em_asm_O0.wat.out

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,97 @@
11
(module
2-
(type $i32_=>_i32 (func (param i32) (result i32)))
32
(type $none_=>_none (func))
4-
(type $none_=>_i32 (func (result i32)))
3+
(type $i32_=>_i32 (func (param i32) (result i32)))
54
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
65
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
7-
(import "env" "emscripten_asm_const_i" (func $emscripten_asm_const_i (param i32) (result i32)))
86
(import "env" "emscripten_asm_const_iii" (func $emscripten_asm_const_iii (param i32 i32 i32) (result i32)))
9-
(import "env" "emscripten_asm_const_ii" (func $emscripten_asm_const_ii (param i32 i32) (result i32)))
107
(memory $0 2)
118
(data (i32.const 568) "{ Module.print(\"Hello world\"); }\00{ return $0 + $1; }\00{ Module.print(\"Got \" + $0); }\00")
129
(table $0 1 1 funcref)
1310
(global $global$0 (mut i32) (i32.const 66192))
14-
(global $global$1 i32 (i32.const 66192))
15-
(global $global$2 i32 (i32.const 652))
11+
(global $global$1 i32 (i32.const 652))
1612
(export "memory" (memory $0))
1713
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
1814
(export "main" (func $main))
19-
(export "__heap_base" (global $global$1))
20-
(export "__data_end" (global $global$2))
15+
(export "__data_end" (global $global$1))
2116
(export "__growWasmMemory" (func $__growWasmMemory))
22-
(func $main (result i32)
23-
(local $t1 i32)
24-
(local $t2 i32)
17+
(func $__wasm_call_ctors
18+
(nop)
19+
)
20+
(func $main (param $0 i32) (param $1 i32) (result i32)
21+
(local $2 i32)
22+
(local $3 i32)
23+
(global.set $global$0
24+
(local.tee $2
25+
(i32.sub
26+
(global.get $global$0)
27+
(i32.const 32)
28+
)
29+
)
30+
)
31+
(i32.store8 offset=31
32+
(local.get $2)
33+
(i32.const 0)
34+
)
2535
(drop
26-
(call $emscripten_asm_const_i
36+
(call $emscripten_asm_const_iii
2737
(i32.const 568)
38+
(i32.add
39+
(local.get $2)
40+
(i32.const 31)
41+
)
42+
(i32.const 0)
43+
)
44+
)
45+
(i32.store8 offset=30
46+
(local.get $2)
47+
(i32.const 0)
48+
)
49+
(i32.store16 offset=28 align=1
50+
(local.get $2)
51+
(i32.const 26985)
52+
)
53+
(i64.store offset=16
54+
(local.get $2)
55+
(i64.const 128849018900)
56+
)
57+
(local.set $3
58+
(call $emscripten_asm_const_iii
59+
(i32.const 601)
60+
(i32.add
61+
(local.get $2)
62+
(i32.const 28)
63+
)
64+
(i32.add
65+
(local.get $2)
66+
(i32.const 16)
67+
)
2868
)
2969
)
30-
(local.set $t1
31-
(i32.const 621)
70+
(i32.store16 offset=26 align=1
71+
(local.get $2)
72+
(i32.const 105)
3273
)
33-
(local.set $t2
34-
(i32.const 601)
74+
(i32.store
75+
(local.get $2)
76+
(i32.const 42)
3577
)
3678
(drop
37-
(call $emscripten_asm_const_ii
38-
(local.get $t1)
39-
(call $emscripten_asm_const_iii
40-
(local.get $t2)
41-
(i32.const 13)
42-
(i32.const 27)
79+
(call $emscripten_asm_const_iii
80+
(i32.const 621)
81+
(i32.add
82+
(local.get $2)
83+
(i32.const 26)
4384
)
85+
(local.get $2)
4486
)
4587
)
46-
(i32.const 0)
47-
)
48-
(func $__wasm_call_ctors
49-
(nop)
88+
(global.set $global$0
89+
(i32.add
90+
(local.get $2)
91+
(i32.const 32)
92+
)
93+
)
94+
(local.get $3)
5095
)
5196
(func $__growWasmMemory (param $newSize i32) (result i32)
5297
(memory.grow
@@ -58,9 +103,9 @@
58103
--BEGIN METADATA --
59104
{
60105
"asmConsts": {
61-
"568": ["{ Module.print(\"Hello world\"); }", ["i"], [""]],
106+
"568": ["{ Module.print(\"Hello world\"); }", ["iii"], [""]],
62107
"601": ["{ return $0 + $1; }", ["iii"], [""]],
63-
"621": ["{ Module.print(\"Got \" + $0); }", ["ii"], [""]]
108+
"621": ["{ Module.print(\"Got \" + $0); }", ["iii"], [""]]
64109
},
65110
"staticBump": 84,
66111
"tableSize": 1,
@@ -77,7 +122,6 @@
77122
"__growWasmMemory"
78123
],
79124
"namedGlobals": {
80-
"__heap_base" : "66192",
81125
"__data_end" : "652"
82126
},
83127
"invokeFuncs": [

test/lld/em_asm_shared.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@
9494
;; memoryalignment: 0
9595
;; tablesize: 0
9696
;; tablealignment: 0
97-
;; custom section "producers", size 112
97+
;; custom section "producers", size 157
9898
)
9999

test/lld/hello_world.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
(func $main (param $0 i32) (param $1 i32) (result i32)
2727
(call $__original_main)
2828
)
29-
;; custom section "producers", size 112
29+
;; custom section "producers", size 157
3030
)
3131

test/lld/init.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
(func $main (param $0 i32) (param $1 i32) (result i32)
4040
(call $__original_main)
4141
)
42-
;; custom section "producers", size 112
42+
;; custom section "producers", size 157
4343
)
4444

test/lld/longjmp.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@
131131
(func $2 (param $0 i32) (param $1 i32) (result i32)
132132
(call $1)
133133
)
134-
;; custom section "producers", size 112
134+
;; custom section "producers", size 157
135135
)
136136

test/lld/recursive.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@
8383
(func $main (param $0 i32) (param $1 i32) (result i32)
8484
(call $__original_main)
8585
)
86-
;; custom section "producers", size 112
86+
;; custom section "producers", size 157
8787
)
8888

test/lld/reserved_func_ptr.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@
106106
)
107107
(i32.const 0)
108108
)
109-
;; custom section "producers", size 112
109+
;; custom section "producers", size 157
110110
)
111111

test/lld/shared.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@
5454
;; memoryalignment: 2
5555
;; tablesize: 0
5656
;; tablealignment: 0
57-
;; custom section "producers", size 112
57+
;; custom section "producers", size 157
5858
)
5959

test/lld/shared_longjmp.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,6 @@
143143
;; memoryalignment: 2
144144
;; tablesize: 0
145145
;; tablealignment: 0
146-
;; custom section "producers", size 112
146+
;; custom section "producers", size 157
147147
)
148148

0 commit comments

Comments
 (0)