From e1f41ed9fafaf7eb4f2da6878a3fabcf2f7c021e Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 09:13:32 +0000 Subject: feat(driver): compile multiple source files with INCLUDE visibility Reject builds without an entry program and duplicate cross-file definitions. Preserve source order for each unit's own constants and import visible exports. Co-Authored-By: Claude Opus 5.5 --- include/cps/CodeGen.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/cps/CodeGen.h') diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h index 9a0b2ef..6e0fab1 100644 --- a/include/cps/CodeGen.h +++ b/include/cps/CodeGen.h @@ -5,6 +5,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "cps/AST.h" +#include "cps/SourceUnit.h" #include "cps/RuntimeCheck.h" #include "cps/FunctionGen.h" #include "cps/TypeSystem.h" @@ -32,6 +33,14 @@ class CodeGen { std::unique_ptr TheModule; std::unique_ptr> Builder; int DiagnosticLine = 0; + const std::vector *Units = nullptr; + size_t CurrentUnit = 0; + size_t MainUnit = 0; + IdentifierMap TypeOwners; + std::vector> Exports; + bool isVisible(size_t Owner) const; + void selectUnit(size_t Unit); + void importSymbols(); IdentifierMap Symbols; IdentifierMap> ClassMethods; std::string CurrentClass; @@ -123,7 +132,7 @@ class CodeGen { void emitCInput(llvm::Value *Addr, const TypeInfo *Info); // TYPE-system registration (Designator.cc) and operators (TypeCheckGen.cc). - void runTypePrePass(const std::vector> &Statements); + void runTypePrePass(const std::vector> &Statements, int Phase); llvm::Value *emitUserKindBinaryOp(int Op, llvm::Value *L, const TypeInfo *LT, llvm::Value *R, const TypeInfo *RT, int Line); @@ -161,6 +170,8 @@ public: CodeGen(); ~CodeGen(); void compile(const std::vector> &Statements); + void compile(const std::vector &Sources); + size_t getMainUnit() const { return MainUnit; } void print(llvm::raw_ostream &Output); const llvm::Module &getModule() const { return *TheModule; } bool hadError() const { return HadError; } -- cgit v1.3.1-4-g156e