Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: engine/UserModuleDescription.java


1   
2   /* **********************************
3    File:UserModuleDescription.java
4    Author: Alec(panovici@elcom.pub.ro)
5    Created on Wed Sep 29 03:16:13 EEST 1999
6    Comments: Part of the vIDE Project
7               Copyright 1999 the vIDE Team.
8   ***********************************/
9   
10  package engine;
11  
12  import java.util.*;
13  import middle.*;
14  
15  /**
16   * A 'user module' is a module whose inner structure
17   * is accessible by the user (UDPs and modules). By contrast,
18   * standard primitives do not have an 'internal structure',
19   * and the links between ports are not made using intermediary
20   * DataHolders.
21   */
22  abstract class UserModuleDescription
23    extends DefaultNameSpaceDescription implements ModuleFactory
24  {
25    UserModuleDescription (String name) {
26      super(name);
27    }
28  
29    /**
30     * Creates the links between ports and their corresponding expressions
31     */
32    void linkModule(Module m, NameSpace parent,
33                    byte strength,
34                    ModuleInstanceDescription miDesc) throws ParseException {
35      if (isTop()) return;
36      try {
37        miDesc.orderPorts(connectionList, connectionHash);
38      } catch (ParseException pex) {
39        throw new ParseException(parent.desc.toString(miDesc.lineNo) + pex);
40      }
41      try {
42        int portIndex = 0;
43      portLoop:
44        for (Enumeration extern = miDesc.portsVector.elements(),
45              intern = connectionList.elements();
46            extern.hasMoreElements() || intern.hasMoreElements() ; portIndex++) {
47          
48          ConnectionDescription cd =
49            (ConnectionDescription)intern.nextElement();
50          try{
51            cd.computeType(this);
52          } catch (ParseException pex) {
53            throw new ParseException (toString(cd.lineNo) + pex);
54          }
55          Monitor mon;
56          ExpressionDescription exp =
57            (ExpressionDescription)extern.nextElement();
58          if(exp == null)continue portLoop; //unconnected port
59          
60          xConsole.debug("matching " + cd + " with " + exp);
61  
62          
63          try{
64            if((cd.type & PortDescription.output) != 0)
65              //prepare exp for continuous assignement
66              try{
67                ((AssignableSelection)exp).toContSelection(strength);  
68              }catch(ClassCastException ex){
69                throw new ParseException("lValue required");
70              }
71            
72            if((cd.type & PortDescription.input) != 0)
73              //prepare port for cont. assign.
74              cd.prepareForContSelection();
75            
76            if ((cd.type & PortDescription.inout) == PortDescription.inout) {
77              mon =
78                MBiContAssignMonitor.
79                createNewMBiContAssignMonitor((WireSelection) cd.
80                                              instantiate(m, null),
81                                              (WireSelection)
82                                              exp.instantiate(parent));
83              mon =
84                MBiContAssignMonitor.
85                createNewMBiContAssignMonitor((WireSelection) exp.instantiate(parent),
86                                              (WireSelection) cd.
87                                              instantiate(m, null));
88            } else {
89              if ((cd.type & PortDescription.input) != 0) {
90                mon =
91                  MContAssignMonitor.
92                  createNewMContAssignMonitor((LeftValue) cd.instantiate(m, null),
93                                              exp.instantiate(parent));
94              } else {
95                mon =
96                  MContAssignMonitor.
97                  createNewMContAssignMonitor((LeftValue) exp.instantiate(parent),
98                                              (Expression) cd.instantiate(m, null));
99              }
100           }
101         } catch (ParseException pex) {
102           xConsole.dumpStack(pex);
103           throw new ParseException (parent.desc.toString(miDesc.lineNo) +
104                                     ": error: bad expression for port #"
105                                     + portIndex + ": "+ pex);
106         }
107       }
108     }catch(NoSuchElementException ex){
109       //oops, the port lists don't match !
110       xConsole.dumpStack(ex);
111       throw new ParseException(parent.desc.toString(miDesc.lineNo) +
112                                ": error : port lists don't match");
113     }
114   }
115 
116   void linkModuleArray(Module[] modules, NameSpace parent,
117                        ModuleInstanceDescription miDesc,
118                        byte strength,
119                        int ars, int are,
120                        int n, int increment)
121     throws ParseException
122   {
123     try {
124       miDesc.orderPorts(connectionList, connectionHash);
125     } catch (ParseException pex) {
126       throw new ParseException(parent.desc.toString(miDesc.lineNo) + pex);
127     }
128     try {
129       //fixing ports
130       int portIndex = 0;
131     portloop:
132       for (Enumeration extern = miDesc.portsVector.elements(),
133              intern = connectionList.elements();
134            extern.hasMoreElements() || intern.hasMoreElements(); portIndex++) {
135         ConnectionDescription cd = (ConnectionDescription) intern.nextElement();
136         try{
137           cd.computeType(this);
138         } catch (ParseException pex) {
139           throw new ParseException (toString(cd.lineNo) + pex);
140         }
141         ExpressionDescription externExpDesc =
142           (ExpressionDescription) extern.nextElement();
143         
144         if (externExpDesc == null) continue portloop;
145         
146         Monitor mon;
147         try {
148           if ((cd.type & PortDescription.output) != 0) {
149             xConsole.debug("output port");
150             try {
151               ((AssignableSelection)externExpDesc).toContSelection();
152             } catch (ClassCastException cex) {
153               throw new ParseException("lValue requierd");
154             }
155           }
156 
157           if ((cd.type & PortDescription.input) != 0)
158             cd.prepareForContSelection();
159           
160           Expression externExpression = externExpDesc.instantiate(parent);
161           Expression internExpression =
162             (Expression) cd.instantiate(modules[0], null);
163         
164           if (externExpression.length == internExpression.length) {
165             for (int mi = 0; mi < n ; mi++) {
166               if (mi != 0) {
167                 internExpression =
168                   (Expression) cd.instantiate(modules[mi], null);
169                 externExpression = externExpDesc.instantiate(parent);
170               }
171               if ((cd.type & PortDescription.inout) == PortDescription.inout) {
172                 mon =
173                   MBiContAssignMonitor.
174                   createNewMBiContAssignMonitor
175                   ((WireSelection) internExpression,
176                    (WireSelection) externExpression);
177                 mon =
178                   MBiContAssignMonitor.
179                   createNewMBiContAssignMonitor
180                   ((WireSelection) externExpDesc.instantiate(parent),
181                    (WireSelection) cd.instantiate(modules[mi], null));
182               } else {
183                 if ((cd.type & PortDescription.output) != 0) {
184                   mon = MContAssignMonitor.createNewMContAssignMonitor
185                     ((LeftValue) externExpression, internExpression);
186                 } else {
187                   mon = MContAssignMonitor.createNewMContAssignMonitor
188                     ((LeftValue) internExpression, externExpression);
189                 }
190               }
191             }
192           } else {
193             if ((externExpression.length / internExpression.length) == n) {
194               //here, at last, slices:
195               if ((cd.type & PortDescription.inout) == PortDescription.inout) {
196                 WireSelection slices[] = new WireSelection[n];
197                 slices[0] = (WireSelection)internExpression;
198                 for (int mi = 1; mi < n; mi++)
199                   slices[mi] = (WireSelection) cd.instantiate(modules[mi],
200                                                               null);
201                 mon = MBiContAssignMonitor.createNewMBiContAssignMonitor
202                   (slices, (WireSelection) externExpression);
203                 
204                 for (int mi = 0; mi < n; mi++)
205                   slices[mi] = (WireSelection) cd.instantiate(modules[mi],
206                                                                 null);
207                 mon = MBiContAssignMonitor.createNewMBiContAssignMonitor
208                   ((WireSelection)externExpDesc.instantiate(parent), slices);
209               } else {
210                 if ((cd.type & PortDescription.input) != 0) {
211                   LeftValue slices[] = new LeftValue[n];
212                   Expression out[] = new Expression[1];
213                   out[0] = externExpression;
214                   slices[0] = (LeftValue)internExpression;
215                   for (int mi = 1; mi < n; mi++) {
216                     slices[mi] = (LeftValue) cd.instantiate(modules[mi],
217                                                             null);
218                   }
219                   mon = new MContAssignMonitor(slices, out);
220                 } else {
221                   Expression slices[] = new Expression[n];
222                   LeftValue out[] = new LeftValue[1];
223                   out[0] = (LeftValue) externExpression;
224                   slices[0] = internExpression;
225                   for (int mi = 1; mi < n; mi++) {
226                     slices[mi] = (Expression) cd.instantiate(modules[mi],
227                                                              null);
228                   }
229                   mon = new MContAssignMonitor(out, slices);
230                 }
231               }
232             } else
233               throw new ParseException ("bad port expression length");
234           }
235         } catch (ParseException pex) {
236           xConsole.dumpStack(pex);
237           throw new ParseException (parent.desc.toString(miDesc.lineNo) +
238                                     ": error: bad expression for port #" +
239                                     + portIndex + ": " + pex);
240         }
241       }
242     } catch (NoSuchElementException ex) {
243       //oops, the port lists don't match !
244       xConsole.dumpStack(ex);
245       throw new ParseException(parent.desc.toString(miDesc.lineNo) +
246                                ": error : port lists don't match");
247     }
248   }
249 }
250 
251 
252 
253 
254 
255 
256 
257