SystemCClang.cpp 4.86 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
#include "SystemCClang.h"
using namespace scpar;
using namespace clang;
using namespace std;

Model *SystemCConsumer::getSystemCModel() {
	return _systemcModel;
}

bool SystemCConsumer::preFire() {
	return true;
}

bool SystemCConsumer::postFire() {
	return true;
}

bool SystemCConsumer::fire()
{

	TranslationUnitDecl *tu = _context.getTranslationUnitDecl();

	_systemcModel = new Model();

	SCModules scmod(tu, _os);

	// ANI : Do we need FindGlobalEvents?
	FindGlobalEvents fglobals(tu, _os);
	FindGlobalEvents::globalEventMapType eventMap = fglobals.getEventMap();
	_systemcModel->addGlobalEvents(eventMap);

	SCModules::moduleMapType scmodules = scmod.getSystemCModulesMap();

	for (SCModules::moduleMapType::iterator mit = scmodules.begin(),
		 mitend = scmodules.end(); mit != mitend; mit++)
	{

		ModuleDecl *md = new ModuleDecl(mit->first, mit->second);
39
40
	 	_os <<"\n Number of instances in this module : " <<md->getNumInstances();
		vector < EntryFunctionContainer * >_entryFunctionContainerVector;
Anirudh Kaushik's avatar
Anirudh Kaushik committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
		
  FindConstructor constructor(mit->second, _os);
		md->addConstructor(constructor.returnConstructorStmt());

		FindPorts ports(mit->second, _os);
		md->addInputPorts(ports.getInputPorts());
		md->addOutputPorts(ports.getOutputPorts());
		md->addInputOutputPorts(ports.getInputOutputPorts());
  
  FindTLMInterfaces findTLMInterfaces(mit->second, _os);
  md->addInputInterfaces(findTLMInterfaces.getInputInterfaces());
  md->addOutputInterfaces(findTLMInterfaces.getOutputInterfaces());
  md->addInputOutputInterfaces(findTLMInterfaces.getInputOutputInterfaces());

		FindSignals signals(mit->second, _os);
		md->addSignals(signals.getSignals());

		FindEntryFunctions findEntries(mit->second, _os);
		FindEntryFunctions::entryFunctionVectorType * entryFunctions =
			findEntries.getEntryFunctions();
61
  
Anirudh Kaushik's avatar
Anirudh Kaushik committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  md->addProcess(entryFunctions);

		for (unsigned int i = 0; i < entryFunctions->size(); i++)
		{
			EntryFunctionContainer *ef = (*entryFunctions)[i];

			FindSensitivity
				findSensitivity(constructor.returnConstructorStmt(), _os);
			ef->addSensitivityInfo(findSensitivity);

			if (ef->getEntryMethod() == NULL)
			{
				_os << "ERROR";
				continue;
			}

			FindWait findWaits(ef->getEntryMethod(), _os);
			ef->addWaits(findWaits);

			FindNotify findNotify(ef->_entryMethodDecl, _os);
			ef->addNotifys(findNotify);
83
    
84
   /*
Anirudh Kaushik's avatar
Anirudh Kaushik committed
85
   SuspensionAutomata suspensionAutomata(findWaits.getWaitCalls(), ef->getEntryMethod(), &_context, llvm::errs());
86
87
   if (suspensionAutomata.initialize()) {
    suspensionAutomata.genSusCFG();
Anirudh's avatar
Anirudh committed
88
    //suspensionAutomata.dumpSusCFG();
89
    suspensionAutomata.genSauto();    
Anirudh's avatar
Anirudh committed
90
    //suspensionAutomata.dumpSauto();
91
92
    ef->addSusCFGAuto(suspensionAutomata); 
   }
93
  	*/ 
Anirudh Kaushik's avatar
Anirudh Kaushik committed
94
			_entryFunctionContainerVector.push_back(ef);
95
96
		
  }
Anirudh Kaushik's avatar
Anirudh Kaushik committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
		_systemcModel->addModuleDecl(md);

	}

	FindSCMain scmain(tu, _os);

	if (scmain.isSCMainFound())
	{
		FunctionDecl *fnDecl = scmain.getSCMainFunctionDecl();

		FindSimTime scstart(fnDecl, _os);
		_systemcModel->addSimulationTime(scstart.returnSimTime());

	}
Anirudh's avatar
Anirudh committed
111
112
113
	else {
		_os <<"\n Could not find SCMain";
	}
Anirudh Kaushik's avatar
Anirudh Kaushik committed
114
	FindNetlist findNetlist(scmain.getSCMainFunctionDecl());
Anirudh's avatar
Anirudh committed
115
116
 	findNetlist.dump();
	_systemcModel->addNetlist(findNetlist); 
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
	
	// Generate SAUTO
	// Placing it here so that unique SAUTO for each instance
	Model::moduleMapType moduleMap = _systemcModel->getModuleDecl();
	for (Model::moduleMapType::iterator it = moduleMap.begin(), eit = moduleMap.end();
									it != eit;
									it++) {
		ModuleDecl *moduleDecl = it->second;
		int numInstances = moduleDecl->getNumInstances();
		for (int i = 0; i<numInstances; i++) {
			vector<EntryFunctionContainer*> entryFunctionContainer = moduleDecl->getEntryFunctionContainer();
			for (int j = 0; j<entryFunctionContainer.size(); j++) {
		
   			SuspensionAutomata suspensionAutomata(entryFunctionContainer.at(j)->getWaitCalls(), entryFunctionContainer.at(j)->getEntryMethod(), &_context, llvm::errs());
   			if (suspensionAutomata.initialize()) {
    			suspensionAutomata.genSusCFG();
    			//suspensionAutomata.dumpSusCFG();
    			suspensionAutomata.genSauto();    
    			//suspensionAutomata.dumpSauto();
    			entryFunctionContainer.at(j)->addSusCFGAuto(suspensionAutomata, i); 
   			}		
			}
		}
	}

142
143
 _os <<"\n SystemC model dump\n";
 _systemcModel->dump(_os); 
Anirudh Kaushik's avatar
Anirudh Kaushik committed
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
176
177
178
179
180
181
182
183
184
185
186
 return true;
}

void SystemCConsumer::HandleTranslationUnit(ASTContext & context)
{
	// ///////////////////////////////////////////////////////////////
	// / Pass 1: Find the necessary information.
	// ///////////////////////////////////////////////////////////////

	bool pre = false;

	pre = preFire();

	if (!pre)
	{
		return;
	}

	bool f = false;

	f = fire();

	if (!f)
	{
		return;
	}
	postFire();
}

SystemCConsumer::SystemCConsumer(CompilerInstance & ci):_os(llvm::errs()), _sm(ci.getSourceManager()), _ci(ci),
_context(ci.getASTContext()),
_systemcModel(NULL)
{

}

SystemCConsumer::~SystemCConsumer()
{
	if (_systemcModel != NULL)
	{
		delete _systemcModel;
	}
}