aboutsummaryrefslogtreecommitdiff
path: root/include/cps/RuntimeCheck.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cps/RuntimeCheck.h')
-rw-r--r--include/cps/RuntimeCheck.h24
1 files changed, 20 insertions, 4 deletions
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);
};
}