You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

source_filename = "func_test.sy"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
define dso_local i32 @add(i32 %0, i32 %1) { ; 定义add函数
%3 = alloca i32, align 4
%4 = alloca i32, align 4
store i32 %0, i32* %3, align 4
store i32 %1, i32* %4, align 4 ; 以上四步把两个参数移到%3 %4必须从3开始
%5 = load i32, i32* %3, align 4
%6 = load i32, i32* %4, align 4
%7 = add i32 %5, %6
%8 = sub i32 %7, 1
ret i32 %8 ; 此处用静态单赋值的方式计算a+b-1
}
define dso_local i32 @main() {
%1 = alloca i32, align 4
%2 = alloca i32, align 4
%3 = alloca i32, align 4
store i32 3, i32* %1, align 4
store i32 2, i32* %2, align 4
store i32 5, i32* %3, align 4 ; %1 浪费不用,%2~%4赋给3,2,5相当于a,b,c。
%4 = load i32, i32* %3, align 4
%5 = load i32, i32* %1, align 4
%6 = load i32, i32* %2, align 4
%7 = call i32 @add(i32 %5, i32 %6) ; 执行函数调用
%8 = add i32 %4, %7 ; 加法
ret i32 %8
}