1 #include "AbstractInterface.h"
2 #include "BlockParameterPort.h"
3 #include "AbstractBlock.h"
5 AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
16 AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name, const QString& _type, const QString& _width, int _direction, int _purpose) {
21 direction = _direction;
23 type = typeFromString(_type);
26 AbstractInterface::AbstractInterface(AbstractInterface* other) {
31 direction = other->direction;
32 purpose = other->purpose;
35 AbstractInterface::~AbstractInterface() {
39 bool AbstractInterface::isReferenceInterface() {
43 bool AbstractInterface::isFunctionalInterface() {
47 bool AbstractInterface::isGroupInterface() {
51 QString AbstractInterface::getPurposeString() {
54 case AbstractInterface::Data:
55 str = QString("data");
57 case AbstractInterface::Clock:
58 str = QString("clock");
60 case AbstractInterface::Reset:
61 str = QString("reset");
63 case AbstractInterface::Wishbone:
64 str = QString("wishbone");
70 QString AbstractInterface::getDirectionString() {
73 case AbstractInterface::Input:
74 str = QString("input");
76 case AbstractInterface::Output:
77 str = QString("output");
79 case AbstractInterface::InOut:
80 str = QString("inout");
86 double AbstractInterface::getDoubleWidth() throw(QException) {
88 static QString fctName = "AbstractInterface::getDoubleWidth()";
90 cout << "call to " << qPrintable(fctName) << endl;
94 cout << "start AbstractInterface::getDoubleWidth()" << endl;
96 double width = getWidth().toDouble(&ok);
99 ArithmeticEvaluator *evaluator = new ArithmeticEvaluator;
100 cout << "evaluator created!" << endl;
101 evaluator->setExpression(getWidth());
102 cout << "expression defined!" << endl;
103 foreach(BlockParameter *param, getOwner()->getParameters()){
104 evaluator->setVariableValue(param->getName(), param->getIntValue());
105 cout << "param : " << param->getName().toStdString() << " evaluated!" << endl;
107 width = evaluator->evaluate();
108 cout << "expression evaluated succefully!" << endl;
110 cout << "real width : " << width << endl;
117 void AbstractInterface::setPurpose(int _purpose) {
118 if ((_purpose>=Data) && (_purpose <= Wishbone)) {
123 void AbstractInterface::setDirection(int _direction) {
124 if ((_direction > Input) && (_direction <= InOut)) {
125 direction = _direction;
130 int AbstractInterface::getIntDirection(QString str) {
131 if(str == "input") return Input;
132 if(str == "output") return Output;
133 if(str == "inOut") return InOut;
138 QString AbstractInterface::getTypeString() {
140 if (type == Boolean) {
143 else if (type == Natural) {
146 else if (type == Expression) {
149 return "invalid_type";
152 int AbstractInterface::typeFromString(const QString &_type) {
155 if (_type == "expression") {
158 else if (_type == "boolean") {
161 else if (_type == "natural") {
167 QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
169 if (isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
174 if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) {
176 QString formatBool = "%1 : %2 std_logic";
177 QString formatVector = "%1 : %2 std_logic_vector(%3 downto %4)";
178 if ((flags & BlockParameter::NoComma) == 0) {
179 formatBool.append(";");
180 formatVector.append(";");
182 QString orientation="";
183 if (direction == Input) {
186 else if (direction == Output) {
190 orientation = "inout";
192 if (type == Boolean) {
193 ret = formatVector.arg(name).arg(orientation);
195 else if (type == Natural) {
196 int w = width.toInt(&ok);
198 throw(Exception(INVALID_VALUE));
202 ret = formatVector.arg(name).arg(orientation).arg(w).arg("0");
205 else if (type == Expression) {
206 /* must check the following conditions :
207 - if it contains user/port parameters : must evaluate their numeric value
208 - if it contains generic parameters : just remove the $ -> the expression is not arithmetically evaluated.
210 QList<BlockParameter*> listGenerics = owner->getGenericParameters();
211 QList<BlockParameter*> listUsers = owner->getUserParameters();
212 QList<BlockParameter*> listPorts = owner->getPortParameters();
213 foreach(BlockParameter* p, listUsers) {
215 var.append(p->getName());
216 if (width.contains(var)) {
217 int w = p->getValue().toInt(&ok);
218 if (!ok) throw(Exception(INVALID_VALUE));
219 msb.replace(var,p->getValue().toString());
222 foreach(BlockParameter* p, listPorts) {
224 var.append(p->getName());
225 if (width.contains(var)) {
226 BlockParameterPort* pp = (BlockParameterPort*)p;
227 AbstractInterface* iface = owner->getIfaceFromName(pp->getIfaceName());
229 int w = p->getValue().toInt(&ok);
230 if (!ok) throw(Exception(INVALID_VALUE));
231 msb.replace(var,p->getValue().toString());
235 ret = formatVector.arg(name).arg(orientation).arg("toto").arg("0");