aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 12:15:33 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 12:15:33 +0000
commit1749b2b4a3e55db7c9bed95376f99b7f07932b49 (patch)
treefca50620a4e6b46609f18abaf205416ea245dce8 /include
parentb9b7f048b0874df0f034f6b1e15e1a4ee2131475 (diff)
refactor: drop per-type micro handlers and the parallel NamedValues map
Integer/Real/Boolean/CharHandler carried only five one-line LLVM API wrappers (now inlined at their call sites in CodeGen.cc) plus dead emitDeclare methods that violated the documented two-table lock-step invariant. StringHandler::emitDeclare (also dead) and its NamedValues reference go too. With the dead writers gone, NamedValues held no information not already in Symbols[].Storage, so the parallel map is removed: getNamedValue reads Symbols, ArrayHandler/FunctionGen take one table, and function bodies save/restore a single map. Behavior unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include')
-rw-r--r--include/cps/ArrayHandler.h2
-rw-r--r--include/cps/BooleanHandler.h24
-rw-r--r--include/cps/CharHandler.h23
-rw-r--r--include/cps/CodeGen.h11
-rw-r--r--include/cps/FunctionGen.h4
-rw-r--r--include/cps/IntegerHandler.h24
-rw-r--r--include/cps/RealHandler.h24
-rw-r--r--include/cps/StringHandler.h8
8 files changed, 4 insertions, 116 deletions
diff --git a/include/cps/ArrayHandler.h b/include/cps/ArrayHandler.h
index e8a57fb..6e2c015 100644
--- a/include/cps/ArrayHandler.h
+++ b/include/cps/ArrayHandler.h
@@ -28,7 +28,6 @@ class ArrayHandler {
llvm::LLVMContext *TheContext;
llvm::IRBuilder<> *Builder;
llvm::Module *TheModule;
- std::map<std::string, llvm::Value*> *NamedValues;
std::map<std::string, SymbolInfo> *Symbols;
TypeSystem &Types;
@@ -57,7 +56,6 @@ public:
ArrayHandler(llvm::LLVMContext &C,
llvm::IRBuilder<> &B,
llvm::Module &M,
- std::map<std::string, llvm::Value*> &NV,
std::map<std::string, SymbolInfo> &Sym,
TypeSystem &TS,
RuntimeCheck &RC);
diff --git a/include/cps/BooleanHandler.h b/include/cps/BooleanHandler.h
deleted file mode 100644
index 67c7778..0000000
--- a/include/cps/BooleanHandler.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include <map>
-#include <string>
-
-namespace cps {
-
-class BooleanHandler {
- llvm::LLVMContext &Context;
- llvm::IRBuilder<> &Builder;
- llvm::Module &Module;
- std::map<std::string, llvm::Value*> &NamedValues;
-
-public:
- BooleanHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, std::map<std::string, llvm::Value*> &NV)
- : Context(Ctx), Builder(B), Module(M), NamedValues(NV) {}
-
- void emitDeclare(const std::string &Name);
- llvm::Value *createLiteral(bool Val);
-};
-
-}
diff --git a/include/cps/CharHandler.h b/include/cps/CharHandler.h
deleted file mode 100644
index 03c86e7..0000000
--- a/include/cps/CharHandler.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-
-namespace cps {
-
-class CharHandler {
- llvm::LLVMContext &Context;
- llvm::IRBuilder<> &Builder;
- llvm::Module &Module;
-
-public:
- CharHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M);
-
- // ASC(ThisChar: CHAR) RETURNS INTEGER
- llvm::Value *emitAsc(llvm::Value *CharVal);
-
- // CHR(x: INTEGER) RETURNS CHAR
- llvm::Value *emitChr(llvm::Value *IntVal);
-};
-
-} // namespace cps
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index def7395..4124e65 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -7,12 +7,8 @@
#include "cps/FunctionGen.h"
#include "cps/TypeSystem.h"
-#include "cps/IntegerHandler.h"
-#include "cps/RealHandler.h"
-#include "cps/BooleanHandler.h"
#include "cps/ArithmeticHandler.h"
#include "cps/StringHandler.h"
-#include "cps/CharHandler.h"
#include "cps/StringConversionHandler.h"
#include <map>
@@ -27,20 +23,15 @@ class CodeGen {
std::unique_ptr<llvm::LLVMContext> TheContext;
std::unique_ptr<llvm::Module> TheModule;
std::unique_ptr<llvm::IRBuilder<>> Builder;
- std::map<std::string, llvm::Value*> NamedValues;
std::map<std::string, SymbolInfo> Symbols;
std::unique_ptr<TypeSystem> Types;
-
+
std::unique_ptr<ArrayHandler> Arrays;
std::unique_ptr<RuntimeCheck> RuntimeChecker;
std::unique_ptr<FunctionGen> FuncGen;
- std::unique_ptr<IntegerHandler> IntHandler;
- std::unique_ptr<RealHandler> RealHelper;
- std::unique_ptr<BooleanHandler> BoolHandler;
std::unique_ptr<ArithmeticHandler> ArithHandler;
std::unique_ptr<StringHandler> StrHandler;
- std::unique_ptr<CharHandler> ChrHandler;
std::unique_ptr<StringConversionHandler> StrConvHandler;
llvm::FunctionCallee PrintfFunc;
diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h
index f55db1b..cce17c3 100644
--- a/include/cps/FunctionGen.h
+++ b/include/cps/FunctionGen.h
@@ -25,7 +25,6 @@ class FunctionGen {
llvm::IRBuilder<> &Builder;
TypeSystem &Types;
- std::map<std::string, llvm::Value*> &NamedValues;
std::map<std::string, SymbolInfo> &Symbols;
bool &HadError;
@@ -38,10 +37,9 @@ public:
llvm::Module &M,
llvm::IRBuilder<> &B,
TypeSystem &TS,
- std::map<std::string, llvm::Value*> &NV,
std::map<std::string, SymbolInfo> &Sym,
bool &HadErrorFlag)
- : Context(C), Module(M), Builder(B), Types(TS), NamedValues(NV), Symbols(Sym), HadError(HadErrorFlag) {}
+ : Context(C), Module(M), Builder(B), Types(TS), Symbols(Sym), HadError(HadErrorFlag) {}
llvm::Type *getLLVMType(const std::string &TypeName);
diff --git a/include/cps/IntegerHandler.h b/include/cps/IntegerHandler.h
deleted file mode 100644
index 2cd0bbc..0000000
--- a/include/cps/IntegerHandler.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include <map>
-#include <string>
-
-namespace cps {
-
-class IntegerHandler {
- llvm::LLVMContext &Context;
- llvm::IRBuilder<> &Builder;
- llvm::Module &Module;
- std::map<std::string, llvm::Value*> &NamedValues;
-
-public:
- IntegerHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, std::map<std::string, llvm::Value*> &NV)
- : Context(Ctx), Builder(B), Module(M), NamedValues(NV) {}
-
- void emitDeclare(const std::string &Name);
- llvm::Value *createLiteral(int64_t Val);
-};
-
-}
diff --git a/include/cps/RealHandler.h b/include/cps/RealHandler.h
deleted file mode 100644
index bdb113e..0000000
--- a/include/cps/RealHandler.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include <map>
-#include <string>
-
-namespace cps {
-
-class RealHandler {
- llvm::LLVMContext &Context;
- llvm::IRBuilder<> &Builder;
- llvm::Module &Module;
- std::map<std::string, llvm::Value*> &NamedValues;
-
-public:
- RealHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, std::map<std::string, llvm::Value*> &NV)
- : Context(Ctx), Builder(B), Module(M), NamedValues(NV) {}
-
- void emitDeclare(const std::string &Name);
- llvm::Value *createLiteral(double Val);
-};
-
-}
diff --git a/include/cps/StringHandler.h b/include/cps/StringHandler.h
index 7226b85..0af0cc7 100644
--- a/include/cps/StringHandler.h
+++ b/include/cps/StringHandler.h
@@ -2,7 +2,6 @@
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
-#include <map>
#include <string>
namespace cps {
@@ -11,7 +10,6 @@ class StringHandler {
llvm::LLVMContext &Context;
llvm::IRBuilder<> &Builder;
llvm::Module &Module;
- std::map<std::string, llvm::Value*> &NamedValues;
llvm::FunctionCallee MallocFunc;
llvm::FunctionCallee StrLenFunc;
@@ -22,11 +20,9 @@ class StringHandler {
llvm::FunctionCallee ToLowerFunc;
public:
- StringHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M,
- std::map<std::string, llvm::Value*> &NV);
-
+ StringHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M);
+
void setupExternalFunctions();
- void emitDeclare(const std::string &Name);
llvm::Value *createLiteral(const std::string &Val);
llvm::Value *emitLength(llvm::Value *Str);