Skip to content

Instantly share code, notes, and snippets.

@riywo
Last active May 4, 2018 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riywo/62ee1b47bd2cb84f2acf5d861ee861c6 to your computer and use it in GitHub Desktop.
Save riywo/62ee1b47bd2cb84f2acf5d861ee861c6 to your computer and use it in GitHub Desktop.
declare i32 @putchar(i32)
@code = private constant [5 x i8*] [
i8* blockaddress(@main, %A),
i8* blockaddress(@main, %B),
i8* blockaddress(@main, %A),
i8* blockaddress(@main, %B),
i8* blockaddress(@main, %exit)
]
define i32 @main() {
entry:
%start = getelementptr [5 x i8*], [5 x i8*]* @code, i32 0 , i32 0
br label %top
top:
%ip = phi i8** [%start, %entry], [%new_ip, %next]
%addr = load i8*, i8** %ip
%new_ip = getelementptr i8*, i8** %ip, i32 1
indirectbr i8* %addr, [label %A, label %B, label %exit]
next:
br label %top
A:
call i32 @putchar(i32 65)
br label %next
B:
call i32 @putchar(i32 66)
br label %next
exit:
call i32 @putchar(i32 10)
ret i32 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment