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
55 void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
\r
57 QString getReferenceXmlFile();
\r
58 QString getReferenceHashMd5();
\r
61 void createPatterns() throw(Exception); // called in Graph, before checking compatibility and computing output pattern
\r
62 void checkInputPatternCompatibility() throw(Exception);
\r
63 void computeOutputPattern(int nbExec = -1) throw(Exception);
\r
64 void computeAdmittanceDelays() throw(Exception); // compute differences between IP and admittance
\r
68 void createDelta() throw(Exception);
\r
69 void createConsumptionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
70 void createProductionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
\r
71 void createProductionCounter() throw(Exception); // initialize a QList<int> from counter defined in implementation
\r
72 void createAdmittance(int nbExec) throw(Exception); // initialize a QList<char> from consumption pattern and delta
\r
74 void clearConsumptionPattern();
\r
75 void clearProductionPattern();
\r
76 void createInputPattern() throw(Exception);
\r
77 void clearInputPattern();
\r
78 void clearOutputPattern();
\r
79 void clearAdmittanceDelays();
\r
80 int createTriggers(); // compute the clock cycle at which the block is triggered
\r
82 double evaluateExpression(const QString& expression) throw(Exception);
\r
83 QList<char>* expandPattern(const QString& patternIn) throw(Exception);
\r
84 QList<char> expandPatternRecur(const QString& patternIn, int* offset) throw(Exception);
\r
85 QString replaceExpressions(const QString& patternIn) throw(Exception);
\r
87 * \brief samePatterns
\r
88 * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest)
\r
89 * \param srcCol the column index within patternSrc
\r
90 * \param patternDest the pattern that must be tested with patternSrc
\r
91 * \param destCol the column index within patternDest
\r
92 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
93 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
95 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
96 bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int>& srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
\r
98 * \brief canCombinePatterns
\r
99 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
100 * \param srcCol the column index within patternSrc
\r
101 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
102 * \param destCol the column index within patternDest
\r
103 * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
\r
104 * NB: if src/destCol are outside the range of the list, false is returned.
\r
106 bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
108 * \brief combinePatterns
\r
109 * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)
\r
110 * \param srcCol the column index within patternSrc
\r
111 * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
\r
112 * \param destCol the column index within patternDest
\r
113 * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
\r
114 leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
\r
116 void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
\r
118 * \brief appendToPattern
\r
119 * \param patternSrc the pattern that must be appended to patternDest
\r
120 * \param srcCol the column index within patternSrc
\r
121 * \param patternDest the pattern that is modified by the append
\r
122 * \param nbCols the numer of columns to append
\r
123 * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
\r
124 * that will be appended
\r
126 void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
\r
128 * \brief removeDataGroup
\r
129 * \param pattern the pattern for which a column is removed
\r
130 * \param offset the index of the column to remove
\r
132 void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
134 * \brief isValidGroup
\r
135 * \param pattern the pattern to test
\r
136 * \param offset the column to test
\r
137 * isValidGroup checks if there is at least one 1 in the column offset of pattern.
\r
139 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
140 bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets);
\r
142 * \brief isOnlyXGroup
\r
143 * \param pattern the pattern to test
\r
144 * \param offset the column to test
\r
145 * isOnlyXGroup checks if there is only X in the column offset of pattern.
\r
147 bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
149 * \brief shifRightPattern
\r
150 * \param pattern the pattern to shift
\r
151 * \param offset the column where to shift
\r
152 * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
\r
153 * this method is used during admittance generation
\r
155 void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
\r
157 void generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception); // generates comments from <comments> element
\r
158 void generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception); // generates libraries from <libraries> element
\r
159 void generateEntity(QTextStream& out, bool hasController=false) throw(Exception); // generate the entity using reference
\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
163 QMap<AbstractInterface*, QList<char>* > consumptionPattern;
\r
164 QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-epilogue, deduced from admittance
\r
165 QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
\r
166 QMap<AbstractInterface*, QList<int>* > admittanceDelays; // the delay between what should be consumed and IP
\r
167 QMap<AbstractInterface*, QList<char>* > productionPattern;
\r
168 QMap<AbstractInterface*,QList<char>* > inputPattern;
\r
169 QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
\r
170 QList<int> productionCounter; // only usefull for control output interfaces
\r
171 QList<int> triggers; // the clock cycles at which the block is triggered, taking into account IP
\r
172 int lengthIP; // for convenience, set in createInputPattern()
\r
173 int lengthCP; // for convenience, set in createConsumptionPattern()
\r
174 int lengthAP; // for convenience, set in createAdmittance()
\r
175 int lengthPP; // for convenience, set in createProductionPattern()
\r
176 int lengthOP; // for convenience, set in computeOutputPattern()
\r
179 ArithmeticEvaluator* evaluator;
\r
181 ReferenceBlock* reference;
\r
182 BlockImplementation* implementation;
\r
186 #endif // __FUNCTIONALBLOCK_H__
\r