1 #include "AbstractInterface.h"
2 #include "BlockParameterPort.h"
3 #include "AbstractBlock.h"
5 AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
13 associatedIface = NULL;
17 AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name, const QString& _type, const QString& _width, int _direction, int _purpose) {
22 direction = _direction;
24 type = typeFromString(_type);
25 associatedIface = NULL;
28 AbstractInterface::AbstractInterface(AbstractInterface* other) {
33 direction = other->direction;
34 purpose = other->purpose;
35 associatedIface = NULL;
38 AbstractInterface::~AbstractInterface() {
42 bool AbstractInterface::isReferenceInterface() {
46 bool AbstractInterface::isFunctionalInterface() {
50 bool AbstractInterface::isGroupInterface() {
54 QString AbstractInterface::getPurposeString() {
57 case AbstractInterface::Data:
58 str = QString("data");
60 case AbstractInterface::Clock:
61 str = QString("clock");
63 case AbstractInterface::Reset:
64 str = QString("reset");
66 case AbstractInterface::Wishbone:
67 str = QString("wishbone");
73 QString AbstractInterface::getDirectionString() {
76 case AbstractInterface::Input:
77 str = QString("input");
79 case AbstractInterface::Output:
80 str = QString("output");
82 case AbstractInterface::InOut:
83 str = QString("inout");
89 double AbstractInterface::getDoubleWidth() throw(QException) {
91 static QString fctName = "AbstractInterface::getDoubleWidth()";
93 cout << "call to " << qPrintable(fctName) << endl;
97 cout << "start AbstractInterface::getDoubleWidth()" << endl;
99 double width = getWidth().toDouble(&ok);
102 ArithmeticEvaluator *evaluator = new ArithmeticEvaluator;
103 cout << "evaluator created!" << endl;
104 evaluator->setExpression(getWidth());
105 cout << "expression defined!" << endl;
106 foreach(BlockParameter *param, getOwner()->getParameters()){
107 evaluator->setVariableValue(param->getName(), param->getIntValue());
108 cout << "param : " << param->getName().toStdString() << " evaluated!" << endl;
110 width = evaluator->evaluate();
111 cout << "expression evaluated succefully!" << endl;
113 cout << "real width : " << width << endl;
120 void AbstractInterface::setPurpose(int _purpose) {
121 if ((_purpose>=Data) && (_purpose <= Wishbone)) {
126 void AbstractInterface::setDirection(int _direction) {
127 if ((_direction > Input) && (_direction <= InOut)) {
128 direction = _direction;
132 bool AbstractInterface::setAssociatedIface(AbstractInterface* iface) {
133 if (purpose != Control) return false;
134 if (iface->purpose != Data) return false;
135 associatedIface = iface;
136 iface->associatedIface = this;
141 int AbstractInterface::getIntDirection(QString str) {
142 if(str == "input") return Input;
143 if(str == "output") return Output;
144 if(str == "inOut") return InOut;
149 QString AbstractInterface::getTypeString() {
151 if (type == Boolean) {
154 else if (type == Natural) {
157 else if (type == Expression) {
160 return "invalid_type";
163 int AbstractInterface::typeFromString(const QString &_type) {
166 if (_type == "expression") {
169 else if (_type == "boolean") {
172 else if (_type == "natural") {
178 QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
180 if (isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
185 if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) {
187 QString formatBool = "%1 : %2 std_logic";
188 QString formatVector = "%1 : %2 std_logic_vector(%3 downto %4)";
189 if ((flags & BlockParameter::NoComma) == 0) {
190 formatBool.append(";");
191 formatVector.append(";");
193 QString orientation="";
194 if (direction == Input) {
197 else if (direction == Output) {
201 orientation = "inout";
203 if (type == Boolean) {
204 ret = formatVector.arg(name).arg(orientation);
206 else if (type == Natural) {
207 int w = width.toInt(&ok);
209 throw(Exception(INVALID_VALUE));
213 ret = formatVector.arg(name).arg(orientation).arg(w).arg("0");
216 else if (type == Expression) {
217 /* must check the following conditions :
218 - if it contains user/port parameters : must evaluate their numeric value
219 - if it contains generic parameters : just remove the $ -> the expression is not arithmetically evaluated.
221 QList<BlockParameter*> listGenerics = owner->getGenericParameters();
222 QList<BlockParameter*> listUsers = owner->getUserParameters();
223 QList<BlockParameter*> listPorts = owner->getPortParameters();
224 foreach(BlockParameter* p, listUsers) {
226 var.append(p->getName());
227 if (width.contains(var)) {
228 int w = p->getValue().toInt(&ok);
229 if (!ok) throw(Exception(INVALID_VALUE));
230 msb.replace(var,p->getValue().toString());
233 foreach(BlockParameter* p, listPorts) {
235 var.append(p->getName());
236 if (width.contains(var)) {
237 BlockParameterPort* pp = (BlockParameterPort*)p;
238 AbstractInterface* iface = owner->getIfaceFromName(pp->getIfaceName());
240 int w = p->getValue().toInt(&ok);
241 if (!ok) throw(Exception(INVALID_VALUE));
242 msb.replace(var,p->getValue().toString());
246 ret = formatVector.arg(name).arg(orientation).arg("toto").arg("0");