aboutsummaryrefslogtreecommitdiff
path: root/include/cps/CodeGen.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-20 11:57:16 +0000
committer_ov4 <ov4@ov4.org>2026-10-20 11:57:16 +0000
commit62b605c6c0ea13e9763c0a0115464007b13a8831 (patch)
tree53c27965f5a365682e0d79fd96e25b228ecb9dca /include/cps/CodeGen.h
parentbfe2e75d7e3b372e55369677028429990c49bc54 (diff)
refactor(strings): replace compiler builtins with the STRING library
Construct literals as STRING values and route string operations through ordinary library functions and operators. Preserve value ownership in records, arrays, constants and file I/O. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/CodeGen.h')
-rw-r--r--include/cps/CodeGen.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index 30f4135..e6281c5 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -11,8 +11,6 @@
#include "cps/TypeSystem.h"
#include "cps/ArithmeticHandler.h"
-#include "cps/StringHandler.h"
-#include "cps/StringConversionHandler.h"
#include <map>
#include <memory>
@@ -93,6 +91,12 @@ class CodeGen {
bool prepareSymbolDeclaration(const std::string &Name, bool IsConstant = false);
bool requireWritable(const SymbolInfo &Info, const std::string &Name);
void emitConstantStmt(ConstantStmtAST *Stmt);
+ std::map<const ConstantStmtAST *, SymbolInfo> StringConstants;
+ const TypeInfo *requireStringType();
+ llvm::Value *emitStringFromCString(llvm::Value *Text);
+ llvm::Value *emitStringCString(llvm::Value *Value);
+ llvm::Value *emitCStringExpr(ExprAST *Expr);
+ bool containsString(const TypeInfo *Type) const;
std::unique_ptr<TypeSystem> Types;
std::unique_ptr<ArrayHandler> Arrays;
@@ -101,14 +105,11 @@ class CodeGen {
std::unique_ptr<FunctionGen> FuncGen;
std::unique_ptr<ArithmeticHandler> ArithHandler;
- std::unique_ptr<StringHandler> StrHandler;
- std::unique_ptr<StringConversionHandler> StrConvHandler;
std::unique_ptr<FileHandler> Files;
std::unique_ptr<MemoryHandler> Memory;
llvm::FunctionCallee PrintfFunc;
llvm::FunctionCallee ScanfFunc;
- llvm::FunctionCallee MallocFunc;
llvm::Value *PrintfFormatStr; // %lld\n
llvm::Value *PrintfFloatFormatStr; // %f\n
@@ -117,7 +118,6 @@ class CodeGen {
llvm::Value *ScanfFormatStr; // %lld
llvm::Value *ScanfFloatFormatStr; // %lf
- llvm::Value *ScanfStringFormatStr; // %s
llvm::Value *TrueStr; // "TRUE"
llvm::Value *FalseStr; // "FALSE"
@@ -157,7 +157,7 @@ class CodeGen {
// Resolves a variable / array element / field chain / deref to an address
// (emitting index and null-pointer checks along the way).
bool emitLValue(ExprAST *E, LValueInfo &Out);
- // The rvalue read: load + the STRING null->"" guard.
+ // Read a value from resolved storage.
llvm::Value *loadFromLValue(const LValueInfo &LV);
llvm::Value *emitAllocationSize(ExprAST *Expr);
llvm::Value *emitCall(const std::string &Callee,
@@ -209,7 +209,7 @@ public:
llvm::Value *emitExpr(ExprAST *Expr);
void emitStmt(StmtAST *Stmt);
- // STRING slots zero-init to null; normalize null to "" at load/print sites.
+ // Normalize a raw C string pointer to "" when explicitly casting it to STRING.
llvm::Value *emitStringNullGuard(llvm::Value *StrVal);
// Name-level admission gate for Enum/Record/Pointer plus the existing