1 #include "ArithmeticEvaluator.h"
\r
2 #include "FunctionalInterface.h"
\r
3 #include "ReferenceInterface.h"
\r
4 #include "GroupInterface.h"
\r
5 #include "FunctionalBlock.h"
\r
6 #include "GroupBlock.h"
\r
9 FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterface *_reference) throw(Exception) : ConnectedInterface(_owner) {
\r
11 if (_owner == NULL) throw(Exception(BLOCK_NULL));
\r
12 if (_reference == NULL) throw(Exception(IFACE_NULL));
\r
14 if (! _owner->isFunctionalBlock()) throw(Exception(BLOCK_INVALID_TYPE));
\r
15 if (! _reference->isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
\r
17 reference = _reference;
\r
19 name = reference->getName();
\r
20 type = reference->getType();
\r
21 endianess = reference->getEndianess();
\r
22 width = reference->getWidthString();
\r
23 direction = reference->getDirection();
\r
24 purpose = reference->getPurpose();
\r
25 connectedFrom = NULL;
\r
28 bool FunctionalInterface::isFunctionalInterface() {
\r
32 int FunctionalInterface::getInterfaceMultiplicity() {
\r
36 FunctionalInterface* iface = NULL;
\r
38 if (direction == AbstractInterface::Input) {
\r
39 QList<AbstractInterface *> inputs = owner->getInputs();
\r
40 for(i=0;i<inputs.size();i++) {
\r
41 iface = AI_TO_FUN(inputs.at(i));
\r
42 if (iface->getReference() == reference) {
\r
47 else if (direction == AbstractInterface::Output) {
\r
48 QList<AbstractInterface *> outputs = owner->getOutputs();
\r
49 for(i=0;i<outputs.size();i++) {
\r
50 iface = AI_TO_FUN(outputs.at(i));
\r
51 if (iface->getReference() == reference) {
\r
56 else if (direction == AbstractInterface::InOut) {
\r
57 QList<AbstractInterface *> bidirs = owner->getBidirs();
\r
58 for(i=0;i<bidirs.size();i++) {
\r
59 iface = AI_TO_FUN(bidirs.at(i));
\r
60 if (iface->getReference() == reference) {
\r
65 if (ifaceCount == 0) {
\r
68 else if ( reference->getMultiplicity() == -1) {
\r
71 else if ( ifaceCount < reference->getMultiplicity()) {
\r
77 AbstractInterface *FunctionalInterface::clone() {
\r
78 int id = getInterfaceMultiplicity();
\r
79 if (id < 0) return NULL;
\r
80 FunctionalInterface *inter = new FunctionalInterface(owner, reference);
\r
81 inter->setWidth(width);
\r
82 inter->setName(reference->getName()+"_"+QString::number(id+1));
\r
86 bool FunctionalInterface::canConnectTo(AbstractInterface *iface) {
\r
89 necessary conditions :
\r
90 - this is an output or in/out interface
\r
91 - iface type must be functional or group interface
\r
92 - iface->connectedFrom must be NULL
\r
95 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
96 1.1 - this is output and iface is input
\r
97 1.2 - both are inout
\r
98 2 - iface is owned by the parent group of the block that owns this
\r
99 2.1 - this is an output, iface is an output of the group
\r
100 2.2 - both are inout
\r
101 3 - this is owned by a source block and iface is owned by the top group
\r
104 if (direction == Input) return false;
\r
105 if (iface->isReferenceInterface()) return false;
\r
106 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
107 if (connIface->getConnectedFrom() != NULL) return false;
\r
108 // first case: interface of blocks within the same group
\r
109 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
111 if ((direction == Output) && (iface->getDirection() == Input)) return true;
\r
112 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
114 // second case: iface = interface of the group that contains owner of this
\r
115 else if (getOwner()->getParent() == iface->getOwner()) {
\r
116 if ((direction == Output) && (iface->getDirection() == Output)) return true;
\r
117 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
119 else if ((getOwner()->isSourceBlock()) && (iface->getOwner()->isTopGroupBlock())) {
\r
120 if ((direction == Output) && (iface->getDirection() == Input)) return true;
\r
127 bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) {
\r
130 necessary conditions :
\r
131 - this is an input or in/out interface
\r
132 - iface type must be functional or group interface
\r
133 - this connectedFrom must be NULL
\r
136 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
137 1.1 - this is input and iface is output
\r
138 1.2 - both are inout
\r
139 2 - iface is owned by the parent group of the block that owns this
\r
140 2.1 - this is an input, iface is an input of the group
\r
141 2.2 - both are inout
\r
143 if (direction == Output) return false;
\r
144 if (iface->isReferenceInterface()) return false;
\r
145 if (connectedFrom != NULL) return false;
\r
147 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
149 if ((direction == Input) && (iface->getDirection() == Output)) return true;
\r
150 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
152 else if (getOwner()->getParent() == iface->getOwner()) {
\r
153 if ((direction == Input) && (iface->getDirection() == Input)) return true;
\r
154 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
161 void FunctionalInterface::connectionsValidation(QStack<AbstractInterface *> *interfacetoValidate, QList<AbstractInterface *> *validatedInterfaces) throw(Exception) {
\r
164 //inputs interfaces
\r
165 double widthInput, widthOutput;
\r
166 if(getDirection() == AbstractInterface::Input){
\r
167 widthInput = getDoubleWidth();
\r
168 widthOutput = getConnectedFrom()->getDoubleWidth();
\r
169 if(widthInput != widthOutput){
\r
170 throw new Exception(WIDTHS_NOT_EQUALS);
\r
172 foreach(AbstractInterface *inter, getOwner()->getOutputs()){
\r
173 if(inter->isConnectedTo()){
\r
174 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
175 interfacetoValidate->push(inter);
\r
180 //outputs interfaces
\r
181 else if(getDirection() == AbstractInterface::Output){
\r
182 widthOutput = getDoubleWidth();
\r
183 foreach(AbstractInterface *inter, getConnectedTo()){
\r
184 widthInput = inter->getDoubleWidth();
\r
185 if(widthInput != widthOutput){
\r
186 throw new Exception(WIDTHS_NOT_EQUALS);
\r
189 foreach(AbstractInterface *inter, getConnectedTo()){
\r
190 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
191 interfacetoValidate->push(inter);
\r
195 else if(getDirection() == AbstractInterface::InOut){
\r