1 #ifndef __ABSTRACTBLOCK_H__
\r
2 #define __ABSTRACTBLOCK_H__
\r
9 #include "AbstractInterface.h"
\r
10 class AbstractInterface;
\r
11 class BlockParameter;
\r
13 #define AB_TO_REF(ptr) ((ReferenceBlock*)ptr)
\r
14 #define AB_TO_FUN(ptr) ((FunctionalBlock*)ptr)
\r
15 #define AB_TO_SPE(ptr) ((SpecialBlock*)ptr)
\r
16 #define AB_TO_GRP(ptr) ((GroupBlock*)ptr)
\r
18 using namespace std;
\r
21 class AbstractBlock {
\r
25 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
26 enum SpecialType { NotSpecial = 0, Source = 1, Sink = 2, ClkConvert = 3 };
\r
30 //AbstractBlock(const QString& _name);
\r
31 virtual ~AbstractBlock();
\r
34 inline QString getName() { return name; }
\r
35 inline int getSpecialType() { return specialType; }
\r
36 inline QString getVersion() { return version; }
\r
37 inline int nbParameters() { return params.size(); }
\r
38 inline QList<BlockParameter *> getParameters() { return params; }
\r
39 inline QList<AbstractInterface*> getInputs() { return inputs; }
\r
40 inline QList<AbstractInterface*> getOutputs() { return outputs; }
\r
41 inline QList<AbstractInterface*> getBidirs() { return bidirs; }
\r
42 QList<BlockParameter *> getUserParameters();
\r
43 QList<BlockParameter *> getGenericParameters();
\r
44 QList<BlockParameter *> getPortParameters();
\r
45 QList<BlockParameter *> getWishboneParameters();
\r
46 inline AbstractBlock* getParent() { return parent; }
\r
47 inline bool getOutputPatternComputed() { return outputPatternComputed; }
\r
48 inline int getTraversalLevel() { return traversalLevel; }
\r
51 void setName(const QString& str);
\r
52 void setSpecialType(int type);
\r
53 inline void setVersion(const QString& _version) { version = _version; }
\r
54 virtual void setParent(AbstractBlock* _parent);
\r
55 inline void setOutputPatternComputed(bool state) { outputPatternComputed = state; }
\r
56 inline void resetTraversalLevel() { traversalLevel = -1; }
\r
57 inline void setTraversalLevel(int level) { traversalLevel = level; }
\r
60 virtual bool isReferenceBlock();
\r
61 virtual bool isFunctionalBlock();
\r
62 virtual bool isSpecialBlock();
\r
63 virtual bool isGroupBlock();
\r
64 virtual bool isStimuliBlock(); //! a stimuli block is outside the top group and simulates a peripheral (NB: this is also a source)
\r
65 virtual bool isTopGroupBlock();
\r
66 bool isSourceBlock(); //! a source block has no data inputs and thus executes infinitely
\r
67 bool isSinkBlock(); //! a sink block has no data outputs and just collects what it receives (i.e. no compatibility check)
\r
68 bool isWBConfigurable();
\r
71 int getSpecialTypeFromString(QString str);
\r
74 * \brief connectClkReset connects the clock and reset inputs to a clkrstgen block or the the group ifaces
\r
75 * \param idBlockClk is the id of the clock interface (there may be severals)
\r
76 * \param idGen is the id of the clkrstgen block
\r
78 void connectClock(QString clkName, int idGen = 0) throw(Exception);
\r
79 void connectReset(QString rstName, int idGen = 0) throw(Exception);
\r
80 virtual QList<QString> getExternalResources() = 0; // returns the list of all external files needed for VHDL generation
\r
81 virtual void generateVHDL(const QString& path) throw(Exception) = 0; // main entry to generate the VHDL code
\r
82 void generateComponent(QTextStream& out, bool hasController=false) throw(Exception); // generate the component using reference
\r
83 void generateEntity(QTextStream& out, bool hasController=false) throw(Exception); // generate the entity using reference
\r
85 virtual void parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock*>* blocksToConfigure) = 0; // ugly but usefull
\r
87 void addParameter(BlockParameter *param);
\r
88 void addInterface(AbstractInterface *inter);
\r
89 void removeInterface(AbstractInterface *inter);
\r
90 void removeAllInterfaces();
\r
91 void defineBlockParam(BlockParameter *param);
\r
93 QList<AbstractInterface *> getInterfaces(int direction = AbstractInterface::AnyDirection, int purpose = AbstractInterface::AnyPurpose);
\r
94 QList<AbstractInterface *> getDataInputs(); //! return all inputs of type data
\r
95 QList<AbstractInterface *> getDataOutputs(); //! return all inputs of type data
\r
96 QList<AbstractInterface *> getControlInputs(); //! return all inputs of type control
\r
97 QList<AbstractInterface *> getControlOutputs(); //! return all outputs of type control
\r
98 AbstractInterface* getIfaceFromName(QString name);
\r
99 BlockParameter* getParameterFromName(QString name);
\r
102 virtual void checkInputPatternCompatibility() throw(Exception) = 0;
\r
103 virtual void computeOutputPattern(int nbExec = -1) throw(Exception) = 0;
\r
104 virtual void computeAdmittanceDelays() throw(Exception) = 0;
\r
114 QList<BlockParameter *> params;
\r
117 QList<AbstractInterface*> inputs;
\r
118 QList<AbstractInterface*> outputs;
\r
119 QList<AbstractInterface*> bidirs;
\r
124 bool outputPatternComputed;
\r
125 int traversalLevel; // the level (0, 1, ...) during the traversal of the graph
\r
127 // NB: only GroupBlock and FunctionalBlock have a real parent, except sources that have no parents
\r
128 AbstractBlock* parent;
\r
130 virtual void generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) = 0; // generates comments from <comments> element
\r
131 virtual void generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) = 0; // generates libraries from <libraries> element
\r
132 virtual void generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) = 0; // generate the architecture using <architecture> element
\r
133 virtual void generateController(QTextStream& out) throw(Exception) = 0; // generate the wishbone controller of the block
\r
134 virtual void generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController=false) throw(Exception) = 0; // generate the entity/compo body using reference
\r
138 #endif // __ABSTRACTBLOCK_H__
\r