X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..18fecf25efe710631fabecbb9f689c2997fdfe18:/AbstractInterface.cpp?ds=inline diff --git a/AbstractInterface.cpp b/AbstractInterface.cpp index 25cd2d3..a32f78e 100644 --- a/AbstractInterface.cpp +++ b/AbstractInterface.cpp @@ -1,6 +1,7 @@ #include "AbstractInterface.h" #include "BlockParameterPort.h" #include "AbstractBlock.h" +#include "Parameters.h" AbstractInterface::AbstractInterface(AbstractBlock* _owner) { @@ -8,34 +9,38 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner) { name = ""; width = "1"; direction = Input; - purpose = Data; - level = Basic; + purpose = Data; type = Boolean; + endianess = LittleEndian; + associatedIface = NULL; } -AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name, const QString& _type, const QString& _width, int _direction, int _purpose, int _level) { +AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose, const QString& _type, const QString& _width, int _endianess) { owner = _owner; - name = _name; + name = Parameters::normalizeName(_name); width = _width; direction = _direction; purpose = _purpose; - level = _level; - if (direction == InOut) { - level = Top; - } type = typeFromString(_type); + endianess = _endianess; + associatedIface = NULL; } AbstractInterface::AbstractInterface(AbstractInterface* other) { owner = NULL; - name = other->name; + name = Parameters::normalizeName(other->name); type = other->type; width = other->width; direction = other->direction; purpose = other->purpose; - level = other->level; + endianess = LittleEndian; + associatedIface = NULL; +} + +void AbstractInterface::setName(const QString& _name) { + name = Parameters::normalizeName(_name); } AbstractInterface::~AbstractInterface() { @@ -54,23 +59,42 @@ bool AbstractInterface::isGroupInterface() { return false; } +QString AbstractInterface::getEndianessString() { + QString str="unknown"; + switch(endianess){ + case AbstractInterface::LittleEndian: + str = QString("little"); + break; + case AbstractInterface::BigEndian: + str = QString("big"); + break; + } + return str; +} + QString AbstractInterface::getPurposeString() { - QString str; - switch(purpose){ - case AbstractInterface::Data: - str = QString("data"); - break; - case AbstractInterface::Clock: - str = QString("clock"); - break; - case AbstractInterface::Reset: - str = QString("reset"); - break; - case AbstractInterface::Wishbone: - str = QString("wishbone"); - break; - } - return str; + QString str; + switch(purpose){ + case AbstractInterface::AnyPurpose: + str = QString("any"); + break; + case AbstractInterface::Data: + str = QString("data"); + break; + case AbstractInterface::Control: + str = QString("control"); + break; + case AbstractInterface::Clock: + str = QString("clock"); + break; + case AbstractInterface::Reset: + str = QString("reset"); + break; + case AbstractInterface::Wishbone: + str = QString("wishbone"); + break; + } + return str; } QString AbstractInterface::getDirectionString() { @@ -89,19 +113,6 @@ QString AbstractInterface::getDirectionString() { return str; } -QString AbstractInterface::getLevelString() { - QString str; - switch(level){ - case AbstractInterface::Basic: - str = QString("basic"); - break; - case AbstractInterface::Top: - str = QString("top"); - break; - } - return str; -} - double AbstractInterface::getDoubleWidth() throw(QException) { static QString fctName = "AbstractInterface::getDoubleWidth()"; @@ -143,34 +154,29 @@ void AbstractInterface::setDirection(int _direction) { if ((_direction > Input) && (_direction <= InOut)) { direction = _direction; } - if (direction == InOut) { - level = Top; - } } -void AbstractInterface::setLevel(int _level) { - if ((_level >= Basic) << (_level < Top)) { - level = _level; - } - if (direction == InOut) { - level = Top; - } +bool AbstractInterface::setAssociatedIface(AbstractInterface* iface) { + if (purpose != Control) return false; + if (iface->purpose != Data) return false; + associatedIface = iface; + iface->associatedIface = this; + return true; } - -int AbstractInterface::getIntDirection(QString str) -{ +int AbstractInterface::getIntDirection(QString str) { if(str == "input") return Input; if(str == "output") return Output; - if(str == "inOut") return InOut; + if(str == "inout") return InOut; return -1; } -int AbstractInterface::getIntLevel(QString str) -{ - if(str == "basic") return Basic; - if(str == "top") return Top; +int AbstractInterface::getIntPurpose(QString str) { + if(str == "data") return Data; + else if(str == "clock") return Clock; + else if(str == "reset") return Reset; + else if(str == "wishbone") return Wishbone; return -1; } @@ -190,7 +196,7 @@ QString AbstractInterface::getTypeString() { int AbstractInterface::typeFromString(const QString &_type) { - int ret; + int ret = Expression; // default type if (_type == "expression") { ret = Expression; } @@ -200,20 +206,29 @@ int AbstractInterface::typeFromString(const QString &_type) { else if (_type == "natural") { ret = Natural; } + else if (_type == "inherited") { + ret = Inherited; + } return ret; } QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) { + if (isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE)); QString msb = width; QString ret=""; bool ok; + cout << "iface " << qPrintable(name) << " must be evaluated to vhdl :" << qPrintable(msb) << " with type = " << qPrintable(getTypeString()) << endl; + if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) { QString formatBool = "%1 : %2 std_logic"; - QString formatVector = "%1 : %2 std_logic_vector(%3 downto %4)"; + QString formatVector = ""; + if (endianess == LittleEndian) formatVector = "%1 : %2 std_logic_vector(%3 downto %4)"; + else formatVector = "%1 : %2 std_logic_vector(%4 to %3)"; + if ((flags & BlockParameter::NoComma) == 0) { formatBool.append(";"); formatVector.append(";"); @@ -229,7 +244,7 @@ QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) { orientation = "inout"; } if (type == Boolean) { - ret = formatVector.arg(name).arg(orientation); + ret = formatBool.arg(name).arg(orientation); } else if (type == Natural) { int w = width.toInt(&ok); @@ -242,6 +257,8 @@ QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) { } } else if (type == Expression) { + + /* must check the following conditions : - if it contains user/port parameters : must evaluate their numeric value - if it contains generic parameters : just remove the $ -> the expression is not arithmetically evaluated. @@ -251,7 +268,7 @@ QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) { QList listPorts = owner->getPortParameters(); foreach(BlockParameter* p, listUsers) { QString var = "$"; - var.append(p->getName()); + var += p->getName(); if (width.contains(var)) { int w = p->getValue().toInt(&ok); if (!ok) throw(Exception(INVALID_VALUE)); @@ -260,18 +277,21 @@ QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) { } foreach(BlockParameter* p, listPorts) { QString var = "$"; - var.append(p->getName()); + var += p->getName(); + if (width.contains(var)) { + msb.replace(var,p->toVHDL(0,0)); + } + } + foreach(BlockParameter* p, listGenerics) { + QString var = "$"; + var += p->getName(); if (width.contains(var)) { - BlockParameterPort* pp = (BlockParameterPort*)p; - AbstractInterface* iface = owner->getIfaceFromName(pp->getIfaceName()); - - int w = p->getValue().toInt(&ok); - if (!ok) throw(Exception(INVALID_VALUE)); - msb.replace(var,p->getValue().toString()); + msb.replace(var,p->getName()); } } - - ret = formatVector.arg(name).arg(orientation).arg("toto").arg("0"); + msb += "-1"; + cout << "iface size :" << qPrintable(msb) << endl; + ret = formatVector.arg(name).arg(orientation).arg(msb).arg("0"); } } return ret;