Joos1W Compiler Framework
All Classes Functions Typedefs Pages
DataflowAnalysis.h
1 #pragma once
2 #include "ast/DeclContext.h"
3 #include "semantic/CFGBuilder.h"
4 namespace semantic {
5 
7  using Heap = std::pmr::memory_resource;
8 
9 public:
10  DataflowAnalysis(diagnostics::DiagnosticEngine& diag, Heap* heap,
11  ast::Semantic& sema, ast::LinkingUnit* lu)
12  : diag{diag}, alloc{heap}, heap{heap}, sema{sema}, lu{lu} {}
13  void init(CFGBuilder* cfgBuilder) { this->cfgBuilder = cfgBuilder; }
14  void Check() const;
15 
16 private:
17  diagnostics::DiagnosticEngine& diag;
18  CFGBuilder* cfgBuilder;
19  mutable BumpAllocator alloc;
20  Heap* heap;
21  ast::Semantic& sema;
22  ast::LinkingUnit* lu;
23 
24  void LiveVariableAnalysis(const CFGNode* node) const;
25  void LiveVariableAnalysisHelper(
26  std::unordered_map<const CFGNode*, std::pmr::set<const ast::VarDecl*>>&
27  in,
28  std::pmr::set<const CFGNode*>& cur,
29  std::pmr::set<const CFGNode*>& next) const;
30  int getLiveVariables(const ast::Expr* expr,
31  std::pmr::set<const ast::VarDecl*>& live_vars, const ast::VarDecl* decl = nullptr) const;
32  void FiniteLengthReturn(const CFGNode* node) const;
33  void ReachabilityCheck(const CFGNode* node) const;
34  void ReachabilityCheckHelper(std::unordered_map<const CFGNode*, bool>& out,
35  std::pmr::set<const CFGNode*>& cur,
36  std::pmr::set<const CFGNode*>& next) const;
37  void getAllNodes(const CFGNode* node,
38  std::pmr::set<const CFGNode*>& list) const;
39 };
40 
41 } // namespace semantic