while loops work!

This commit is contained in:
SpookyDervish
2025-10-15 18:44:15 +11:00
parent 549f650b54
commit 9f6fff9977
7 changed files with 155 additions and 86 deletions

View File

@@ -1,30 +1,34 @@
; ModuleID = "main"
target triple = "arm64-apple-darwin24.5.0"
target triple = "x86_64-pc-windows-msvc"
target datalayout = ""
declare i32 @"printf"(i8* %".1", ...)
@"true" = constant i1 1
@"false" = constant i1 0
define i32 @"add"(i32 %".1", i32 %".2")
{
add_entry:
%".4" = alloca i32
store i32 %".1", i32* %".4"
%".6" = alloca i32
store i32 %".2", i32* %".6"
%".8" = load i32, i32* %".4"
%".9" = load i32, i32* %".6"
%".10" = add i32 %".8", %".9"
ret i32 %".10"
}
define i32 @"main"()
{
main_entry:
%".2" = call i32 @"add"(i32 1, i32 2)
%".3" = alloca i32
store i32 %".2", i32* %".3"
%".5" = load i32, i32* %".3"
ret i32 %".5"
%".2" = alloca i32
store i32 0, i32* %".2"
%".4" = load i32, i32* %".2"
%".5" = icmp slt i32 %".4", 10
br i1 %".5", label %"while_loop_entry_1", label %"while_loop_otherwise_1"
while_loop_entry_1:
%".7" = load i32, i32* %".2"
%".8" = alloca [9 x i8]*
store [9 x i8]* @"__str_2", [9 x i8]** %".8"
%".10" = bitcast [9 x i8]* @"__str_2" to i8*
%".11" = call i32 (i8*, ...) @"printf"(i8* %".10", i32 %".7")
%".12" = load i32, i32* %".2"
%".13" = add i32 %".12", 1
store i32 %".13", i32* %".2"
%".15" = load i32, i32* %".2"
%".16" = icmp slt i32 %".15", 10
br i1 %".16", label %"while_loop_entry_1", label %"while_loop_otherwise_1"
while_loop_otherwise_1:
%".18" = load i32, i32* %".2"
ret i32 %".18"
}
@"__str_2" = internal constant [9 x i8] c"a = %i\0a\00\00"