From 06538905915b15bde6364459929fe89cf0b8de5c Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 13:43:50 +0000 Subject: feat(codegen): arrange EXTERN signatures with clang's C ABI Every EXTERN "C" signature is now arranged by clang's CodeGen (arrangeFreeFunctionCall) for the host triple and applied by one generic lowering routine, replacing the hand-written signext/zeroext rule. clangCodeGen is linked statically into CPSCodeGen. Records still cross only through pointer types, so generated code is unchanged. Co-Authored-By: Claude Opus 5.5 --- include/cps/FunctionGen.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/cps/FunctionGen.h') diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h index 1b4a07a..8b63d67 100644 --- a/include/cps/FunctionGen.h +++ b/include/cps/FunctionGen.h @@ -1,4 +1,5 @@ #pragma once +#include "cps/CABI.h" #include "cps/Identifier.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" @@ -45,9 +46,11 @@ struct FuncSig { std::vector Params; size_t OwnerUnit = 0; // EXTERN "C": called through its declared C type, which may differ from a - // runtime declaration of the same libc symbol. + // runtime declaration of the same libc symbol. ExternABI is clang's + // arrangement of the fixed parameters; ExternType and ExternAttrs lower it. bool IsExternal = false; bool IsVariadic = false; + CABISignature ExternABI; llvm::FunctionType *ExternType = nullptr; llvm::AttributeList ExternAttrs; }; @@ -83,6 +86,7 @@ private: std::function BeforeCall; ArrayParamBinder BindArrayParam; std::function RegisterCopy; + ClangABI ABI{Context, Types}; // clang context created on the first EXTERN void createArgumentAllocas(llvm::Function *F, const std::vector &Params, bool IsMethod); llvm::Type *getLLVMType(const std::string &TypeName); -- cgit v1.3.1-4-g156e