aboutsummaryrefslogtreecommitdiff
path: root/include/cps/FunctionGen.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cps/FunctionGen.h')
-rw-r--r--include/cps/FunctionGen.h38
1 files changed, 34 insertions, 4 deletions
diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h
index 9bb6eef..d914162 100644
--- a/include/cps/FunctionGen.h
+++ b/include/cps/FunctionGen.h
@@ -3,23 +3,50 @@
#include "llvm/IR/Module.h"
#include "cps/FunctionAST.h"
#include "cps/TypeSystem.h"
+#include <cstdint>
#include <map>
+#include <utility>
#include <vector>
#include <functional>
#include <string>
-#include <tuple>
namespace cps {
+// Array-parameter ABI: each rank-R array parameter is flattened into the
+// data pointer followed by kBoundArgsPerDim i64 bounds per dimension.
+inline constexpr unsigned kBoundArgsPerDim = 2; // lower, upper
+inline constexpr const char *kLowerBoundSuffix = ".lb";
+inline constexpr const char *kUpperBoundSuffix = ".ub";
+
+// Pseudocode-level signature of one FUNCTION/PROCEDURE parameter; for arrays
+// TypeName is the ELEMENT type and DeclaredBounds mirrors ParamDecl.
+struct ParamSig {
+ std::string TypeName;
+ bool IsByRef = false;
+ bool IsArray = false;
+ int Rank = 0;
+ std::vector<std::pair<int64_t, int64_t>> DeclaredBounds;
+};
+
// Pseudocode-level signature of a FUNCTION/PROCEDURE, kept so call sites can
-// dispatch on declared parameter types and BYREF flags instead of inferring
-// them back from LLVM types.
+// dispatch on declared parameter types and modes instead of inferring them
+// back from LLVM types.
struct FuncSig {
std::string ReturnTypeName;
- std::vector<std::pair<std::string, bool>> Params; // (TypeName, IsByRef)
+ std::vector<ParamSig> Params;
};
class FunctionGen {
+public:
+ // Injected by CodeGen (StmtEmitter inversion precedent) so array
+ // parameters can be bound into ArrayHandler without FunctionGen ever
+ // seeing it: (param, incoming data ptr, per-dim lower/upper bounds).
+ using ArrayParamBinder =
+ std::function<void(const ParamDecl &, llvm::Value *,
+ const std::vector<llvm::Value*> &,
+ const std::vector<llvm::Value*> &)>;
+
+private:
llvm::LLVMContext &Context;
llvm::Module &Module;
llvm::IRBuilder<> &Builder;
@@ -29,6 +56,7 @@ class FunctionGen {
bool &HadError;
std::map<std::string, FuncSig> Signatures;
+ ArrayParamBinder BindArrayParam;
void createArgumentAllocas(llvm::Function *F, const std::vector<ParamDecl> &Params);
@@ -43,6 +71,8 @@ public:
llvm::Type *getLLVMType(const std::string &TypeName);
+ void setArrayParamBinder(ArrayParamBinder Binder) { BindArrayParam = std::move(Binder); }
+
const FuncSig *getSignature(const std::string &Name) const;
llvm::Function *emitPrototype(PrototypeAST *Proto);