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_GRP(ptr) ((GroupBlock*)ptr)
\r
17 using namespace std;
\r
20 class AbstractBlock {
\r
24 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 //AbstractBlock(const QString& _name);
\r
28 virtual ~AbstractBlock();
\r
31 inline QString getName() { return name; }
\r
32 inline int nbParameters() { return params.size(); }
\r
33 inline QList<BlockParameter *> getParameters() { return params; }
\r
34 inline QList<AbstractInterface*> getInputs() { return inputs; }
\r
35 inline QList<AbstractInterface*> getOutputs() { return outputs; }
\r
36 inline QList<AbstractInterface*> getBidirs() { return bidirs; }
\r
37 QList<BlockParameter *> getUserParameters();
\r
38 QList<BlockParameter *> getGenericParameters();
\r
39 QList<BlockParameter *> getPortParameters();
\r
40 QList<BlockParameter *> getWishboneParameters();
\r
41 inline AbstractBlock* getParent() { return parent; }
\r
42 inline bool getPatternComputed() { return patternComputed; }
\r
43 inline int getTraversalLevel() { return traversalLevel; }
\r
46 void setName(const QString& str);
\r
47 virtual void setParent(AbstractBlock* _parent);
\r
48 inline void setPatternComputed(bool state) { patternComputed = state; }
\r
49 inline void resetTraversalLevel() { traversalLevel = -1; }
\r
50 inline void setTraversalLevel(int level) { traversalLevel = level; }
\r
53 virtual bool isReferenceBlock();
\r
54 virtual bool isFunctionalBlock();
\r
55 virtual bool isGroupBlock();
\r
56 virtual bool isSourceBlock(); //! a source block is outside the top group and simulates a peripheral (NB: this is also a generator)
\r
57 virtual bool isTopGroupBlock();
\r
58 bool isGeneratorBlock(); //! a generator block has no data inputs and thus executes infinitely
\r
59 bool isWBConfigurable();
\r
64 * \brief connectClkReset connects the clock and reset inputs to a clkrstgen block or the the group ifaces
\r
65 * \param idBlockClk is the id of the clock interface (there may be severals)
\r
66 * \param idGen is the id of the clkrstgen block
\r
68 void connectClock(QString clkName, int idGen = 0) throw(Exception);
\r
69 void connectReset(QString rstName, int idGen = 0) throw(Exception);
\r
70 virtual QList<QString> getExternalResources() = 0; // returns the list of all external files needed for VHDL generation
\r
71 virtual void generateVHDL(const QString& path) throw(Exception) = 0; // main entry to generate the VHDL code
\r
72 void generateComponent(QTextStream& out, bool hasController=false) throw(Exception); // generate the component using reference
\r
73 void generateEntity(QTextStream& out, bool hasController=false) throw(Exception); // generate the entity using reference
\r
75 virtual void parametersValidation(QList<AbstractBlock*>* checkedBlocks, QList<AbstractBlock*>* blocksToConfigure) = 0; // ugly but usefull
\r
77 void addParameter(BlockParameter *param);
\r
78 void addInterface(AbstractInterface *inter);
\r
79 void removeInterface(AbstractInterface *inter);
\r
80 void removeAllInterfaces();
\r
81 void defineBlockParam(BlockParameter *param);
\r
83 QList<AbstractInterface *> getInterfaces(int direction = AbstractInterface::AnyDirection, int purpose = AbstractInterface::AnyPurpose);
\r
84 QList<AbstractInterface *> getDataInputs(); //! return all inputs of type data
\r
85 QList<AbstractInterface *> getDataOutputs(); //! return all inputs of type data
\r
86 QList<AbstractInterface *> getControlInputs(); //! return all inputs of type control
\r
87 QList<AbstractInterface *> getControlOutputs(); //! return all outputs of type control
\r
88 AbstractInterface* getIfaceFromName(QString name);
\r
89 BlockParameter* getParameterFromName(QString name);
\r
92 virtual void checkInputPatternCompatibility() throw(Exception) = 0;
\r
93 virtual void computeOutputPattern(int nbExec = -1) throw(Exception) = 0;
\r
94 virtual void computeAdmittanceDelays() throw(Exception) = 0;
\r
102 QList<BlockParameter *> params;
\r
105 QList<AbstractInterface*> inputs;
\r
106 QList<AbstractInterface*> outputs;
\r
107 QList<AbstractInterface*> bidirs;
\r
112 bool patternComputed;
\r
113 int traversalLevel; // the level (0, 1, ...) during the traversal of the graph
\r
115 // NB: only GroupBlock and FunctionalBlock have a real parent, except sources that have no parents
\r
116 AbstractBlock* parent;
\r
118 virtual void generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception) = 0; // generates comments from <comments> element
\r
119 virtual void generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception) = 0; // generates libraries from <libraries> element
\r
120 virtual void generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception) = 0; // generate the architecture using <architecture> element
\r
121 virtual void generateController(QTextStream& out) throw(Exception) = 0; // generate the wishbone controller of the block
\r
122 virtual void generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController=false) throw(Exception) = 0; // generate the entity/compo body using reference
\r
126 #endif // __ABSTRACTBLOCK_H__
\r