feat: support source pointers and references
This commit is contained in:
@@ -168,6 +168,27 @@ emit_instruction proc(state @mut State, block @ir.Block, instruction ir.Instruct
|
||||
try io.print(" %r{} = insertvalue %address poison, ptr %r{}, 0\n", output, {address, pointer})
|
||||
try io.print(" %r{} = insertvalue %address %r{}, ptr null, 1\n", output, {result, address})
|
||||
}
|
||||
.pointer_from_address: {
|
||||
address :: try load(state, instruction.left)
|
||||
flag :: fresh(state)
|
||||
position :: location(state.line_starts, instruction.span)
|
||||
try io.print(" %r{} = extractvalue %address %r{}, 1\n", output, {flag, address})
|
||||
try io.print(" call void @check_init(ptr %r{}, i1 true, i64 {}, i64 {}, i64 {})\n", output, {flag, usize(instruction.span.source), position.line, position.column})
|
||||
try io.print(" %r{} = extractvalue %address %r{}, 0\n", output, {result, address})
|
||||
}
|
||||
.pointer_address: {
|
||||
pointer :: try load(state, instruction.left)
|
||||
address :: fresh(state)
|
||||
try io.print(" %r{} = insertvalue %address poison, ptr %r{}, 0\n", output, {address, pointer})
|
||||
try io.print(" %r{} = insertvalue %address %r{}, ptr null, 1\n", output, {result, address})
|
||||
}
|
||||
.pointer_offset: {
|
||||
pointer :: try load(state, instruction.left)
|
||||
index :: try load(state, instruction.right)
|
||||
try io.print(" %r{} = getelementptr ", output, {result})
|
||||
try write_type(output, state.module, Type{ kind = instruction.pointee, shape = instruction.array_type })
|
||||
try io.print(", ptr %r{}, i64 %r{}\n", output, {pointer, index})
|
||||
}
|
||||
.load_address, .store_address: {
|
||||
address :: try load(state, instruction.left)
|
||||
pointer :: fresh(state)
|
||||
|
||||
@@ -133,7 +133,7 @@ write_type proc(output io.Writer, module @ir.Module, type Type) void ! io.WriteE
|
||||
.float: try io.write_all(output, "double")
|
||||
.bool: try io.write_all(output, "i1")
|
||||
.string: try io.write_all(output, "%string")
|
||||
.function: try io.write_all(output, "ptr")
|
||||
.function, .pointer: try io.write_all(output, "ptr")
|
||||
.address: try io.write_all(output, "%address")
|
||||
.array: {
|
||||
shape :: module.arrays.items[usize(type.shape)]
|
||||
@@ -275,6 +275,7 @@ print_call proc(output io.Writer, module @ir.Module, type Type, operand usize) v
|
||||
.float: try io.print(" call void @print_float(double %r{})\n", output, {operand})
|
||||
.bool: try io.print(" call void @print_bool(i1 %r{})\n", output, {operand})
|
||||
.string: try io.print(" call void @print_string(%string %r{})\n", output, {operand})
|
||||
.pointer: try io.write_all(output, " call void @out(i32 1, ptr @pointer_text, i64 9)\n")
|
||||
.array, .record: {
|
||||
try io.print(" call void @print_array{}(", output, {u32(type.shape)})
|
||||
try write_type(output, module, type)
|
||||
|
||||
@@ -37,6 +37,7 @@ runtime ::
|
||||
`@fmt_float = private constant [6 x i8] c"%.17g\00"
|
||||
`@true = private constant [4 x i8] c"true"
|
||||
`@false = private constant [5 x i8] c"false"
|
||||
`@pointer_text = private constant [9 x i8] c"<pointer>"
|
||||
`@colon = private constant [1 x i8] c":"
|
||||
`@error = private constant [9 x i8] c": error: "
|
||||
`@runtime_trap = private constant [16 x i8] c": runtime trap: "
|
||||
|
||||
Reference in New Issue
Block a user