aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cps/ArrayHandler.h18
-rw-r--r--include/cps/CodeGen.h3
-rw-r--r--include/cps/TypeSystem.h5
3 files changed, 25 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
diff --git a/include/cps/CodeGen.h b/include/cps/CodeGen.h
index 43d3a32..2451cbd 100644
--- a/include/cps/CodeGen.h
+++ b/include/cps/CodeGen.h
@@ -87,6 +87,9 @@ public:
llvm::Value *emitExpr(ExprAST *Expr);
void emitStmt(StmtAST *Stmt);
+ // STRING slots zero-init to null; normalize null to "" at load/print sites.
+ llvm::Value *emitStringNullGuard(llvm::Value *StrVal);
+
const TypeInfo *resolveType(const std::string &TypeName) const;
llvm::Type *getLLVMType(const std::string &TypeName) const;
llvm::Value *getNamedValue(const std::string &Name) const;
diff --git a/include/cps/TypeSystem.h b/include/cps/TypeSystem.h
index 32c348f..14a21bd 100644
--- a/include/cps/TypeSystem.h
+++ b/include/cps/TypeSystem.h
@@ -66,6 +66,11 @@ public:
llvm::Type *getLLVMType(const std::string &TypeName) const;
uint64_t getElementSize(const std::string &TypeName) const;
llvm::Constant *getZeroValue(const std::string &TypeName) const;
+
+ // Target-independent sizeof: a null-GEP+ptrtoint i64 constant the backend
+ // folds with the *real* target's DataLayout. The module carries no
+ // DataLayout string, so sizes must never be computed host-side.
+ llvm::Constant *getSizeOfConstant(llvm::Type *Ty) const;
};
} // namespace cps