1 #include <AbstractBlock.h>
\r
2 #include <QInputDialog>
\r
3 #include <QMessageBox>
\r
4 #include "AbstractInterface.h"
\r
5 #include "BlockParameter.h"
\r
6 #include "Parameters.h"
\r
7 #include "GroupBlock.h"
\r
8 #include "ConnectedInterface.h"
\r
11 AbstractBlock::AbstractBlock() {
\r
14 specialType = NotSpecial;
\r
18 AbstractBlock::AbstractBlock(const QString& _name) {
\r
19 name = Parameters::normalizeName(_name);
\r
24 AbstractBlock::~AbstractBlock() {
\r
26 removeAllInterfaces();
\r
28 foreach(BlockParameter* p, params) {
\r
34 void AbstractBlock::setName(const QString& str) {
\r
35 name = Parameters::normalizeName(str);
\r
38 void AbstractBlock::setSpecialType(int type) {
\r
39 if ((type >= NotSpecial) && (type <= ClkConvert)) {
\r
43 specialType = NotSpecial;
\r
47 void AbstractBlock::setParent(AbstractBlock* _parent) {
\r
51 bool AbstractBlock::isReferenceBlock() {
\r
55 bool AbstractBlock::isFunctionalBlock() {
\r
59 bool AbstractBlock::isSpecialBlock() {
\r
63 bool AbstractBlock::isGroupBlock() {
\r
67 bool AbstractBlock::isTopGroupBlock() {
\r
71 bool AbstractBlock::isStimuliBlock() {
\r
74 /* NB: a source is a block that has no data inputs
\r
75 * and has at least one data output.
\r
76 * By the way, blocks that have no data input/output
\r
77 * (like clkrstgen) are not sources !
\r
79 bool AbstractBlock::isSourceBlock() {
\r
80 if (getDataInputs().size() > 0) return false;
\r
81 if (getDataOutputs().size() == 0) return false;
\r
85 /* NB: a sink is a block without outputs of any type */
\r
86 bool AbstractBlock::isSinkBlock() {
\r
87 if (getOutputs().size() == 0) return true;
\r
91 int AbstractBlock::getSpecialTypeFromString(QString str) {
\r
92 if (str == "source") {
\r
95 else if (str == "sink") {
\r
98 else if (str == "clkconvert") {
\r
105 void AbstractBlock::addParameter(BlockParameter *param) {
\r
106 params.append(param);
\r
110 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
111 foreach(BlockParameter* p, params) {
\r
112 if (p->getName() == name) return p;
\r
117 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
118 if(inter->getDirection() == AbstractInterface::Input){
\r
119 inputs.append(inter);
\r
120 } else if(inter->getDirection() == AbstractInterface::Output){
\r
121 outputs.append(inter);
\r
122 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
123 bidirs.append(inter);
\r
127 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
128 /* CAUTION: no check is done about the connection state of this interface
\r
129 Thus, if it is still connected to/from, there will be a crash
\r
131 if(inter->getDirection() == AbstractInterface::Input){
\r
132 inputs.removeAll(inter);
\r
133 } else if(inter->getDirection() == AbstractInterface::Output){
\r
134 outputs.removeAll(inter);
\r
135 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
136 bidirs.removeAll(inter);
\r
141 void AbstractBlock::removeAllInterfaces() {
\r
143 foreach(AbstractInterface* iface, inputs) {
\r
146 foreach(AbstractInterface* iface, outputs) {
\r
149 foreach(AbstractInterface* iface, bidirs) {
\r
158 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
160 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
162 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
164 while (!ok && value.isEmpty())
\r
166 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
167 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
169 param->setValue(value);
\r
172 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
173 QList<AbstractInterface *> list;
\r
174 bool selIn = false;
\r
175 bool selOut = false;
\r
176 bool selInOut = false;
\r
178 if (direction == AbstractInterface::AnyDirection) {
\r
183 else if (direction == AbstractInterface::Input) {
\r
186 else if (direction == AbstractInterface::Output) {
\r
189 else if (direction == AbstractInterface::InOut) {
\r
193 foreach(AbstractInterface* iface, inputs) {
\r
194 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
198 foreach(AbstractInterface* iface, outputs) {
\r
199 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
203 foreach(AbstractInterface* iface, bidirs) {
\r
204 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
210 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
211 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
214 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
215 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
218 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
219 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
222 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
223 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
226 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
228 foreach(AbstractInterface* iface, inputs) {
\r
229 if (iface->getName() == name) return iface;
\r
231 foreach(AbstractInterface* iface, outputs) {
\r
232 if (iface->getName() == name) return iface;
\r
234 foreach(AbstractInterface* iface, bidirs) {
\r
235 if (iface->getName() == name) return iface;
\r
240 bool AbstractBlock::isWBConfigurable() {
\r
242 foreach(BlockParameter* p, params) {
\r
243 if (p->isWishboneParameter()) return true;
\r
248 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
249 QList<BlockParameter *> lst;
\r
250 foreach(BlockParameter* p, params) {
\r
251 if (p->isUserParameter()) lst.append(p);
\r
256 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
257 QList<BlockParameter *> lst;
\r
258 foreach(BlockParameter* p, params) {
\r
259 if (p->isGenericParameter()) lst.append(p);
\r
264 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
265 QList<BlockParameter *> lst;
\r
266 foreach(BlockParameter* p, params) {
\r
267 if (p->isPortParameter()) lst.append(p);
\r
272 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
273 QList<BlockParameter *> lst;
\r
274 foreach(BlockParameter* p, params) {
\r
275 if (p->isWishboneParameter()) lst.append(p);
\r
280 void AbstractBlock::connectClock(QString clkName, int idGen) throw(Exception) {
\r
282 GroupBlock* parentBlock = AB_TO_GRP(parent);
\r
283 ConnectedInterface* fromClk = NULL;
\r
284 ConnectedInterface* toClk = AI_TO_CON(getIfaceFromName(clkName));
\r
286 if (parentBlock->isTop()) {
\r
287 QString genName = "clkrstgen_" + QString::number(idGen);
\r
288 AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName(genName);
\r
289 if (clkrstgen == NULL) {
\r
290 throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));
\r
293 fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk"));
\r
295 cout << "connecting clock for " << qPrintable(name) << " to " << qPrintable(genName) << endl;
\r
298 // searching for ext_clk_idGen
\r
299 QString name = "ext_clk_"+QString::number(idGen);
\r
300 fromClk = AI_TO_CON(parentBlock->getIfaceFromName(name));
\r
301 cout << "connecting clk for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;
\r
304 if (fromClk == NULL) {
\r
305 throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));
\r
308 fromClk->connectTo(toClk);
\r
309 cout << "connection done between " << qPrintable(toClk->getConnectedFrom()->getOwner()->getName()) << "/" << qPrintable(toClk->getConnectedFrom()->getName());
\r
310 cout << " and " << qPrintable(toClk->getOwner()->getName()) << "/" << qPrintable(toClk->getName()) << endl;
\r
314 void AbstractBlock::connectReset(QString rstName, int idGen) throw(Exception) {
\r
316 GroupBlock* parentBlock = AB_TO_GRP(parent);
\r
317 ConnectedInterface* fromRst = NULL;
\r
318 ConnectedInterface* toRst = AI_TO_CON(getIfaceFromName(rstName));
\r
320 if (parentBlock->isTop()) {
\r
321 QString genName = "clkrstgen_" + QString::number(idGen);
\r
322 AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName(genName);
\r
323 if (clkrstgen == NULL) {
\r
324 throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));
\r
327 fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset"));
\r
329 cout << "connecting reset for " << qPrintable(name) << " to " << qPrintable(genName) << endl;
\r
332 QString name = "ext_reset_"+QString::number(idGen);
\r
333 fromRst = AI_TO_CON(parentBlock->getIfaceFromName(name));
\r
334 cout << "connecting reset for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;
\r
337 if (fromRst == NULL) {
\r
338 throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));
\r
341 fromRst->connectTo(toRst);
\r
342 cout << "connection done between " << qPrintable(toRst->getConnectedFrom()->getOwner()->getName()) << "/" << qPrintable(toRst->getConnectedFrom()->getName());
\r
343 cout << " and " << qPrintable(toRst->getOwner()->getName()) << "/" << qPrintable(toRst->getName()) << endl;
\r
347 void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {
\r
349 out << "entity " << name << " is" << endl;
\r
351 generateEntityOrComponentBody(out, 0, hasController);
\r
353 catch(Exception e) {
\r
356 out << "end entity " << name << ";" << endl << endl;
\r
359 void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) {
\r
361 out << " component " << name << " is" << endl;
\r
363 generateEntityOrComponentBody(out, 2, hasController);
\r
365 catch(Exception e) {
\r
368 out << " end component; " << endl << endl;
\r