1 #ifndef __ABSTRACTBLOCK_H__
\r
2 #define __ABSTRACTBLOCK_H__
\r
9 #include "AbstractInterface.h"
\r
10 class AbstractInterface;
\r
11 class BlockParameter;
\r
14 #define AB_TO_REF(ptr) ((ReferenceBlock*)ptr)
\r
15 #define AB_TO_FUN(ptr) ((FunctionalBlock*)ptr)
\r
16 #define AB_TO_SPE(ptr) ((SpecialBlock*)ptr)
\r
17 #define AB_TO_GRP(ptr) ((GroupBlock*)ptr)
\r
19 using namespace std;
\r
22 class AbstractBlock {
\r
26 enum BlockVHDLContext {AnyContext = 0, Entity = 1, Component = 2, Architecture = 3 }; // NB : 3 is when creating an instance of the block that owns this iface
\r
27 enum SpecialType { NotSpecial = 0, Source = 1, Sink = 2, ClkConvert = 3 };
\r
30 AbstractBlock(Graph* _graph);
\r
31 //AbstractBlock(const QString& _name);
\r
32 virtual ~AbstractBlock();
\r
35 inline QString getName() { return name; }
\r
36 inline int getSpecialType() { return specialType; }
\r
37 inline QString getVersion() { return version; }
\r
38 inline int nbParameters() { return params.size(); }
\r
39 inline Graph* getGraph() { return graph; }
\r
41 inline QList<AbstractInterface*> getInputs() { return inputs; }
\r
42 inline QList<AbstractInterface*> getOutputs() { return outputs; }
\r
43 inline QList<AbstractInterface*> getBidirs() { return bidirs; }
\r
44 QList<AbstractInterface *> getInterfaces(int direction = AbstractInterface::AnyDirection, int purpose = AbstractInterface::AnyPurpose);
\r
45 QList<AbstractInterface *> getDataInputs(); //! return all inputs of type data
\r
46 QList<AbstractInterface *> getDataOutputs(); //! return all inputs of type data
\r
47 QList<AbstractInterface *> getControlInputs(); //! return all inputs of type control
\r
48 QList<AbstractInterface *> getControlOutputs(); //! return all outputs of type control
\r
49 AbstractInterface* getIfaceFromName(QString name);
\r
51 inline QList<BlockParameter *> getParameters() { return params; }
\r
52 BlockParameter* getParameterFromName(QString name);
\r
53 QList<BlockParameter *> getUserParameters();
\r
54 QList<BlockParameter *> getGenericParameters();
\r
55 QList<BlockParameter *> getPortParameters();
\r
56 QList<BlockParameter *> getWishboneParameters();
\r
58 inline AbstractBlock* getParent() { return parent; }
\r
59 inline bool getOutputPatternComputed() { return outputPatternComputed; }
\r
60 inline int getTraversalLevel() { return traversalLevel; }
\r
63 void setName(const QString& str);
\r
64 void setSpecialType(int type);
\r
65 inline void setVersion(const QString& _version) { version = _version; }
\r
66 virtual void setParent(AbstractBlock* _parent);
\r
67 inline void setOutputPatternComputed(bool state) { outputPatternComputed = state; }
\r
68 inline void resetTraversalLevel() { traversalLevel = -1; }
\r
69 inline void setTraversalLevel(int level) { traversalLevel = level; }
\r
72 virtual bool isReferenceBlock();
\r
73 virtual bool isFunctionalBlock();
\r
74 virtual bool isSpecialBlock();
\r
75 virtual bool isGroupBlock();
\r
76 virtual bool isStimuliBlock(); //! a stimuli block is outside the top group and simulates a peripheral (NB: this is also a source)
\r
77 virtual bool isTopGroupBlock();
\r
78 bool isSourceBlock(); //! a source block is either a block that has no data inputs or that is of special type source. Thus it executes infinitely
\r
79 bool isSinkBlock(); //! a sink block has no data outputs and just collects what it receives (i.e. no compatibility check)
\r
80 bool isWBConfigurable();
\r
83 int getSpecialTypeFromString(QString str);
\r
86 * \brief connectClkReset connects the clock and reset inputs to a clkrstgen block or the the group ifaces
\r
87 * \param idBlockClk is the id of the clock interface (there may be severals)
\r
88 * \param idGen is the id of the clkrstgen block
\r
90 virtual QList<QString> getExternalResources() = 0; // returns the list of all external files needed for VHDL generation
\r
91 virtual void generateVHDL(const QString& path) throw(Exception) = 0; // main entry to generate the VHDL code
\r
92 void generateComponent(QTextStream& out, bool hasController=false) throw(Exception); // generate the component using reference
\r
93 void generateEntity(QTextStream& out, bool hasController=false) throw(Exception); // generate the entity using reference
\r
95 virtual void parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock*>* blocksToConfigure) = 0; // ugly but usefull
\r
97 void addParameter(BlockParameter *param);
\r
98 void addInterface(AbstractInterface *inter);
\r
99 void removeInterface(AbstractInterface *inter);
\r
100 void removeAllInterfaces();
\r
101 void defineBlockParam(BlockParameter *param);
\r
105 virtual void checkInputPatternCompatibility() throw(Exception) = 0;
\r
106 virtual void computeOutputPattern(int nbExec = -1) throw(Exception) = 0;
\r
107 virtual void computeAdmittanceDelays() throw(Exception) = 0;
\r
118 QList<BlockParameter *> params;
\r
121 QList<AbstractInterface*> inputs;
\r
122 QList<AbstractInterface*> outputs;
\r
123 QList<AbstractInterface*> bidirs;
\r
128 bool outputPatternComputed;
\r
129 int traversalLevel; // the level (0, 1, ...) during the traversal of the graph
\r
131 // NB: only GroupBlock and FunctionalBlock have a real parent, except sources that have no parents
\r
132 AbstractBlock* parent;
\r
134 virtual void generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) = 0; // generates comments from <comments> element
\r
135 virtual void generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) = 0; // generates libraries from <libraries> element
\r
136 virtual void generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) = 0; // generate the architecture using <architecture> element
\r
137 virtual void generateController(QTextStream& out) throw(Exception) = 0; // generate the wishbone controller of the block
\r
138 virtual void generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController=false) throw(Exception) = 0; // generate the entity/compo body using reference
\r
142 #endif // __ABSTRACTBLOCK_H__
\r