]> AND Private Git Repository - blast.git/blobdiff - ReferenceBlock.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
source connection ok
[blast.git] / ReferenceBlock.cpp
index 8b50bfa4d0d6d466402614e53154304dab18893b..05fd29a785e921fbf1f42fa1ae6869ca1249ef99 100644 (file)
@@ -68,6 +68,14 @@ void ReferenceBlock::load(QDomElement &elt) throw(Exception) {
   try {
     loadInterfaces(eltInter);
   }
   try {
     loadInterfaces(eltInter);
   }
+  catch(int err) {
+    throw(err);
+  }
+
+  // create interfaces that correspond to a wishbone parameter, if any.
+  try {
+    createInterfaceForParameters();    
+  }
   catch(int err) {
     throw(err);
   }  
   catch(int err) {
     throw(err);
   }  
@@ -161,11 +169,16 @@ void ReferenceBlock::loadParameters(QDomElement &elt) throw(Exception) {
       int duration = 0;
       QString wbValue = "";
       QStringList listWb = wbStr.split(",");
       int duration = 0;
       QString wbValue = "";
       QStringList listWb = wbStr.split(",");
+      cout << "wb param has:";
+      foreach(QString s, listWb) {
+        cout << qPrintable(s) << " | ";
+      }
+      cout << endl;
 
       if (listWb.at(0) == "r") {
         access = BlockParameter::Read;
       }
 
       if (listWb.at(0) == "r") {
         access = BlockParameter::Read;
       }
-      else if (wbStr == "w") {
+      else if (listWb.at(0) == "w") {
         access = BlockParameter::Write;
         bool ok;
         wbValue = listWb.at(1).toInt(&ok);
         access = BlockParameter::Write;
         bool ok;
         wbValue = listWb.at(1).toInt(&ok);
@@ -204,8 +217,6 @@ void ReferenceBlock::loadInterfaces(QDomElement &elt) throw(Exception) {
   QString widthStr;
   QString purposeStr;
   int purpose;
   QString widthStr;
   QString purposeStr;
   int purpose;
-  QString levelStr;
-  int level;
   QString multStr;
   int mult;
   AbstractInterface* inter;
   QString multStr;
   int mult;
   AbstractInterface* inter;
@@ -213,6 +224,7 @@ void ReferenceBlock::loadInterfaces(QDomElement &elt) throw(Exception) {
   if ((elt.isNull()) || (elt.tagName() != "interfaces")) throw (Exception(BLOCKFILE_CORRUPTED));
 
   QDomElement eltInputs = elt.firstChildElement("inputs");
   if ((elt.isNull()) || (elt.tagName() != "interfaces")) throw (Exception(BLOCKFILE_CORRUPTED));
 
   QDomElement eltInputs = elt.firstChildElement("inputs");
+  // getting each input
   QDomNodeList listNodeInputs = eltInputs.elementsByTagName("input");
   for(int i=0;i<listNodeInputs.size();i++) {
     QDomNode node = listNodeInputs.at(i);
   QDomNodeList listNodeInputs = eltInputs.elementsByTagName("input");
   for(int i=0;i<listNodeInputs.size();i++) {
     QDomNode node = listNodeInputs.at(i);
@@ -225,15 +237,28 @@ void ReferenceBlock::loadInterfaces(QDomElement &elt) throw(Exception) {
     cout << "purpose for " << nameStr.toStdString() << " : " << purposeStr.toStdString() << endl;
     purpose = ReferenceInterface::translatePurpose(purposeStr);
     cout << "translated purpose : " << purpose << endl;
     cout << "purpose for " << nameStr.toStdString() << " : " << purposeStr.toStdString() << endl;
     purpose = ReferenceInterface::translatePurpose(purposeStr);
     cout << "translated purpose : " << purpose << endl;
-    levelStr = eltInput.attribute("level","none");
-    level = ReferenceInterface::translateLevel(levelStr);
     multStr = eltInput.attribute("multiplicity","none");
     mult = ReferenceInterface::translateMultiplicity(multStr);
 
     multStr = eltInput.attribute("multiplicity","none");
     mult = ReferenceInterface::translateMultiplicity(multStr);
 
-    inter = new ReferenceInterface(this,nameStr,typeStr,widthStr,AbstractInterface::Input, purpose, level, mult);
+    inter = new ReferenceInterface(this,nameStr,typeStr,widthStr,AbstractInterface::Input, purpose, mult);
+    inputs.append(inter);
+  }
+  // getting each control
+  QDomNodeList listNodeInCtl = eltInputs.elementsByTagName("control");
+  for(int i=0;i<listNodeInCtl.size();i++) {
+    QDomNode node = listNodeInCtl.at(i);
+    QDomElement eltInput = node.toElement();
+    nameStr = eltInput.attribute("iface","none");
+    AbstractInterface* dataIface = getIfaceFromName(nameStr);
+    if (dataIface == NULL) throw (Exception(BLOCKFILE_CORRUPTED));
+    nameStr = dataIface->getName()+"_ctl";
+    inter = new ReferenceInterface(this,nameStr,"boolean","1",AbstractInterface::Input, AbstractInterface::Control, 1);
+    if (!inter->setAssociatedIface(dataIface)) {
+      throw (Exception(BLOCKFILE_CORRUPTED));      
+    }
+    cout << "created a control input named " << qPrintable(inter->getName()) << endl;
     inputs.append(inter);
   }
     inputs.append(inter);
   }
-
   QDomElement eltOutputs = eltInputs.nextSiblingElement("outputs");
   QDomNodeList listNodeOutputs = eltOutputs.elementsByTagName("output");
   for(int i=0;i<listNodeOutputs.size();i++) {
   QDomElement eltOutputs = eltInputs.nextSiblingElement("outputs");
   QDomNodeList listNodeOutputs = eltOutputs.elementsByTagName("output");
   for(int i=0;i<listNodeOutputs.size();i++) {
@@ -242,14 +267,28 @@ void ReferenceBlock::loadInterfaces(QDomElement &elt) throw(Exception) {
     nameStr = eltOutput.attribute("name","none");
     typeStr = eltOutput.attribute("type","none");
     widthStr = eltOutput.attribute("width","none");
     nameStr = eltOutput.attribute("name","none");
     typeStr = eltOutput.attribute("type","none");
     widthStr = eltOutput.attribute("width","none");
-    purposeStr = eltOutput.attribute("type","none");
+    purposeStr = eltOutput.attribute("purpose","none");
     purpose = ReferenceInterface::translatePurpose(purposeStr);
     purpose = ReferenceInterface::translatePurpose(purposeStr);
-    levelStr = eltOutput.attribute("level","none");
-    level = ReferenceInterface::translateLevel(levelStr);
     multStr = eltOutput.attribute("multiplicity","none");
     mult = ReferenceInterface::translateMultiplicity(multStr);
 
     multStr = eltOutput.attribute("multiplicity","none");
     mult = ReferenceInterface::translateMultiplicity(multStr);
 
-    inter = new ReferenceInterface(this,nameStr,typeStr,widthStr,AbstractInterface::Output, purpose, level, mult);
+    inter = new ReferenceInterface(this,nameStr,typeStr,widthStr,AbstractInterface::Output, purpose, mult);
+    outputs.append(inter);
+  }
+  // getting each control
+  QDomNodeList listNodeOutCtl = eltOutputs.elementsByTagName("control");
+  for(int i=0;i<listNodeOutCtl.size();i++) {
+    QDomNode node = listNodeOutCtl.at(i);
+    QDomElement eltOutput = node.toElement();
+    nameStr = eltOutput.attribute("iface","none");
+    AbstractInterface* dataIface = getIfaceFromName(nameStr);
+    if (dataIface == NULL) throw (Exception(BLOCKFILE_CORRUPTED));
+    nameStr = dataIface->getName()+"_ctl";
+    inter = new ReferenceInterface(this,nameStr,"boolean","1",AbstractInterface::Output, AbstractInterface::Control, 1);
+    if (!inter->setAssociatedIface(dataIface)) {
+      throw (Exception(BLOCKFILE_CORRUPTED));      
+    }
+    cout << "created a control output named " << qPrintable(inter->getName()) << endl;
     outputs.append(inter);
   }
 
     outputs.append(inter);
   }
 
@@ -261,20 +300,41 @@ void ReferenceBlock::loadInterfaces(QDomElement &elt) throw(Exception) {
     nameStr = eltBidir.attribute("name","none");
     typeStr = eltBidir.attribute("type","none");
     widthStr = eltBidir.attribute("width","none");
     nameStr = eltBidir.attribute("name","none");
     typeStr = eltBidir.attribute("type","none");
     widthStr = eltBidir.attribute("width","none");
-    purposeStr = eltBidir.attribute("type","none");
+    purposeStr = eltBidir.attribute("purpose","none");
     purpose = ReferenceInterface::translatePurpose(purposeStr);
     purpose = ReferenceInterface::translatePurpose(purposeStr);
-    levelStr = eltBidir.attribute("level","none");
-    level = ReferenceInterface::translateLevel(levelStr);
     multStr = eltBidir.attribute("multiplicity","none");
     mult = ReferenceInterface::translateMultiplicity(multStr);
 
     multStr = eltBidir.attribute("multiplicity","none");
     mult = ReferenceInterface::translateMultiplicity(multStr);
 
-    inter = new ReferenceInterface(this,nameStr,typeStr,widthStr,AbstractInterface::InOut, purpose, level, mult);
+    inter = new ReferenceInterface(this,nameStr,typeStr,widthStr,AbstractInterface::InOut, purpose, mult);
     bidirs.append(inter);
   }
 }
 
     bidirs.append(inter);
   }
 }
 
-void ReferenceBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure)
-{
+void ReferenceBlock::createInterfaceForParameters() throw(Exception){
+  ReferenceInterface* iface = NULL;
+  foreach(BlockParameter* param, params) {
+    
+    if (param->isWishboneParameter()) {
+      
+      BlockParameterWishbone* p = (BlockParameterWishbone*)param;      
+      cout << "creating interface for parameter wb " << qPrintable(p->getName()) << endl;
+      
+      if (p->getWBAccess() == BlockParameter::Read) {
+        iface = new ReferenceInterface(this,p->getName(),p->getTypeString(),p->getWidth(), AbstractInterface::Output, AbstractInterface::Wishbone,1);
+        outputs.append(iface);        
+      }
+      else if (p->getWBAccess() == BlockParameter::Write) {
+        iface = new ReferenceInterface(this,p->getName(),p->getTypeString(),p->getWidth(), AbstractInterface::Input, AbstractInterface::Wishbone,1);
+        inputs.append(iface);                
+      }
+      else {
+        throw (Exception(BLOCKFILE_CORRUPTED));
+      }
+    }
+  }
+}
+
+void ReferenceBlock::parametersValidation(QList<AbstractBlock *> *checkedBlocks, QList<AbstractBlock *> *blocksToConfigure) {
     return;
 }
 
     return;
 }
 
@@ -318,24 +378,50 @@ QDataStream& operator<<(QDataStream &out, const ReferenceBlock &b) {
   }
 
   toWrite << b.inputs.size();
   }
 
   toWrite << b.inputs.size();
+  // firstly write control ifaces
   for(int i=0; i<b.inputs.size(); i++){
     ReferenceInterface *iface = (ReferenceInterface *)(b.inputs.at(i));
   for(int i=0; i<b.inputs.size(); i++){
     ReferenceInterface *iface = (ReferenceInterface *)(b.inputs.at(i));
-    toWrite << iface->getName();
-    toWrite << iface->getWidth();
-    toWrite << iface->getPurpose();
-    toWrite << iface->getDirection();
-    toWrite << iface->getLevel();
-    toWrite << iface->getMultiplicity();
+    if (iface->getPurpose() == AbstractInterface::Control) {
+      toWrite << iface->getName();
+      toWrite << iface->getWidth();
+      toWrite << iface->getPurpose();
+      toWrite << iface->getDirection();    
+      toWrite << iface->getMultiplicity();
+    }
+  }
+  // secondly, write other ifaces
+  for(int i=0; i<b.inputs.size(); i++){
+    ReferenceInterface *iface = (ReferenceInterface *)(b.inputs.at(i));
+    if (iface->getPurpose() != AbstractInterface::Control) {
+      toWrite << iface->getName();
+      toWrite << iface->getWidth();
+      toWrite << iface->getPurpose();
+      toWrite << iface->getDirection();    
+      toWrite << iface->getMultiplicity();
+    }
   }
   toWrite << b.outputs.size();
   }
   toWrite << b.outputs.size();
+  // firstly write control ifaces
   for(int i=0; i<b.outputs.size(); i++){
     ReferenceInterface *iface = (ReferenceInterface *)(b.outputs.at(i));
   for(int i=0; i<b.outputs.size(); i++){
     ReferenceInterface *iface = (ReferenceInterface *)(b.outputs.at(i));
-    toWrite << iface->getName();
-    toWrite << iface->getWidth();
-    toWrite << iface->getPurpose();
-    toWrite << iface->getDirection();
-    toWrite << iface->getLevel();
-    toWrite << iface->getMultiplicity();
+    if (iface->getPurpose() == AbstractInterface::Control) {
+      toWrite << iface->getName();
+      toWrite << iface->getWidth();
+      toWrite << iface->getPurpose();
+      toWrite << iface->getDirection();    
+      toWrite << iface->getMultiplicity();
+    }
+  }
+  // secondly, write other ifaces
+  for(int i=0; i<b.outputs.size(); i++){
+    ReferenceInterface *iface = (ReferenceInterface *)(b.outputs.at(i));
+    if (iface->getPurpose() != AbstractInterface::Control) {
+      toWrite << iface->getName();
+      toWrite << iface->getWidth();
+      toWrite << iface->getPurpose();
+      toWrite << iface->getDirection();    
+      toWrite << iface->getMultiplicity();
+    }
   }
   toWrite << b.bidirs.size();
   for(int i=0; i<b.bidirs.size(); i++){
   }
   toWrite << b.bidirs.size();
   for(int i=0; i<b.bidirs.size(); i++){
@@ -343,8 +429,7 @@ QDataStream& operator<<(QDataStream &out, const ReferenceBlock &b) {
     toWrite << iface->getName();
     toWrite << iface->getWidth();
     toWrite << iface->getPurpose();
     toWrite << iface->getName();
     toWrite << iface->getWidth();
     toWrite << iface->getPurpose();
-    toWrite << iface->getDirection();
-    toWrite << iface->getLevel();
+    toWrite << iface->getDirection();    
     toWrite << iface->getMultiplicity();
   }
 
     toWrite << iface->getMultiplicity();
   }
 
@@ -419,14 +504,21 @@ QDataStream& operator>>(QDataStream &in, ReferenceBlock &b) {
     in >> txt;
     iface->setWidth(txt);
     in >> val;
     in >> txt;
     iface->setWidth(txt);
     in >> val;
-    iface->setPurpose(val);
-    in >> val;
-    iface->setDirection(val);
+    iface->setPurpose(val);    
     in >> val;
     in >> val;
-    iface->setLevel(val);
+    iface->setDirection(val);    
     in >> val;
     iface->setMultiplicity(val);
     b.inputs.append(iface);
     in >> val;
     iface->setMultiplicity(val);
     b.inputs.append(iface);
+    if (iface->getPurpose() == AbstractInterface::Data) {
+      QString ctlRefName = iface->getName()+"_ctl";
+      ReferenceInterface* ctlRefIface = AI_TO_REF(b.getIfaceFromName(ctlRefName));      
+      if (ctlRefIface != NULL) {        
+        if (! ctlRefIface->setAssociatedIface(iface)) {
+          cerr << "Abnormal case while reading a reference block in library" << endl;
+        }      
+      }        
+    }    
   }
 
   b.outputs.clear();
   }
 
   b.outputs.clear();
@@ -438,14 +530,21 @@ QDataStream& operator>>(QDataStream &in, ReferenceBlock &b) {
     in >> txt;
     iface->setWidth(txt);
     in >> val;
     in >> txt;
     iface->setWidth(txt);
     in >> val;
-    iface->setPurpose(val);
+    iface->setPurpose(val);    
     in >> val;
     iface->setDirection(val);
     in >> val;
     iface->setDirection(val);
-    in >> val;
-    iface->setLevel(val);
-    in >> val;
+    in >> val;   
     iface->setMultiplicity(val);
     b.outputs.append(iface);
     iface->setMultiplicity(val);
     b.outputs.append(iface);
+    if (iface->getPurpose() == AbstractInterface::Data) {
+      QString ctlRefName = iface->getName()+"_ctl";      
+      ReferenceInterface* ctlRefIface = AI_TO_REF(b.getIfaceFromName(ctlRefName));      
+      if (ctlRefIface != NULL) {        
+        if (! ctlRefIface->setAssociatedIface(iface)) {
+          cerr << "Abnormal case while reading a reference block in library" << endl;
+        }      
+      }        
+    }    
   }
 
   b.bidirs.clear();
   }
 
   b.bidirs.clear();
@@ -460,9 +559,7 @@ QDataStream& operator>>(QDataStream &in, ReferenceBlock &b) {
     iface->setPurpose(val);
     in >> val;
     iface->setDirection(val);
     iface->setPurpose(val);
     in >> val;
     iface->setDirection(val);
-    in >> val;
-    iface->setLevel(val);
-    in >> val;
+    in >> val;    
     iface->setMultiplicity(val);
     b.bidirs.append(iface);
   }
     iface->setMultiplicity(val);
     b.bidirs.append(iface);
   }