-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.wasi
184 lines (181 loc) · 7.01 KB
/
hello.wasi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
(module
(import "wasi_unstable" "fd_write" (func $__wasi_fd_write (param i32 i32 i32 i32) (result i32)))
(import "wasi_unstable" "fd_read" (func $__wasi_fd_read (param i32 i32 i32 i32) (result i32)))
(import "wasi_unstable" "proc_exit" (func $__wasi_proc_exit (param i32)))
(memory (export "memory") 1025)
(global $a (mut i32) (i32.const 0))
(global $b (mut i32) (i32.const 0))
(global $c (mut i32) (i32.const 0))
(global $d (mut i32) (i32.const 0))
(global $bp (mut i32) (i32.const 0))
(global $sp (mut i32) (i32.const 0))
(global $pc (mut i32) (i32.const 0))
(func $init_memory
(i32.store (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 4)) (i32.const 0)) ;; buffer
(i32.store (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 8)) (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 4))) ;; buf pointer
(i32.store (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 12)) (i32.const 1)) ;; buf length
(i32.store (i32.mul (i32.const 4) (i32.const 0)) (i32.const 72))
(i32.store (i32.mul (i32.const 4) (i32.const 1)) (i32.const 101))
(i32.store (i32.mul (i32.const 4) (i32.const 2)) (i32.const 108))
(i32.store (i32.mul (i32.const 4) (i32.const 3)) (i32.const 108))
(i32.store (i32.mul (i32.const 4) (i32.const 4)) (i32.const 111))
(i32.store (i32.mul (i32.const 4) (i32.const 5)) (i32.const 44))
(i32.store (i32.mul (i32.const 4) (i32.const 6)) (i32.const 32))
(i32.store (i32.mul (i32.const 4) (i32.const 7)) (i32.const 119))
(i32.store (i32.mul (i32.const 4) (i32.const 8)) (i32.const 111))
(i32.store (i32.mul (i32.const 4) (i32.const 9)) (i32.const 114))
(i32.store (i32.mul (i32.const 4) (i32.const 10)) (i32.const 108))
(i32.store (i32.mul (i32.const 4) (i32.const 11)) (i32.const 100))
(i32.store (i32.mul (i32.const 4) (i32.const 12)) (i32.const 33))
(i32.store (i32.mul (i32.const 4) (i32.const 13)) (i32.const 10))
(i32.store (i32.mul (i32.const 4) (i32.const 15)) (i32.const 16))
) ;; func init_memory
(func $f0
(loop $loop0
(br_if 1 (i32.or (i32.gt_u (i32.const 0) (get_global $pc)) (i32.ge_u (get_global $pc) (i32.const 512))))
(if
(i32.eqz (i32.const 1))
(then
(nop)
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 0))
(then
(if
(i32.eqz (i32.const 0))
(then
(set_global $pc (i32.const 1))
(br $loop0)
) ;; then
) ;; if
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 1))
(then
(set_global $d (get_global $sp))
(set_global $d (i32.and (i32.add (get_global $d) (i32.const 16777215)) (i32.const 16777215)))
(i32.store (i32.mul (i32.const 4) (get_global $d)) (get_global $bp))
(set_global $sp (get_global $d))
(set_global $bp (get_global $sp))
(set_global $sp (i32.and (i32.sub (get_global $sp) (i32.const 1)) (i32.const 16777215)))
(set_global $a (i32.const 0))
(set_global $b (get_global $sp))
(set_global $a (i32.const 0))
(set_global $b (get_global $bp))
(set_global $b (i32.and (i32.add (get_global $b) (i32.const 16777215)) (i32.const 16777215)))
(i32.store (i32.mul (i32.const 4) (get_global $b)) (get_global $a))
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 2))
(then
(set_global $b (get_global $bp))
(set_global $b (i32.and (i32.add (get_global $b) (i32.const 16777215)) (i32.const 16777215)))
(set_global $a (i32.load (i32.mul (i32.const 4) (get_global $b))))
(set_global $b (get_global $a))
(set_global $a (i32.load (i32.mul (i32.const 4) (get_global $b))))
(if
(i32.eq (get_global $a) (i32.const 0))
(then
(set_global $pc (i32.const 4))
(br $loop0)
) ;; then
) ;; if
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 3))
(then
(if
(i32.eqz (i32.const 0))
(then
(set_global $pc (i32.const 5))
(br $loop0)
) ;; then
) ;; if
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 4))
(then
(if
(i32.eqz (i32.const 0))
(then
(set_global $pc (i32.const 7))
(br $loop0)
) ;; then
) ;; if
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 5))
(then
(set_global $b (get_global $bp))
(set_global $b (i32.and (i32.add (get_global $b) (i32.const 16777215)) (i32.const 16777215)))
(set_global $a (i32.load (i32.mul (i32.const 4) (get_global $b))))
(set_global $b (get_global $a))
(set_global $a (i32.load (i32.mul (i32.const 4) (get_global $b))))
(set_global $d (get_global $sp))
(set_global $d (i32.and (i32.add (get_global $d) (i32.const 16777215)) (i32.const 16777215)))
(i32.store (i32.mul (i32.const 4) (get_global $d)) (get_global $a))
(set_global $sp (get_global $d))
(i32.store (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 4)) (get_global $a))
(drop (call $__wasi_fd_write (i32.const 1) (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 8)) (i32.const 1) (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 16))))
(i32.store (i32.add (i32.mul (i32.const 4) (i32.const 16777215)) (i32.const 4)) (i32.const 0))
(set_global $sp (i32.and (i32.add (get_global $sp) (i32.const 1)) (i32.const 16777215)))
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 6))
(then
(set_global $b (get_global $bp))
(set_global $b (i32.and (i32.add (get_global $b) (i32.const 16777215)) (i32.const 16777215)))
(set_global $a (i32.load (i32.mul (i32.const 4) (get_global $b))))
(set_global $d (get_global $sp))
(set_global $d (i32.and (i32.add (get_global $d) (i32.const 16777215)) (i32.const 16777215)))
(i32.store (i32.mul (i32.const 4) (get_global $d)) (get_global $a))
(set_global $sp (get_global $d))
(set_global $a (i32.and (i32.add (get_global $a) (i32.const 1)) (i32.const 16777215)))
(set_global $b (get_global $bp))
(set_global $b (i32.and (i32.add (get_global $b) (i32.const 16777215)) (i32.const 16777215)))
(i32.store (i32.mul (i32.const 4) (get_global $b)) (get_global $a))
(set_global $a (i32.load (i32.mul (i32.const 4) (get_global $sp))))
(set_global $sp (i32.and (i32.add (get_global $sp) (i32.const 1)) (i32.const 16777215)))
(if
(i32.eqz (i32.const 0))
(then
(set_global $pc (i32.const 2))
(br $loop0)
) ;; then
) ;; if
) ;; then
) ;; if
(if
(i32.eq (get_global $pc) (i32.const 7))
(then
(set_global $a (i32.const 0))
(set_global $b (get_global $a))
(call $__wasi_proc_exit (i32.const 0))
(call $__wasi_proc_exit (i32.const 0))
) ;; then
) ;; if
(set_global $pc (i32.add (get_global $pc) (i32.const 1)))
(br $loop0)
) ;; loop $loop0
) ;; func $f d
(table anyfunc
(elem
$f0
) ;; elem
) ;; table
(func $main
(call $init_memory)
(loop $loop_main
(call_indirect (i32.div_u (get_global $pc) (i32.const 512)))
(br $loop_main)
) ;; loop $loop_main
) ;; func main
(export "_start" (func $main))
) ;; module