aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cps/FunctionGen.h2
-rw-r--r--include/cps/Lexer.h3
-rw-r--r--include/cps/RuntimeCheck.h6
-rw-r--r--include/cps/SourceUnit.h1
4 files changed, 12 insertions, 0 deletions
diff --git a/include/cps/FunctionGen.h b/include/cps/FunctionGen.h
index 5eb0f82..57a27ff 100644
--- a/include/cps/FunctionGen.h
+++ b/include/cps/FunctionGen.h
@@ -79,6 +79,7 @@ private:
std::map<size_t, std::string> UnitPaths;
size_t CurrentUnit = 0;
std::function<bool(size_t)> Visible;
+ std::function<void(const FuncSig &)> BeforeCall;
ArrayParamBinder BindArrayParam;
std::function<void(llvm::Value *, const std::string &, int)> RegisterCopy;
@@ -103,6 +104,7 @@ public:
}
void setCurrentUnit(size_t Unit, const std::string &Path) { CurrentUnit = Unit; UnitPaths[Unit] = Path; }
+ void setCallHook(std::function<void(const FuncSig &)> Hook) { BeforeCall = std::move(Hook); }
void setVisibility(std::function<bool(size_t)> Predicate) { Visible = std::move(Predicate); }
std::vector<const FuncSig *> getOverloads(const std::string &Name) const;
bool hasFunction(const std::string &Name) const { return !getOverloads(Name).empty(); }
diff --git a/include/cps/Lexer.h b/include/cps/Lexer.h
index 1c4723e..588a5fa 100644
--- a/include/cps/Lexer.h
+++ b/include/cps/Lexer.h
@@ -120,6 +120,8 @@ class Lexer {
int CurrentLine = 1;
int TokenLine = 1;
bool HadError = false;
+ bool Library = false;
+ bool LineStart = true;
struct TokenData {
int Kind, Line;
std::string Identifier, String;
@@ -145,6 +147,7 @@ public:
int peekToken(unsigned Offset = 0);
int peekLine(unsigned Offset = 0);
int getLine() const { return TokenLine; }
+ bool isLibrary() const { return Library; }
bool hadError() const { return HadError; }
};
diff --git a/include/cps/RuntimeCheck.h b/include/cps/RuntimeCheck.h
index 30a1910..d2ee1ea 100644
--- a/include/cps/RuntimeCheck.h
+++ b/include/cps/RuntimeCheck.h
@@ -18,6 +18,8 @@ class RuntimeCheck {
llvm::FunctionCallee StderrFunc; // Windows: __acrt_iob_func(2)
llvm::GlobalVariable *StderrVar; // elsewhere: the C library's stderr
ExceptionHandler &Exceptions;
+ bool LibraryMode = false;
+ llvm::GlobalVariable *UserLine;
llvm::Value *DivZeroMsg;
llvm::Value *OutOfBoundsMsg;
llvm::Value *EnumRangeMsg;
@@ -31,6 +33,10 @@ public:
RuntimeCheck(llvm::Module &M, llvm::LLVMContext &C, llvm::IRBuilder<> &B,
ExceptionHandler &EH);
+ void setLibraryMode(bool Enabled) { LibraryMode = Enabled; }
+ llvm::Value *lineValue(int Line);
+ void setUserLine(int Line);
+
// Format a runtime diagnostic (printf-style) and write it to stderr.
void emitStderr(llvm::Value *Msg, llvm::ArrayRef<llvm::Value *> FmtArgs = {});
diff --git a/include/cps/SourceUnit.h b/include/cps/SourceUnit.h
index db9ad30..34266ac 100644
--- a/include/cps/SourceUnit.h
+++ b/include/cps/SourceUnit.h
@@ -9,5 +9,6 @@ struct SourceUnit {
std::string Path;
const std::vector<std::unique_ptr<StmtAST>> &Statements;
std::vector<bool> Visible;
+ bool IsLibrary = false;
};
}