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") {
175 else if (_type == "inherited") {
181 QString AbstractInterface::toVHDL(int context, int flags) throw(Exception) {
183 if (isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
188 if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) {
190 QString formatBool = "%1 : %2 std_logic";
191 QString formatVector = "%1 : %2 std_logic_vector(%3 downto %4)";
192 if ((flags & BlockParameter::NoComma) == 0) {
193 formatBool.append(";");
194 formatVector.append(";");
196 QString orientation="";
197 if (direction == Input) {
200 else if (direction == Output) {
204 orientation = "inout";
206 if (type == Boolean) {
207 ret = formatVector.arg(name).arg(orientation);
209 else if (type == Natural) {
210 int w = width.toInt(&ok);
212 throw(Exception(INVALID_VALUE));
216 ret = formatVector.arg(name).arg(orientation).arg(w).arg("0");
219 else if (type == Expression) {
220 /* must check the following conditions :
221 - if it contains user/port parameters : must evaluate their numeric value
222 - if it contains generic parameters : just remove the $ -> the expression is not arithmetically evaluated.
224 QList<BlockParameter*> listGenerics = owner->getGenericParameters();
225 QList<BlockParameter*> listUsers = owner->getUserParameters();
226 QList<BlockParameter*> listPorts = owner->getPortParameters();
227 foreach(BlockParameter* p, listUsers) {
229 var.append(p->getName());
230 if (width.contains(var)) {
231 int w = p->getValue().toInt(&ok);
232 if (!ok) throw(Exception(INVALID_VALUE));
233 msb.replace(var,p->getValue().toString());
236 foreach(BlockParameter* p, listPorts) {
238 var.append(p->getName());
239 if (width.contains(var)) {
240 BlockParameterPort* pp = (BlockParameterPort*)p;
241 AbstractInterface* iface = owner->getIfaceFromName(pp->getIfaceName());
243 int w = p->getValue().toInt(&ok);
244 if (!ok) throw(Exception(INVALID_VALUE));
245 msb.replace(var,p->getValue().toString());
249 ret = formatVector.arg(name).arg(orientation).arg("toto").arg("0");