aboutsummaryrefslogtreecommitdiff
path: root/include/cps/FunctionGen.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-22 13:43:50 +0000
committer_ov4 <ov4@ov4.org>2026-10-22 13:43:50 +0000
commit06538905915b15bde6364459929fe89cf0b8de5c (patch)
tree1ec58f49ee4d990484001c13395aae2a8e5cd328 /include/cps/FunctionGen.h
parent90bf56f456e22dcd98458eca14e0b152a5efb179 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/FunctionGen.h')
-rw-r--r--include/cps/FunctionGen.h6
1 files changed, 5 insertions, 1 deletions
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<ParamSig> 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<void(const FuncSig &)> BeforeCall;
ArrayParamBinder BindArrayParam;
std::function<void(llvm::Value *, const std::string &, int)> RegisterCopy;
+ ClangABI ABI{Context, Types}; // clang context created on the first EXTERN
void createArgumentAllocas(llvm::Function *F, const std::vector<ParamDecl> &Params, bool IsMethod);
llvm::Type *getLLVMType(const std::string &TypeName);