aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 12:02:32 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 12:02:32 +0000
commit4df7c22b99349dcf2175d69679eafa175d49aa9f (patch)
tree1b44c329ed3e3f75787d9410d211ad0ed597b681 /include/cps/CodeGen.h
parent0b4cdf7b28b3855d2dee18d91e9319d66a8ec25f (diff)
refactor: batch 1 - correctness and error contract
- MID/RIGHT/LEFT integer args now coerced at call sites (RIGHT(s, n/2) no longer emits invalid IR); drop emitLeft's private conversion - FOR loop direction decided at run time via select on STEP sign; descending FOR works, STEP evaluated once per iteration - ArrayHandler: extract emitCheckedIndices/loadElement; index count is validated before emission, fixing a compiler-crash (vector OOB UB) on OUTPUT with too many indices - Error contract: Lexer/Parser/CodeGen track errors; all silent failure paths now print Error: diagnostics with line numbers; unterminated char literal no longer truncates the rest of the program; module is verified with verifyModule; driver exits non-zero on any error Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/CodeGen.h')
-rw-r--r--include/cps/CodeGen.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index 07ff3e8..268ba7e 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -59,6 +59,8 @@ class CodeGen {
llvm::Value *FalseStr; // "FALSE"
llvm::Value *EmptyStringStr; // ""
+ bool HadError = false;
+
void SetupExternalFunctions();
llvm::AllocaInst *CreateEntryBlockAlloca(llvm::Function *TheFunction, const std::string &VarName);
llvm::AllocaInst *CreateEntryBlockAlloca(llvm::Function *TheFunction, llvm::Type *AllocType, const std::string &VarName);
@@ -80,6 +82,8 @@ public:
~CodeGen();
void compile(const std::vector<std::unique_ptr<StmtAST>> &Statements);
void print();
+ bool hadError() const { return HadError; }
+ void reportError(const char *Fmt, ...);
llvm::Value *emitExpr(ExprAST *Expr);
void emitStmt(StmtAST *Stmt);