systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
FindNetlist.cpp
Go to the documentation of this file.
1#include "FindNetlist.h"
2using namespace systemc_clang;
3
4FindNetlist::FindNetlist(FunctionDecl *fdecl) : _pass{1} {
5 TraverseDecl(fdecl);
6 _pass = 2;
7}
8
14
22
23void FindNetlist::updateInstanceListModuleMap(const std::string &instanceName,
24 const std::string &moduleName) {
25 if (inst_list_module_map_.find(moduleName) == inst_list_module_map_.end()) {
26 vector<string> instanceList;
27 instanceList.push_back(instanceName);
29 instanceListModulePairType(moduleName, instanceList));
30 } else {
31 instanceListModuleMapType::iterator instanceListModuleMapFound =
32 inst_list_module_map_.find(moduleName);
33 std::vector<std::string> instanceList{instanceListModuleMapFound->second};
34 instanceList.push_back(instanceName);
35 inst_list_module_map_.erase(moduleName);
37 instanceListModulePairType(moduleName, instanceList));
38 }
39}
40
41bool FindNetlist::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *ce) {
42 bool foundME = false;
43
44 std::string moduleName;
45 std::string instanceName;
46 std::string portName;
47 std::string signalName;
48
49 for (Stmt::child_iterator it = ce->IgnoreImpCasts()->child_begin(),
50 eit = ce->IgnoreImpCasts()->child_end();
51 it != eit; it++) {
52 if (Expr *e = dyn_cast<Expr>(*it)) {
53 if (MemberExpr *me = dyn_cast<MemberExpr>(e->IgnoreImpCasts())) {
54 if (DeclRefExpr *de =
55 dyn_cast<DeclRefExpr>(me->getBase()->IgnoreImpCasts())) {
56 moduleName =
57 de->getDecl()->getType().getBaseTypeIdentifier()->getName().str();
58 instanceName = de->getFoundDecl()->getNameAsString();
59 }
60 portName = me->getMemberDecl()->getNameAsString();
61 foundME = true;
62 }
63 if (DeclRefExpr *de = dyn_cast<DeclRefExpr>(e->IgnoreImpCasts())) {
64 if (foundME) {
65 signalName = de->getNameInfo().getAsString();
66 foundME = false;
67 }
68 }
69 }
70 }
71
72 if (inst_module_map_.find(instanceName) == inst_module_map_.end()) {
73 inst_module_map_.insert(instanceModulePairType(instanceName, moduleName));
74 port_signal_map_.clear();
75 updateInstanceListModuleMap(instanceName, moduleName);
76 }
77
78 port_signal_map_.insert(portSignalPairType(portName, signalName));
79
80 if (inst_port_signal_map_.find(instanceName) ==
84 } else {
85 inst_port_signal_map_.erase(instanceName);
88 }
89
90 return true;
91}
92
93int FindNetlist::getNumInstances(string moduleName) {
94 int counter = 0;
95 for (instanceModuleMapType::iterator it = inst_module_map_.begin(),
96 eit = inst_module_map_.end();
97 it != eit; it++) {
98 string modName = it->second;
99 if (modName == moduleName) {
100 counter++;
101 }
102 }
103 return counter;
104}
105
109
114
118
123
125 llvm::errs() << "\n ----------------- Netlist dump ----------------- \n";
126
127 for (instanceModuleMapType::iterator it = inst_module_map_.begin(),
128 eit = inst_module_map_.end();
129 it != eit; it++) {
130 llvm::errs() << "\n Instance Name : " << it->first
131 << " Module Name : " << it->second;
132 string instanceName = it->first;
133
134 if (inst_port_signal_map_.find(instanceName) !=
135 inst_port_signal_map_.end()) {
136 instancePortSignalMapType::iterator instancePortSignalMapFound =
137 inst_port_signal_map_.find(instanceName);
138 portSignalMapType portSignalMap = instancePortSignalMapFound->second;
139 for (portSignalMapType::iterator pit = portSignalMap.begin(),
140 pite = portSignalMap.end();
141 pit != pite; pit++) {
142 llvm::errs() << "\n Port : " << pit->first << " ------> "
143 << pit->second;
144 }
145 } else {
146 llvm::errs() << "\n No instance name found ////// weird.";
147 }
148 llvm::errs()
149 << "\n ------------------------------------------------------\n";
150 }
151}
virtual bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *ce)
void updateInstanceListModuleMap(const std::string &, const std::string &)
const instancePortSignalMapType & getInstancePortSignalMap()
portSignalMapType port_signal_map_
Definition FindNetlist.h:51
pair< string, vector< string > > instanceListModulePairType
Definition FindNetlist.h:33
instanceListModuleMapType inst_list_module_map_
Definition FindNetlist.h:53
pair< string, string > portSignalPairType
Definition FindNetlist.h:27
const portSignalMapType & getPortSignalMap()
const instanceListModuleMapType & getInstanceListModuleMap()
pair< string, string > instanceModulePairType
Definition FindNetlist.h:24
instancePortSignalMapType inst_port_signal_map_
Definition FindNetlist.h:52
map< string, portSignalMapType > instancePortSignalMapType
Definition FindNetlist.h:31
pair< string, portSignalMapType > instancePortSignalPairType
Definition FindNetlist.h:30
instanceModuleMapType inst_module_map_
Definition FindNetlist.h:50
const instanceModuleMapType & getInstanceModuleMap()
FindNetlist(FunctionDecl *)
map< string, vector< string > > instanceListModuleMapType
Definition FindNetlist.h:34
int getNumInstances(std::string)
map< string, string > instanceModuleMapType
Definition FindNetlist.h:25
map< string, string > portSignalMapType
Definition FindNetlist.h:28