From dc33cd2faf6fa52486c02e86038c8f8c07c0fe27 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 15:06:44 +0000 Subject: feat(codegen): declare and call EXTERN C functions Variadic arguments must be C values and receive C default argument promotions; narrow integer parameters carry sign/zero extension. Co-Authored-By: Claude Opus 5.5 --- include/cps/FunctionGen.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/cps/FunctionGen.h') diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h index c168e1c..5eb0f82 100644 --- a/include/cps/FunctionGen.h +++ b/include/cps/FunctionGen.h @@ -43,6 +43,12 @@ struct FuncSig { std::string ReturnTypeName; 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. + bool IsExternal = false; + bool IsVariadic = false; + llvm::FunctionType *ExternType = nullptr; + llvm::AttributeList ExternAttrs; }; class FunctionGen { @@ -103,10 +109,12 @@ public: const FuncSig *getSignatureByLink(const std::string &Name) const; llvm::Function *emitPrototype(PrototypeAST *Proto); + bool emitExternPrototype(PrototypeAST *Proto); llvm::Function *emitFunctionDef(FunctionDefAST *FuncAST, const std::function &StmtEmitter, unsigned ScopeID); llvm::Value *emitCall(const std::string &Callee, const std::vector &Args); + llvm::Value *emitCall(const FuncSig &Sig, const std::vector &Args); void emitReturn(ReturnStmtAST *Ret, llvm::Value *RetVal); }; -- cgit v1.3.1-4-g156e