doc: sample: add match-statement syntax and ir samples
This commit is contained in:
47
doc/sample/Match.mie
Normal file
47
doc/sample/Match.mie
Normal file
@@ -0,0 +1,47 @@
|
||||
define void @init() static {
|
||||
entry:
|
||||
%age = alloca id
|
||||
store i32 #65, ptr %age
|
||||
|
||||
%yz = alloca id
|
||||
store i32 #32, ptr %yz
|
||||
|
||||
%p3 = alloca id
|
||||
store i32 #3, ptr %p3
|
||||
|
||||
%1 = load id, ptr %yz
|
||||
%2 = load id, ptr %p3
|
||||
|
||||
switch id %1, label %match.d,
|
||||
[ i32 #1, label %match.0 ],
|
||||
[ i32 #2, label %match.1 ],
|
||||
[ i32 %2, label %match.2 ]
|
||||
match.0:
|
||||
%wq = alloca id
|
||||
store i32 #32, ptr %wq
|
||||
|
||||
%3 = load id, ptr %wq
|
||||
%multmp = mul id %3, i32 #2
|
||||
br label %match.end
|
||||
|
||||
match.1:
|
||||
%4 = load id, ptr %age
|
||||
%divtmp = mul id %4, i32 #12
|
||||
br label %match.end
|
||||
match.2:
|
||||
%5 = load id, ptr %age
|
||||
%divtmp.0 = mul id %5, i32 #365
|
||||
br label %match.end
|
||||
match.d:
|
||||
br label %match.end
|
||||
match.end:
|
||||
%match.result = phi id
|
||||
[ %match.0, %multmp],
|
||||
[ %match.1, %divtmp ],
|
||||
[ %match.2, %divtmp.0 ],
|
||||
[ %match.d, #0 ]
|
||||
|
||||
%q = alloca id
|
||||
store id %match.result, ptr %q
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user