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

Private GIT Repository
finished testbench generation
[blast.git] / AbstractInterface.cpp
index 6c51907dc047bd9e89702cac62d696821ca8386c..83aa4c399e46373c5703ec518513bcb63b7d0bca 100644 (file)
@@ -2,10 +2,11 @@
 #include "BlockParameterPort.h"
 #include "AbstractBlock.h"
 #include "Parameters.h"
+#include "Graph.h"
 
 AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
 
-  owner = _owner;
+  owner = _owner;  
   name = "";
   width = "1";
   direction = Input;
@@ -13,6 +14,8 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
   type = Boolean;
   endianess = LittleEndian;
   associatedIface = NULL;
+  clkIfaceName = "";
+  clkIfaceType = NoName;
 
 }
 
@@ -26,6 +29,8 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name
   type = typeFromString(_type);
   endianess = _endianess;
   associatedIface = NULL;
+  clkIfaceName = "";
+  clkIfaceType = NoName;
 }
 
 AbstractInterface::AbstractInterface(AbstractInterface* other) {
@@ -37,6 +42,8 @@ AbstractInterface::AbstractInterface(AbstractInterface* other) {
   purpose = other->purpose;
   endianess = LittleEndian;
   associatedIface = NULL;
+  clkIfaceName = other->clkIfaceName;
+  clkIfaceType = other->clkIfaceType;
 }
 
 void AbstractInterface::setName(const QString& _name) {
@@ -186,36 +193,6 @@ QString AbstractInterface::getDirectionString() {
     return str;
 }
 
-double AbstractInterface::getDoubleWidth() throw(QException) {
-
-  static QString fctName = "AbstractInterface::getDoubleWidth()";
- #ifdef DEBUG_FCTNAME
-   cout << "call to " << qPrintable(fctName) << endl;
- #endif
-
-   /*
-    cout << "start AbstractInterface::getDoubleWidth()" << endl;
-    bool ok;
-    double width = getWidth().toDouble(&ok);
-
-    if(!ok){
-      ArithmeticEvaluator *evaluator = new ArithmeticEvaluator;
-      cout << "evaluator created!" << endl;
-      evaluator->setExpression(getWidth());
-      cout << "expression defined!" << endl;
-      foreach(BlockParameter *param, getOwner()->getParameters()){
-        evaluator->setVariableValue(param->getName(), param->getIntValue());
-        cout << "param : " << param->getName().toStdString() << " evaluated!" << endl;
-      }
-      width = evaluator->evaluate();
-      cout << "expression evaluated succefully!" << endl;
-    }
-    cout << "real width : " << width << endl;
-    return width;
-    */
-
-   return 1.0;
-}
 
 void AbstractInterface::setPurpose(int _purpose) {
   if ((_purpose>=Data) && (_purpose <= Wishbone)) {
@@ -237,6 +214,39 @@ bool AbstractInterface::setAssociatedIface(AbstractInterface* iface) {
   return true;
 }
 
+AbstractInterface* AbstractInterface::getClockIface() {
+  if (clkIfaceType == ClockName) {
+    return owner->getIfaceFromName(clkIfaceName);
+  }
+  return NULL;
+}
+
+
+double AbstractInterface::getClockFrequency() throw(Exception) {
+
+  int idClock = -1;
+
+  if (clkIfaceType == ParameterName) {
+    BlockParameter* param = owner->getParameterFromName(clkIfaceName);
+    if (!param->isUserParameter()) throw(Exception(IFACE_INVALID_CLKFREQ,this));
+    bool ok;
+    double freq = param->getDoubleValue(&ok);
+    if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this));
+    return freq;
+  }
+  else {
+    try {
+      idClock = getClockDomain();
+    }
+    catch(Exception e) {
+      throw(e);
+    }
+    return owner->getGraph()->getClock(idClock);
+  }
+  return 0.0;
+}
+
+
 
 int AbstractInterface::getIntDirection(QString str) {
     if(str == "input") return Input;
@@ -288,7 +298,7 @@ int AbstractInterface::typeFromString(const QString &_type) {
   return ret;
 }
 
-QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
+QString AbstractInterface::toVHDL(IfaceVHDLContext context, int flags) throw(Exception) {
 
 
   if (isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
@@ -298,7 +308,20 @@ QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
   QString ret="";
 
   bool ok;
-  cout << "iface " << qPrintable(name) << " must be evaluated to vhdl :" << qPrintable(width) << " with type = " << qPrintable(getTypeString()) << endl;
+  //cout << "iface " << qPrintable(name) << " must be evaluated to vhdl :" << qPrintable(width) << " with type = " << qPrintable(getTypeString()) << endl;
+
+  if (context == Instance) {
+    if (direction == Input) {
+      ret = owner->getName()+"_"+name;
+    }
+    else if (direction == Output) {
+      ret = "from_"+owner->getName()+"_"+name;
+    }
+    else if (direction == InOut) {
+      ret = "fromto_"+owner->getName()+"_"+name;
+    }
+    return ret;
+  }
 
   // create the width part
   QString widthStr = "";
@@ -411,10 +434,15 @@ QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
     ret += widthStr;
   }
   else if (context == Signal) {
-    ret = widthStr;
-  }
-  else if (context == Architecture) {
-
+    if (direction == Output) {
+      ret = "from_"+owner->getName()+"_"+name+" : "+widthStr;
+    }
+    else if (direction == InOut) {
+      ret = "fromto_"+owner->getName()+"_"+name+" : "+widthStr;
+    }
+    else if (direction == Input) {
+      ret = owner->getName()+"_"+name+" : "+widthStr;
+    }
   }
 
   return ret;