aboutsummaryrefslogtreecommitdiff
path: root/include/cps/ArrayHandler.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-07-26 17:13:15 +0000
committer_ov4 <ov4@ov4.org>2026-07-26 17:13:15 +0000
commit0fef2986daa2945c9e3d050c0f750d56792b30bd (patch)
tree4db469725cc64bb0c45978951e071dacaf58a687 /include/cps/ArrayHandler.h
parent344206d57e834b2394cbe2ec0df50b04a8b3c171 (diff)
refactor: groundwork for TYPE — sizeof constants, string guard, array scoping
- Element sizes now flow as target-folded null-GEP sizeof constants (TypeSystem::getSizeOfConstant); the module has no DataLayout string, so host-side size math would diverge from the backend on padded structs. - Extract the triplicated STRING null->"" select into CodeGen::emitStringNullGuard. - Scope ArrayTable per function via ArrayHandler::exchangeTable, mirroring the Symbols save/clear/restore discipline. - Promote checked element addressing to public ArrayHandler::emitElementAddress for the upcoming lvalue layer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'include/cps/ArrayHandler.h')
-rw-r--r--include/cps/ArrayHandler.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/include/cps/ArrayHandler.h b/include/cps/ArrayHandler.h
index 6e2c015..e4ccc51 100644
--- a/include/cps/ArrayHandler.h
+++ b/include/cps/ArrayHandler.h
@@ -16,7 +16,7 @@ struct ArrayMetadata {
int Rank = 0;
std::string ElementTypeName;
llvm::Type *ElementType = nullptr;
- uint64_t ElementSize = 0;
+ llvm::Constant *ElementSizeC = nullptr; // i64 sizeof constant (target-folded)
std::vector<llvm::Value*> LowerBounds;
std::vector<llvm::Value*> UpperBounds;
std::vector<llvm::Value*> Multipliers;
@@ -67,6 +67,22 @@ public:
llvm::Value *emitArrayAccess(ArrayAccessExprAST *Expr, CodeGen &CG);
bool tryEmitArrayOutput(ExprAST *Expr, CodeGen &CG);
+
+ // Full-rank checked element address (bounds checks included); reports the
+ // element type name through ElemTypeNameOut. The lvalue layer builds
+ // field/deref accesses on top of this.
+ llvm::Value *emitElementAddress(const std::string &Name,
+ const std::vector<std::unique_ptr<ExprAST>> &IndexExprs,
+ int Line,
+ CodeGen &CG,
+ std::string &ElemTypeNameOut);
+ llvm::Value *emitElementAddress(ArrayAccessExprAST *Expr,
+ CodeGen &CG,
+ std::string &ElemTypeNameOut);
+
+ // Swap in a fresh table (function bodies get their own scope, mirroring
+ // the Symbols save/clear/restore discipline); returns the previous table.
+ std::map<std::string, ArrayMetadata> exchangeTable(std::map<std::string, ArrayMetadata> NewTable);
};
} // namespace cps