Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ModuleID = '<string>'
- target triple = "unknown-unknown-unknown"
- %thunk = type { i1, i8* }
- %closure.1 = type { %thunk*, i8* (%thunk*, %thunk*)* }
- %thunk_inner = type { i8*, i8* (i8*)* }
- @add_null = private constant %closure.1 { %thunk* null, i8* (%thunk*, %thunk*)* @add_closure }
- @add = linkonce_odr constant %thunk { i1 true, i8* bitcast (%closure.1* @add_null to i8*) }
- declare i8* @malloc(i32)
- define private i8* @add_ptr(%thunk* %.1, %thunk* %.2) {
- .3:
- %.4 = call i8* @eval_thunk(%thunk* %.1)
- %.5 = bitcast i8* %.4 to i32*
- %.6 = load i32* %.5
- %.7 = call i8* @eval_thunk(%thunk* %.2)
- %.8 = bitcast i8* %.7 to i32*
- %.9 = load i32* %.8
- %res = call i32 @add_intern(i32 %.6, i32 %.9)
- %res_ptr = call i8* @malloc(i32 4)
- %res_cast = bitcast i8* %res_ptr to i32*
- store i32 %res, i32* %res_cast
- ret i8* %res_ptr
- }
- define linkonce_odr i8* @add_closure(%thunk* %env_null, %thunk* %arg) {
- .3:
- %res = call i8* @make_closure(%thunk* %arg, i8* (%thunk*, %thunk*)* @add_ptr)
- ret i8* %res
- }
- define i32 @main() {
- entry:
- %env_pass = insertvalue [1 x %thunk*] zeroinitializer, %thunk* @add, 0
- %env_pass_ptr = call i8* @malloc(i32 8)
- %env_pass_cast = bitcast i8* %env_pass_ptr to [1 x %thunk*]*
- store [1 x %thunk*] %env_pass, [1 x %thunk*]* %env_pass_cast
- %thunk.1 = call %thunk* @make_thunk(i8* %env_pass_ptr, i8* (i8*)* @.1)
- %res_ptr = call i8* @eval_thunk(%thunk* %thunk.1)
- %res_cast = bitcast i8* %res_ptr to i32*
- %res = load i32* %res_cast
- ret i32 %res
- }
- define private i8* @.1(i8* %env) {
- .3:
- %env_ptr = bitcast i8* %env to [1 x %thunk*]*
- %env_val = load [1 x %thunk*]* %env_ptr
- %"+" = extractvalue [1 x %thunk*] %env_val, 0
- %env_pass = insertvalue [1 x %thunk*] zeroinitializer, %thunk* %"+", 0
- %env_pass_ptr = call i8* @malloc(i32 8)
- %env_pass_cast = bitcast i8* %env_pass_ptr to [1 x %thunk*]*
- store [1 x %thunk*] %env_pass, [1 x %thunk*]* %env_pass_cast
- %thunk.1 = call %thunk* @make_thunk(i8* %env_pass_ptr, i8* (i8*)* @.2)
- %num = call i8* @malloc(i32 4)
- %num32 = bitcast i8* %num to i32*
- store i32 20, i32* %num32
- %thunk.2 = call %thunk* @wrap_thunk(i8* %num)
- %operator = call i8* @eval_thunk(%thunk* %thunk.1)
- %res = tail call i8* @apply_closure(i8* %operator, %thunk* %thunk.2)
- ret i8* %res
- }
- define private i8* @.2(i8* %env) {
- .3:
- %env_ptr = bitcast i8* %env to [1 x %thunk*]*
- %env_val = load [1 x %thunk*]* %env_ptr
- %"+" = extractvalue [1 x %thunk*] %env_val, 0
- %num = call i8* @malloc(i32 4)
- %num32 = bitcast i8* %num to i32*
- store i32 10, i32* %num32
- %thunk.1 = call %thunk* @wrap_thunk(i8* %num)
- %operator = call i8* @eval_thunk(%thunk* %"+")
- %res = tail call i8* @apply_closure(i8* %operator, %thunk* %thunk.1)
- ret i8* %res
- }
- define linkonce_odr i8* @make_closure(%thunk* %env, i8* (%thunk*, %thunk*)* %fun) {
- %c1 = insertvalue %closure.1 zeroinitializer, %thunk* %env, 0
- %c2 = insertvalue %closure.1 %c1, i8* (%thunk*, %thunk*)* %fun, 1
- %c_ptr = call i8* @malloc(i32 16)
- %c_cast = bitcast i8* %c_ptr to %closure.1*
- store %closure.1 %c2, %closure.1* %c_cast
- ret i8* %c_ptr
- }
- define linkonce_odr i8* @apply_closure(i8* %c_ptr, %thunk* %arg) {
- %c_cast = bitcast i8* %c_ptr to %closure.1*
- %c = load %closure.1* %c_cast
- %env = extractvalue %closure.1 %c, 0
- %fun = extractvalue %closure.1 %c, 1
- %res = call i8* %fun(%thunk* %env, %thunk* %arg)
- ret i8* %res
- }
- define linkonce_odr %thunk* @make_thunk(i8* %env, i8* (i8*)* %fun) {
- %ti1 = insertvalue %thunk_inner zeroinitializer, i8* %env, 0
- %ti2 = insertvalue %thunk_inner %ti1, i8* (i8*)* %fun, 1
- %ti_ptr = call i8* @malloc(i32 16)
- %ti_cast = bitcast i8* %ti_ptr to %thunk_inner*
- store %thunk_inner %ti2, %thunk_inner* %ti_cast
- %t = insertvalue %thunk zeroinitializer, i8* %ti_ptr, 1
- %t_ptr = call i8* @malloc(i32 16)
- %t_cast = bitcast i8* %t_ptr to %thunk*
- store %thunk %t, %thunk* %t_cast
- ret %thunk* %t_cast
- }
- define linkonce_odr %thunk* @wrap_thunk(i8* %val) {
- %t = insertvalue %thunk { i1 true, i8* null }, i8* %val, 1
- %t_ptr = call i8* @malloc(i32 16)
- %t_cast = bitcast i8* %t_ptr to %thunk*
- store %thunk %t, %thunk* %t_cast
- ret %thunk* %t_cast
- }
- define linkonce_odr i8* @eval_thunk(%thunk* %t_ptr) {
- entry:
- %t = load %thunk* %t_ptr
- %evald = extractvalue %thunk %t, 0
- %val = extractvalue %thunk %t, 1
- br i1 %evald, label %return_val, label %evaluate
- evaluate: ; preds = %entry
- %tin_cast = bitcast i8* %val to %thunk_inner*
- %tin = load %thunk_inner* %tin_cast
- %env = extractvalue %thunk_inner %tin, 0
- %fun = extractvalue %thunk_inner %tin, 1
- %res = call i8* %fun(i8* %env)
- %t_new = insertvalue %thunk { i1 true, i8* null }, i8* %res, 1
- store %thunk %t_new, %thunk* %t_ptr
- ret i8* %res
- return_val: ; preds = %entry
- ret i8* %val
- }
- define linkonce_odr i32 @add_intern(i32 %x, i32 %y) {
- %res = add i32 %x, %y
- ret i32 %res
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement