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
17 AbstractBlock::AbstractBlock(const QString& _name) {
\r
18 name = Parameters::normalizeName(_name);
\r
23 AbstractBlock::~AbstractBlock() {
\r
25 removeAllInterfaces();
\r
27 foreach(BlockParameter* p, params) {
\r
33 void AbstractBlock::setName(const QString& str) {
\r
34 name = Parameters::normalizeName(str);
\r
37 void AbstractBlock::setParent(AbstractBlock* _parent) {
\r
41 bool AbstractBlock::isReferenceBlock() {
\r
45 bool AbstractBlock::isFunctionalBlock() {
\r
49 bool AbstractBlock::isGroupBlock() {
\r
53 bool AbstractBlock::isTopGroupBlock() {
\r
57 bool AbstractBlock::isSourceBlock() {
\r
60 /* NB: a generator is a block that has no data inputs
\r
61 * and has at least one data output.
\r
62 * By the way, blocks that have no data input/output
\r
63 * (like clkrstgen) are not generators !
\r
65 bool AbstractBlock::isGeneratorBlock() {
\r
66 if (getDataInputs().size() > 0) return false;
\r
67 if (getDataOutputs().size() == 0) return false;
\r
71 void AbstractBlock::addParameter(BlockParameter *param) {
\r
72 params.append(param);
\r
76 BlockParameter* AbstractBlock::getParameterFromName(QString name) {
\r
77 foreach(BlockParameter* p, params) {
\r
78 if (p->getName() == name) return p;
\r
83 void AbstractBlock::addInterface(AbstractInterface *inter) {
\r
84 if(inter->getDirection() == AbstractInterface::Input){
\r
85 inputs.append(inter);
\r
86 } else if(inter->getDirection() == AbstractInterface::Output){
\r
87 outputs.append(inter);
\r
88 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
89 bidirs.append(inter);
\r
93 void AbstractBlock::removeInterface(AbstractInterface *inter) {
\r
94 /* CAUTION: no check is done about the connection state of this interface
\r
95 Thus, if it is still connected to/from, there will be a crash
\r
97 if(inter->getDirection() == AbstractInterface::Input){
\r
98 inputs.removeAll(inter);
\r
99 } else if(inter->getDirection() == AbstractInterface::Output){
\r
100 outputs.removeAll(inter);
\r
101 } else if(inter->getDirection() == AbstractInterface::InOut){
\r
102 bidirs.removeAll(inter);
\r
107 void AbstractBlock::removeAllInterfaces() {
\r
109 foreach(AbstractInterface* iface, inputs) {
\r
112 foreach(AbstractInterface* iface, outputs) {
\r
115 foreach(AbstractInterface* iface, bidirs) {
\r
124 void AbstractBlock::defineBlockParam(BlockParameter *param)
\r
126 cout << "definition of param : " << param->getName().toStdString() << endl;
\r
128 QString value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + "?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
130 while (!ok && value.isEmpty())
\r
132 QMessageBox::critical(NULL, "Error", "You have to insert a value for the parameter or accept the default value !");
\r
133 value = QInputDialog::getText(NULL, "Block parameter", "value for the "+ param->getName() +" parameter of " + param->getOwner()->getName() + " ?", QLineEdit::Normal, param->getValue().toString(), &ok);
\r
135 param->setValue(value);
\r
138 QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {
\r
139 QList<AbstractInterface *> list;
\r
140 bool selIn = false;
\r
141 bool selOut = false;
\r
142 bool selInOut = false;
\r
144 if (direction == AbstractInterface::AnyDirection) {
\r
149 else if (direction == AbstractInterface::Input) {
\r
152 else if (direction == AbstractInterface::Output) {
\r
155 else if (direction == AbstractInterface::InOut) {
\r
159 foreach(AbstractInterface* iface, inputs) {
\r
160 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
164 foreach(AbstractInterface* iface, outputs) {
\r
165 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
169 foreach(AbstractInterface* iface, bidirs) {
\r
170 if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface);
\r
176 QList<AbstractInterface *> AbstractBlock::getDataInputs() {
\r
177 return getInterfaces(AbstractInterface::Input, AbstractInterface::Data);
\r
180 QList<AbstractInterface *> AbstractBlock::getDataOutputs() {
\r
181 return getInterfaces(AbstractInterface::Output, AbstractInterface::Data);
\r
184 QList<AbstractInterface *> AbstractBlock::getControlInputs() {
\r
185 return getInterfaces(AbstractInterface::Input, AbstractInterface::Control);
\r
188 QList<AbstractInterface *> AbstractBlock::getControlOutputs() {
\r
189 return getInterfaces(AbstractInterface::Output, AbstractInterface::Control);
\r
192 AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {
\r
194 foreach(AbstractInterface* iface, inputs) {
\r
195 if (iface->getName() == name) return iface;
\r
197 foreach(AbstractInterface* iface, outputs) {
\r
198 if (iface->getName() == name) return iface;
\r
200 foreach(AbstractInterface* iface, bidirs) {
\r
201 if (iface->getName() == name) return iface;
\r
206 bool AbstractBlock::isWBConfigurable() {
\r
208 foreach(BlockParameter* p, params) {
\r
209 if (p->isWishboneParameter()) return true;
\r
214 QList<BlockParameter *> AbstractBlock::getUserParameters() {
\r
215 QList<BlockParameter *> lst;
\r
216 foreach(BlockParameter* p, params) {
\r
217 if (p->isUserParameter()) lst.append(p);
\r
222 QList<BlockParameter *> AbstractBlock::getGenericParameters() {
\r
223 QList<BlockParameter *> lst;
\r
224 foreach(BlockParameter* p, params) {
\r
225 if (p->isGenericParameter()) lst.append(p);
\r
230 QList<BlockParameter *> AbstractBlock::getPortParameters() {
\r
231 QList<BlockParameter *> lst;
\r
232 foreach(BlockParameter* p, params) {
\r
233 if (p->isPortParameter()) lst.append(p);
\r
238 QList<BlockParameter *> AbstractBlock::getWishboneParameters() {
\r
239 QList<BlockParameter *> lst;
\r
240 foreach(BlockParameter* p, params) {
\r
241 if (p->isWishboneParameter()) lst.append(p);
\r
246 void AbstractBlock::connectClock(QString clkName, int idGen) throw(Exception) {
\r
248 GroupBlock* parentBlock = AB_TO_GRP(parent);
\r
249 ConnectedInterface* fromClk = NULL;
\r
250 ConnectedInterface* toClk = AI_TO_CON(getIfaceFromName(clkName));
\r
252 if (parentBlock->isTop()) {
\r
253 QString genName = "clkrstgen_" + QString::number(idGen);
\r
254 AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName(genName);
\r
255 if (clkrstgen == NULL) {
\r
256 throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));
\r
259 fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk"));
\r
261 cout << "connecting clock for " << qPrintable(name) << " to " << qPrintable(genName) << endl;
\r
264 // searching for ext_clk_idGen
\r
265 QString name = "ext_clk_"+QString::number(idGen);
\r
266 fromClk = AI_TO_CON(parentBlock->getIfaceFromName(name));
\r
267 cout << "connecting clk for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;
\r
270 if (fromClk == NULL) {
\r
271 throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));
\r
274 fromClk->connectTo(toClk);
\r
275 cout << "connection done between " << qPrintable(toClk->getConnectedFrom()->getOwner()->getName()) << "/" << qPrintable(toClk->getConnectedFrom()->getName());
\r
276 cout << " and " << qPrintable(toClk->getOwner()->getName()) << "/" << qPrintable(toClk->getName()) << endl;
\r
280 void AbstractBlock::connectReset(QString rstName, int idGen) throw(Exception) {
\r
282 GroupBlock* parentBlock = AB_TO_GRP(parent);
\r
283 ConnectedInterface* fromRst = NULL;
\r
284 ConnectedInterface* toRst = AI_TO_CON(getIfaceFromName(rstName));
\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 fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset"));
\r
295 cout << "connecting reset for " << qPrintable(name) << " to " << qPrintable(genName) << endl;
\r
298 QString name = "ext_reset_"+QString::number(idGen);
\r
299 fromRst = AI_TO_CON(parentBlock->getIfaceFromName(name));
\r
300 cout << "connecting reset for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;
\r
303 if (fromRst == NULL) {
\r
304 throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));
\r
307 fromRst->connectTo(toRst);
\r
308 cout << "connection done between " << qPrintable(toRst->getConnectedFrom()->getOwner()->getName()) << "/" << qPrintable(toRst->getConnectedFrom()->getName());
\r
309 cout << " and " << qPrintable(toRst->getOwner()->getName()) << "/" << qPrintable(toRst->getName()) << endl;
\r
313 void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {
\r
315 out << "entity " << name << " is" << endl;
\r
317 generateEntityOrComponentBody(out, 0, hasController);
\r
319 catch(Exception e) {
\r
322 out << "end entity " << name << ";" << endl << endl;
\r
325 void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) {
\r
327 out << " component " << name << " is" << endl;
\r
329 generateEntityOrComponentBody(out, 2, hasController);
\r
331 catch(Exception e) {
\r
334 out << " end component; " << endl << endl;
\r