aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--AGENTS/CONVENTIONS.md14
-rw-r--r--CMakeLists.txt4
-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
-rw-r--r--lib/CodeGen/ArrayHandler.cc8
-rw-r--r--lib/CodeGen/BooleanHandler.cc16
-rw-r--r--lib/CodeGen/CharHandler.cc15
-rw-r--r--lib/CodeGen/CodeGen.cc23
-rw-r--r--lib/CodeGen/FunctionGen.cc5
-rw-r--r--lib/CodeGen/IntegerHandler.cc16
-rw-r--r--lib/CodeGen/RealHandler.cc16
-rw-r--r--lib/CodeGen/StringHandler.cc15
18 files changed, 23 insertions, 229 deletions
diff --git a/AGENTS/CONVENTIONS.md b/AGENTS/CONVENTIONS.md
index cd1adfc..6d6bb81 100644
--- a/AGENTS/CONVENTIONS.md
+++ b/AGENTS/CONVENTIONS.md
@@ -40,14 +40,12 @@ operations (including `&` concatenation, `StringHandler::emitConcat`) live in
and INPUT STRING buffers — declared in `SetupExternalFunctions`, never fetched with a
bare `getFunction("malloc")`.
-**One flat symbol namespace.** Two parallel maps in CodeGen — `NamedValues`
-(name → storage `Value*`) and `Symbols` (name → `SymbolInfo{Storage, TypeName,
-IsArray}`) — must always be updated in lock-step: via `registerSymbol()`, or directly
-but both together as `FunctionGen::createArgumentAllocas` does for parameters. (The
-per-type handlers' `emitDeclare` methods set `NamedValues` alone — that is dead code;
-don't imitate it.) There is no scope stack. `FunctionGen` saves/clears/restores both
-maps around a function body, but `ArrayHandler::ArrayTable` is *not* scoped (see
-`PITFALLS.md`).
+**One flat symbol namespace, one table.** `Symbols` (name → `SymbolInfo{Storage,
+TypeName, IsArray}`) in CodeGen is the only symbol table; register through
+`registerSymbol()` (or directly, as `FunctionGen::createArgumentAllocas` does for
+parameters) and read storage through `getNamedValue()`/`getSymbolInfo()`. There is no
+scope stack. `FunctionGen` saves/clears/restores the table around a function body, but
+`ArrayHandler::ArrayTable` is *not* scoped (see `PITFALLS.md`).
**Dispatch is by `dynamic_cast` chain, not virtual methods.** `CodeGen::emitStmt` and
`emitExpr` walk a linear if-chain of casts. **A statement type missing from the chain is
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b82c9d4..4f80d0a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,12 +23,8 @@ add_library(CPSCodeGen
lib/CodeGen/ArrayHandler.cc
lib/CodeGen/RuntimeCheck.cc
lib/CodeGen/FunctionGen.cc
- lib/CodeGen/IntegerHandler.cc
- lib/CodeGen/RealHandler.cc
- lib/CodeGen/BooleanHandler.cc
lib/CodeGen/ArithmeticHandler.cc
lib/CodeGen/StringHandler.cc
- lib/CodeGen/CharHandler.cc
lib/CodeGen/StringConversionHandler.cc
lib/CodeGen/TypeSystem.cc
)
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);
diff --git a/lib/CodeGen/ArrayHandler.cc b/lib/CodeGen/ArrayHandler.cc
index af16692..83204a7 100644
--- a/lib/CodeGen/ArrayHandler.cc
+++ b/lib/CodeGen/ArrayHandler.cc
@@ -12,14 +12,12 @@ using namespace cps;
ArrayHandler::ArrayHandler(LLVMContext &C,
IRBuilder<> &B,
Module &M,
- std::map<std::string, Value*> &NV,
std::map<std::string, SymbolInfo> &Sym,
TypeSystem &TS,
RuntimeCheck &RC)
: TheContext(&C),
Builder(&B),
TheModule(&M),
- NamedValues(&NV),
Symbols(&Sym),
Types(TS),
RuntimeChecker(RC) {
@@ -58,11 +56,11 @@ Value *ArrayHandler::computeFlatIndex(const std::string &Name, const std::vector
}
Value *ArrayHandler::getArrayBasePointer(const std::string &Name) {
- auto It = NamedValues->find(Name);
- if (It == NamedValues->end() || !It->second) {
+ auto It = Symbols->find(Name);
+ if (It == Symbols->end() || !It->second.Storage) {
return nullptr;
}
- return Builder->CreateLoad(PointerType::getUnqual(*TheContext), It->second, (Name + "_raw").c_str());
+ return Builder->CreateLoad(PointerType::getUnqual(*TheContext), It->second.Storage, (Name + "_raw").c_str());
}
Value *ArrayHandler::getElementPointer(const std::string &Name, Value *Offset) {
diff --git a/lib/CodeGen/BooleanHandler.cc b/lib/CodeGen/BooleanHandler.cc
deleted file mode 100644
index 558ac95..0000000
--- a/lib/CodeGen/BooleanHandler.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "cps/BooleanHandler.h"
-
-using namespace llvm;
-using namespace cps;
-
-void BooleanHandler::emitDeclare(const std::string &Name) {
- Function *TheFunction = Builder.GetInsertBlock()->getParent();
- IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin());
- AllocaInst *Alloca = TmpB.CreateAlloca(Type::getInt1Ty(Context), nullptr, Name);
- Builder.CreateStore(ConstantInt::get(Context, APInt(1, 0)), Alloca);
- NamedValues[Name] = Alloca;
-}
-
-Value *BooleanHandler::createLiteral(bool Val) {
- return ConstantInt::get(Context, APInt(1, Val ? 1 : 0));
-}
diff --git a/lib/CodeGen/CharHandler.cc b/lib/CodeGen/CharHandler.cc
deleted file mode 100644
index 5e9b502..0000000
--- a/lib/CodeGen/CharHandler.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "cps/CharHandler.h"
-
-using namespace llvm;
-using namespace cps;
-
-CharHandler::CharHandler(LLVMContext &Ctx, IRBuilder<> &B, llvm::Module &M)
- : Context(Ctx), Builder(B), Module(M) {}
-
-Value *CharHandler::emitAsc(Value *CharVal) {
- return Builder.CreateZExt(CharVal, Type::getInt32Ty(Context), "asc_val");
-}
-
-Value *CharHandler::emitChr(Value *IntVal) {
- return Builder.CreateTrunc(IntVal, Type::getInt8Ty(Context), "chr_val");
-}
diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc
index de64a15..31a0274 100644
--- a/lib/CodeGen/CodeGen.cc
+++ b/lib/CodeGen/CodeGen.cc
@@ -66,7 +66,6 @@ CodeGen::CodeGen() {
Arrays = std::make_unique<ArrayHandler>(*TheContext,
*Builder,
*TheModule,
- NamedValues,
Symbols,
*Types,
*RuntimeChecker);
@@ -75,16 +74,11 @@ CodeGen::CodeGen() {
*TheModule,
*Builder,
*Types,
- NamedValues,
Symbols,
HadError);
- IntHandler = std::make_unique<IntegerHandler>(*TheContext, *Builder, *TheModule, NamedValues);
- RealHelper = std::make_unique<RealHandler>(*TheContext, *Builder, *TheModule, NamedValues);
- BoolHandler = std::make_unique<BooleanHandler>(*TheContext, *Builder, *TheModule, NamedValues);
ArithHandler = std::make_unique<ArithmeticHandler>(*TheContext, *Builder, HadError);
- StrHandler = std::make_unique<StringHandler>(*TheContext, *Builder, *TheModule, NamedValues);
- ChrHandler = std::make_unique<CharHandler>(*TheContext, *Builder, *TheModule);
+ StrHandler = std::make_unique<StringHandler>(*TheContext, *Builder, *TheModule);
StrConvHandler = std::make_unique<StringConversionHandler>(*TheContext, *Builder, *TheModule);
SetupExternalFunctions();
@@ -135,7 +129,6 @@ void CodeGen::registerSymbol(const std::string &Name,
Value *Storage,
const std::string &TypeName,
bool IsArray) {
- NamedValues[Name] = Storage;
Symbols[Name] = {Storage, TypeName, IsArray};
}
@@ -156,8 +149,8 @@ Type *CodeGen::getLLVMType(const std::string &TypeName) const {
}
Value *CodeGen::getNamedValue(const std::string &Name) const {
- auto It = NamedValues.find(Name);
- return It == NamedValues.end() ? nullptr : It->second;
+ auto It = Symbols.find(Name);
+ return It == Symbols.end() ? nullptr : It->second.Storage;
}
const TypeInfo *CodeGen::getExprTypeInfo(ExprAST *Expr) const {
@@ -443,15 +436,15 @@ Value *CodeGen::emitExpr(ExprAST *Expr) {
if (!Expr) return nullptr;
if (auto *Num = dynamic_cast<IntegerExprAST*>(Expr)) {
- return IntHandler->createLiteral(Num->getVal());
+ return ConstantInt::get(*TheContext, APInt(64, Num->getVal(), true));
}
if (auto *Real = dynamic_cast<RealExprAST*>(Expr)) {
- return RealHelper->createLiteral(Real->getVal());
+ return ConstantFP::get(*TheContext, APFloat(Real->getVal()));
}
if (auto *Bool = dynamic_cast<BooleanExprAST*>(Expr)) {
- return BoolHandler->createLiteral(Bool->getVal());
+ return ConstantInt::get(*TheContext, APInt(1, Bool->getVal() ? 1 : 0));
}
if (auto *Chr = dynamic_cast<CharExprAST*>(Expr)) {
@@ -557,12 +550,12 @@ Value *CodeGen::emitExpr(ExprAST *Expr) {
} else {
CharVal = Builder->CreateLoad(Type::getInt8Ty(*TheContext), ArgVal, "char_load");
}
- Value *AscVal = ChrHandler->emitAsc(CharVal);
+ Value *AscVal = Builder->CreateZExt(CharVal, Type::getInt32Ty(*TheContext), "asc_val");
return coerceValueToType(AscVal, resolveType("INTEGER"));
}
if (Name == "CHR") {
Value *IntVal = coerceValueToType(emitExpr(Call->getArgs()[0].get()), resolveType("INTEGER"));
- Value *CharVal = ChrHandler->emitChr(IntVal);
+ Value *CharVal = Builder->CreateTrunc(IntVal, Type::getInt8Ty(*TheContext), "chr_val");
return coerceValueToType(CharVal, resolveType("STRING"));
}
if (Name == "IS_NUM") {
diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc
index 57454b1..2e5a704 100644
--- a/lib/CodeGen/FunctionGen.cc
+++ b/lib/CodeGen/FunctionGen.cc
@@ -26,7 +26,6 @@ void FunctionGen::createArgumentAllocas(Function *F, const std::vector<std::tupl
ArgVal->setName(ArgName);
if (IsRef) {
- NamedValues[ArgName] = ArgVal;
Symbols[ArgName] = {ArgVal, ArgTypeStr, false};
continue;
}
@@ -36,7 +35,6 @@ void FunctionGen::createArgumentAllocas(Function *F, const std::vector<std::tupl
AllocaInst *Alloca = TmpB.CreateAlloca(ArgType, nullptr, ArgName);
Builder.CreateStore(ArgVal, Alloca);
- NamedValues[ArgName] = Alloca;
Symbols[ArgName] = {Alloca, ArgTypeStr, false};
}
}
@@ -96,9 +94,7 @@ Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST,
BasicBlock *BB = BasicBlock::Create(Context, "entry", TheFunction);
Builder.SetInsertPoint(BB);
- std::map<std::string, llvm::Value*> OldNamedValues = NamedValues;
std::map<std::string, SymbolInfo> OldSymbols = Symbols;
- NamedValues.clear();
Symbols.clear();
createArgumentAllocas(TheFunction, Proto->getArgs());
@@ -115,7 +111,6 @@ Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST,
}
}
- NamedValues = OldNamedValues;
Symbols = OldSymbols;
return TheFunction;
}
diff --git a/lib/CodeGen/IntegerHandler.cc b/lib/CodeGen/IntegerHandler.cc
deleted file mode 100644
index 8161593..0000000
--- a/lib/CodeGen/IntegerHandler.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "cps/IntegerHandler.h"
-
-using namespace llvm;
-using namespace cps;
-
-void IntegerHandler::emitDeclare(const std::string &Name) {
- Function *TheFunction = Builder.GetInsertBlock()->getParent();
- IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin());
- AllocaInst *Alloca = TmpB.CreateAlloca(Type::getInt64Ty(Context), nullptr, Name);
- Builder.CreateStore(ConstantInt::get(Context, APInt(64, 0)), Alloca);
- NamedValues[Name] = Alloca;
-}
-
-Value *IntegerHandler::createLiteral(int64_t Val) {
- return ConstantInt::get(Context, APInt(64, Val, true));
-}
diff --git a/lib/CodeGen/RealHandler.cc b/lib/CodeGen/RealHandler.cc
deleted file mode 100644
index a73dee2..0000000
--- a/lib/CodeGen/RealHandler.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "cps/RealHandler.h"
-
-using namespace llvm;
-using namespace cps;
-
-void RealHandler::emitDeclare(const std::string &Name) {
- Function *TheFunction = Builder.GetInsertBlock()->getParent();
- IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin());
- AllocaInst *Alloca = TmpB.CreateAlloca(Type::getDoubleTy(Context), nullptr, Name);
- Builder.CreateStore(ConstantFP::get(Context, APFloat(0.0)), Alloca);
- NamedValues[Name] = Alloca;
-}
-
-Value *RealHandler::createLiteral(double Val) {
- return ConstantFP::get(Context, APFloat(Val));
-}
diff --git a/lib/CodeGen/StringHandler.cc b/lib/CodeGen/StringHandler.cc
index 56b5aea..463bf96 100644
--- a/lib/CodeGen/StringHandler.cc
+++ b/lib/CodeGen/StringHandler.cc
@@ -6,9 +6,8 @@
using namespace llvm;
using namespace cps;
-StringHandler::StringHandler(LLVMContext &Ctx, IRBuilder<> &B, llvm::Module &M,
- std::map<std::string, Value*> &NV)
- : Context(Ctx), Builder(B), Module(M), NamedValues(NV) {
+StringHandler::StringHandler(LLVMContext &Ctx, IRBuilder<> &B, llvm::Module &M)
+ : Context(Ctx), Builder(B), Module(M) {
setupExternalFunctions();
}
@@ -34,16 +33,6 @@ void StringHandler::setupExternalFunctions() {
ToLowerFunc = Module.getOrInsertFunction("tolower", CharCaseType);
}
-void StringHandler::emitDeclare(const std::string &Name) {
- Function *TheFunction = Builder.GetInsertBlock()->getParent();
- IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin());
- AllocaInst *Alloca = TmpB.CreateAlloca(PointerType::getUnqual(Context), nullptr, Name);
-
- Value *EmptyStr = createLiteral("");
- Builder.CreateStore(EmptyStr, Alloca);
- NamedValues[Name] = Alloca;
-}
-
Value *StringHandler::createLiteral(const std::string &Val) {
return Builder.CreateGlobalStringPtr(Val);
}