aboutsummaryrefslogtreecommitdiff
path: root/include/cps/RuntimeCheck.h
diff options
context:
space:
mode:
authorov-4 <hausemasterstream@gmail.com>2026-01-30 02:06:37 +0000
committerov-4 <hausemasterstream@gmail.com>2026-01-30 02:06:37 +0000
commit766a4b8e5236bffb40984439a79186c5ee823ff8 (patch)
treea4226690b4b95c916908afa0047899ff60e63c81 /include/cps/RuntimeCheck.h
parent943ed04b775949e8bc4948bcb8d762a32ab14f76 (diff)
Added runtime check for array index and division
Diffstat (limited to 'include/cps/RuntimeCheck.h')
-rw-r--r--include/cps/RuntimeCheck.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h
new file mode 100644
index 0000000..3c31f41
--- /dev/null
+++ b/include/cps/RuntimeCheck.h
@@ -0,0 +1,28 @@
+#pragma once
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+
+namespace cps {
+
+class RuntimeCheck {
+ llvm::Module &TheModule;
+ llvm::LLVMContext &TheContext;
+ llvm::IRBuilder<> &Builder;
+
+ llvm::FunctionCallee PrintfFunc;
+ llvm::FunctionCallee ExitFunc;
+ llvm::Value *DivZeroMsg;
+ llvm::Value *OutOfBoundsMsg;
+
+ void setupExternalFunctions();
+ void emitErrorAndExit(llvm::Value *Condition, llvm::Value *Msg, int Line);
+
+public:
+ RuntimeCheck(llvm::Module &M, llvm::LLVMContext &C, llvm::IRBuilder<> &B);
+
+ void emitDivZeroCheck(llvm::Value *Divisor, int Line);
+ void emitIndexCheck(llvm::Value *Index, llvm::Value *Lower, llvm::Value *Upper, int Line);
+};
+
+}