summaryrefslogtreecommitdiff
path: root/Context.hh
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-30 02:33:00 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-30 02:33:00 +0800
commit63d2a1c552b0d190a0131c2db2045d154b9ec138 (patch)
tree9cd8addea1f49355ec2ecb7669daf12dd4ee61a2 /Context.hh
parent56d68765016fc7aa68fe7b522de5e84c7a12123a (diff)
support for break, continue and void type
Diffstat (limited to 'Context.hh')
-rw-r--r--Context.hh23
1 files changed, 21 insertions, 2 deletions
diff --git a/Context.hh b/Context.hh
index 0a00ba4..bc360b4 100644
--- a/Context.hh
+++ b/Context.hh
@@ -24,13 +24,32 @@ class Context {
std::shared_ptr<FunctionType> GetFunctionType(std::string name);
void AddFunctionType(std::string name, std::shared_ptr<FunctionType> type);
+ // every time we enter a while, repeat or for statement, we push the
+ // destination of break and continue.
+ void PushBreakDestination(llvm::BasicBlock* dest);
+ void PopBreakDestination();
+ llvm::BasicBlock* GetBreakDestination();
+ void PushContinueDestination(llvm::BasicBlock* dest);
+ void PopContinueDestination();
+ llvm::BasicBlock* GetContinueDestination();
+ void SetJumpingFlag(bool flag);
+ bool GetJumpingFlag();
+
private:
+ llvm::IRBuilder<> builder_;
+ llvm::Module module_;
TypeManager TypeManager_;
VariableList globals_;
std::stack<VariableList*> scopes_;
- llvm::IRBuilder<> builder_;
- llvm::Module module_;
std::unordered_map<std::string, std::shared_ptr<FunctionType>> FuncTypes_;
+ std::stack<llvm::BasicBlock*> BreakDestinations_;
+ std::stack<llvm::BasicBlock*> ContinueDestinations_;
+ // if statments always link then and else block with the endif block, it
+ // assumes that no instruction will jump out from the body. break and
+ // continue break this assumption, which makes IfStatementNode creates extra
+ // br instructions, and LLVM will complain "No predecessors!". we use this
+ // flag to tell IfStatementNode if there is a break or continue inside it.
+ bool JumpingFlag_;
};
extern llvm::LLVMContext GlobalLLVMContext;