aboutsummaryrefslogtreecommitdiff
path: root/include/cps
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-27 13:27:14 +0000
committer_ov4 <ov4@ov4.org>2026-10-27 13:27:14 +0000
commit0dd0b0908300eee08a06ee51d9eb48b85fd97d74 (patch)
tree8e18df810a1d88f686f2b85ed2f05e3aa0985119 /include/cps
parent790e0fd7c5a81b9a27a6d84e0f3f4c7a0b17d04b (diff)
refactor(memory)!: move allocation functions into memory.cps
Route keyword NEW and DELETE through the same library runtime and retain allocation tracking, runtime diagnostics and exception behavior. BREAKING CHANGE: -no-std programs using NEW or DELETE must explicitly import memory.cps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps')
-rw-r--r--include/cps/CodeGen.h4
-rw-r--r--include/cps/MemoryHandler.h46
2 files changed, 1 insertions, 49 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index 45660b8..0962753 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -21,7 +21,6 @@ namespace cps {
class ArrayHandler;
class FileHandler;
-class MemoryHandler;
class ExceptionHandler;
class CastExprAST;
class TemplateDeclAST;
@@ -157,7 +156,6 @@ class CodeGen {
std::unique_ptr<ArithmeticHandler> ArithHandler;
std::unique_ptr<FileHandler> Files;
- std::unique_ptr<MemoryHandler> Memory;
llvm::FunctionCallee PrintfFunc;
@@ -208,7 +206,7 @@ class CodeGen {
bool emitLValue(ExprAST *E, LValueInfo &Out);
// Read a value from resolved storage.
llvm::Value *loadFromLValue(const LValueInfo &LV);
- llvm::Value *emitAllocationSize(ExprAST *Expr);
+ llvm::Value *emitMemoryCall(const char *Name, llvm::Value *Argument, int Line);
static bool isLogicalOperand(const TypeInfo *T);
llvm::Value *emitShortCircuit(BinaryExprAST *Bin, const TypeInfo *LT, const TypeInfo *RT);
llvm::Value *emitIntBuiltin(ExprAST *Arg, int Line);
diff --git a/include/cps/MemoryHandler.h b/include/cps/MemoryHandler.h
deleted file mode 100644
index 45c24dc..0000000
--- a/include/cps/MemoryHandler.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#pragma once
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Module.h"
-
-namespace cps {
-
-class TypeSystem;
-class RuntimeCheck;
-class ExceptionHandler;
-
-// Explicit memory builtins and keyword NEW own entries in this allocation list.
-// Internal STRING/ARRAY storage retains its existing lifetime rules.
-class MemoryHandler {
- llvm::LLVMContext &Context;
- llvm::IRBuilder<> &Builder;
- llvm::Module &Module;
- TypeSystem &Types;
- RuntimeCheck &Checker;
- ExceptionHandler &Exceptions;
- llvm::IntegerType *SizeTy = nullptr;
- llvm::StructType *NodeTy = nullptr;
- llvm::GlobalVariable *Head = nullptr;
- llvm::FunctionCallee Malloc, Free, Realloc;
- llvm::Function *AllocateFn = nullptr, *ReleaseFn = nullptr, *FindFn = nullptr,
- *ResizeFn = nullptr;
- llvm::Value *AllocationError = nullptr, *TrackingError = nullptr, *InvalidAddress = nullptr;
-
- void ensureRuntime();
- llvm::Function *createHelper(const char *Name, llvm::ArrayRef<llvm::Type *> Args);
- void buildFind();
- void buildAllocate();
- void buildRelease();
- void buildResize();
-
-public:
- MemoryHandler(llvm::LLVMContext &C, llvm::IRBuilder<> &B, llvm::Module &M,
- TypeSystem &TS, RuntimeCheck &RC, ExceptionHandler &EH)
- : Context(C), Builder(B), Module(M), Types(TS), Checker(RC), Exceptions(EH) {}
-
- llvm::Value *emitAllocate(llvm::Value *Size, int Line);
- void emitValidate(llvm::Value *Address, int Line);
- llvm::Value *emitRelease(llvm::Value *Address, int Line);
- llvm::Value *emitResize(llvm::Value *Address, llvm::Value *Size, int Line);
-};
-
-} // namespace cps