diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-17 09:35:19 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-17 09:35:19 +0000 |
| commit | 6b332f91c82da6e19efad92b58ac1d9c1bc9eec0 (patch) | |
| tree | a553b6aab0589dd7cafe5b2508cb274ac0ae9e98 /include/cps/RuntimeCheck.h | |
| parent | b25cbba212354e44921d23490765782f61787bc8 (diff) | |
feat(runtime): write runtime diagnostics to stderr
Runtime check messages and the unhandled-exception message were printed
to stdout by the generated program, so `cpsc x.cps -r >out.txt` captured
them. They are now formatted with snprintf and written with write(2).
Test expectations and docs are updated accordingly.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/RuntimeCheck.h')
| -rw-r--r-- | include/cps/RuntimeCheck.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h index f5a8aa7..8f33e99 100644 --- a/include/cps/RuntimeCheck.h +++ b/include/cps/RuntimeCheck.h @@ -14,7 +14,10 @@ class RuntimeCheck { llvm::LLVMContext &TheContext; llvm::IRBuilder<> &Builder; - llvm::FunctionCallee PrintfFunc; + llvm::FunctionCallee SnprintfFunc; + llvm::FunctionCallee WriteFunc; + llvm::FunctionCallee StrLenFunc; + llvm::GlobalVariable *ErrBuf; ExceptionHandler &Exceptions; llvm::Value *DivZeroMsg; llvm::Value *OutOfBoundsMsg; @@ -29,6 +32,9 @@ public: RuntimeCheck(llvm::Module &M, llvm::LLVMContext &C, llvm::IRBuilder<> &B, ExceptionHandler &EH); + // Format a runtime diagnostic (printf-style) and write it to stderr. + void emitStderr(llvm::Value *Msg, llvm::ArrayRef<llvm::Value *> FmtArgs = {}); + void emitDivZeroCheck(llvm::Value *Divisor, int Line); void emitIndexCheck(llvm::Value *Index, llvm::Value *Lower, llvm::Value *Upper, int Line); @@ -44,7 +50,7 @@ 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. + // Print the diagnostic to stderr, 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 |
