aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-15 02:41:11 +0000
committer_ov4 <ov4@ov4.org>2026-10-15 02:41:11 +0000
commitc4565386553ea86308a9487650d2435804893ed0 (patch)
treeeae3556d3a1e05b3f91b13b218cab3a72eb3bbef /include
parentab86ae0284469a9a941f5b196f9cc99a90305e3a (diff)
fix(codegen): restore runtime diagnostics before throwing
Reuse historical runtime messages and source-line reporting for arithmetic, array, enum, pointer and file checks while preserving anonymous exceptions. Update the manuals and subsystem guidance to describe diagnostic output. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include')
-rw-r--r--include/cps/FileHandler.h4
-rw-r--r--include/cps/RuntimeCheck.h24
2 files changed, 24 insertions, 4 deletions
diff --git a/include/cps/FileHandler.h b/include/cps/FileHandler.h
index 8b8ddf4..50593de 100644
--- a/include/cps/FileHandler.h
+++ b/include/cps/FileHandler.h
@@ -38,6 +38,10 @@ class FileHandler {
llvm::Value *ModeReadStr = nullptr, *ModeWriteStr = nullptr, *ModeAppendStr = nullptr;
+ llvm::Value *ErrOpenFail = nullptr, *ErrAlreadyOpen = nullptr, *ErrTableFull = nullptr,
+ *ErrNotOpen = nullptr, *ErrNotRead = nullptr, *ErrNotWrite = nullptr,
+ *ErrPastEof = nullptr;
+
// synthesized helpers (internal linkage; pseudocode identifiers cannot
// start with '_', so these names are un-collidable)
llvm::Function *FindFn = nullptr, *OpenFn = nullptr, *ReadFn = nullptr,
diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h
index d9a69b6..f5a8aa7 100644
--- a/include/cps/RuntimeCheck.h
+++ b/include/cps/RuntimeCheck.h
@@ -10,15 +10,24 @@ namespace cps {
class ExceptionHandler;
class RuntimeCheck {
+ llvm::Module &TheModule;
llvm::LLVMContext &TheContext;
llvm::IRBuilder<> &Builder;
+
+ llvm::FunctionCallee PrintfFunc;
ExceptionHandler &Exceptions;
+ llvm::Value *DivZeroMsg;
+ llvm::Value *OutOfBoundsMsg;
+ llvm::Value *EnumRangeMsg;
+ llvm::Value *NullDerefMsg;
+ llvm::Value *ArrayArgBoundsMsg;
-public:
- RuntimeCheck(llvm::LLVMContext &C, llvm::IRBuilder<> &B, ExceptionHandler &EH);
+ void setupExternalFunctions();
+ void emitCheck(llvm::Value *Condition, llvm::Value *Msg, int Line);
- // Split the block, throwing an anonymous exception when Condition is true.
- void emitCheck(llvm::Value *Condition);
+public:
+ RuntimeCheck(llvm::Module &M, llvm::LLVMContext &C, llvm::IRBuilder<> &B,
+ ExceptionHandler &EH);
void emitDivZeroCheck(llvm::Value *Divisor, int Line);
void emitIndexCheck(llvm::Value *Index, llvm::Value *Lower, llvm::Value *Upper, int Line);
@@ -35,6 +44,13 @@ public:
void emitArrayArgBoundsCheck(llvm::Value *ActualLower, llvm::Value *ActualUpper,
int64_t DeclaredLower, int64_t DeclaredUpper, int Line);
+ // Print the diagnostic, then throw an anonymous exception on failure.
+ // Runtime-computed variant: FmtArgs are the printf varargs after Msg
+ // (e.g. {i32 line, ptr filename}). Needed when the failure site is inside
+ // a synthesized helper function, where the line number is an argument
+ // rather than a compile-time constant.
+ void emitCheck(llvm::Value *Condition, llvm::Value *Msg,
+ llvm::ArrayRef<llvm::Value *> FmtArgs);
};
}