wip
This commit is contained in:
parent
a0b2218cc3
commit
844004d954
44
src/compiler.bbb
Normal file → Executable file
44
src/compiler.bbb
Normal file → Executable file
@ -3735,7 +3735,7 @@ parse_name = fn (module: &Module) []u8
|
||||
result = parse_identifier(module);
|
||||
}
|
||||
|
||||
return result;
|
||||
return arena_duplicate_string(module.arena, result);
|
||||
}
|
||||
|
||||
new_value = fn (module: &Module) &Value
|
||||
@ -5488,7 +5488,7 @@ parse_aggregate_initialization = fn (module: &Module, scope: &Scope, builder: Va
|
||||
|
||||
if (consume_character_if_match(module, '.'))
|
||||
{
|
||||
>name = parse_identifier(module);
|
||||
>name = arena_duplicate_string(module.arena, parse_identifier(module));
|
||||
skip_space(module);
|
||||
expect_character(module, '=');
|
||||
skip_space(module);
|
||||
@ -6499,7 +6499,7 @@ parse_right = fn (module: &Module, scope: &Scope, builder: ValueBuilder) &Value
|
||||
|
||||
skip_space(module);
|
||||
|
||||
>identifier = parse_identifier(module);
|
||||
>identifier = arena_duplicate_string(module.arena, parse_identifier(module));
|
||||
result = new_value(module);
|
||||
|
||||
result.& = {
|
||||
@ -7370,7 +7370,7 @@ parse = fn (module: &Module) void
|
||||
}
|
||||
|
||||
>field_line = get_line(module);
|
||||
>field_name = parse_identifier(module);
|
||||
>field_name = arena_duplicate_string(module.arena, parse_identifier(module));
|
||||
|
||||
skip_space(module);
|
||||
expect_character(module, ':');
|
||||
@ -7865,7 +7865,7 @@ parse = fn (module: &Module) void
|
||||
|
||||
>field_index = field_count;
|
||||
>field_line = get_line(module);
|
||||
>field_name = parse_identifier(module);
|
||||
>field_name = arena_duplicate_string(module.arena, parse_identifier(module));
|
||||
|
||||
skip_space(module);
|
||||
expect_character(module, ':');
|
||||
@ -7990,7 +7990,7 @@ parse = fn (module: &Module) void
|
||||
field_count += 1;
|
||||
|
||||
>field_line = get_line(module);
|
||||
>field_name = parse_identifier(module);
|
||||
>field_name = arena_duplicate_string(module.arena, parse_identifier(module));
|
||||
|
||||
skip_space(module);
|
||||
expect_character(module, ':');
|
||||
@ -12008,7 +12008,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi
|
||||
zero,
|
||||
});
|
||||
|
||||
>element_length_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_struct_type.llvm.abi, array_element_pointer, 1, "");
|
||||
>element_length_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_struct_type.llvm.abi, array_element_pointer, 1, "length");
|
||||
>element_length = create_load(module, {
|
||||
.type = u64_type,
|
||||
.pointer = element_length_pointer,
|
||||
@ -12061,7 +12061,7 @@ analyze_type = fn (module: &Module, value: &Value, expected_type: &Type, analysi
|
||||
zero,
|
||||
});
|
||||
|
||||
>element_pointer_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_struct_type.llvm.abi, length_array_element_pointer, 0, "");
|
||||
>element_pointer_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_struct_type.llvm.abi, length_array_element_pointer, 0, "pointer");
|
||||
>element_pointer = create_load(module, {
|
||||
.type = get_pointer_type(module, u8_type),
|
||||
.pointer = element_pointer_pointer,
|
||||
@ -12770,7 +12770,7 @@ create_coerced_store = fn (module: &Module, source_value: &LLVMValue, source_typ
|
||||
{
|
||||
>field = &fields[i];
|
||||
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, source_type.llvm.abi, destination_value, @truncate(i), "");
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, source_type.llvm.abi, destination_value, @truncate(i), field.name.pointer);
|
||||
>field_value = LLVMBuildExtractValue(module.llvm.builder, source_value, @truncate(i), "");
|
||||
|
||||
create_store(module, {
|
||||
@ -13208,7 +13208,7 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type
|
||||
for (i: 0..coerce_fields.length)
|
||||
{
|
||||
>field = &coerce_fields[i];
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.memory, source, @truncate(i), "");
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.memory, source, @truncate(i), field.name.pointer);
|
||||
>maybe_undef: u1 = 0;
|
||||
if (maybe_undef)
|
||||
{
|
||||
@ -13256,8 +13256,8 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type
|
||||
|
||||
for (i: 0..coerce_fields.length)
|
||||
{
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, global, @truncate(i), "");
|
||||
>field = &coerce_fields[i];
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, global, @truncate(i), field.name.pointer);
|
||||
|
||||
>maybe_undef: u1 = 0;
|
||||
if (maybe_undef)
|
||||
@ -13724,6 +13724,7 @@ emit_field_access = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, l
|
||||
|
||||
assert(result_field != zero);
|
||||
>field_index: u32 = @truncate(result_field - fields.pointer);
|
||||
>field = &fields[field_index];
|
||||
|
||||
field_access = {
|
||||
.type = resolved_aggregate_type.content.struct.fields[field_index].type,
|
||||
@ -13760,7 +13761,7 @@ emit_field_access = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, l
|
||||
else => { unreachable; },
|
||||
}
|
||||
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, field_access.struct_type, v, field_access.field_index, "");
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, field_access.struct_type, v, field_access.field_index, field_name.pointer);
|
||||
|
||||
if (left_llvm)
|
||||
{
|
||||
@ -14023,7 +14024,7 @@ emit_va_arg_from_memory = fn (module: &Module, va_list_pointer: &LLVMValue, va_l
|
||||
{
|
||||
assert(va_list_struct.id == .struct);
|
||||
|
||||
>overflow_arg_area_pointer = LLVMBuildStructGEP2(module.llvm.builder, va_list_struct.llvm.abi, va_list_pointer, 2, "");
|
||||
>overflow_arg_area_pointer = LLVMBuildStructGEP2(module.llvm.builder, va_list_struct.llvm.abi, va_list_pointer, 2, "overflow_arg_area");
|
||||
>overflow_arg_area_type = va_list_struct.content.struct.fields[2].type;
|
||||
>overflow_arg_area = create_load(module, {
|
||||
.type = overflow_arg_area_type,
|
||||
@ -14116,7 +14117,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty
|
||||
|
||||
if (needed_registers.gpr != 0)
|
||||
{
|
||||
gpr_offset_pointer = LLVMBuildStructGEP2(module.llvm.builder, va_list_struct_llvm, va_list_value_llvm, 0, "");
|
||||
gpr_offset_pointer = LLVMBuildStructGEP2(module.llvm.builder, va_list_struct_llvm, va_list_value_llvm, 0, "gpr_offset");
|
||||
gpr_offset = create_load(module, {
|
||||
.type = va_list_struct.content.struct.fields[0].type,
|
||||
.pointer = gpr_offset_pointer,
|
||||
@ -14190,7 +14191,7 @@ emit_va_arg = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_ty
|
||||
>reg_save_area_type = va_list_struct.content.struct.fields[3].type;
|
||||
>reg_save_area = create_load(module, {
|
||||
.type = reg_save_area_type,
|
||||
.pointer = LLVMBuildStructGEP2(module.llvm.builder, va_list_struct_llvm, va_list_value_llvm, 3, ""),
|
||||
.pointer = LLVMBuildStructGEP2(module.llvm.builder, va_list_struct_llvm, va_list_value_llvm, 3, "reg_save_area"),
|
||||
.alignment = 16,
|
||||
zero,
|
||||
});
|
||||
@ -15731,11 +15732,12 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type,
|
||||
{
|
||||
>string_literal = emit_string_literal(module, right);
|
||||
>slice_type = get_slice_type(module, uint8(module));
|
||||
|
||||
>slice_fields = slice_type.content.struct.fields;
|
||||
for (i: 0..string_literal.length)
|
||||
{
|
||||
>member_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_type.llvm.abi, left_llvm, @truncate(i), "");
|
||||
>slice_member_type = slice_type.content.struct.fields[i].type;
|
||||
>slice_field = &slice_fields[i];
|
||||
>member_pointer = LLVMBuildStructGEP2(module.llvm.builder, slice_type.llvm.abi, left_llvm, @truncate(i), slice_field.name.pointer);
|
||||
>slice_member_type = slice_field.type;
|
||||
create_store(module, {
|
||||
.source = string_literal[i],
|
||||
.destination = member_pointer,
|
||||
@ -15834,7 +15836,7 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type,
|
||||
|
||||
>field = &fields[declaration_index];
|
||||
|
||||
>destination_pointer = LLVMBuildStructGEP2(module.llvm.builder, resolved_value_type.llvm.memory, left_llvm, @truncate(declaration_index), "");
|
||||
>destination_pointer = LLVMBuildStructGEP2(module.llvm.builder, resolved_value_type.llvm.memory, left_llvm, @truncate(declaration_index), field.name.pointer);
|
||||
|
||||
emit_assignment(module, destination_pointer, get_pointer_type(module, field.type), value);
|
||||
}
|
||||
@ -15906,7 +15908,7 @@ emit_assignment = fn (module: &Module, left_llvm: &LLVMValue, left_type: &Type,
|
||||
zero,
|
||||
});
|
||||
|
||||
>slice_length_destination = LLVMBuildStructGEP2(module.llvm.builder, resolved_value_type.llvm.abi, left_llvm, 1, "");
|
||||
>slice_length_destination = LLVMBuildStructGEP2(module.llvm.builder, resolved_value_type.llvm.abi, left_llvm, 1, "length");
|
||||
create_store(module, {
|
||||
.source = slice_values[1],
|
||||
.destination = slice_length_destination,
|
||||
@ -17859,7 +17861,7 @@ emit = fn (module: &Module) void
|
||||
for (i: 0..fields.length)
|
||||
{
|
||||
>field = &fields[i];
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, address, @truncate(i), "");
|
||||
>gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, address, @truncate(i), field.name.pointer);
|
||||
create_store(module, {
|
||||
.source = argument_abi_arguments[i],
|
||||
.destination = gep,
|
||||
|
@ -2070,6 +2070,66 @@ breakpoint = fn () void
|
||||
}
|
||||
}
|
||||
|
||||
CPUArchitecture = enum
|
||||
{
|
||||
x86_64,
|
||||
}
|
||||
|
||||
OperatingSystem = enum
|
||||
{
|
||||
linux,
|
||||
}
|
||||
|
||||
Target = struct
|
||||
{
|
||||
cpu: CPUArchitecture,
|
||||
os: OperatingSystem,
|
||||
host_cpu_model: u1,
|
||||
}
|
||||
|
||||
struct_arbitrary_int_abi_function = fn [cc(c)] (host_cpu_model: u1) Target
|
||||
{
|
||||
return {
|
||||
.cpu = .x86_64,
|
||||
.os = .linux,
|
||||
.host_cpu_model = host_cpu_model,
|
||||
};
|
||||
}
|
||||
|
||||
StructArbitraryIntAbiContainer = struct
|
||||
{
|
||||
a: u8,
|
||||
b: u8,
|
||||
c: Target,
|
||||
d: u8,
|
||||
e: u8
|
||||
f: u8,
|
||||
g: u8,
|
||||
}
|
||||
|
||||
struct_arbitrary_int_abi = fn () void
|
||||
{
|
||||
>some_struct: StructArbitraryIntAbiContainer = {
|
||||
.f = 45,
|
||||
.g = 46,
|
||||
.e = 123,
|
||||
.d = 231,
|
||||
.c = struct_arbitrary_int_abi_function(0),
|
||||
.a = 123,
|
||||
.b = 231,
|
||||
};
|
||||
|
||||
require(some_struct.a == 123);
|
||||
require(some_struct.b == 231);
|
||||
require(some_struct.c.cpu == .x86_64);
|
||||
require(some_struct.c.os == .linux);
|
||||
require(!some_struct.c.host_cpu_model);
|
||||
require(some_struct.d == 231);
|
||||
require(some_struct.e == 123);
|
||||
require(some_struct.f == 45);
|
||||
require(some_struct.g == 46);
|
||||
}
|
||||
|
||||
[export] main = fn [cc(c)] (argc: s32, argv: &&u8, envp: &&u8) s32
|
||||
{
|
||||
>rc = return_constant();
|
||||
@ -2335,5 +2395,7 @@ breakpoint = fn () void
|
||||
|
||||
breakpoint();
|
||||
|
||||
struct_arbitrary_int_abi();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user