#include <QMessageBox>\r
#include "AbstractInterface.h"\r
#include "BlockParameter.h"\r
+#include "Parameters.h"\r
#include "GroupBlock.h"\r
#include "ConnectedInterface.h"\r
\r
-AbstractBlock::AbstractBlock() {\r
+\r
+AbstractBlock::AbstractBlock(Graph *_graph) {\r
name = "";\r
parent = NULL;\r
+ specialType = NotSpecial;\r
+ graph = _graph;\r
}\r
\r
/*\r
AbstractBlock::AbstractBlock(const QString& _name) {\r
- name = normalizeName(_name);\r
+ name = Parameters::normalizeName(_name);\r
parent = NULL;\r
}\r
*/\r
}\r
\r
void AbstractBlock::setName(const QString& str) {\r
- name = normalizeName(str);\r
+ name = Parameters::normalizeName(str);\r
+}\r
+\r
+void AbstractBlock::setSpecialType(int type) {\r
+ if ((type >= NotSpecial) && (type <= ClkConvert)) {\r
+ specialType = type;\r
+ }\r
+ else {\r
+ specialType = NotSpecial;\r
+ }\r
}\r
\r
void AbstractBlock::setParent(AbstractBlock* _parent) {\r
return false;\r
}\r
\r
+bool AbstractBlock::isSpecialBlock() {\r
+ return false;\r
+}\r
+\r
bool AbstractBlock::isGroupBlock() {\r
return false;\r
}\r
return false;\r
}\r
\r
-bool AbstractBlock::isSourceBlock() {\r
+bool AbstractBlock::isStimuliBlock() {\r
return false;\r
}\r
-/* NB: a generator is a block that has no data inputs\r
+/* NB: a source is a block that has no data inputs\r
* and has at least one data output.\r
+ * By the way, blocks that have no data input/output\r
+ * (like clkrstgen) are not sources !\r
*/\r
-bool AbstractBlock::isGeneratorBlock() {\r
+bool AbstractBlock::isSourceBlock() {\r
if (getDataInputs().size() > 0) return false;\r
- \r
+ if (getDataOutputs().size() == 0) return false;\r
return true;\r
}\r
\r
+/* NB: a sink is a block without outputs of any type */\r
+bool AbstractBlock::isSinkBlock() {\r
+ if (getOutputs().size() == 0) return true;\r
+ return false;\r
+}\r
+\r
+int AbstractBlock::getSpecialTypeFromString(QString str) {\r
+ if (str == "source") {\r
+ return Source;\r
+ }\r
+ else if (str == "sink") {\r
+ return Sink;\r
+ }\r
+ else if (str == "clkconvert") {\r
+ return ClkConvert;\r
+ }\r
+ return NotSpecial;\r
+}\r
+\r
+\r
void AbstractBlock::addParameter(BlockParameter *param) {\r
params.append(param);\r
}\r
return lst;\r
}\r
\r
-QString AbstractBlock::normalizeName(const QString &name) {\r
- QString s = name;\r
- s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_");\r
- s.replace(QRegularExpression("[_]+"),"_");\r
- return s;\r
-}\r
-\r
-void AbstractBlock::connectClkReset() throw(Exception) {\r
-\r
- GroupBlock* parentBlock = AB_TO_GRP(parent);\r
+void AbstractBlock::generateEntity(QTextStream& out, bool hasController) throw(Exception) {\r
\r
- cout << "connecting clk/rst for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;\r
-\r
- QList<AbstractInterface* > lstClk = getInterfaces(AbstractInterface::Input,AbstractInterface::Clock);\r
- QList<AbstractInterface* > lstRst = getInterfaces(AbstractInterface::Input,AbstractInterface::Reset);\r
-\r
- if ((lstClk.isEmpty()) || (lstRst.isEmpty())) {\r
- throw(Exception(IFACE_GROUP_NOCLKRST,this));\r
+ out << "entity " << name << " is" << endl;\r
+ try {\r
+ generateEntityOrComponentBody(out, 0, hasController);\r
}\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ out << "end entity " << name << ";" << endl << endl;\r
+}\r
\r
- ConnectedInterface* toClk = AI_TO_CON(lstClk.at(0));\r
- ConnectedInterface* toRst = AI_TO_CON(lstRst.at(0));\r
-\r
- ConnectedInterface* fromClk = NULL;\r
- ConnectedInterface* fromRst = NULL;\r
+void AbstractBlock::generateComponent(QTextStream& out, bool hasController) throw(Exception) {\r
\r
- if (parentBlock->isTop()) {\r
- AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName("clkrstgen");\r
- if (clkrstgen == NULL) {\r
- throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));\r
- }\r
- else {\r
- fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk"));\r
- fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset"));\r
- }\r
+ out << " component " << name << " is" << endl;\r
+ try {\r
+ generateEntityOrComponentBody(out, 2, hasController);\r
}\r
- else {\r
- fromClk = AI_TO_CON(parentBlock->getIfaceFromName("clk"));\r
- fromRst = AI_TO_CON(parentBlock->getIfaceFromName("reset"));\r
+ catch(Exception e) {\r
+ throw(e);\r
}\r
- if ((fromClk == NULL) || (fromRst == NULL)) {\r
- throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));\r
- }\r
- else {\r
- fromClk->connectTo(toClk);\r
- fromRst->connectTo(toRst);\r
- }\r
-\r
-\r
+ out << " end component; " << endl << endl;\r
}\r
\r
\r
-\r