systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
HDLBody.h
Go to the documentation of this file.
1#ifndef _HDLBODY_H
2#define _HDLBODY_H
3
4// clang-format off
5#include <vector>
6#include <string>
7#include <unordered_set>
8#include <ctype.h>
9#include "clang/AST/DeclCXX.h"
10#include "clang/AST/Stmt.h"
11#include "clang/AST/Expr.h"
12#include "llvm/Support/raw_ostream.h"
13#include "clang/AST/RecursiveASTVisitor.h"
14#include "clang/Basic/Diagnostic.h"
15
16#include "llvm/ADT/StringRef.h"
17
18// look at https://chromium.googlesource.com/chromium/src.git/+/62.0.3178.1/tools/clang/value_cleanup/ListValueRewriter.h#include "llvm/Support/FileSystem.h"
19
20#include "SystemCClang.h"
21#include "hNode.h"
22#include "HDLType.h"
23
24// clang-format on
25
26using namespace clang;
27using namespace systemc_clang;
28
29using namespace hnode;
30
31namespace systemc_hdl {
33
34class HDLBody : public RecursiveASTVisitor<HDLBody> {
35 public:
36 HDLBody(clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context,
37 hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethodecls,
38 overridden_method_map_t &overridden_method_map);
39
40 virtual ~HDLBody();
41
42 void Run(Stmt *stmt, hNodep &h_top, HDLBodyMode runmode,
43 HDLType *HDLt_userclassesp = NULL);
44
45 bool TraverseStmt(Stmt *stmt);
46
47 bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *opcall);
48 bool VisitCXXMemberCallExpr(CXXMemberCallExpr *callexpr);
49 bool VisitCallExpr(CallExpr *callexpr);
50
51 bool VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *stmt);
52 bool VisitReturnStmt(ReturnStmt *stmt);
53 bool VisitInitListExpr(InitListExpr *stmt);
54 bool VisitCaseStmt(CaseStmt *stmt);
55 bool VisitDefaultStmt(DefaultStmt *stmt);
56 bool VisitBreakStmt (BreakStmt *stmt);
57 bool VisitContinueStmt(ContinueStmt *stmt);
58 bool VisitCompoundStmt(CompoundStmt *compoundStmt);
59 bool VisitDeclStmt(DeclStmt *declstmt);
60 bool ProcessVarDecl(VarDecl *vardecl);
61 bool VisitBinaryOperator(BinaryOperator *expr);
62 bool VisitUnaryOperator(UnaryOperator *expr);
63 bool VisitConditionalOperator(ConditionalOperator *expr);
64 bool VisitIntegerLiteral(IntegerLiteral *lit);
65 bool VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *b);
66 bool VisitDeclRefExpr(DeclRefExpr *expr);
67 bool VisitArraySubscriptExpr(ArraySubscriptExpr *expr);
68 bool VisitMemberExpr(MemberExpr *memberexpr);
69 bool VisitIfStmt(IfStmt *ifs);
70 bool VisitForStmt(ForStmt *fors);
71 bool VisitSwitchStmt(SwitchStmt *switchs);
72 bool VisitWhileStmt(WhileStmt *whiles);
73 bool VisitDoStmt(DoStmt *whiles);
74 bool ProcessSwitchCase(SwitchCase *cases);
75 string FindVname(NamedDecl *vard);
76 void AddVnames(hNodep &hvns);
77 string FindFname(FunctionDecl *funcd);
78
79 void GetWaitArg(hNodep &h_callp, Expr *callarg);
81 void NormalizeSwitchStmt(hNodep hswitchbody);
82
83 // bool isSCConstruct(const Type* type, const CXXMemberCallExpr* ce) const;
84 hfunc_name_map_t methodecls; // methods called in this SC_METHOD or function
85
86 clang::DiagnosticsEngine &diag_e;
87
89
91
92 private:
93 hNodep h_ret; // value returned by each subexpression
94
95 // hdecl_name_map_t vname_map;
97
98 bool add_info; // variation in some hcode generated for modinit body
99
100 const string nextstate_string = "_scclang_nextstate_";
101
104
106
107 inline bool isUserClass(const Type *classrectype) {
108 return (
109 (thismode == ruserdefclass) && (HDLt_userclassesp_ != NULL) &&
110 (HDLt_userclassesp_->usertype_info.userrectypes.count(classrectype)));
111 }
112
113 bool isLogicalOp(clang::OverloadedOperatorKind opc);
114
115 inline bool isAssignOp(hNodep hp) {
116 return (hp->h_op == hNode::hdlopsEnum::hBinop) && (hp->h_name == "=");
117 }
118
119 inline bool isArrayRef(hNodep hp) {
120 return (hp->h_op == hNode::hdlopsEnum::hBinop) &&
121 (hp->h_name == "ARRAYSUBSCRIPT");
122 }
123
124 inline string generate_vname(string nm) {
125 return vname_map.get_prefix() + nm;
126 }
127
129
130 const ASTContext &ast_context_;
131};
132
133class StmtVisitor : public clang::RecursiveASTVisitor<StmtVisitor> {
134 public:
136
137 public:
138 StmtVisitor(clang::Stmt *st, HDLBodyMode mode);
139 virtual ~StmtVisitor();
140
142 virtual bool VisitStmt(Stmt *s);
143 bool VisitCaseStmt(CaseStmt *st);
144 bool VisitCompoundStmt(Stmt *st);
145 bool VisitDefaultStmt(DefaultStmt *st);
146 bool VisitBreakStmt(BreakStmt *st);
147 bool VisitContinueStmt(ContinueStmt *st);
148 bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *st);
149 bool VisitReturnStmt(ReturnStmt *st);
151
152 private:
155};
156
157} // namespace systemc_hdl
158
159#endif
usertype_info_t usertype_info
Definition HDLType.h:44
hdlopsEnum h_op
Definition hNode.h:107
string h_name
Definition hNode.h:106
string get_prefix()
Definition hNode.h:575
const ASTContext & ast_context_
Definition HDLBody.h:130
bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *opcall)
Definition HDLBody.cpp:886
bool VisitBinaryOperator(BinaryOperator *expr)
Definition HDLBody.cpp:468
HDLBodyMode thismode
Definition HDLBody.h:102
bool isLogicalOp(clang::OverloadedOperatorKind opc)
Definition HDLBody.cpp:871
bool VisitCaseStmt(CaseStmt *stmt)
Definition HDLBody.cpp:234
string FindFname(FunctionDecl *funcd)
Definition HDLBody.cpp:1300
hdecl_name_map_t vname_map
Definition HDLBody.h:88
overridden_method_map_t & overridden_method_map_
Definition HDLBody.h:90
hfunc_name_map_t methodecls
Definition HDLBody.h:84
bool VisitCompoundStmt(CompoundStmt *compoundStmt)
Definition HDLBody.cpp:284
bool VisitDefaultStmt(DefaultStmt *stmt)
Definition HDLBody.cpp:257
void NormalizeSwitchStmt(hNodep hswitchbody)
Definition HDLBody.cpp:1359
void GetWaitArg(hNodep &h_callp, Expr *callarg)
Definition HDLBody.cpp:1347
bool VisitConditionalOperator(ConditionalOperator *expr)
Definition HDLBody.cpp:558
bool VisitReturnStmt(ReturnStmt *stmt)
Definition HDLBody.cpp:224
bool VisitDeclStmt(DeclStmt *declstmt)
Definition HDLBody.cpp:315
bool ProcessVarDecl(VarDecl *vardecl)
Definition HDLBody.cpp:332
bool VisitMemberExpr(MemberExpr *memberexpr)
Definition HDLBody.cpp:982
string generate_vname(string nm)
Definition HDLBody.h:124
bool VisitUnaryOperator(UnaryOperator *expr)
Definition HDLBody.cpp:530
bool isUserClass(const Type *classrectype)
Definition HDLBody.h:107
const string nextstate_string
Definition HDLBody.h:100
bool VisitArraySubscriptExpr(ArraySubscriptExpr *expr)
Definition HDLBody.cpp:685
void AddVnames(hNodep &hvns)
Definition HDLBody.cpp:1309
bool VisitSwitchStmt(SwitchStmt *switchs)
Definition HDLBody.cpp:1190
bool TraverseStmt(Stmt *stmt)
Definition HDLBody.cpp:111
HDLBody(clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context, hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethodecls, overridden_method_map_t &overridden_method_map)
Definition HDLBody.cpp:63
hdecl_name_map_t & mod_vname_map_
Definition HDLBody.h:96
hfunc_name_map_t & allmethodecls_
Definition HDLBody.h:103
bool isAssignOp(hNodep hp)
Definition HDLBody.h:115
bool VisitWhileStmt(WhileStmt *whiles)
Definition HDLBody.cpp:1243
bool VisitContinueStmt(ContinueStmt *stmt)
Definition HDLBody.cpp:277
HDLType * HDLt_userclassesp_
Definition HDLBody.h:105
void Run(Stmt *stmt, hNodep &h_top, HDLBodyMode runmode, HDLType *HDLt_userclassesp=NULL)
Definition HDLBody.cpp:75
hNodep NormalizeAssignmentChain(hNodep hinp)
Definition HDLBody.cpp:1330
bool VisitInitListExpr(InitListExpr *stmt)
Definition HDLBody.cpp:214
clang::DiagnosticsEngine & diag_e
Definition HDLBody.h:86
bool ProcessSwitchCase(SwitchCase *cases)
Definition HDLBody.cpp:1161
bool VisitDoStmt(DoStmt *whiles)
Definition HDLBody.cpp:1270
bool isArrayRef(hNodep hp)
Definition HDLBody.h:119
bool VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *b)
Definition HDLBody.cpp:581
bool VisitIfStmt(IfStmt *ifs)
Definition HDLBody.cpp:1099
bool VisitCallExpr(CallExpr *callexpr)
Definition HDLBody.cpp:1057
bool VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *stmt)
Definition HDLBody.cpp:199
bool VisitBreakStmt(BreakStmt *stmt)
Definition HDLBody.cpp:270
string FindVname(NamedDecl *vard)
Definition HDLBody.cpp:1291
bool VisitCXXMemberCallExpr(CXXMemberCallExpr *callexpr)
Definition HDLBody.cpp:703
bool VisitDeclRefExpr(DeclRefExpr *expr)
Definition HDLBody.cpp:589
bool VisitForStmt(ForStmt *fors)
Definition HDLBody.cpp:1126
bool VisitIntegerLiteral(IntegerLiteral *lit)
Definition HDLBody.cpp:573
bool VisitMaterializeTemporaryExpr(Stmt *st)
bool VisitBreakStmt(BreakStmt *st)
bool shouldVisitTemplateInstantiations() const
bool VisitReturnStmt(ReturnStmt *st)
bool VisitCaseStmt(CaseStmt *st)
StmtVisitor(clang::Stmt *st, HDLBodyMode mode)
bool VisitCompoundStmt(Stmt *st)
bool VisitContinueStmt(ContinueStmt *st)
bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *st)
bool VisitDefaultStmt(DefaultStmt *st)
virtual bool VisitStmt(Stmt *s)
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
@ ruserdefclass
Definition HDLBody.h:32
userrectype_map_t userrectypes
Definition HDLType.h:28