]> AND Private Git Repository - blast.git/blob - FunctionalInterface.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
modif in VHDLConverter
[blast.git] / FunctionalInterface.cpp
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
7 \r
8 \r
9 FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterface *_reference) throw(Exception) : ConnectedInterface(_owner) {\r
10 \r
11   if (_owner == NULL) throw(Exception(BLOCK_NULL));\r
12   if (_reference == NULL) throw(Exception(IFACE_NULL));\r
13 \r
14   if (! _owner->isFunctionalBlock()) throw(Exception(BLOCK_INVALID_TYPE));\r
15   if (! _reference->isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));\r
16 \r
17   reference = _reference;\r
18 \r
19   name = reference->getName();\r
20   endianess = reference->getEndianess();\r
21   width = reference->getWidth();\r
22   direction = reference->getDirection();\r
23   purpose = reference->getPurpose();  \r
24   connectedFrom = NULL;  \r
25 }\r
26 \r
27 bool FunctionalInterface::isFunctionalInterface() {\r
28   return true;\r
29 }\r
30 \r
31 int FunctionalInterface::getInterfaceMultiplicity() {\r
32 \r
33   int i=0;\r
34   int ifaceCount = 0;\r
35   FunctionalInterface* iface = NULL;\r
36 \r
37   if (direction == AbstractInterface::Input) {\r
38     QList<AbstractInterface *> inputs = owner->getInputs();\r
39     for(i=0;i<inputs.size();i++) {\r
40       iface = AI_TO_FUN(inputs.at(i));\r
41       if (iface->getReference() == reference) {\r
42         ifaceCount += 1;\r
43       }\r
44     }\r
45   }\r
46   else if (direction == AbstractInterface::Output) {\r
47     QList<AbstractInterface *> outputs = owner->getOutputs();\r
48     for(i=0;i<outputs.size();i++) {\r
49       iface = AI_TO_FUN(outputs.at(i));\r
50       if (iface->getReference() == reference) {\r
51         ifaceCount += 1;\r
52       }\r
53     }\r
54   }\r
55   else if (direction == AbstractInterface::InOut) {\r
56     QList<AbstractInterface *> bidirs = owner->getBidirs();\r
57     for(i=0;i<bidirs.size();i++) {\r
58       iface = AI_TO_FUN(bidirs.at(i));\r
59       if (iface->getReference() == reference) {\r
60         ifaceCount += 1;\r
61       }\r
62     }\r
63   }\r
64   if (ifaceCount == 0) {\r
65     return -1;\r
66   }\r
67   else if ( reference->getMultiplicity() == -1) {\r
68     return ifaceCount;\r
69   }\r
70   else if ( ifaceCount < reference->getMultiplicity()) {\r
71     return ifaceCount;\r
72   }\r
73   return -1;\r
74 }\r
75 \r
76 AbstractInterface *FunctionalInterface::clone() { \r
77   int id = getInterfaceMultiplicity();\r
78   if (id < 0) return NULL;\r
79   FunctionalInterface *inter = new FunctionalInterface(owner, reference);\r
80   inter->setWidth(width);  \r
81   inter->setName(reference->getName()+"_"+QString::number(id+1));\r
82   return inter;\r
83 }\r
84 \r
85 bool FunctionalInterface::canConnectTo(AbstractInterface *iface) {\r
86 \r
87   /* NOTE :\r
88      necessary conditions :\r
89         - this is an output or in/out interface\r
90         - iface type must be functional or group interface\r
91         - iface->connectedFrom must be NULL\r
92 \r
93      valid cases:\r
94      1 - iface is owned by a block (group or func) that is within the same group as the block that own this\r
95         1.1 - this is output and iface is input\r
96         1.2 - both are inout\r
97      2 - iface is owned by the parent group of the block that owns this\r
98         2.1 - this is an output, iface is an output of the group\r
99         2.2 - both are inout\r
100      3 - this is owned by a source block and iface is owned by the top group\r
101 \r
102   */\r
103   if (direction == Input) return false;\r
104   if (iface->isReferenceInterface()) return false;\r
105   ConnectedInterface* connIface = AI_TO_CON(iface);\r
106   if (connIface->getConnectedFrom() != NULL) return false;\r
107   // first case: interface of blocks within the same group\r
108   if (getOwner()->getParent() == iface->getOwner()->getParent()) {\r
109 \r
110     if ((direction == Output) && (iface->getDirection() == Input)) return true;\r
111     if ((direction == InOut) && (iface->getDirection() == InOut)) return true;\r
112   }\r
113   // second case: iface = interface of the group that contains owner of this\r
114   else if (getOwner()->getParent() == iface->getOwner()) {\r
115     if ((direction == Output) && (iface->getDirection() == Output)) return true;\r
116     if ((direction == InOut) && (iface->getDirection() == InOut)) return true;\r
117   }\r
118   else if ((getOwner()->isSourceBlock()) && (iface->getOwner()->isTopGroupBlock())) {\r
119     if ((direction == Output) && (iface->getDirection() == Input)) return true;\r
120   }\r
121 \r
122   return false;\r
123 \r
124 }\r
125 \r
126 bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) {\r
127 \r
128   /* NOTE :\r
129      necessary conditions :\r
130         - this is an input or in/out interface\r
131         - iface type must be functional or group interface\r
132         - this connectedFrom must be NULL\r
133 \r
134      valid cases:\r
135      1 - iface is owned by a block (group or func) that is within the same group as the block that own this\r
136         1.1 - this is input and iface is output\r
137         1.2 - both are inout\r
138      2 - iface is owned by the parent group of the block that owns this\r
139         2.1 - this is an input, iface is an input of the group\r
140         2.2 - both are inout\r
141   */\r
142   if (direction == Output) return false;\r
143   if (iface->isReferenceInterface()) return false;\r
144   if (connectedFrom != NULL) return false;\r
145 \r
146   if (getOwner()->getParent() == iface->getOwner()->getParent()) {\r
147 \r
148     if ((direction == Input) && (iface->getDirection() == Output)) return true;\r
149     if ((direction == InOut) && (iface->getDirection() == InOut)) return true;\r
150   }\r
151   else if (getOwner()->getParent() == iface->getOwner()) {\r
152     if ((direction == Input) && (iface->getDirection() == Input)) return true;\r
153     if ((direction == InOut) && (iface->getDirection() == InOut)) return true;\r
154   }\r
155 \r
156   return false;\r
157 }\r
158 \r
159 \r
160 void FunctionalInterface::connectionsValidation(QStack<AbstractInterface *> *interfacetoValidate, QList<AbstractInterface *> *validatedInterfaces) throw(Exception) {\r
161 \r
162   /*\r
163   //inputs interfaces\r
164   double widthInput, widthOutput;\r
165   if(getDirection() == AbstractInterface::Input){\r
166     widthInput = getDoubleWidth();\r
167     widthOutput = getConnectedFrom()->getDoubleWidth();\r
168     if(widthInput != widthOutput){\r
169       throw new Exception(WIDTHS_NOT_EQUALS);\r
170     }\r
171     foreach(AbstractInterface *inter, getOwner()->getOutputs()){\r
172       if(inter->isConnectedTo()){\r
173         if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){\r
174           interfacetoValidate->push(inter);\r
175         }\r
176       }\r
177     }\r
178   }\r
179   //outputs interfaces\r
180   else if(getDirection() == AbstractInterface::Output){\r
181     widthOutput = getDoubleWidth();\r
182     foreach(AbstractInterface *inter, getConnectedTo()){\r
183       widthInput = inter->getDoubleWidth();\r
184       if(widthInput != widthOutput){\r
185         throw new Exception(WIDTHS_NOT_EQUALS);\r
186       }\r
187     }\r
188     foreach(AbstractInterface *inter, getConnectedTo()){\r
189       if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){\r
190         interfacetoValidate->push(inter);\r
191       }\r
192     }\r
193   }\r
194   else if(getDirection() == AbstractInterface::InOut){\r
195 \r
196   }\r
197 \r
198   */\r
199 }\r