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

Quick Search    Search Deep

Source code: engine/TranGateDescription.java


1   
2   /* **********************************
3    File: TranGateDescription.java
4    Author: Alec(panovici@elcom.pub.ro)
5    Created on Thu Oct 21 23:47:16 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 java.io.*;
14  import middle.*;
15  
16  /**
17   * Transistors:
18   * [r]tran, [r]tranif(0|1)
19   * There is no associated TranGate class, since
20   * a tran is a pair of MContAssignMonitors (to which I have
21   * added reduceing strength capabiliies).
22   ***
23   * Since the standard does not specify the exact behaviour of tran gates
24   * (no truth tables & stuff), I suppose the most probable one
25   * should be as foloows: if the control wire (we're spaking about
26   * tranif?) has any value other than 1, the tranif? is off.
27   */
28  
29  class TranGateDescription extends StdGateDescription
30  {
31    
32    TranGateDescription (byte type) {
33      super(type, type == tran || type == rtran ? 0 : 2);
34    }
35  
36    ///////////////////////////////
37    // ModuleFactory implementation
38    ///////////////////////////////
39  
40    public Object createNewModule(NameSpace parent,
41                                  ModuleInstanceDescription miDesc,
42                                  byte strength,
43                                  ScopeNode scope)
44      throws ParseException
45    {
46      xConsole.debug("creating new TranGate");
47      
48      try {
49        if (miDesc.portsVector.size() < 2)
50          throw new ParseException("wrong number of ports");
51        ExpressionDescription port1, port2, control;
52        Enumeration e = miDesc.portsVector.elements();
53        port1 = (ExpressionDescription) e.nextElement();
54        port2 = (ExpressionDescription) e.nextElement();
55        Expression p1, p2, ctrl;
56  
57        if (port1 == null ||  port2 == null) {
58          xConsole.warn(parent.desc.toString(miDesc.lineNo) +
59                        "warning: tran not created: one data port is HiZ");
60          return null;
61        }
62        
63        preparePortExpression(port1);
64        preparePortExpression(port2);
65  
66        if (type == tran || type == rtran) {
67          try {
68            return new TranGate(parent,
69                                (WireSelection)port1.instantiate(parent),
70                                (WireSelection)port2.instantiate(parent),
71                                miDesc, type);
72          } catch (ClassCastException cex) {
73            throw new ParseException("wrong port type: not a lValue");
74          }
75        } else {
76          if (!e.hasMoreElements())
77            throw new ParseException("missing control port");
78          control = (ExpressionDescription) e.nextElement();
79          if (control == null) {
80            xConsole.warn(parent.desc.toString(miDesc.lineNo) +
81                          "warning: tranif? not created: control port is HiZ");
82            return null;
83          }
84          try {
85            return new TranGate(parent, delay,
86                                (WireSelection)port1.instantiate(parent),
87                                (WireSelection)port2.instantiate(parent),
88                                control.instantiate(parent),
89                                miDesc, type);
90          } catch (ClassCastException cex) {
91            throw new ParseException ("wrong port type: not a lValue");
92          }
93        }
94      } catch (ParseException pex) {
95        throw new ParseException(parent.desc.toString(miDesc.lineNo) +
96                                 ": error: "  + pex);
97      }
98    }
99  
100   /**
101    * 
102    */
103   public Object createNewModuleArray(NameSpace parent,
104                                 ModuleInstanceDescription miDesc,
105                                 byte strength,
106                                 ScopeNode scope, int ars, int are,
107                                 int n, int increment)
108     throws ParseException
109   {
110 
111     xConsole.debug("creating new TranGate[]");
112     try {
113             if (miDesc.portsVector.size() < 2)
114         throw new ParseException("wrong number of ports");
115       ExpressionDescription port1, port2, control;
116       Enumeration e = miDesc.portsVector.elements();
117       port1 = (ExpressionDescription) e.nextElement();
118       port2 = (ExpressionDescription) e.nextElement();
119       WireSelection p1, p2;
120 
121       boolean isTran = type == tran || type == rtran;
122 
123       WireSelection portsA[] = new WireSelection[n];
124       WireSelection portsB[] = new WireSelection[n];
125 
126       Monitor m;
127       TranGate trans[] = new TranGate[n];
128 
129       if (port1 == null ||  port2 == null) {
130         xConsole.warn(parent.desc.toString(miDesc.lineNo) +
131                       "warning: tran not created: one data port is HiZ");
132         return null;
133       }
134 
135       preparePortExpression(port1);
136       preparePortExpression(port2);
137       
138       try {
139         p1 = (WireSelection) port1.instantiate(parent);
140       } catch (ClassCastException cex) {
141         throw new ParseException("bad port expression #1: not a net");
142       }
143 
144       try {
145         p2 = (WireSelection) port2.instantiate(parent);
146       } catch (ClassCastException cex) {
147         throw new ParseException("bad port expression #2: not a net");
148       }
149       
150       makeInternalPorts(parent, port1, p1, portsA, n);
151       makeInternalPorts(parent, port2, p2, portsB, n);
152       
153       if (isTran) {
154         try {
155           for (int i = 0; i < n; i++)
156             trans[i] = new TranGate(parent,
157                                     portsA[i],
158                                     portsB[i],
159                                     miDesc, type);
160           return trans;
161         } catch (ClassCastException cex) {
162           throw new ParseException("wrong port type: not a lValue");
163         }
164       } else {
165         Expression ctrls[] = new Expression[n];
166         Expression ctrl = null;
167         
168         if (!e.hasMoreElements())
169           throw new ParseException("missing control port");
170         control = (ExpressionDescription) e.nextElement();
171         if (control == null) {
172           xConsole.warn(parent.desc.toString(miDesc.lineNo) +
173                         "warning: tranif? not created: control port is HiZ");
174           return null;
175         } else
176           ctrl = control.instantiate(parent);
177         
178         if (ctrl.length != 1) {
179           if (ctrl.length != n)
180             throw new ParseException("bad port experssion length for port #3");
181           Wire buffer = new Wire (null, null, Assignable.typeWire,
182                               n - 1, 0,
183                               WireDescription.defaultExpandType,
184                               Delay3.nullDelay());
185           m = MContAssignMonitor.
186             createNewMContAssignMonitor(new ContBitSelect(parent, buffer,
187                                                           null, n-1, 0), ctrl);
188           for (int i = 0; i < n ; i--)
189             ctrls[i] = new BitSelect(parent, buffer, null, i, i);
190         } else {
191           ctrls[0] = ctrl;
192           for (int i = 1; i < n; i++)
193             ctrls[i] = control.instantiate(parent);
194         }
195         for(int i = 0; i < n; i++)
196           trans[i] =  new TranGate(parent, delay,
197                                     portsA[i],
198                                     portsB[i],
199                                     ctrls[i],
200                                     miDesc, type);
201         return trans;
202       }
203     } catch (ParseException pex) {
204       throw new ParseException(parent.desc.toString(miDesc.lineNo) +
205                                ": error: "  + pex);
206     }
207   }
208 
209 
210   void makeInternalPorts(NameSpace parent, ExpressionDescription portDesc,
211                          WireSelection p, WireSelection intern[], int n)
212     throws ParseException
213   {
214     Monitor m;
215     if (p.length != 1) {
216       if (p.length != n)
217         throw new ParseException("bad port experssion length for port #1");
218       p.breakSelection(intern, 0);
219       p.release();
220     } else {
221       intern[0] = p;
222       for (int i = 1; i < n ; i--)
223         intern[i] = (WireSelection) portDesc.instantiate(parent);
224     }
225   }
226                          
227   
228   void preparePortExpression(ExpressionDescription port)
229     throws ParseException
230   {
231     try {
232       ((AssignableSelection)port).toContSelection();
233     } catch (ClassCastException cex) {
234       throw new ParseException("bad port expression \"" +
235                                port + "\" not a net");
236     }
237   }
238 
239 }
240 
241 
242 
243 
244 
245