systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
PortBinding.h
Go to the documentation of this file.
1#ifndef _PORT_BINDING_H_
2#define _PORT_BINDING_H_
3
4using namespace systemc_clang;
5
6#include "ArrayTypeUtils.h"
7#include "APIntUtils.h"
8namespace systemc_clang {
9
11
13 public:
14 typedef std::vector<const clang::Expr *> ArraySubscriptsExprType;
15
16 private:
17 //
19 const clang::Expr *caller_expr_;
20 const clang::ArraySubscriptExpr *caller_array_expr_;
21 const clang::MemberExpr *caller_instance_me_expr_;
22 const clang::Expr *caller_port_array_expr_;
24 const clang::MemberExpr *caller_port_me_expr_;
26
28 const clang::Expr *callee_expr_;
29 const clang::MemberExpr *callee_port_me_expr_; // port
30 const clang::MemberExpr *callee_instance_me_expr_; // instance
31 const clang::ArraySubscriptExpr *callee_array_expr_;
33
35
36 // Instance information
38 std::string caller_port_name_;
40
42 std::string callee_port_name_;
43 std::string callee_type_name_;
44
45 std::string instance_type_;
46 std::string instance_var_name_;
48 // Declaration for the instance's type.
49 const clang::CXXRecordDecl *instance_type_decl_;
50
51 public:
52 const std::string getCallerInstanceName() const {
54 }
55 const std::string getCallerInstanceTypeName() const {
57 }
58 const std::string getCallerPortName() const { return caller_port_name_; }
59
60 const std::string getCalleeInstanceName() const {
62 }
63 const std::string getCalleePortName() const { return callee_port_name_; }
64
68
72
76
77 void setInstanceVarName(const std::string &name) {
78 instance_var_name_ = name;
79 }
80 void setInstanceConstructorName(const std::string &name) {
82 }
83
84 const std::string &getPortName() const { return callee_instance_name_; }
85 const clang::MemberExpr *getCallerMemberExpr() const {
87 }
88 const std::string &getInstanceType() const { return instance_type_; }
89 const std::string &getInstanceVarName() const { return instance_var_name_; }
90 const std::string &getInstanceConstructorName() const {
92 }
93 const clang::CXXRecordDecl *getInstanceTypeDecl() const {
95 }
96
101 const std::string toString() const {
102 std::string return_str{getCallerInstanceTypeName()};
103
104 if (getCallerInstanceName() != "") {
105 return_str = return_str + " " + getCallerInstanceName();
106 }
107 if (getInstanceConstructorName() != "") {
108 return_str = return_str + " " + getInstanceConstructorName();
109 }
110
111 for (const auto &sub : getCallerArraySubscripts()) {
112 auto is_int_lit{clang::dyn_cast<clang::IntegerLiteral>(sub)};
113 auto is_dref_expr{clang::dyn_cast<clang::DeclRefExpr>(sub)};
114
115 if (is_int_lit) {
116 //return_str += " " + is_int_lit->getValue().toString(to_str, 32, true);
117 return_str += " " + systemc_clang::utils::apint::toString(is_int_lit->getValue());
118 }
119
120 if (is_dref_expr) {
121 return_str += " " + is_dref_expr->getNameInfo().getName().getAsString();
122 }
123 }
124
126 if (getCallerPortName() != "") {
127 return_str = return_str + " " + getCallerPortName();
128 }
129
130 for (const auto &sub : getCallerPortArraySubscripts()) {
131 auto is_int_lit{clang::dyn_cast<clang::IntegerLiteral>(sub)};
132 auto is_dref_expr{clang::dyn_cast<clang::DeclRefExpr>(sub)};
133
134 if (is_int_lit) {
135 //return_str += " " + is_int_lit->getValue().toString(to_str, 32, true);
136 return_str += " " + systemc_clang::utils::apint::toString(is_int_lit->getValue());
137 }
138
139 if (is_dref_expr) {
140 return_str += " " + is_dref_expr->getNameInfo().getName().getAsString();
141 }
142 }
143
144 if (getCalleeInstanceName() != "") {
145 return_str = return_str + " " + getCalleeInstanceName();
146 }
147
148 for (const auto &sub : getCalleeArraySubscripts()) {
149 auto is_int_lit{clang::dyn_cast<clang::IntegerLiteral>(sub)};
150 auto is_dref_expr{clang::dyn_cast<clang::DeclRefExpr>(sub)};
151
152 if (is_int_lit) {
153 //return_str += " " + is_int_lit->getValue().toString(to_str,32, true);
154 return_str += " " + systemc_clang::utils::apint::toString(is_int_lit->getValue());
155 }
156
157 if (is_dref_expr) {
158 return_str += " " + is_dref_expr->getNameInfo().getName().getAsString();
159 }
160 }
161
162 if (getCalleePortName() != "") {
163 return_str = return_str + " " + getCalleePortName();
164 }
165 return return_str;
166 }
167
170 void dump() {
171 llvm::outs() << "caller instance type name : " << caller_instance_type_name_
172 << " "
173 << "caller instance name : " << caller_instance_name_ << " "
174 << "subscripts: ";
175 for (const auto sub : caller_array_subscripts_) {
176 auto int_lit{clang::dyn_cast<clang::IntegerLiteral>(sub)};
177 if (int_lit) {
178 llvm::outs() << " " << int_lit->getValue();
179 }
180
181 auto decl_ref_expr{clang::dyn_cast<clang::DeclRefExpr>(sub)};
182 if (decl_ref_expr) {
183 llvm::outs() << " "
184 << decl_ref_expr->getNameInfo().getName().getAsString();
185 }
186 }
187
188 llvm::outs() << "\n";
189
190 llvm::outs() << "caller port name : " << caller_port_name_ << " "
191 << "subscripts: ";
192 for (const auto &sub : caller_port_array_subscripts_) {
193 auto int_lit{clang::dyn_cast<clang::IntegerLiteral>(sub)};
194 if (int_lit) {
195 llvm::outs() << " " << int_lit->getValue();
196 }
197
198 auto decl_ref_expr{clang::dyn_cast<clang::DeclRefExpr>(sub)};
199 if (decl_ref_expr) {
200 llvm::outs() << " "
201 << decl_ref_expr->getNameInfo().getName().getAsString();
202 }
203 }
204
205 llvm::outs() << "\nCALLEE\n"
206 << "callee instance name : " << callee_instance_name_ << " "
207 << "callee port name : " << callee_port_name_ << " "
208 << "subscripts: ";
209 for (const auto sub : callee_array_subscripts_) {
210 auto int_lit{clang::dyn_cast<clang::IntegerLiteral>(sub)};
211 if (int_lit) {
212 llvm::outs() << " " << int_lit->getValue();
213 }
214
215 auto decl_ref_expr{clang::dyn_cast<clang::DeclRefExpr>(sub)};
216 if (decl_ref_expr) {
217 llvm::outs() << " "
218 << decl_ref_expr->getNameInfo().getName().getAsString();
219 }
220 }
221
222 llvm::outs() << "\n";
223 }
224
230 PortBinding(clang::Expr *caller_expr, clang::Expr *caller_port_expr,
231 clang::MemberExpr *caller_port_me_expr, clang::Expr *callee_expr,
232 clang::MemberExpr *callee_port_me_expr)
233 : caller_expr_{caller_expr},
234 callee_expr_{callee_expr},
235 caller_port_array_expr_{caller_port_expr},
236 caller_port_me_expr_{caller_port_me_expr},
237 callee_port_me_expr_{callee_port_me_expr} {
239 caller_array_expr_ = dyn_cast<clang::ArraySubscriptExpr>(caller_expr);
240
241 LLVM_DEBUG(llvm::dbgs() << "==> Extract caller port name\n";);
242 // Check to see if the port is initself an array
246 }
247
249 // caller_port_me_expr_->dump();
251 caller_port_me_expr_->getMemberNameInfo().getAsString();
252 }
253
255 if (caller_array_expr_) {
258 } else {
259 caller_instance_me_expr_ = dyn_cast<clang::MemberExpr>(caller_expr);
260 }
261
264 caller_instance_me_expr_->getMemberNameInfo().getAsString();
265 LLVM_DEBUG(
266 llvm::dbgs() << "========= CALLER ME EXPR ======== \n";
268 );
270 ->getType()
271 .getBaseTypeIdentifier()
272 ->getName().str();
273 }
274
275 LLVM_DEBUG(llvm::dbgs() << "==> Extract callee port name\n";);
277 // callee_port_me_expr_->dump();
279 callee_port_me_expr_->getMemberNameInfo().getAsString();
280 LLVM_DEBUG(
281 llvm::dbgs() << " **** callee_port_name_: " << callee_port_name_ << "\n";
282 );
283 }
284
285 // Callee is an array
286 callee_array_expr_ = dyn_cast<clang::ArraySubscriptExpr>(callee_expr);
287 if (callee_array_expr_) {
288 LLVM_DEBUG(llvm::dbgs() << "extract callee name\n";);
291 } else {
292 callee_instance_me_expr_ = dyn_cast<clang::MemberExpr>(callee_expr);
293 }
296 callee_instance_me_expr_->getMemberNameInfo().getAsString();
297 }
298 }
299
300}; // namespace systemc_clang
301}; // namespace systemc_clang
302#endif // ifdef
const clang::Expr * caller_expr_
Caller.
Definition PortBinding.h:19
ArraySubscriptsExprType callee_array_subscripts_
Definition PortBinding.h:32
const std::string getCalleePortName() const
Definition PortBinding.h:63
const std::string getCalleeInstanceName() const
Definition PortBinding.h:60
const std::string & getPortName() const
Definition PortBinding.h:84
std::string caller_instance_type_name_
Definition PortBinding.h:39
const clang::ArraySubscriptExpr * caller_array_expr_
Definition PortBinding.h:20
std::string instance_constructor_name_
Definition PortBinding.h:47
const std::string getCallerInstanceTypeName() const
Definition PortBinding.h:55
const std::string toString() const
const clang::MemberExpr * callee_instance_me_expr_
Definition PortBinding.h:30
PortBinding(clang::Expr *caller_expr, clang::Expr *caller_port_expr, clang::MemberExpr *caller_port_me_expr, clang::Expr *callee_expr, clang::MemberExpr *callee_port_me_expr)
const clang::MemberExpr * callee_port_me_expr_
Definition PortBinding.h:29
const std::string getCallerInstanceName() const
Definition PortBinding.h:52
const clang::Expr * callee_expr_
Callee.
Definition PortBinding.h:28
void setInstanceConstructorName(const std::string &name)
Definition PortBinding.h:80
std::vector< const clang::Expr * > ArraySubscriptsExprType
Definition PortBinding.h:14
std::string caller_instance_name_
We no longer support sc_main parsing.
Definition PortBinding.h:37
ArraySubscriptsExprType caller_port_array_subscripts_
Definition PortBinding.h:23
const clang::Expr * caller_port_array_expr_
Definition PortBinding.h:22
ArraySubscriptsExprType getCalleeArraySubscripts() const
Definition PortBinding.h:73
const std::string & getInstanceType() const
Definition PortBinding.h:88
const clang::CXXRecordDecl * instance_type_decl_
Definition PortBinding.h:49
const std::string & getInstanceConstructorName() const
Definition PortBinding.h:90
std::string callee_instance_name_
Definition PortBinding.h:41
const clang::ArraySubscriptExpr * callee_array_expr_
Definition PortBinding.h:31
const std::string & getInstanceVarName() const
Definition PortBinding.h:89
ArraySubscriptsExprType caller_array_subscripts_
Definition PortBinding.h:25
const clang::MemberExpr * caller_port_me_expr_
Definition PortBinding.h:24
ArraySubscriptsExprType getCallerArraySubscripts() const
Definition PortBinding.h:65
void setInstanceVarName(const std::string &name)
Definition PortBinding.h:77
const clang::CXXRecordDecl * getInstanceTypeDecl() const
Definition PortBinding.h:93
ArraySubscriptsExprType getCallerPortArraySubscripts() const
Definition PortBinding.h:69
const clang::MemberExpr * caller_instance_me_expr_
Definition PortBinding.h:21
const std::string getCallerPortName() const
Definition PortBinding.h:58
const clang::MemberExpr * getCallerMemberExpr() const
Definition PortBinding.h:85
ArraySizesExprType getArraySubscripts(const clang::Expr *expr)
const clang::MemberExpr * getArrayMemberExprName(const clang::Expr *expr)
std::string toString(const T &i)
Definition APIntUtils.h:14