1 #ifndef __FUNCTIONALBLOCK_H__
\r
2 #define __FUNCTIONALBLOCK_H__
\r
8 #include "AbstractBlock.h"
\r
10 class ReferenceBlock;
\r
12 #include "Exception.h"
\r
14 class BlockImplementation;
\r
15 class ArithmeticEvaluator;
\r
19 using namespace std;
\r
23 - NEVER forget to call populate() after creating an instance of GraphBlock.
\r
26 class FunctionalBlock : public AbstractBlock {
\r
29 FunctionalBlock(GroupBlock* _parent, ReferenceBlock* _reference) throw(Exception);
\r
32 inline ReferenceBlock* getReference() { return reference; }
\r
33 inline QList<int> getProductionCounter() { return productionCounter; }
\r
34 inline QMap<AbstractInterface*, QList<char>* > getConsumptionPattern() { return consumptionPattern; }
\r
35 inline QMap<AbstractInterface*, QList<char>* > getProductionPattern() { return productionPattern; }
\r
36 inline QMap<AbstractInterface*, QList<int>* > getAdmittanceDelays() { return admittanceDelays; }
\r
37 inline int getConsumptionPatternLength() { return lengthCP; }
\r
38 inline int getProductionPatternLength() { return lengthPP; }
\r
39 inline int getDelta() { return delta; }
\r
42 inline void setImplementation(BlockImplementation* impl) { implementation = impl; }
\r
43 inline void setProductionCounter(QList<int> pattern) { productionCounter = pattern; }
\r
44 inline void setDelta(int _delta) { delta = _delta; }
\r
48 bool isFunctionalBlock();
\r
49 bool isSourceBlock(); //! a source block has no parent and has no data inputs
\r
53 void populate(); // create parameters and interface from reference block
\r
54 void generateVHDL(const QString& path) throw(Exception); // main entry to generate the VHDL code
\r
56 void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
\r
58 QString getReferenceXmlFile();
\r
59 QString getReferenceHashMd5();
\r
62 void createPatterns() throw(Exception); // called in Graph, before checking compatibility and computing output pattern
\r
63 void checkInputPatternCompatibility() throw(Exception);
\r
64 void computeOutputPattern(int nbExec = -1) throw(Exception);
\r
65 void computeAdmittanceDelays() throw(Exception); // compute differences between IP and admittance
\r
69 void createDelta() throw(Exception);
\r
70 void createConsumptionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
71 void createProductionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
72 void createProductionCounter() throw(Exception); // initialize a QList<int> from counter defined in implementation
\r
73 void createAdmittance(int nbExec) throw(Exception); // initialize a QList<char> from consumption pattern and delta
\r
75 void clearConsumptionPattern();
\r
76 void clearProductionPattern();
\r
77 void createInputPattern() throw(Exception);
\r
78 void clearInputPattern();
\r
79 void clearOutputPattern();
\r
80 void clearAdmittanceDelays();
\r
81 int createTriggers(); // compute the clock cycle at which the block is triggered
\r
83 double evaluateExpression(const QString& expression) throw(Exception);
\r
84 QList<char>* expandPattern(const QString& patternIn) throw(Exception);
\r
85 QList<char> expandPatternRecur(const QString& patternIn, int* offset) throw(Exception);
\r
86 QString replaceExpressions(const QString& patternIn) throw(Exception);
\r
88 * \brief samePatterns
\r
89 * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest)
\r
90 * \param srcCol the column index within patternSrc
\r
91 * \param patternDest the pattern that must be tested with patternSrc
\r
92 * \param destCol the column index within patternDest
\r
93 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
94 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
96 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
97 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int>& srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
99 * \brief canCombinePatterns
\r
100 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
101 * \param srcCol the column index within patternSrc
\r
102 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
103 * \param destCol the column index within patternDest
\r
104 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
105 * NB: if src/destCol are outside the range of the list, false is returned.
\r
107 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
109 * \brief combinePatterns
\r
110 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
111 * \param srcCol the column index within patternSrc
\r
112 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
113 * \param destCol the column index within patternDest
\r
114 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
115 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
117 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
119 * \brief appendToPattern
\r
120 * \param patternSrc the pattern that must be appended to patternDest
\r
121 * \param srcCol the column index within patternSrc
\r
122 * \param patternDest the pattern that is modified by the append
\r
123 * \param nbCols the numer of columns to append
\r
124 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
125 * that will be appended
\r
127 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
129 * \brief removeDataGroup
\r
130 * \param pattern the pattern for which a column is removed
\r
131 * \param offset the index of the column to remove
\r
133 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
135 * \brief isValidGroup
\r
136 * \param pattern the pattern to test
\r
137 * \param offset the column to test
\r
138 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
140 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
141 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets);
\r
143 * \brief isOnlyXGroup
\r
144 * \param pattern the pattern to test
\r
145 * \param offset the column to test
\r
146 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
148 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
150 * \brief shifRightPattern
\r
151 * \param pattern the pattern to shift
\r
152 * \param offset the column where to shift
\r
153 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
154 * this method is used during admittance generation
\r
156 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
158 void generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception); // generates comments from <comments> element
\r
159 void generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception); // generates libraries from <libraries> element
\r
160 void generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception); // generate the architecture using <architecture> element
\r
161 void generateController(QTextStream& out) throw(Exception); // generate the wishbone controller of the block
\r
162 void generateEntityOrComponentBody(QTextStream& out, int indentLevel, bool hasController=false) throw(Exception); // generate the entity/compo body using reference
\r
164 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
165 QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-epilogue, deduced from admittance
\r
166 QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
\r
167 QMap<AbstractInterface*, QList<int>* > admittanceDelays; // the delay between what should be consumed and IP
\r
168 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
169 QMap<AbstractInterface*,QList<char>* > inputPattern;
\r
170 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
171 QList<int> productionCounter; // only usefull for control output interfaces
\r
172 QList<int> triggers; // the clock cycles at which the block is triggered, taking into account IP
\r
173 int lengthIP; // for convenience, set in createInputPattern()
\r
174 int lengthCP; // for convenience, set in createConsumptionPattern()
\r
175 int lengthAP; // for convenience, set in createAdmittance()
\r
176 int lengthPP; // for convenience, set in createProductionPattern()
\r
177 int lengthOP; // for convenience, set in computeOutputPattern()
\r
180 ArithmeticEvaluator* evaluator;
\r
182 ReferenceBlock* reference;
\r
183 BlockImplementation* implementation;
\r
187 #endif // __FUNCTIONALBLOCK_H__
\r