1 #include "AbstractInterface.h"
2 #include "BlockParameterPort.h"
3 #include "AbstractBlock.h"
5 AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
17 AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name, const QString& _type, const QString& _width, int _direction, int _purpose, int _level) {
22 direction = _direction;
25 if (direction == InOut) {
28 type = typeFromString(_type);
31 AbstractInterface::AbstractInterface(AbstractInterface* other) {
36 direction = other->direction;
37 purpose = other->purpose;
41 AbstractInterface::~AbstractInterface() {
45 bool AbstractInterface::isReferenceInterface() {
49 bool AbstractInterface::isFunctionalInterface() {
53 bool AbstractInterface::isGroupInterface() {
57 QString AbstractInterface::getPurposeString() {
60 case AbstractInterface::Data:
61 str = QString("data");
63 case AbstractInterface::Clock:
64 str = QString("clock");
66 case AbstractInterface::Reset:
67 str = QString("reset");
69 case AbstractInterface::Wishbone:
70 str = QString("wishbone");
76 QString AbstractInterface::getDirectionString() {
79 case AbstractInterface::Input:
80 str = QString("input");
82 case AbstractInterface::Output:
83 str = QString("output");
85 case AbstractInterface::InOut:
86 str = QString("inout");
92 QString AbstractInterface::getLevelString() {
95 case AbstractInterface::Basic:
96 str = QString("basic");
98 case AbstractInterface::Top:
105 double AbstractInterface::getDoubleWidth() throw(QException) {
107 static QString fctName = "AbstractInterface::getDoubleWidth()";
109 cout << "call to " << qPrintable(fctName) << endl;
113 cout << "start AbstractInterface::getDoubleWidth()" << endl;
115 double width = getWidth().toDouble(&ok);
118 ArithmeticEvaluator *evaluator = new ArithmeticEvaluator;
119 cout << "evaluator created!" << endl;
120 evaluator->setExpression(getWidth());
121 cout << "expression defined!" << endl;
122 foreach(BlockParameter *param, getOwner()->getParameters()){
123 evaluator->setVariableValue(param->getName(), param->getIntValue());
124 cout << "param : " << param->getName().toStdString() << " evaluated!" << endl;
126 width = evaluator->evaluate();
127 cout << "expression evaluated succefully!" << endl;
129 cout << "real width : " << width << endl;
136 void AbstractInterface::setPurpose(int _purpose) {
137 if ((_purpose>=Data) && (_purpose <= Wishbone)) {
142 void AbstractInterface::setDirection(int _direction) {
143 if ((_direction > Input) && (_direction <= InOut)) {
144 direction = _direction;
146 if (direction == InOut) {
151 void AbstractInterface::setLevel(int _level) {
152 if ((_level >= Basic) << (_level < Top)) {
155 if (direction == InOut) {
162 int AbstractInterface::getIntDirection(QString str)
164 if(str == "input") return Input;
165 if(str == "output") return Output;
166 if(str == "inOut") return InOut;
170 int AbstractInterface::getIntLevel(QString str)
172 if(str == "basic") return Basic;
173 if(str == "top") return Top;
177 QString AbstractInterface::getTypeString() {
179 if (type == Boolean) {
182 else if (type == Natural) {
185 else if (type == Expression) {
188 return "invalid_type";
191 int AbstractInterface::typeFromString(const QString &_type) {
194 if (_type == "expression") {
197 else if (_type == "boolean") {
200 else if (_type == "natural") {
206 QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
208 if (isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
213 if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) {
215 QString formatBool = "%1 : %2 std_logic";
216 QString formatVector = "%1 : %2 std_logic_vector(%3 downto %4)";
217 if ((flags & BlockParameter::NoComma) == 0) {
218 formatBool.append(";");
219 formatVector.append(";");
221 QString orientation="";
222 if (direction == Input) {
225 else if (direction == Output) {
229 orientation = "inout";
231 if (type == Boolean) {
232 ret = formatVector.arg(name).arg(orientation);
234 else if (type == Natural) {
235 int w = width.toInt(&ok);
237 throw(Exception(INVALID_VALUE));
241 ret = formatVector.arg(name).arg(orientation).arg(w).arg("0");
244 else if (type == Expression) {
245 /* must check the following conditions :
246 - if it contains user/port parameters : must evaluate their numeric value
247 - if it contains generic parameters : just remove the $ -> the expression is not arithmetically evaluated.
249 QList<BlockParameter*> listGenerics = owner->getGenericParameters();
250 QList<BlockParameter*> listUsers = owner->getUserParameters();
251 QList<BlockParameter*> listPorts = owner->getPortParameters();
252 foreach(BlockParameter* p, listUsers) {
254 var.append(p->getName());
255 if (width.contains(var)) {
256 int w = p->getValue().toInt(&ok);
257 if (!ok) throw(Exception(INVALID_VALUE));
258 msb.replace(var,p->getValue().toString());
261 foreach(BlockParameter* p, listPorts) {
263 var.append(p->getName());
264 if (width.contains(var)) {
265 BlockParameterPort* pp = (BlockParameterPort*)p;
266 AbstractInterface* iface = owner->getIfaceFromName(pp->getIfaceName());
268 int w = p->getValue().toInt(&ok);
269 if (!ok) throw(Exception(INVALID_VALUE));
270 msb.replace(var,p->getValue().toString());
274 ret = formatVector.arg(name).arg(orientation).arg("toto").arg("0");