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.

32 lines
909 B

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 = "while_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"
@b = dso_local global i32 0, align 4
@a = dso_local global i32 0, align 4
define dso_local i32 @main() {
store i32 0, i32* @b, align 4
store i32 3, i32* @a, align 4 ; b, a分别赋给0, 3
br label %1 ; 跳转到标签2处
1:
%2 = load i32, i32* @a, align 4
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %10 ; 判断a是否大于0大于则进入循环
4:
%5 = load i32, i32* @b, align 4
%6 = load i32, i32* @a, align 4
%7 = add i32 %5, %6
store i32 %7, i32* @b, align 4
%8 = load i32, i32* @a, align 4
%9 = sub i32 %8, 1
store i32 %9, i32* @a, align 4 ; 进入循环执行b = b+a; a = a-1;
br label %1 ; 跳转循环开头
10:
%11 = load i32, i32* @b, align 4
ret i32 %11 ; 加载%b并返回
}