Skip to content

Instantly share code, notes, and snippets.

@yhara
Created Mar 16, 2020
Embed
What would you like to do?
; ModuleID = 'main'
source_filename = "main"
%Void = type <{}>
%Math = type <{}>
%Object = type <{}>
@"::ITER" = internal global i32 0
@"::Void" = internal global %Void* null
@"::LIMIT_SQUARED" = internal global double 0.000000e+00
declare i32 @putchar(i32)
declare void @GC_init()
declare i8* @GC_malloc(i64)
declare double @sin(double)
declare double @cos(double)
declare double @sqrt(double)
declare double @fabs(double)
define i1 @"Float#=="(double %self, double %other) {
%eq = fcmp oeq double %self, %other
ret i1 %eq
}
define i1 @"Float#!="(double %self, double %other) {
%neq = fcmp une double %self, %other
ret i1 %neq
}
define i1 @"Float#<"(double %self, double %other) {
%lt = fcmp olt double %self, %other
ret i1 %lt
}
define i1 @"Float#>"(double %self, double %other) {
%gt = fcmp ogt double %self, %other
ret i1 %gt
}
define i1 @"Float#<="(double %self, double %other) {
%leq = fcmp ole double %self, %other
ret i1 %leq
}
define i1 @"Float#>="(double %self, double %other) {
%geq = fcmp oge double %self, %other
ret i1 %geq
}
define double @"Float#+"(double %self, double %other) {
%add = fadd double %self, %other
ret double %add
}
define double @"Float#-"(double %self, double %other) {
%sub = fsub double %self, %other
ret double %sub
}
define double @"Float#*"(double %self, double %other) {
%mul = fmul double %self, %other
ret double %mul
}
define double @"Float#/"(double %self, double %other) {
%div = fdiv double %self, %other
ret double %div
}
define double @"Float#abs"(double %self) {
%result = call double @fabs(double %self)
ret double %result
}
define i32 @"Float#to_i"(double %self) {
%int = fptosi double %self to i32
ret i32 %int
}
define double @"Meta:Math#sin"(%Math* %self, double %x) {
%result = call double @sin(double %x)
ret double %result
}
define double @"Meta:Math#cos"(%Math* %self, double %x) {
%result = call double @cos(double %x)
ret double %result
}
define double @"Meta:Math#sqrt"(%Math* %self, double %x) {
%result = call double @sqrt(double %x)
ret double %result
}
define void @"Object#putchar"(%Object* %self, i32 %ord) {
%1 = call i32 @putchar(i32 %ord)
ret void
}
define i1 @"Int#=="(i32 %self, i32 %other) {
%eq = icmp eq i32 %self, %other
ret i1 %eq
}
define i1 @"Int#!="(i32 %self, i32 %other) {
%neq = icmp ne i32 %self, %other
ret i1 %neq
}
define i1 @"Int#<"(i32 %self, i32 %other) {
%lt = icmp slt i32 %self, %other
ret i1 %lt
}
define i1 @"Int#>"(i32 %self, i32 %other) {
%gt = icmp sgt i32 %self, %other
ret i1 %gt
}
define i1 @"Int#<="(i32 %self, i32 %other) {
%leq = icmp sle i32 %self, %other
ret i1 %leq
}
define i1 @"Int#>="(i32 %self, i32 %other) {
%geq = icmp sge i32 %self, %other
ret i1 %geq
}
define i32 @"Int#+"(i32 %self, i32 %other) {
%add = add i32 %self, %other
ret i32 %add
}
define i32 @"Int#-"(i32 %self, i32 %other) {
%sub = sub i32 %self, %other
ret i32 %sub
}
define i32 @"Int#*"(i32 %self, i32 %other) {
%mul = mul i32 %self, %other
ret i32 %mul
}
define i32 @"Int#/"(i32 %self, i32 %other) {
%div = sdiv i32 %self, %other
ret i32 %div
}
define i32 @"Int#&"(i32 %self, i32 %other) {
%and = and i32 %self, %other
ret i32 %and
}
define i32 @"Int#|"(i32 %self, i32 %other) {
%or = or i32 %self, %other
ret i32 %or
}
define i32 @"Int#^"(i32 %self, i32 %other) {
%xor = xor i32 %self, %other
ret i32 %xor
}
define i32 @"Int#<<"(i32 %self, i32 %other) {
%lshift = shl i32 %self, %other
ret i32 %lshift
}
define i32 @"Int#>>"(i32 %self, i32 %other) {
%rshift = ashr i32 %self, %other
ret i32 %rshift
}
define double @"Int#to_f"(i32 %self) {
%float = sitofp i32 %self to double
ret double %float
}
define i32 @main() {
call void @GC_init()
%raw_addr = call i8* @GC_malloc(i64 ptrtoint (%Object* getelementptr (%Object, %Object* null, i32 1) to i64))
%addr = bitcast i8* %raw_addr to %Object*
%raw_addr1 = call i8* @GC_malloc(i64 ptrtoint (%Void* getelementptr (%Void, %Void* null, i32 1) to i64))
%addr2 = bitcast i8* %raw_addr1 to %Void*
store %Void* %addr2, %Void** @"::Void"
store i32 49, i32* @"::ITER"
store double 4.000000e+00, double* @"::LIMIT_SQUARED"
%size = alloca i32
store i32 600, i32* %size
call void @"Object#putchar"(%Object* %addr, i32 80)
call void @"Object#putchar"(%Object* %addr, i32 52)
call void @"Object#putchar"(%Object* %addr, i32 10)
call void @"Object#putchar"(%Object* %addr, i32 54)
call void @"Object#putchar"(%Object* %addr, i32 48)
call void @"Object#putchar"(%Object* %addr, i32 48)
call void @"Object#putchar"(%Object* %addr, i32 32)
call void @"Object#putchar"(%Object* %addr, i32 54)
call void @"Object#putchar"(%Object* %addr, i32 48)
call void @"Object#putchar"(%Object* %addr, i32 48)
call void @"Object#putchar"(%Object* %addr, i32 10)
store i32 49, i32* @"::ITER"
store double 4.000000e+00, double* @"::LIMIT_SQUARED"
%byte_acc = alloca i32
store i32 0, i32* %byte_acc
%bit_num = alloca i32
store i32 0, i32* %bit_num
%size3 = load i32, i32* %size
%result = call i32 @"Int#-"(i32 %size3, i32 1)
%count_size = alloca i32
store i32 %result, i32* %count_size
%y = alloca i32
store i32 0, i32* %y
br label %WhileBegin
WhileBegin: ; preds = %WhileEnd12, %0
%y4 = load i32, i32* %y
%count_size5 = load i32, i32* %count_size
%result6 = call i1 @"Int#<="(i32 %y4, i32 %count_size5)
br i1 %result6, label %WhileBody, label %WhileEnd
WhileBody: ; preds = %WhileBegin
%x = alloca i32
store i32 0, i32* %x
br label %WhileBegin7
WhileEnd: ; preds = %WhileBegin
ret i32 0
WhileBegin7: ; preds = %IfEnd70, %WhileBody
%x8 = load i32, i32* %x
%count_size9 = load i32, i32* %count_size
%result10 = call i1 @"Int#<="(i32 %x8, i32 %count_size9)
br i1 %result10, label %WhileBody11, label %WhileEnd12
WhileBody11: ; preds = %WhileBegin7
%zr = alloca double
store double 0.000000e+00, double* %zr
%zi = alloca double
store double 0.000000e+00, double* %zi
%x13 = load i32, i32* %x
%result14 = call double @"Int#to_f"(i32 %x13)
%result15 = call double @"Float#*"(double 2.000000e+00, double %result14)
%size16 = load i32, i32* %size
%result17 = call double @"Int#to_f"(i32 %size16)
%result18 = call double @"Float#/"(double %result15, double %result17)
%result19 = call double @"Float#-"(double %result18, double 1.500000e+00)
%cr = alloca double
store double %result19, double* %cr
%y20 = load i32, i32* %y
%result21 = call double @"Int#to_f"(i32 %y20)
%result22 = call double @"Float#*"(double 2.000000e+00, double %result21)
%size23 = load i32, i32* %size
%result24 = call double @"Int#to_f"(i32 %size23)
%result25 = call double @"Float#/"(double %result22, double %result24)
%result26 = call double @"Float#-"(double %result25, double 1.000000e+00)
%ci = alloca double
store double %result26, double* %ci
%escape = alloca i1
store i1 false, i1* %escape
%dummy = alloca i32
store i32 0, i32* %dummy
br label %WhileBegin27
WhileEnd12: ; preds = %WhileBegin7
%y90 = load i32, i32* %y
%result91 = call i32 @"Int#+"(i32 %y90, i32 1)
store i32 %result91, i32* %y
br label %WhileBegin
WhileBegin27: ; preds = %IfEnd, %WhileBody11
%dummy28 = load i32, i32* %dummy
%"::ITER" = load i32, i32* @"::ITER"
%result29 = call i1 @"Int#<="(i32 %dummy28, i32 %"::ITER")
br i1 %result29, label %WhileBody30, label %WhileEnd31
WhileBody30: ; preds = %WhileBegin27
%zr32 = load double, double* %zr
%zr33 = load double, double* %zr
%result34 = call double @"Float#*"(double %zr32, double %zr33)
%zi35 = load double, double* %zi
%zi36 = load double, double* %zi
%result37 = call double @"Float#*"(double %zi35, double %zi36)
%result38 = call double @"Float#-"(double %result34, double %result37)
%cr39 = load double, double* %cr
%result40 = call double @"Float#+"(double %result38, double %cr39)
%tr = alloca double
store double %result40, double* %tr
%zr41 = load double, double* %zr
%result42 = call double @"Float#*"(double 2.000000e+00, double %zr41)
%zi43 = load double, double* %zi
%result44 = call double @"Float#*"(double %result42, double %zi43)
%ci45 = load double, double* %ci
%result46 = call double @"Float#+"(double %result44, double %ci45)
%ti = alloca double
store double %result46, double* %ti
%tr47 = load double, double* %tr
store double %tr47, double* %zr
%ti48 = load double, double* %ti
store double %ti48, double* %zi
%zr49 = load double, double* %zr
%zr50 = load double, double* %zr
%result51 = call double @"Float#*"(double %zr49, double %zr50)
%zi52 = load double, double* %zi
%zi53 = load double, double* %zi
%result54 = call double @"Float#*"(double %zi52, double %zi53)
%result55 = call double @"Float#+"(double %result51, double %result54)
%"::LIMIT_SQUARED" = load double, double* @"::LIMIT_SQUARED"
%result56 = call i1 @"Float#>"(double %result55, double %"::LIMIT_SQUARED")
br i1 %result56, label %IfThen, label %IfEnd
WhileEnd31: ; preds = %IfThen, %WhileBegin27
%byte_acc59 = load i32, i32* %byte_acc
%result60 = call i32 @"Int#<<"(i32 %byte_acc59, i32 1)
br label %IfBegin
IfThen: ; preds = %WhileBody30
store i1 true, i1* %escape
br label %WhileEnd31
br label %IfEnd
IfEnd: ; preds = %IfThen, %WhileBody30
%dummy57 = load i32, i32* %dummy
%result58 = call i32 @"Int#+"(i32 %dummy57, i32 1)
store i32 %result58, i32* %dummy
br label %WhileBegin27
IfBegin: ; preds = %WhileEnd31
%escape63 = load i1, i1* %escape
br i1 %escape63, label %IfThen61, label %IfElse
IfThen61: ; preds = %IfBegin
br label %IfEnd62
IfElse: ; preds = %IfBegin
br label %IfEnd62
IfEnd62: ; preds = %IfElse, %IfThen61
%ifResult = phi i32 [ 0, %IfThen61 ], [ 1, %IfElse ]
%result64 = call i32 @"Int#|"(i32 %result60, i32 %ifResult)
store i32 %result64, i32* %byte_acc
%bit_num65 = load i32, i32* %bit_num
%result66 = call i32 @"Int#+"(i32 %bit_num65, i32 1)
store i32 %result66, i32* %bit_num
br label %IfBegin67
IfBegin67: ; preds = %IfEnd62
%bit_num71 = load i32, i32* %bit_num
%result72 = call i1 @"Int#=="(i32 %bit_num71, i32 8)
br i1 %result72, label %IfThen68, label %IfElse69
IfThen68: ; preds = %IfBegin67
%byte_acc73 = load i32, i32* %byte_acc
call void @"Object#putchar"(%Object* %addr, i32 %byte_acc73)
store i32 0, i32* %byte_acc
store i32 0, i32* %bit_num
br label %IfEnd70
IfElse69: ; preds = %IfBegin67
br label %IfBegin74
IfEnd70: ; preds = %IfEnd77, %IfThen68
%ifResult87 = phi i32 [ 0, %IfThen68 ], [ %ifResult86, %IfEnd77 ]
%x88 = load i32, i32* %x
%result89 = call i32 @"Int#+"(i32 %x88, i32 1)
store i32 %result89, i32* %x
br label %WhileBegin7
IfBegin74: ; preds = %IfElse69
%x78 = load i32, i32* %x
%count_size79 = load i32, i32* %count_size
%result80 = call i1 @"Int#=="(i32 %x78, i32 %count_size79)
br i1 %result80, label %IfThen75, label %IfElse76
IfThen75: ; preds = %IfBegin74
%byte_acc81 = load i32, i32* %byte_acc
%bit_num82 = load i32, i32* %bit_num
%result83 = call i32 @"Int#-"(i32 8, i32 %bit_num82)
%result84 = call i32 @"Int#<<"(i32 %byte_acc81, i32 %result83)
store i32 %result84, i32* %byte_acc
%byte_acc85 = load i32, i32* %byte_acc
call void @"Object#putchar"(%Object* %addr, i32 %byte_acc85)
store i32 0, i32* %byte_acc
store i32 0, i32* %bit_num
br label %IfEnd77
IfElse76: ; preds = %IfBegin74
br label %IfEnd77
IfEnd77: ; preds = %IfElse76, %IfThen75
%ifResult86 = phi i32 [ 0, %IfThen75 ], [ 0, %IfElse76 ]
br label %IfEnd70
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment