-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathinline_test_return.wat
More file actions
97 lines (90 loc) · 1.89 KB
/
inline_test_return.wat
File metadata and controls
97 lines (90 loc) · 1.89 KB
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
;; Test inlined functions with explicit RETURN, including nested control flow
;; and paths where extra values are on the stack at the time of return.
(module
;; Two levels of nested ifs; in the early-return path, 2*a is an extra value
;; on the value stack below the returned a+b.
(func $weighted (param i32) (param i32) (result i32)
block (result i32)
local.get 0
i32.const 2
i32.mul ;; [2a] -- extra below when early return fires
block
local.get 0
i32.const 0
i32.gt_s
if
local.get 1
i32.const 0
i32.gt_s
if
;; both positive: return a+b; 2a is extra on stack
local.get 0
local.get 1
i32.add
return
end
end
end
local.get 1
i32.add ;; fallthrough: 2a+b
end
)
;; Clamp x to [lo, hi]; two levels of nesting, returns on multiple paths.
(func $clamp (param i32) (param i32) (param i32) (result i32)
local.get 0
local.get 1
i32.lt_s
if
local.get 1
return
end
local.get 0
local.get 2
i32.gt_s
if
local.get 2
return
end
local.get 0
)
(func (export "main") (result i32)
i32.const 3
i32.const 4
call $weighted
i32.const 7 ;; both positive: 3+4=7
i32.ne
i32.const 3
i32.const -1
call $weighted
i32.const 5 ;; b<=0: 2*3+(-1)=5
i32.ne
i32.or
i32.const -1
i32.const 4
call $weighted
i32.const 2 ;; a<=0: 2*(-1)+4=2
i32.ne
i32.or
i32.const 5
i32.const 0
i32.const 10
call $clamp
i32.const 5
i32.ne
i32.or
i32.const -3
i32.const 0
i32.const 10
call $clamp
i32.const 0
i32.ne
i32.or
i32.const 15
i32.const 0
i32.const 10
call $clamp
i32.const 10
i32.ne
i32.or
)
)