From 1749b2b4a3e55db7c9bed95376f99b7f07932b49 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 26 Jul 2026 12:15:33 +0000 Subject: 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 --- include/cps/ArrayHandler.h | 2 -- include/cps/BooleanHandler.h | 24 ------------------------ include/cps/CharHandler.h | 23 ----------------------- include/cps/CodeGen.h | 11 +---------- include/cps/FunctionGen.h | 4 +--- include/cps/IntegerHandler.h | 24 ------------------------ include/cps/RealHandler.h | 24 ------------------------ include/cps/StringHandler.h | 8 ++------ 8 files changed, 4 insertions(+), 116 deletions(-) delete mode 100644 include/cps/BooleanHandler.h delete mode 100644 include/cps/CharHandler.h delete mode 100644 include/cps/IntegerHandler.h delete mode 100644 include/cps/RealHandler.h (limited to 'include/cps') 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 *NamedValues; std::map *Symbols; TypeSystem &Types; @@ -57,7 +56,6 @@ public: ArrayHandler(llvm::LLVMContext &C, llvm::IRBuilder<> &B, llvm::Module &M, - std::map &NV, std::map &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 -#include - -namespace cps { - -class BooleanHandler { - llvm::LLVMContext &Context; - llvm::IRBuilder<> &Builder; - llvm::Module &Module; - std::map &NamedValues; - -public: - BooleanHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, std::map &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 @@ -27,20 +23,15 @@ class CodeGen { std::unique_ptr TheContext; std::unique_ptr TheModule; std::unique_ptr> Builder; - std::map NamedValues; std::map Symbols; std::unique_ptr Types; - + std::unique_ptr Arrays; std::unique_ptr RuntimeChecker; std::unique_ptr FuncGen; - std::unique_ptr IntHandler; - std::unique_ptr RealHelper; - std::unique_ptr BoolHandler; std::unique_ptr ArithHandler; std::unique_ptr StrHandler; - std::unique_ptr ChrHandler; std::unique_ptr 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 &NamedValues; std::map &Symbols; bool &HadError; @@ -38,10 +37,9 @@ public: llvm::Module &M, llvm::IRBuilder<> &B, TypeSystem &TS, - std::map &NV, std::map &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 -#include - -namespace cps { - -class IntegerHandler { - llvm::LLVMContext &Context; - llvm::IRBuilder<> &Builder; - llvm::Module &Module; - std::map &NamedValues; - -public: - IntegerHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, std::map &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 -#include - -namespace cps { - -class RealHandler { - llvm::LLVMContext &Context; - llvm::IRBuilder<> &Builder; - llvm::Module &Module; - std::map &NamedValues; - -public: - RealHandler(llvm::LLVMContext &Ctx, llvm::IRBuilder<> &B, llvm::Module &M, std::map &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 #include namespace cps { @@ -11,7 +10,6 @@ class StringHandler { llvm::LLVMContext &Context; llvm::IRBuilder<> &Builder; llvm::Module &Module; - std::map &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 &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); -- cgit v1.3.1-4-g156e