progs/fun2/sqr.ll
changeset 854 ce4a7bab6bd8
parent 826 b0352633bf48
equal deleted inserted replaced
853:568671822d52 854:ce4a7bab6bd8
    25 
    25 
    26 define void @skip() #0 {
    26 define void @skip() #0 {
    27   ret void
    27   ret void
    28 }
    28 }
    29 
    29 
    30 @.str = private constant [4 x i8] c"%d\0A\00"
    30 @.str_int = private constant [3 x i8] c"%d\00"
    31 
    31 
    32 define void @print_int(i32 %x) {
    32 define void @print_int(i32 %x) {
    33    %t0 = getelementptr [4 x i8], [4 x i8]* @.str, i32 0, i32 0
    33    %t0 = getelementptr [3 x i8], [3 x i8]* @.str_int, i32 0, i32 0
       
    34    call i32 (i8*, ...) @printf(i8* %t0, i32 %x) 
       
    35    ret void
       
    36 }
       
    37 
       
    38 @.str_char = private constant [3 x i8] c"%c\00"
       
    39 
       
    40 define void @print_char(i32 %x) {
       
    41    %t0 = getelementptr [3 x i8], [3 x i8]* @.str_char, i32 0, i32 0
    34    call i32 (i8*, ...) @printf(i8* %t0, i32 %x) 
    42    call i32 (i8*, ...) @printf(i8* %t0, i32 %x) 
    35    ret void
    43    ret void
    36 }
    44 }
    37 
    45 
    38 ; END OF BUILD-IN FUNCTIONS (prelude)
    46 ; END OF BUILD-IN FUNCTIONS (prelude)
    45 }
    53 }
    46 
    54 
    47 define void @all (i32 %n) {
    55 define void @all (i32 %n) {
    48    %tmp_22 = load i32, i32* @Max
    56    %tmp_22 = load i32, i32* @Max
    49    %tmp_21 = icmp sle i32  %n, %tmp_22
    57    %tmp_21 = icmp sle i32  %n, %tmp_22
    50    br i1 %tmp_21, label %if_branch_28, label %else_branch_29
    58    br i1 %tmp_21, label %if_branch_29, label %else_branch_30
    51 
    59 
    52 if_branch_28:
    60 if_branch_29:
    53    %tmp_23 = call i32 @sqr (i32 %n)
    61    %tmp_23 = call i32 @sqr (i32 %n)
    54    call void @print_int (i32 %tmp_23)
    62    call void @print_int (i32 %tmp_23)
    55    %tmp_25 = add i32  %n, 1
    63    call void @new_line ()
    56    call void @all (i32 %tmp_25)
    64    %tmp_26 = add i32  %n, 1
       
    65    call void @all (i32 %tmp_26)
    57    ret void
    66    ret void
    58 
    67 
    59 else_branch_29:
    68 else_branch_30:
    60    call void @skip ()
    69    call void @skip ()
    61    ret void
    70    ret void
    62 }
    71 }
    63 
    72 
    64 define i32 @main() {
    73 define i32 @main() {