X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/624231601a0f5daea9b8809993ad3503beafce4f..9bfa0c13066918f440ac2b5461fb3f8847f43fd6:/FunctionalBlock.h

diff --git a/FunctionalBlock.h b/FunctionalBlock.h
index c122dcf..d3bd581 100644
--- a/FunctionalBlock.h
+++ b/FunctionalBlock.h
@@ -11,6 +11,9 @@ class ReferenceBlock;
 class GroupBlock;
 #include "Exception.h"
 class Exception;
+class BlockImplementation;
+class ArithmeticEvaluator;
+    
 
 
 using namespace std;
@@ -24,26 +27,159 @@ class FunctionalBlock : public AbstractBlock {
 public:
 
   FunctionalBlock(GroupBlock* _parent, ReferenceBlock* _reference) throw(Exception);
-
+  ~FunctionalBlock();
   // getters
   inline ReferenceBlock* getReference() { return reference; }
-
+  inline QList<int> getProductionCounter() { return productionCounter; }
+  inline QMap<AbstractInterface*, QList<char>* > getConsumptionPattern() { return consumptionPattern; }
+  inline QMap<AbstractInterface*, QList<char>* > getProductionPattern() { return productionPattern; }
+  inline QMap<AbstractInterface*, QList<int>* > getAdmittanceDelays() { return admittanceDelays; }
+  inline int getConsumptionPatternLength() { return lengthCP; }
+  inline int getProductionPatternLength() { return lengthPP; }
+  inline int getDelta() { return delta; }
+  
   // setters
+  inline void setImplementation(BlockImplementation* impl) { implementation = impl; }
+  inline void setProductionCounter(QList<int> pattern) { productionCounter = pattern; }
+  inline void setDelta(int _delta) { delta = _delta; }
+  
 
   // testers
   bool isFunctionalBlock();
-  bool isSourceBlock(); //! a source block has no parent
+  bool isSourceBlock(); //! a source block has no parent and has no data inputs
 
   // others
 
   void populate(); // create parameters and interface from reference block
+  void generateVHDL(const QString& path) throw(Exception); // main entry to generate the VHDL code
   void parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock*>* blocksToConfigure);
 
   QString getReferenceXmlFile();
   QString getReferenceHashMd5();
+  
+  // patterns
+  void createPatterns() throw(Exception); // called in Graph, before checking compatibility and computing output pattern
+  void checkInputPatternCompatibility() throw(Exception);
+  void computeOutputPattern(int nbExec = -1) throw(Exception);
+  void computeAdmittanceDelays() throw(Exception); // compute differences between IP and admittance
 
 private:  
+  // patterns
+  void createDelta() throw(Exception);
+  void createConsumptionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
+  void createProductionPattern() throw(Exception); // initialize a QList<char> for each interface from patterns defined in implementation
+  void createProductionCounter() throw(Exception); // initialize a QList<int> from counter defined in implementation
+  void createAdmittance(int nbExec) throw(Exception); // initialize a QList<char> from consumption pattern and delta
+
+  void clearConsumptionPattern();
+  void clearProductionPattern();
+  void createInputPattern() throw(Exception);
+  void clearInputPattern();
+  void clearOutputPattern();
+  void clearAdmittanceDelays();
+  int createTriggers(); // compute the clock cycle at which the block is triggered
+  
+  double evaluateExpression(const QString& expression) throw(Exception);
+  QList<char>* expandPattern(const QString& patternIn) throw(Exception);
+  QList<char> expandPatternRecur(const QString& patternIn, int* offset)  throw(Exception);
+  QString replaceExpressions(const QString& patternIn) throw(Exception);
+  /*!
+   * \brief samePatterns
+   * \param patternSrc the pattern that must be tested with patternDest (is patternDest == patternDest)  
+   * \param srcCol the column index within patternSrc
+   * \param patternDest the pattern that must be tested with patternSrc
+   * \param destCol the column index within patternDest      
+   * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
+   leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
+   */
+  bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
+  bool samePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, const QList<int>& srcCols, const QMap<AbstractInterface*, QList<char>* >& patternDest, int destCol);
+  /*!
+   * \brief canCombinePatterns
+   * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)  
+   * \param srcCol the column index within patternSrc
+   * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
+   * \param destCol the column index within patternDest  
+   * \return true if the combination is possible, and false else (e.g. when X1 must be combined with 11)
+   * NB: if src/destCol are outside the range of the list, false is returned.   
+   */
+  bool canCombinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
+  /*!
+   * \brief combinePatterns
+   * \param patternSrc the pattern that must be combined with patternDest (patternDest = patternDest OR patternSrc)  
+   * \param srcCol the column index within patternSrc
+   * \param patternDest the pattern that is modified by the combination (patternDest = patternDest OR patternSrc)
+   * \param destCol the column index within patternDest      
+   * BEWARE: this method returns as soons as there is an acces problem (i.e. out of list range, impossible combine, ...)
+   leaving the dest pattern in an inconsistent state. Thus, it is a good idea to call canCombine before.
+   */
+  void combinePatterns(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int destCol);
+  /*!
+   * \brief appendToPattern
+   * \param patternSrc the pattern that must be appended to patternDest
+   * \param srcCol the column index within patternSrc
+   * \param patternDest the pattern that is modified by the append   
+   * \param nbCols the numer of columns to append   
+   * BEWARE: if nbCols is not consistent with the real length of src pattern, there may be less that nbCols
+   * that will be appended
+   */
+  void appendToPattern(const QMap<AbstractInterface*, QList<char>* >& patternSrc, int srcCol, QMap<AbstractInterface*, QList<char>* > patternDest, int nbCols);
+  /*!
+  * \brief removeDataGroup
+  * \param pattern the pattern for which a column is removed
+  * \param offset the index of the column to remove 
+  */
+  void removeDataGroup(QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
+  /*!
+  * \brief isValidGroup
+  * \param pattern the pattern to test
+  * \param offset the column to test
+  * isValidGroup checks if there is at least one 1 in the column offset of pattern.
+  */
+  bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
+  bool isValidDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, const QList<int> offsets);
+  /*!
+  * \brief isOnlyXGroup
+  * \param pattern the pattern to test
+  * \param offset the column to test
+  * isOnlyXGroup checks if there is only X in the column offset of pattern.
+  */
+  bool isOnlyXDataGroup(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
+  /*!
+  * \brief shifRightPattern
+  * \param pattern the pattern to shift
+  * \param offset the column where to shift
+  * shiftRightPattern insert a null colmun in pattern, which leads to shift right the pattern at offset.
+  * this method is used during admittance generation
+  */
+  void shiftRightPattern(const QMap<AbstractInterface*, QList<char>* >& pattern, int offset);
+
+  void generateComments(QTextStream& out, QDomElement &elt, QString coreFile) throw(Exception); // generates comments from <comments> element
+  void generateLibraries(QTextStream& out, QDomElement &elt) throw(Exception); // generates libraries from <libraries> element
+  void generateEntity(QTextStream& out, bool hasController=false) throw(Exception); // generate the entity using reference
+  void generateArchitecture(QTextStream& out, QDomElement &elt ) throw(Exception); // generate the architecture using <architecture> element
+  void generateController(QTextStream& out) throw(Exception); // generate the wishbone controller of the block
+
+  QMap<AbstractInterface*, QList<char>* > consumptionPattern;
+  QMap<AbstractInterface*, QString > admittanceCyclic; // the admittance expressed as prologue-cyclic part-epilogue, deduced from admittance
+  QMap<AbstractInterface*, QList<char>* > admittance; // the admittance taking into account nb exec.
+  QMap<AbstractInterface*, QList<int>* > admittanceDelays; // the delay between what should be consumed and IP
+  QMap<AbstractInterface*, QList<char>* > productionPattern;
+  QMap<AbstractInterface*,QList<char>* > inputPattern;
+  QMap<AbstractInterface*, QList<char>* > outputPattern; // CAUTION: the QList<char>* must also be stored in the outputPattern attributes of AbstractInterface
+  QList<int> productionCounter; // only usefull for control output interfaces
+  QList<int> triggers; // the clock cycles at which the block is triggered, taking into account IP
+  int lengthIP; // for convenience, set in createInputPattern()
+  int lengthCP; // for convenience, set in createConsumptionPattern()
+  int lengthAP; // for convenience, set in createAdmittance()
+  int lengthPP;  // for convenience, set in createProductionPattern()
+  int lengthOP;  // for convenience, set in computeOutputPattern()
+  int delta;
+    
+  ArithmeticEvaluator* evaluator;
+  
   ReferenceBlock* reference;
+  BlockImplementation* implementation;
 
 };