From 7abff8975e93fcc721784aabe0563d440cc26410 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Fri, 13 Jun 2025 19:04:35 -0600 Subject: [PATCH] Pass some more C ABI tests --- src/compiler.bbb | 43 ++++++++++++++++++++++++++++++++++++++++++- src/emitter.cpp | 4 ++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/compiler.bbb b/src/compiler.bbb index 2145037..8ae67ce 100644 --- a/src/compiler.bbb +++ b/src/compiler.bbb @@ -10122,7 +10122,44 @@ emit_call = fn (module: &Module, value: &Value, left_llvm: &LLVMValue, left_type { .aggregate_initialization => { - #trap(); + >is_constant = semantic_call_argument_value.content.aggregate_initialization.is_constant; + + if (is_constant) + { + >linkage: LLVMLinkage = .internal; + >thread_local_mode: LLVMThreadLocalMode = .none; + >externally_initialized: u1 = 0; + >alignment = get_byte_alignment(semantic_argument_type); + >unnamed_address: LLVMUnnamedAddress = .global; + + >global = llvm_create_global_variable(module.llvm.module, semantic_argument_type.llvm.memory, is_constant, linkage, semantic_call_argument_value.llvm, "const.struct", thread_local_mode, externally_initialized, alignment, unnamed_address); + + for (i: 0..coerce_fields.length) + { + >gep = LLVMBuildStructGEP2(module.llvm.builder, coerce_to_type.llvm.abi, global, #truncate(i), ""); + >field = &coerce_fields[i]; + + >maybe_undef: u1 = 0; + if (maybe_undef) + { + #trap(); + } + + >load = create_load(module, { + .type = field.type, + .pointer = gep, + .alignment = alignment, + zero, + }); + + llvm_abi_argument_value_buffer[abi_argument_count] = load; + abi_argument_count += 1; + } + } + else + { + #trap(); + } } .zero => { @@ -13871,6 +13908,10 @@ names: [_][]u8 = "c_abi1", "c_med_struct_ints", "c_ret_struct_array", + "c_split_struct_ints", + "c_string_to_slice", + "c_struct_with_array", + "c_function_pointer", ]; [export] main = fn [cc(c)] (argument_count: u32, argv: &&u8, envp: &&u8) s32 diff --git a/src/emitter.cpp b/src/emitter.cpp index ff5b292..2506be8 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -853,7 +853,7 @@ fn AbiSystemVClassifyResult abi_system_v_classify_type(Type* type, AbiSystemVCla u64 vector_size = 16; - if (byte_size > 16 && (byte_size != get_byte_size(element_type) || byte_size > vector_size)) + if (byte_size > 16 && (byte_size != element_size || byte_size > vector_size)) { unreachable(); } @@ -5554,7 +5554,7 @@ fn LLVMValueRef emit_call(Module* module, Value* value, LLVMValueRef left_llvm, bool externally_initialized = false; auto alignment = get_byte_alignment(semantic_argument_type); - auto global = llvm_module_create_global_variable(module->llvm.module, semantic_argument_type->llvm.memory, is_constant, linkage_type, semantic_call_argument_value->llvm, string_literal("conststruct"), thread_local_mode, externally_initialized, alignment, LLVMGlobalUnnamedAddr); + auto global = llvm_module_create_global_variable(module->llvm.module, semantic_argument_type->llvm.memory, is_constant, linkage_type, semantic_call_argument_value->llvm, string_literal("const.struct"), thread_local_mode, externally_initialized, alignment, LLVMGlobalUnnamedAddr); for (u32 i = 0; i < coerce_fields.length; i += 1) {