aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/GlobalGen.cc
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 /lib/CodeGen/GlobalGen.cc
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 'lib/CodeGen/GlobalGen.cc')
-rw-r--r--lib/CodeGen/GlobalGen.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/CodeGen/GlobalGen.cc b/lib/CodeGen/GlobalGen.cc
index 46b6f0c..b5c39a8 100644
--- a/lib/CodeGen/GlobalGen.cc
+++ b/lib/CodeGen/GlobalGen.cc
@@ -39,10 +39,19 @@ void CodeGen::runGlobalPrePass(const SourceUnit &Unit, int Phase) {
reportError("Global %s conflicts with an existing definition", Name.c_str());
continue;
}
+ const TypeInfo *Type = resolveType(TypeName);
+ if (!Type) {
+ reportError("Unknown type %s", TypeName.c_str());
+ continue;
+ }
auto *Storage = new GlobalVariable(*TheModule, Types->getLLVMType(TypeName), false,
GlobalValue::InternalLinkage, Types->getZeroValue(TypeName), "__cps_global." + Name);
SymbolInfo Info{Storage, TypeName, false, nullptr, 0, false, true};
Exports[CurrentUnit].emplace(Name, Info);
+ if (Type->isString()) {
+ size_t Lifetime = registerStackObject(Storage, Type->Name, DiagnosticLine);
+ if (emitDefaultConstruct(Type->Name, Storage, DiagnosticLine)) activateStackObject(Lifetime);
+ }
} else if (auto *Assign = dynamic_cast<AssignStmtAST*>(S.get())) {
if (Phase != 1) continue;
const SymbolInfo *Info = getSymbolInfo(Assign->getName());
@@ -55,6 +64,11 @@ void CodeGen::runGlobalPrePass(const SourceUnit &Unit, int Phase) {
reportError("GLOBAL initializer must be a literal");
continue;
}
+ if (const auto *Type = resolveType(Info->TypeName); Type && Type->isString()) {
+ emitAssignment({Info->Storage, Info->TypeName}, Assign->getExpr(), Info);
+ cleanupTemporaries();
+ continue;
+ }
auto *Value = dyn_cast_or_null<Constant>(
emitCoercedExpr(Assign->getExpr(), resolveType(Info->TypeName)));
if (!Value) {