Model.cpp 4.69 KB
Newer Older
Anirudh Kaushik's avatar
Anirudh Kaushik committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <string>
#include "Model.h"
#include "SCModules.h"
using namespace scpar;
using namespace std;

Model::Model()
{
  
}

Model::~Model()
{
  llvm::errs() << "\n[[ Destructor Model ]]\n";
  // Delete all ModuleDecl pointers.
  for (Model::moduleMapType::iterator mit = _modules.begin();
       mit != _modules.end(); mit++) {
    // Second is the ModuleDecl type.
    delete mit->second;
  }
  _modules.clear(); 
}

Model::Model(const Model & from)
{  
  _modules = from._modules;
}

void Model::addModuleDecl(ModuleDecl * md)
{
  _modules.insert(Model::modulePairType(md->getName(), md));
}

void Model::addSimulationTime(FindSimTime::simulationTimeMapType simTime)
{
  _simTime = simTime;
}

void Model::addGlobalEvents(FindGlobalEvents::globalEventMapType eventMap)
{
  for (FindGlobalEvents::globalEventMapType::iterator it = eventMap.begin();
       it != eventMap.end(); it++) {
    string eventName = it->first;
    EventContainer *event = new EventContainer(eventName, it->second);

    _eventMap.insert(eventPairType(eventName, event));
  }
}

void Model::addSCMain(FunctionDecl *fnDecl){
 _scmainFcDecl = fnDecl;
}

void Model::addNetlist(FindNetlist &n) {
  _instanceModuleMap = n.getInstanceModuleMap();
  _portSignalMap = n.getPortSignalMap();
  _instancePortSignalMap = n.getInstancePortSignalMap();
  _instanceListModuleMap = n.getInstanceListModuleMap();
  
  updateModuleDecl();
}

void Model::updateModuleDecl() {

  for (moduleMapType::iterator it = _modules.begin(), eit = _modules.end();
     it != eit;
     it++) {
   string moduleName = it->first;

   ModuleDecl* md = it->second;
   vector<string> instanceList;
   if (_instanceListModuleMap.find(moduleName) != _instanceListModuleMap.end()) {
     FindNetlist::instanceListModuleMapType::iterator instanceListModuleMapFind = _instanceListModuleMap.find(moduleName);
     md->addInstances(instanceListModuleMapFind->second);   
     for (int i = 0 ; i<instanceListModuleMapFind->second.size(); i++) {
      if (_instancePortSignalMap.find(instanceListModuleMapFind->second.at(i)) != _instancePortSignalMap.end()) {
       FindNetlist::instancePortSignalMapType::iterator portSignalMapFound = _instancePortSignalMap.find(instanceListModuleMapFind->second.at(i));
       FindNetlist::portSignalMapType portSignalMap = portSignalMapFound->second;

       md->addSignalBinding(portSignalMap);
      }
      else {
        llvm::errs() <<"\n Could not find instance and signal";
      }
     }
   }
   else {
     llvm::errs() <<"\n ERROR: Could not find module";
   }
 }
}

void Model::addSCModules(SCModules * m)
{
  SCModules::moduleMapType mods = m->getSystemCModulesMap();

  for (SCModules::moduleMapType::iterator mit = mods.begin();
       mit != mods.end(); mit++) {
    addModuleDecl(new ModuleDecl(mit->first, mit->second));
  }
}


Model::moduleMapType Model::getModuleDecl()
{
  return _modules;
}

Model::eventMapType Model::getEventMapType()
{
  return _eventMap;
}

unsigned int Model::getNumEvents()
{
  return (_eventMap.size() - 3);          
}

void Model::dump(raw_ostream & os)
{

  int counterModel = 0;

  os << "\nNumber of Models : " << _modules.size();

  for (Model::moduleMapType::iterator mit = _modules.begin();
       mit != _modules.end(); mit++) {
    // Second is the ModuleDecl type.

    os << "\nModel " << counterModel++;
    mit->second->dump(os);
  }
  os << "\nGlobal Events:\n";
  for (Model::eventMapType::iterator it = _eventMap.begin(), ite =
       _eventMap.end(); it != ite; it++) {

    os << "   Event: " << it->first << "  VarDecl: " << it->second << "\n";
  }


  os << "\nSimulation Time : ";
  for (FindSimTime::simulationTimeMapType::iterator it =
       _simTime.begin(), eit = _simTime.end(); it != eit; it++) {
    os << it->first << " " << it->second;    
  }

  os <<"\n Netlist : " ;
   for (FindNetlist::instanceModuleMapType::iterator it = _instanceModuleMap.begin(), eit =
		 _instanceModuleMap.end(); it != eit; it++)
	{
   llvm::errs() << "\n Instance Name : " << it->first << " Module Name : " << it->
			second;
		string instanceName = it->first;
		if (_instancePortSignalMap.find(instanceName) !=
			_instancePortSignalMap.end())
		{
    FindNetlist::instancePortSignalMapType::iterator instancePortSignalMapFound =
				_instancePortSignalMap.find(instanceName);
    FindNetlist::portSignalMapType portSignalMap =
				instancePortSignalMapFound->second;
			for (FindNetlist::portSignalMapType::iterator pit =
				 portSignalMap.begin(), pite = portSignalMap.end();
				 pit != pite; pit++)
			{
     llvm::errs() << "\n Port : " << pit->
					first << " bound to signal " << pit->second;
			}
		}
		else
		{
    llvm::errs() << "\n No instance name found ////// weird.";
		}
  llvm::errs() << "\n ------------------------------------------------------\n";
	}
}