systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
HDLThread.h
Go to the documentation of this file.
1#ifndef _HDLTHREAD_H
2#define _HDLTHREAD_H
3
4// clang-format off
5
6#include "SystemCClang.h"
7#include "clang/Analysis/CFG.h"
8#include "llvm/Support/raw_ostream.h"
9#include "llvm/Support/Debug.h"
10#include "llvm/ADT/StringRef.h"
11#include "hNode.h"
12#include "HDLBody.h"
13#include "SplitCFG.h"
14#include <unordered_set>
15
16// clang-format on
17
18using namespace clang;
19using namespace systemc_clang;
20using namespace hnode;
21using namespace llvm;
22
23namespace systemc_hdl {
24
25 class HDLThread {
26 public:
27 HDLThread(EntryFunctionContainer *efc, hNodep &h_top, hNodep &h_portsigvarlist,
28 clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context,
29 hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethods, overridden_method_map_t &overridden_method_map, hNodep h_resetvarinfo);
30 virtual ~HDLThread();
31
32 hfunc_name_map_t methodecls; // methods called in this SC_METHOD or function
33
34 clang::DiagnosticsEngine &diag_e;
35
36 private:
37
39 hNodep h_ret; // value returned by each subexpression
41 hNodep h_top_; // reference to calling hnode pointer
42 hNodep hthreadblocksp; // collect the case alternatives here
43 hNodep hlocalvarsp; // collect the local vars here
44
47 hdecl_name_map_t &mod_vname_map_; // reference to module level names
48
50
58 string waitnextstate_string; // holds the state# to set when ctr=0
59 string savewaitnextstate_string; // signal to hold the waitnextstate
62
63 const string nextstring{"_next_"};
64 const string shadowstring{"_main_"};
65 const string statestringsymbol{"#"};
66
67 inline string NameNext(string &s) {return nextstring+s;} // convention for variable name holding next value of var s
68
69 // inline string
70 std::unordered_map<std::string, int> SGVisited; // Split Graph Blocks visited
71 //std::unordered_map<unsigned int, int> CFGVisited; // CFG Blocks visited
72 std::unordered_set<int> pathnodevisited; // index of visited node in path
73
74 inline void updatepnvisited(int i) {
75 if (pathnodevisited.find(i) == pathnodevisited.end()) { //haven't visited
76 pathnodevisited.insert(i);
77 }
78 }
79
80 inline bool isBreak(const Stmt* S) {
81 return dyn_cast<BreakStmt> (S) != NULL;
82 }
83
84 // pre-pass over BB to mark subexpressions
85 void FindStatements(const CFGBlock &B, std::vector<const Stmt *> &SS);
86 void FindStatements(const SplitCFGBlock *B, std::vector<const Stmt *> &SS);
87 void MarkStatements(const Stmt *S, llvm::SmallDenseMap<const Stmt*, bool> &Map);
88 void CheckVardecls(hNodep &hp, string &cfgblockid);
89 void ProcessDeclStmt(const DeclStmt *declstmt, hNodep htmp);
90
91 int GetFalseLength(const SplitCFG::SplitCFGPath &pt, int cond_node_ix, int state_num);
92
94 int startix, int num_ele,
95 int state_num, hNodep h_switchcase);
96
98 int thisix,
99 int state_num, hNodep h_switchcase);
100 void GenerateStateUpdate(hNodep hstatemethod, hNodep hlocalvarsp);
101 void GenerateStateVar(string sname);
102 void GenerateWaitCntUpdate(hNodep h_switchcase);
103 hNodep GenerateBinop(string opname, string lhs, string rhs, bool rhs_is_literal=true);
104 bool IsWaitStmt(hNodep hp);
105 bool isContinueorBreak(const Stmt *S);
106 void ProcessHWait(hNodep htmp, int nxtstate); // rewrite the hWait into next state update
107
109
110 const clang::ASTContext& ast_context_;
111
112 // these functions are no longer used
113 void ProcessBB(const CFGBlock &BI);
114 void AddThreadMethod(const CFGBlock &BI);
115
116 };
117
118}
119
120#endif
llvm::SmallVector< SplitCFGPathPair > SplitCFGPath
Definition SplitCFG.h:95
void ProcessSplitGraphGroup(const SplitCFG::SplitCFGPath pt, int startix, int num_ele, int state_num, hNodep h_switchcase)
void GenerateStateVar(string sname)
int GetFalseLength(const SplitCFG::SplitCFGPath &pt, int cond_node_ix, int state_num)
void GenerateStateUpdate(hNodep hstatemethod, hNodep hlocalvarsp)
string savewaitnextstate_string
Definition HDLThread.h:59
bool isContinueorBreak(const Stmt *S)
clang::DiagnosticsEngine & diag_e
Definition HDLThread.h:34
void CheckVardecls(hNodep &hp, string &cfgblockid)
const string nextstring
Definition HDLThread.h:63
const clang::ASTContext & ast_context_
Definition HDLThread.h:110
hdecl_name_map_t & mod_vname_map_
Definition HDLThread.h:47
const string statestringsymbol
Definition HDLThread.h:65
hfunc_name_map_t allmethodecls_
Definition HDLThread.h:52
void ProcessHWait(hNodep htmp, int nxtstate)
const string shadowstring
Definition HDLThread.h:64
void ProcessSplitGraphBlock(const SplitCFG::SplitCFGPath &pt, int thisix, int state_num, hNodep h_switchcase)
hfunc_name_map_t methodecls
Definition HDLThread.h:32
void updatepnvisited(int i)
Definition HDLThread.h:74
bool isBreak(const Stmt *S)
Definition HDLThread.h:80
void AddThreadMethod(const CFGBlock &BI)
std::unordered_map< std::string, int > SGVisited
Definition HDLThread.h:70
overridden_method_map_t & overridden_method_map_
Definition HDLThread.h:53
std::unordered_set< int > pathnodevisited
Definition HDLThread.h:72
void MarkStatements(const Stmt *S, llvm::SmallDenseMap< const Stmt *, bool > &Map)
hNodep GenerateBinop(string opname, string lhs, string rhs, bool rhs_is_literal=true)
void ProcessBB(const CFGBlock &BI)
string NameNext(string &s)
Definition HDLThread.h:67
void GenerateWaitCntUpdate(hNodep h_switchcase)
bool IsWaitStmt(hNodep hp)
HDLThread(EntryFunctionContainer *efc, hNodep &h_top, hNodep &h_portsigvarlist, clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context, hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethods, overridden_method_map_t &overridden_method_map, hNodep h_resetvarinfo)
Definition HDLThread.cpp:24
void FindStatements(const CFGBlock &B, std::vector< const Stmt * > &SS)
EntryFunctionContainer * efc_
Definition HDLThread.h:40
hdecl_name_map_t thread_vname_map
Definition HDLThread.h:45
void ProcessDeclStmt(const DeclStmt *declstmt, hNodep htmp)
Clang forward declarations.
Definition FindArgument.h:6
Definition hNode.h:24
std::unordered_map< const CXXMethodDecl *, const CXXMethodDecl * > overridden_method_map_t
Definition hNode.h:628