Skip to content

Instantly share code, notes, and snippets.

@obiknows
Created May 11, 2017 02:39
Show Gist options
  • Save obiknows/07ebbc549fd8982b89d1d2e6a18bc61b to your computer and use it in GitHub Desktop.
Save obiknows/07ebbc549fd8982b89d1d2e6a18bc61b to your computer and use it in GitHub Desktop.
Test:
make clean && make
./warhol.native -c < tests/tppp.wl > tppp.ll
lli tppp.ll
Source:
fun int main() {
int[2] k;
k[0] = 0;
k[1] = 1;
int[] kp;
kp = @k;
kp = ++kp;
print(&kp);
}
Output:
plt@ubuntu-plt:~/work/warhol$ lli tppp.ll
1
LLVM IR:
; ModuleID = 'Warhol'
@fmt = private unnamed_addr constant [4 x i8] c"%d\0A\00"
declare i32 @printf(i8*, ...)
declare i32 @openfile(i8*, ...)
define i32 @main() {
entry:
%k = alloca [2 x i32]
%kp = alloca i32*
%k1 = getelementptr [2 x i32]* %k, i32 0, i32 0
store i32 0, i32* %k1
%k2 = getelementptr [2 x i32]* %k, i32 0, i32 1
store i32 1, i32* %k2
%k3 = getelementptr inbounds [2 x i32]* %k, i32 0, i32 0
store i32* %k3, i32** %kp
%kp4 = getelementptr inbounds i32** %kp, i32 0
%kp5 = load i32** %kp4
%kp6 = getelementptr inbounds i32* %kp5, i32 1
store i32* %kp6, i32** %kp
%kp7 = load i32** %kp
%kp8 = load i32* %kp7
%printf = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([4 x i8]* @fmt, i32 0, i32 0), i32 %kp8)
ret i32 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment