Skip to content

Instantly share code, notes, and snippets.

@antonijn
Last active August 29, 2015 13:56
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 antonijn/8791396 to your computer and use it in GitHub Desktop.
Save antonijn/8791396 to your computer and use it in GitHub Desktop.
A bit of aqua, in various stages of its compilation.
import aqua.std;
public class Program
{
private static native int putchar(int ch);
private static void print(char ch)
{
putchar(ch);
}
private static void main()
{
for (int i = 0; i < 100; ++i)
{
print('H');
print('e');
print('l');
print('l');
print('o');
}
}
}
declare i32 @putchar(i32)
define internal void @class.Program.print.3311(i8* %this, i8 zeroext %ch) {
.entry.4:
%l.0 = alloca i8
store i8 %ch, i8* %l.0
%l.1 = load i8* %l.0
%l.2 = zext i8 %l.1 to i32
%l.3 = call i32 @putchar(i32 %l.2)
ret void
}
define internal void @class.Program.main.0(i8* %this) {
.entry.0:
%l.0 = alloca i32
store i32 0, i32* %l.0
br label %.for.start.1
.for.start.1:
%l.1 = load i32* %l.0
%l.2 = icmp slt i32 %l.1, 100
br i1 %l.2, label %.for.cont.2, label %.for.skip.3
.for.cont.2:
call void @class.Program.print.3311(i8* undef, i8 72)
call void @class.Program.print.3311(i8* undef, i8 101)
call void @class.Program.print.3311(i8* undef, i8 108)
call void @class.Program.print.3311(i8* undef, i8 108)
call void @class.Program.print.3311(i8* undef, i8 111)
%l.3 = load i32* %l.0
%l.4 = add i32 %l.3, 1
store i32 %l.4, i32* %l.0
br label %.for.start.1
.for.skip.3:
ret void
}
define i32 @main(i32 %argc, i8** %argv) {
call void @class.Program.main.0(i8* undef)
ret i32 0
}
; ModuleID = 'result.ll'
; Function Attrs: nounwind
declare i32 @putchar(i32) #0
; Function Attrs: nounwind
define i32 @main(i32 %argc, i8** nocapture readnone %argv) #0 {
br label %.for.cont.2.i
.for.cont.2.i: ; preds = %.for.cont.2.i, %0
%l.45.i = phi i32 [ 0, %0 ], [ %l.4.i, %.for.cont.2.i ]
%l.3.i.i = tail call i32 @putchar(i32 72) #0
%l.3.i1.i = tail call i32 @putchar(i32 101) #0
%l.3.i2.i = tail call i32 @putchar(i32 108) #0
%l.3.i3.i = tail call i32 @putchar(i32 108) #0
%l.3.i4.i = tail call i32 @putchar(i32 111) #0
%l.4.i = add i32 %l.45.i, 1
%exitcond.i = icmp eq i32 %l.4.i, 100
br i1 %exitcond.i, label %class.Program.main.0.exit, label %.for.cont.2.i
class.Program.main.0.exit: ; preds = %.for.cont.2.i
ret i32 0
}
attributes #0 = { nounwind }
.file "result.opt.bc"
.text
.globl main
.align 16, 0x90
.type main,@function
main: # @main
# BB#0:
pushq %rbx
movl $100, %ebx
.align 16, 0x90
.LBB0_1: # %.for.cont.2.i
# =>This Inner Loop Header: Depth=1
movl $72, %edi
callq putchar
movl $101, %edi
callq putchar
movl $108, %edi
callq putchar
movl $108, %edi
callq putchar
movl $111, %edi
callq putchar
decl %ebx
jne .LBB0_1
# BB#2: # %class.Program.main.0.exit
xorl %eax, %eax
popq %rbx
ret
.Ltmp0:
.size main, .Ltmp0-main
.section ".note.GNU-stack","",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment