aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 09:13:32 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 09:13:32 +0000
commite1f41ed9fafaf7eb4f2da6878a3fabcf2f7c021e (patch)
treec4cd67b10e8513bb6dfad58e3c3b55033745ed12 /include/cps/CodeGen.h
parent59a2bb6acb975d820ab29be63a6f909d6e6ef40f (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/CodeGen.h')
-rw-r--r--include/cps/CodeGen.h13
1 files changed, 12 insertions, 1 deletions
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<llvm::Module> TheModule;
std::unique_ptr<llvm::IRBuilder<>> Builder;
int DiagnosticLine = 0;
+ const std::vector<SourceUnit> *Units = nullptr;
+ size_t CurrentUnit = 0;
+ size_t MainUnit = 0;
+ IdentifierMap<size_t> TypeOwners;
+ std::vector<IdentifierMap<SymbolInfo>> Exports;
+ bool isVisible(size_t Owner) const;
+ void selectUnit(size_t Unit);
+ void importSymbols();
IdentifierMap<SymbolInfo> Symbols;
IdentifierMap<IdentifierMap<FunctionDefAST*>> 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<std::unique_ptr<StmtAST>> &Statements);
+ void runTypePrePass(const std::vector<std::unique_ptr<StmtAST>> &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<std::unique_ptr<StmtAST>> &Statements);
+ void compile(const std::vector<SourceUnit> &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; }