while loops

This commit is contained in:
2026-06-21 23:26:11 +02:00
parent f4194492cc
commit 380b5943b3
12 changed files with 548 additions and 16 deletions
+18 -1
View File
@@ -497,6 +497,20 @@ float_predicate :: proc(predicate: ir.Compare_Predicate) -> string {
return "oeq"
}
emit_entry_allocas :: proc(emitter: ^Emitter, instructions: []ir.Instruction) {
for instruction, instruction_index in instructions {
if instruction.op == .Alloca &&
types.is_runtime_value(instruction.type, &emitter.module.types) {
fmt.sbprintf(
&emitter.builder,
" %%v%d = alloca %s\n",
instruction_index,
llvm_type(instruction.type, &emitter.module.types),
)
}
}
}
emit_instruction_stream :: proc(
emitter: ^Emitter,
instructions: []ir.Instruction,
@@ -706,7 +720,9 @@ emit_instruction_stream :: proc(
emit_recovery_value(emitter, instruction_index, instruction, "invalid allocation type")
continue
}
fmt.sbprintf(&emitter.builder, " %%v%d = alloca %s\n", instruction_index, llvm_type(instruction.type, &emitter.module.types))
if global_initializer {
fmt.sbprintf(&emitter.builder, " %%v%d = alloca %s\n", instruction_index, llvm_type(instruction.type, &emitter.module.types))
}
case .Index_Address:
if !valid_instruction(instructions, instruction.a) ||
!valid_value(instructions, instruction.b, types.USIZE, &emitter.module.types) {
@@ -1726,6 +1742,7 @@ emit_functions :: proc(emitter: ^Emitter) {
continue
}
strings.write_string(&emitter.builder, ") {\nentry:\n")
emit_entry_allocas(emitter, function.instructions)
if function.calling_convention == .C {
for param_type, index in function.param_types {
if !types.is_record(param_type, &emitter.module.types) {