Merge lp:~danilovesky/workcraft/trunk-verilog-export-translate into lp:workcraft
- trunk-verilog-export-translate
- Merge into trunk
Proposed by
Danil Sokolov
Status: | Merged |
---|---|
Merged at revision: | 667 |
Proposed branch: | lp:~danilovesky/workcraft/trunk-verilog-export-translate |
Merge into: | lp:workcraft |
Diff against target: |
3388 lines (+1990/-643) 18 files modified
CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitSettings.java (+23/-0) CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitUtils.java (+6/-6) CircuitPlugin/src/org/workcraft/plugins/circuit/interop/GenlibImporter.java (+8/-2) CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java (+24/-6) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.java (+191/-121) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.jj (+2/-1) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.java (+266/-171) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.jj (+3/-1) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.java (+315/-0) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.jj (+100/-0) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserConstants.java (+35/-0) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserTokenManager.java (+399/-0) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.java (+482/-327) CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.jj (+1/-1) CircuitPlugin/src/org/workcraft/plugins/circuit/serialisation/VerilogSerialiser.java (+93/-4) CircuitPlugin/src/org/workcraft/plugins/circuit/stg/CircuitToStgConverter.java (+3/-3) CircuitPlugin/src/org/workcraft/plugins/circuit/verilog/SubstitutionRule.java (+16/-0) WorkcraftCore/src/org/workcraft/plugins/shared/CommonDebugSettings.java (+23/-0) |
To merge this branch: | bzr merge lp:~danilovesky/workcraft/trunk-verilog-export-translate |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danil Sokolov | Pending | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitSettings.java' |
2 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitSettings.java 2015-10-29 18:40:12 +0000 |
3 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitSettings.java 2015-11-09 09:38:45 +0000 |
4 | @@ -21,6 +21,7 @@ |
5 | private static final String keyWireWidth = prefix + ".wireWidth"; |
6 | private static final String keySimplifyStg = prefix + ".simplifyStg"; |
7 | private static final String keyGateLibrary = prefix + ".gateLibrary"; |
8 | + private static final String keySubstitutionLibrary = prefix + ".substitutionLibrary"; |
9 | private static final String keyOpenSynthesisResult = prefix + ".openSynthesisResult"; |
10 | |
11 | private static final boolean defaultShowContacts = false; |
12 | @@ -30,6 +31,7 @@ |
13 | private static final Double defaultWireWidth = 0.04; |
14 | private static final boolean defaultSimplifyStg = true; |
15 | private static final String defaultGateLibrary = "tools/petrify/petrify.lib"; |
16 | + private static final String defaultSubstitutionLibrary = ""; |
17 | private static final boolean defaultOpenSynthesisResult = true; |
18 | |
19 | private static boolean showContacts = defaultShowContacts; |
20 | @@ -39,6 +41,7 @@ |
21 | private static Double wireWidth = defaultWireWidth; |
22 | private static boolean simplifyStg = defaultSimplifyStg; |
23 | private static String gateLibrary = defaultGateLibrary; |
24 | + private static String substitutionLibrary = defaultSubstitutionLibrary; |
25 | private static boolean openSynthesisResult = defaultOpenSynthesisResult; |
26 | |
27 | public CircuitSettings() { |
28 | @@ -112,6 +115,16 @@ |
29 | } |
30 | }); |
31 | |
32 | + properties.add(new PropertyDeclaration<CircuitSettings, String>( |
33 | + this, "Substitution rules for export", String.class, true, false, false) { |
34 | + protected void setter(CircuitSettings object, String value) { |
35 | + setSubstitutionLibrary(value); |
36 | + } |
37 | + protected String getter(CircuitSettings object) { |
38 | + return getSubstitutionLibrary(); |
39 | + } |
40 | + }); |
41 | + |
42 | properties.add(new PropertyDeclaration<CircuitSettings, Boolean>( |
43 | this, "Import synthesis result", Boolean.class, true, false, false) { |
44 | protected void setter(CircuitSettings object, Boolean value) { |
45 | @@ -147,6 +160,7 @@ |
46 | setWireWidth(config.getDouble(keyWireWidth, defaultWireWidth)); |
47 | setSimplifyStg(config.getBoolean(keySimplifyStg, defaultSimplifyStg)); |
48 | setGateLibrary(config.getString(keyGateLibrary, defaultGateLibrary)); |
49 | + setSubstitutionLibrary(config.getString(keySubstitutionLibrary, defaultSubstitutionLibrary)); |
50 | setOpenSynthesisResult(config.getBoolean(keyOpenSynthesisResult, defaultOpenSynthesisResult)); |
51 | } |
52 | |
53 | @@ -159,6 +173,7 @@ |
54 | config.setDouble(keyWireWidth, getWireWidth()); |
55 | config.setBoolean(keySimplifyStg, getSimplifyStg()); |
56 | config.set(keyGateLibrary, getGateLibrary()); |
57 | + config.set(keySubstitutionLibrary, getSubstitutionLibrary()); |
58 | config.setBoolean(keyOpenSynthesisResult, getOpenSynthesisResult()); |
59 | } |
60 | |
61 | @@ -217,6 +232,14 @@ |
62 | public static void setGateLibrary(String value) { |
63 | gateLibrary = value; |
64 | } |
65 | + |
66 | + public static String getSubstitutionLibrary() { |
67 | + return substitutionLibrary; |
68 | + } |
69 | + |
70 | + public static void setSubstitutionLibrary(String value) { |
71 | + substitutionLibrary = value; |
72 | + } |
73 | |
74 | public static boolean getOpenSynthesisResult() { |
75 | return openSynthesisResult; |
76 | |
77 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitUtils.java' |
78 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitUtils.java 2015-10-30 19:09:08 +0000 |
79 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/CircuitUtils.java 2015-11-09 09:38:45 +0000 |
80 | @@ -139,14 +139,14 @@ |
81 | return zeroDelayOutput; |
82 | } |
83 | |
84 | - public static Contact findSignal(Circuit circuit, Contact contact) { |
85 | + public static Contact findSignal(Circuit circuit, Contact contact, boolean transparentZeroDelayComponents) { |
86 | Contact result = contact; |
87 | - Contact driver = findDriver(circuit, contact, true); |
88 | + Contact driver = findDriver(circuit, contact, transparentZeroDelayComponents); |
89 | if (driver != null) { |
90 | result = driver; |
91 | for (Contact signal : Hierarchy.getDescendantsOfType(circuit.getRoot(), Contact.class)) { |
92 | if (signal.isPort() && signal.isOutput()) { |
93 | - if (driver == CircuitUtils.findDriver(circuit, signal, true)) { |
94 | + if (driver == CircuitUtils.findDriver(circuit, signal, transparentZeroDelayComponents)) { |
95 | result = signal; |
96 | break; |
97 | } |
98 | @@ -156,15 +156,15 @@ |
99 | return result; |
100 | } |
101 | |
102 | - public static VisualContact findSignal(VisualCircuit circuit, VisualContact contact) { |
103 | - Contact mathSignal = findSignal((Circuit)circuit.getMathModel(), contact.getReferencedContact()); |
104 | + public static VisualContact findSignal(VisualCircuit circuit, VisualContact contact, boolean transparentZeroDelayComponents) { |
105 | + Contact mathSignal = findSignal((Circuit)circuit.getMathModel(), contact.getReferencedContact(), transparentZeroDelayComponents); |
106 | return circuit.getVisualComponent(mathSignal, VisualContact.class); |
107 | } |
108 | |
109 | public static String getWireName(Circuit circuit, Contact contact) { |
110 | String result = null; |
111 | if (!circuit.getPreset(contact).isEmpty() || !circuit.getPostset(contact).isEmpty()) { |
112 | - Contact signal = findSignal(circuit, contact); |
113 | + Contact signal = findSignal(circuit, contact, false); |
114 | result = getContactName(circuit, signal); |
115 | } |
116 | return result; |
117 | |
118 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/interop/GenlibImporter.java' |
119 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/interop/GenlibImporter.java 2015-07-30 15:45:39 +0000 |
120 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/interop/GenlibImporter.java 2015-11-09 09:38:45 +0000 |
121 | @@ -33,6 +33,7 @@ |
122 | import org.workcraft.plugins.circuit.genlib.Library; |
123 | import org.workcraft.plugins.circuit.javacc.GenlibParser; |
124 | import org.workcraft.plugins.circuit.javacc.ParseException; |
125 | +import org.workcraft.plugins.shared.CommonDebugSettings; |
126 | import org.workcraft.workspace.ModelEntry; |
127 | |
128 | public class GenlibImporter implements Importer { |
129 | @@ -54,9 +55,14 @@ |
130 | |
131 | public Circuit importGenlib(InputStream in) throws DeserialisationException { |
132 | final Circuit circuit = new Circuit(); |
133 | - GenlibParser parser = new GenlibParser(in); |
134 | + GenlibParser genlibParser = new GenlibParser(in); |
135 | + if (CommonDebugSettings.getParserTracing()) { |
136 | + genlibParser.enable_tracing(); |
137 | + } else { |
138 | + genlibParser.disable_tracing(); |
139 | + } |
140 | try { |
141 | - Library library = parser.parseGenlib(); |
142 | + Library library = genlibParser.parseGenlib(); |
143 | for (final String name: library.getNames()) { |
144 | final Gate gate = library.get(name); |
145 | GenlibUtils.instantiateGate(gate, null, circuit); |
146 | |
147 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java' |
148 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java 2015-11-02 12:32:29 +0000 |
149 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java 2015-11-09 09:38:45 +0000 |
150 | @@ -128,8 +128,13 @@ |
151 | |
152 | public Circuit importCircuit(InputStream in) throws DeserialisationException { |
153 | try { |
154 | - VerilogParser parser = new VerilogParser(in); |
155 | - HashMap<String, Module> modules = getModuleMap(parser.parseCircuit()); |
156 | + VerilogParser verilogParser = new VerilogParser(in); |
157 | + if (CommonDebugSettings.getParserTracing()) { |
158 | + verilogParser.enable_tracing(); |
159 | + } else { |
160 | + verilogParser.disable_tracing(); |
161 | + } |
162 | + HashMap<String, Module> modules = getModuleMap(verilogParser.parseCircuit()); |
163 | HashSet<Module> topModules = getTopModule(modules); |
164 | if (topModules.size() == 0) { |
165 | throw new RuntimeException("No top module found."); |
166 | @@ -214,6 +219,7 @@ |
167 | |
168 | private Circuit createCircuit(Module topModule, HashMap<String, Module> modules) { |
169 | Circuit circuit = new Circuit(); |
170 | + circuit.setTitle(topModule.name); |
171 | HashMap<Instance, FunctionComponent> instanceComponentMap = new HashMap<>(); |
172 | HashMap<String, Wire> wires = createPorts(circuit, topModule); |
173 | for (Assign assign: topModule.assigns) { |
174 | @@ -363,10 +369,15 @@ |
175 | |
176 | private Expression convertStringToExpression(String formula) { |
177 | InputStream expressionStream = new ByteArrayInputStream(formula.getBytes()); |
178 | - ExpressionParser parser = new ExpressionParser(expressionStream); |
179 | + ExpressionParser expressionParser = new ExpressionParser(expressionStream); |
180 | + if (CommonDebugSettings.getParserTracing()) { |
181 | + expressionParser.enable_tracing(); |
182 | + } else { |
183 | + expressionParser.disable_tracing(); |
184 | + } |
185 | Expression expression = null; |
186 | try { |
187 | - expression = parser.parseExpression(); |
188 | + expression = expressionParser.parseExpression(); |
189 | } catch (ParseException e1) { |
190 | System.out.println("Warning: could not parse assign expression '" + formula + "'."); |
191 | } |
192 | @@ -383,8 +394,15 @@ |
193 | final Framework framework = Framework.getInstance(); |
194 | if (framework.checkFile(libraryFile, "Gate library access error")) { |
195 | try { |
196 | - InputStream genlibInputStream = new FileInputStream(CircuitSettings.getGateLibrary()); |
197 | - library = new GenlibParser(genlibInputStream).parseGenlib(); |
198 | + InputStream genlibInputStream = new FileInputStream(libraryFileName); |
199 | + GenlibParser genlibParser = new GenlibParser(genlibInputStream); |
200 | + if (CommonDebugSettings.getParserTracing()) { |
201 | + genlibParser.enable_tracing(); |
202 | + } else { |
203 | + genlibParser.disable_tracing(); |
204 | + } |
205 | + library = genlibParser.parseGenlib(); |
206 | + System.out.println("Info: mapping the imported Verilog into the gate library '" + libraryFileName + "'."); |
207 | } catch (FileNotFoundException e) { |
208 | } catch (ParseException e) { |
209 | System.out.println("Warning: could not parse the gate library '" + libraryFileName + "'."); |
210 | |
211 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.java' |
212 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.java 2015-10-22 16:04:43 +0000 |
213 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.java 2015-11-09 09:38:45 +0000 |
214 | @@ -24,172 +24,197 @@ |
215 | public class ExpressionParser implements ExpressionParserConstants { |
216 | |
217 | final public Expression parseExpression() throws ParseException { |
218 | + trace_call("parseExpression"); |
219 | + try { |
220 | Expression term; |
221 | List<Expression> terms = new LinkedList<Expression>(); |
222 | - term = parseTerm(); |
223 | + term = parseTerm(); |
224 | terms.add(term); |
225 | - label_1: |
226 | - while (true) { |
227 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
228 | - case 9: |
229 | - case 10: |
230 | - case 11: |
231 | - ; |
232 | - break; |
233 | - default: |
234 | - jj_la1[0] = jj_gen; |
235 | - break label_1; |
236 | - } |
237 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
238 | - case 9: |
239 | - jj_consume_token(9); |
240 | - break; |
241 | - case 10: |
242 | - jj_consume_token(10); |
243 | - break; |
244 | - case 11: |
245 | - jj_consume_token(11); |
246 | - break; |
247 | - default: |
248 | - jj_la1[1] = jj_gen; |
249 | - jj_consume_token(-1); |
250 | - throw new ParseException(); |
251 | - } |
252 | - term = parseTerm(); |
253 | + label_1: |
254 | + while (true) { |
255 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
256 | + case 9: |
257 | + case 10: |
258 | + case 11: |
259 | + ; |
260 | + break; |
261 | + default: |
262 | + jj_la1[0] = jj_gen; |
263 | + break label_1; |
264 | + } |
265 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
266 | + case 9: |
267 | + jj_consume_token(9); |
268 | + break; |
269 | + case 10: |
270 | + jj_consume_token(10); |
271 | + break; |
272 | + case 11: |
273 | + jj_consume_token(11); |
274 | + break; |
275 | + default: |
276 | + jj_la1[1] = jj_gen; |
277 | + jj_consume_token(-1); |
278 | + throw new ParseException(); |
279 | + } |
280 | + term = parseTerm(); |
281 | terms.add(term); |
282 | - } |
283 | + } |
284 | if (terms.size() > 1) { |
285 | {if (true) return new Formula(terms);} |
286 | } else { |
287 | {if (true) return term;} |
288 | } |
289 | throw new Error("Missing return statement in function"); |
290 | + } finally { |
291 | + trace_return("parseExpression"); |
292 | + } |
293 | } |
294 | |
295 | final public Expression parseTerm() throws ParseException { |
296 | + trace_call("parseTerm"); |
297 | + try { |
298 | Expression factor; |
299 | List<Expression> factors = new LinkedList<Expression>(); |
300 | - factor = parseFactor(); |
301 | + factor = parseFactor(); |
302 | factors.add(factor); |
303 | - label_2: |
304 | - while (true) { |
305 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
306 | - case CONST0: |
307 | - case CONST1: |
308 | - case NAME: |
309 | - case 12: |
310 | - case 13: |
311 | - case 14: |
312 | - case 15: |
313 | - case 16: |
314 | - case 17: |
315 | - ; |
316 | - break; |
317 | - default: |
318 | - jj_la1[2] = jj_gen; |
319 | - break label_2; |
320 | - } |
321 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
322 | - case 12: |
323 | - case 13: |
324 | - case 14: |
325 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
326 | - case 12: |
327 | - jj_consume_token(12); |
328 | - break; |
329 | - case 13: |
330 | - jj_consume_token(13); |
331 | - break; |
332 | - case 14: |
333 | - jj_consume_token(14); |
334 | - break; |
335 | - default: |
336 | - jj_la1[3] = jj_gen; |
337 | - jj_consume_token(-1); |
338 | - throw new ParseException(); |
339 | - } |
340 | - break; |
341 | - default: |
342 | - jj_la1[4] = jj_gen; |
343 | - ; |
344 | - } |
345 | - factor = parseFactor(); |
346 | + label_2: |
347 | + while (true) { |
348 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
349 | + case CONST0: |
350 | + case CONST1: |
351 | + case NAME: |
352 | + case 12: |
353 | + case 13: |
354 | + case 14: |
355 | + case 15: |
356 | + case 16: |
357 | + case 17: |
358 | + ; |
359 | + break; |
360 | + default: |
361 | + jj_la1[2] = jj_gen; |
362 | + break label_2; |
363 | + } |
364 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
365 | + case 12: |
366 | + case 13: |
367 | + case 14: |
368 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
369 | + case 12: |
370 | + jj_consume_token(12); |
371 | + break; |
372 | + case 13: |
373 | + jj_consume_token(13); |
374 | + break; |
375 | + case 14: |
376 | + jj_consume_token(14); |
377 | + break; |
378 | + default: |
379 | + jj_la1[3] = jj_gen; |
380 | + jj_consume_token(-1); |
381 | + throw new ParseException(); |
382 | + } |
383 | + break; |
384 | + default: |
385 | + jj_la1[4] = jj_gen; |
386 | + ; |
387 | + } |
388 | + factor = parseFactor(); |
389 | factors.add(factor); |
390 | - } |
391 | + } |
392 | if (factors.size() > 1) { |
393 | {if (true) return new Term(factors);} |
394 | } else { |
395 | {if (true) return factor;} |
396 | } |
397 | throw new Error("Missing return statement in function"); |
398 | + } finally { |
399 | + trace_return("parseTerm"); |
400 | + } |
401 | } |
402 | |
403 | final public Expression parseFactor() throws ParseException { |
404 | + trace_call("parseFactor"); |
405 | + try { |
406 | Expression expression; |
407 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
408 | - case NAME: |
409 | - expression = parseLiteral(); |
410 | - break; |
411 | - case CONST0: |
412 | - case CONST1: |
413 | - expression = parseConstant(); |
414 | - break; |
415 | - case 15: |
416 | - case 16: |
417 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
418 | + case NAME: |
419 | + expression = parseLiteral(); |
420 | + break; |
421 | + case CONST0: |
422 | + case CONST1: |
423 | + expression = parseConstant(); |
424 | + break; |
425 | case 15: |
426 | - jj_consume_token(15); |
427 | - break; |
428 | case 16: |
429 | - jj_consume_token(16); |
430 | - break; |
431 | - default: |
432 | - jj_la1[5] = jj_gen; |
433 | - jj_consume_token(-1); |
434 | - throw new ParseException(); |
435 | - } |
436 | - expression = parseFactor(); |
437 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
438 | + case 15: |
439 | + jj_consume_token(15); |
440 | + break; |
441 | + case 16: |
442 | + jj_consume_token(16); |
443 | + break; |
444 | + default: |
445 | + jj_la1[5] = jj_gen; |
446 | + jj_consume_token(-1); |
447 | + throw new ParseException(); |
448 | + } |
449 | + expression = parseFactor(); |
450 | {if (true) return new Negation(expression);} |
451 | - break; |
452 | - case 17: |
453 | - jj_consume_token(17); |
454 | - expression = parseExpression(); |
455 | - jj_consume_token(18); |
456 | + break; |
457 | + case 17: |
458 | + jj_consume_token(17); |
459 | + expression = parseExpression(); |
460 | + jj_consume_token(18); |
461 | {if (true) return new Factor(expression);} |
462 | - break; |
463 | - default: |
464 | - jj_la1[6] = jj_gen; |
465 | - jj_consume_token(-1); |
466 | - throw new ParseException(); |
467 | - } |
468 | + break; |
469 | + default: |
470 | + jj_la1[6] = jj_gen; |
471 | + jj_consume_token(-1); |
472 | + throw new ParseException(); |
473 | + } |
474 | {if (true) return expression;} |
475 | throw new Error("Missing return statement in function"); |
476 | + } finally { |
477 | + trace_return("parseFactor"); |
478 | + } |
479 | } |
480 | |
481 | final public Expression parseLiteral() throws ParseException { |
482 | + trace_call("parseLiteral"); |
483 | + try { |
484 | Token nameToken; |
485 | - nameToken = jj_consume_token(NAME); |
486 | + nameToken = jj_consume_token(NAME); |
487 | String name = nameToken.image; |
488 | {if (true) return new Literal(name);} |
489 | throw new Error("Missing return statement in function"); |
490 | + } finally { |
491 | + trace_return("parseLiteral"); |
492 | + } |
493 | } |
494 | |
495 | final public Expression parseConstant() throws ParseException { |
496 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
497 | - case CONST0: |
498 | - jj_consume_token(CONST0); |
499 | + trace_call("parseConstant"); |
500 | + try { |
501 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
502 | + case CONST0: |
503 | + jj_consume_token(CONST0); |
504 | {if (true) return new Constant(false);} |
505 | - break; |
506 | - case CONST1: |
507 | - jj_consume_token(CONST1); |
508 | + break; |
509 | + case CONST1: |
510 | + jj_consume_token(CONST1); |
511 | {if (true) return new Constant(true);} |
512 | - break; |
513 | - default: |
514 | - jj_la1[7] = jj_gen; |
515 | - jj_consume_token(-1); |
516 | - throw new ParseException(); |
517 | + break; |
518 | + default: |
519 | + jj_la1[7] = jj_gen; |
520 | + jj_consume_token(-1); |
521 | + throw new ParseException(); |
522 | + } |
523 | + throw new Error("Missing return statement in function"); |
524 | + } finally { |
525 | + trace_return("parseConstant"); |
526 | } |
527 | - throw new Error("Missing return statement in function"); |
528 | } |
529 | |
530 | /** Generated Token Manager. */ |
531 | @@ -283,6 +308,7 @@ |
532 | jj_ntk = -1; |
533 | if (token.kind == kind) { |
534 | jj_gen++; |
535 | + trace_token(token, ""); |
536 | return token; |
537 | } |
538 | token = oldToken; |
539 | @@ -297,6 +323,7 @@ |
540 | else token = token.next = token_source.getNextToken(); |
541 | jj_ntk = -1; |
542 | jj_gen++; |
543 | + trace_token(token, " (in getNextToken)"); |
544 | return token; |
545 | } |
546 | |
547 | @@ -352,12 +379,55 @@ |
548 | return new ParseException(token, exptokseq, tokenImage); |
549 | } |
550 | |
551 | - /** Enable tracing. */ |
552 | + private int trace_indent = 0; |
553 | + private boolean trace_enabled = true; |
554 | + |
555 | +/** Enable tracing. */ |
556 | final public void enable_tracing() { |
557 | + trace_enabled = true; |
558 | } |
559 | |
560 | - /** Disable tracing. */ |
561 | +/** Disable tracing. */ |
562 | final public void disable_tracing() { |
563 | + trace_enabled = false; |
564 | + } |
565 | + |
566 | + private void trace_call(String s) { |
567 | + if (trace_enabled) { |
568 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
569 | + System.out.println("Call: " + s); |
570 | + } |
571 | + trace_indent = trace_indent + 2; |
572 | + } |
573 | + |
574 | + private void trace_return(String s) { |
575 | + trace_indent = trace_indent - 2; |
576 | + if (trace_enabled) { |
577 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
578 | + System.out.println("Return: " + s); |
579 | + } |
580 | + } |
581 | + |
582 | + private void trace_token(Token t, String where) { |
583 | + if (trace_enabled) { |
584 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
585 | + System.out.print("Consumed token: <" + tokenImage[t.kind]); |
586 | + if (t.kind != 0 && !tokenImage[t.kind].equals("\"" + t.image + "\"")) { |
587 | + System.out.print(": \"" + t.image + "\""); |
588 | + } |
589 | + System.out.println(" at line " + t.beginLine + " column " + t.beginColumn + ">" + where); |
590 | + } |
591 | + } |
592 | + |
593 | + private void trace_scan(Token t1, int t2) { |
594 | + if (trace_enabled) { |
595 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
596 | + System.out.print("Visited token: <" + tokenImage[t1.kind]); |
597 | + if (t1.kind != 0 && !tokenImage[t1.kind].equals("\"" + t1.image + "\"")) { |
598 | + System.out.print(": \"" + t1.image + "\""); |
599 | + } |
600 | + System.out.println(" at line " + t1.beginLine + " column " + t1.beginColumn + ">; Expected token: <" + tokenImage[t2] + ">"); |
601 | + } |
602 | } |
603 | |
604 | } |
605 | |
606 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.jj' |
607 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.jj 2015-10-22 16:04:43 +0000 |
608 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/ExpressionParser.jj 2015-11-09 09:38:45 +0000 |
609 | @@ -6,7 +6,8 @@ |
610 | JDK_VERSION = "1.7"; |
611 | LOOKAHEAD = 1; |
612 | STATIC = false; |
613 | - DEBUG_PARSER = false; |
614 | + DEBUG_PARSER = true; |
615 | + DEBUG_LOOKAHEAD = false; |
616 | DEBUG_TOKEN_MANAGER = false; |
617 | } |
618 | |
619 | |
620 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.java' |
621 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.java 2015-10-19 17:34:06 +0000 |
622 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.java 2015-11-09 09:38:45 +0000 |
623 | @@ -20,241 +20,291 @@ |
624 | public class GenlibParser implements GenlibParserConstants { |
625 | |
626 | final public Library parseGenlib() throws ParseException { |
627 | + trace_call("parseGenlib"); |
628 | + try { |
629 | List<Gate> gates; |
630 | - gates = parseGates(); |
631 | + gates = parseGates(); |
632 | {if (true) return new Library(gates);} |
633 | throw new Error("Missing return statement in function"); |
634 | + } finally { |
635 | + trace_return("parseGenlib"); |
636 | + } |
637 | } |
638 | |
639 | final public List<Gate> parseGates() throws ParseException { |
640 | + trace_call("parseGates"); |
641 | + try { |
642 | Gate gate; |
643 | List<Gate> gates = new LinkedList<Gate>(); |
644 | - label_1: |
645 | - while (true) { |
646 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
647 | - case GATE: |
648 | - case LATCH: |
649 | - ; |
650 | - break; |
651 | - default: |
652 | - jj_la1[0] = jj_gen; |
653 | - break label_1; |
654 | - } |
655 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
656 | - case GATE: |
657 | - gate = parseGate(); |
658 | - break; |
659 | - case LATCH: |
660 | - gate = parseLatch(); |
661 | - break; |
662 | - default: |
663 | - jj_la1[1] = jj_gen; |
664 | - jj_consume_token(-1); |
665 | - throw new ParseException(); |
666 | - } |
667 | + label_1: |
668 | + while (true) { |
669 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
670 | + case GATE: |
671 | + case LATCH: |
672 | + ; |
673 | + break; |
674 | + default: |
675 | + jj_la1[0] = jj_gen; |
676 | + break label_1; |
677 | + } |
678 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
679 | + case GATE: |
680 | + gate = parseGate(); |
681 | + break; |
682 | + case LATCH: |
683 | + gate = parseLatch(); |
684 | + break; |
685 | + default: |
686 | + jj_la1[1] = jj_gen; |
687 | + jj_consume_token(-1); |
688 | + throw new ParseException(); |
689 | + } |
690 | gates.add(gate); |
691 | - } |
692 | + } |
693 | {if (true) return gates;} |
694 | throw new Error("Missing return statement in function"); |
695 | + } finally { |
696 | + trace_return("parseGates"); |
697 | + } |
698 | } |
699 | |
700 | final public Gate parseGate() throws ParseException { |
701 | + trace_call("parseGate"); |
702 | + try { |
703 | String name; |
704 | Function function; |
705 | - jj_consume_token(GATE); |
706 | - name = parseName(); |
707 | - jj_consume_token(NUMERAL); |
708 | - function = parseFunction(); |
709 | - label_2: |
710 | - while (true) { |
711 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
712 | - case PIN: |
713 | - ; |
714 | - break; |
715 | - default: |
716 | - jj_la1[2] = jj_gen; |
717 | - break label_2; |
718 | + jj_consume_token(GATE); |
719 | + name = parseName(); |
720 | + jj_consume_token(NUMERAL); |
721 | + function = parseFunction(); |
722 | + label_2: |
723 | + while (true) { |
724 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
725 | + case PIN: |
726 | + ; |
727 | + break; |
728 | + default: |
729 | + jj_la1[2] = jj_gen; |
730 | + break label_2; |
731 | + } |
732 | + parsePin(); |
733 | } |
734 | - parsePin(); |
735 | - } |
736 | {if (true) return new Gate(name, function, null, false);} |
737 | throw new Error("Missing return statement in function"); |
738 | + } finally { |
739 | + trace_return("parseGate"); |
740 | + } |
741 | } |
742 | |
743 | final public Gate parseLatch() throws ParseException { |
744 | + trace_call("parseLatch"); |
745 | + try { |
746 | String name; |
747 | Function function; |
748 | String next; |
749 | - jj_consume_token(LATCH); |
750 | - name = parseName(); |
751 | - jj_consume_token(NUMERAL); |
752 | - function = parseFunction(); |
753 | - label_3: |
754 | - while (true) { |
755 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
756 | - case PIN: |
757 | - ; |
758 | - break; |
759 | - default: |
760 | - jj_la1[3] = jj_gen; |
761 | - break label_3; |
762 | - } |
763 | - parsePin(); |
764 | - } |
765 | - next = parseSeq(); |
766 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
767 | - case CONTROL: |
768 | - parseControl(); |
769 | - break; |
770 | - default: |
771 | - jj_la1[4] = jj_gen; |
772 | - ; |
773 | - } |
774 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
775 | - case CONSTRAINT: |
776 | - parseConstraint(); |
777 | - break; |
778 | - default: |
779 | - jj_la1[5] = jj_gen; |
780 | - ; |
781 | - } |
782 | + jj_consume_token(LATCH); |
783 | + name = parseName(); |
784 | + jj_consume_token(NUMERAL); |
785 | + function = parseFunction(); |
786 | + label_3: |
787 | + while (true) { |
788 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
789 | + case PIN: |
790 | + ; |
791 | + break; |
792 | + default: |
793 | + jj_la1[3] = jj_gen; |
794 | + break label_3; |
795 | + } |
796 | + parsePin(); |
797 | + } |
798 | + next = parseSeq(); |
799 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
800 | + case CONTROL: |
801 | + parseControl(); |
802 | + break; |
803 | + default: |
804 | + jj_la1[4] = jj_gen; |
805 | + ; |
806 | + } |
807 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
808 | + case CONSTRAINT: |
809 | + parseConstraint(); |
810 | + break; |
811 | + default: |
812 | + jj_la1[5] = jj_gen; |
813 | + ; |
814 | + } |
815 | {if (true) return new Gate(name, function, next, false);} |
816 | throw new Error("Missing return statement in function"); |
817 | + } finally { |
818 | + trace_return("parseLatch"); |
819 | + } |
820 | } |
821 | |
822 | final public String parseName() throws ParseException { |
823 | + trace_call("parseName"); |
824 | + try { |
825 | Token nameToken; |
826 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
827 | - case NAME: |
828 | - nameToken = jj_consume_token(NAME); |
829 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
830 | + case NAME: |
831 | + nameToken = jj_consume_token(NAME); |
832 | {if (true) return nameToken.image;} |
833 | - break; |
834 | - case STRING: |
835 | - nameToken = jj_consume_token(STRING); |
836 | + break; |
837 | + case STRING: |
838 | + nameToken = jj_consume_token(STRING); |
839 | String s = nameToken.image; |
840 | {if (true) return s.substring(1, s.length()-1);} |
841 | - break; |
842 | - default: |
843 | - jj_la1[6] = jj_gen; |
844 | - jj_consume_token(-1); |
845 | - throw new ParseException(); |
846 | + break; |
847 | + default: |
848 | + jj_la1[6] = jj_gen; |
849 | + jj_consume_token(-1); |
850 | + throw new ParseException(); |
851 | + } |
852 | + throw new Error("Missing return statement in function"); |
853 | + } finally { |
854 | + trace_return("parseName"); |
855 | } |
856 | - throw new Error("Missing return statement in function"); |
857 | } |
858 | |
859 | final public Function parseFunction() throws ParseException { |
860 | + trace_call("parseFunction"); |
861 | + try { |
862 | Token nameToken; |
863 | Token formulaToken; |
864 | - nameToken = jj_consume_token(NAME); |
865 | - formulaToken = jj_consume_token(FORMULA); |
866 | + nameToken = jj_consume_token(NAME); |
867 | + formulaToken = jj_consume_token(FORMULA); |
868 | String formula = formulaToken.image.replaceAll("^=", "").replaceAll(";$", ""); |
869 | {if (true) return new Function(nameToken.image, formula);} |
870 | throw new Error("Missing return statement in function"); |
871 | + } finally { |
872 | + trace_return("parseFunction"); |
873 | + } |
874 | } |
875 | |
876 | final public void parsePin() throws ParseException { |
877 | - jj_consume_token(PIN); |
878 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
879 | - case NAME: |
880 | - jj_consume_token(NAME); |
881 | - break; |
882 | - case ANY_NAME: |
883 | - jj_consume_token(ANY_NAME); |
884 | - break; |
885 | - default: |
886 | - jj_la1[7] = jj_gen; |
887 | - jj_consume_token(-1); |
888 | - throw new ParseException(); |
889 | - } |
890 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
891 | - case INV: |
892 | - case NONINV: |
893 | - case UNKNOWN: |
894 | + trace_call("parsePin"); |
895 | + try { |
896 | + jj_consume_token(PIN); |
897 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
898 | + case NAME: |
899 | + jj_consume_token(NAME); |
900 | + break; |
901 | + case ANY_NAME: |
902 | + jj_consume_token(ANY_NAME); |
903 | + break; |
904 | + default: |
905 | + jj_la1[7] = jj_gen; |
906 | + jj_consume_token(-1); |
907 | + throw new ParseException(); |
908 | + } |
909 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
910 | case INV: |
911 | - jj_consume_token(INV); |
912 | - break; |
913 | case NONINV: |
914 | - jj_consume_token(NONINV); |
915 | - break; |
916 | case UNKNOWN: |
917 | - jj_consume_token(UNKNOWN); |
918 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
919 | + case INV: |
920 | + jj_consume_token(INV); |
921 | + break; |
922 | + case NONINV: |
923 | + jj_consume_token(NONINV); |
924 | + break; |
925 | + case UNKNOWN: |
926 | + jj_consume_token(UNKNOWN); |
927 | + break; |
928 | + default: |
929 | + jj_la1[8] = jj_gen; |
930 | + jj_consume_token(-1); |
931 | + throw new ParseException(); |
932 | + } |
933 | break; |
934 | default: |
935 | - jj_la1[8] = jj_gen; |
936 | - jj_consume_token(-1); |
937 | - throw new ParseException(); |
938 | + jj_la1[9] = jj_gen; |
939 | + ; |
940 | } |
941 | - break; |
942 | - default: |
943 | - jj_la1[9] = jj_gen; |
944 | - ; |
945 | + jj_consume_token(NUMERAL); |
946 | + jj_consume_token(NUMERAL); |
947 | + jj_consume_token(NUMERAL); |
948 | + jj_consume_token(NUMERAL); |
949 | + jj_consume_token(NUMERAL); |
950 | + jj_consume_token(NUMERAL); |
951 | + } finally { |
952 | + trace_return("parsePin"); |
953 | } |
954 | - jj_consume_token(NUMERAL); |
955 | - jj_consume_token(NUMERAL); |
956 | - jj_consume_token(NUMERAL); |
957 | - jj_consume_token(NUMERAL); |
958 | - jj_consume_token(NUMERAL); |
959 | - jj_consume_token(NUMERAL); |
960 | } |
961 | |
962 | final public String parseSeq() throws ParseException { |
963 | + trace_call("parseSeq"); |
964 | + try { |
965 | Token nextToken = null; |
966 | - jj_consume_token(SEQ); |
967 | - jj_consume_token(NAME); |
968 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
969 | - case NAME: |
970 | - nextToken = jj_consume_token(NAME); |
971 | - break; |
972 | - case ANY: |
973 | - jj_consume_token(ANY); |
974 | - break; |
975 | - default: |
976 | - jj_la1[10] = jj_gen; |
977 | - jj_consume_token(-1); |
978 | - throw new ParseException(); |
979 | - } |
980 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
981 | - case ACTIVE_LOW: |
982 | - jj_consume_token(ACTIVE_LOW); |
983 | - break; |
984 | - case ACTIVE_HIGH: |
985 | - jj_consume_token(ACTIVE_HIGH); |
986 | - break; |
987 | - case RISING_EDGE: |
988 | - jj_consume_token(RISING_EDGE); |
989 | - break; |
990 | - case FALLING_EDGE: |
991 | - jj_consume_token(FALLING_EDGE); |
992 | - break; |
993 | - case ASYNCH: |
994 | - jj_consume_token(ASYNCH); |
995 | - break; |
996 | - default: |
997 | - jj_la1[11] = jj_gen; |
998 | - jj_consume_token(-1); |
999 | - throw new ParseException(); |
1000 | - } |
1001 | + jj_consume_token(SEQ); |
1002 | + jj_consume_token(NAME); |
1003 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
1004 | + case NAME: |
1005 | + nextToken = jj_consume_token(NAME); |
1006 | + break; |
1007 | + case ANY: |
1008 | + jj_consume_token(ANY); |
1009 | + break; |
1010 | + default: |
1011 | + jj_la1[10] = jj_gen; |
1012 | + jj_consume_token(-1); |
1013 | + throw new ParseException(); |
1014 | + } |
1015 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
1016 | + case ACTIVE_LOW: |
1017 | + jj_consume_token(ACTIVE_LOW); |
1018 | + break; |
1019 | + case ACTIVE_HIGH: |
1020 | + jj_consume_token(ACTIVE_HIGH); |
1021 | + break; |
1022 | + case RISING_EDGE: |
1023 | + jj_consume_token(RISING_EDGE); |
1024 | + break; |
1025 | + case FALLING_EDGE: |
1026 | + jj_consume_token(FALLING_EDGE); |
1027 | + break; |
1028 | + case ASYNCH: |
1029 | + jj_consume_token(ASYNCH); |
1030 | + break; |
1031 | + default: |
1032 | + jj_la1[11] = jj_gen; |
1033 | + jj_consume_token(-1); |
1034 | + throw new ParseException(); |
1035 | + } |
1036 | {if (true) return ((nextToken == null) ? null : nextToken.image);} |
1037 | throw new Error("Missing return statement in function"); |
1038 | + } finally { |
1039 | + trace_return("parseSeq"); |
1040 | + } |
1041 | } |
1042 | |
1043 | final public void parseControl() throws ParseException { |
1044 | - jj_consume_token(CONTROL); |
1045 | - jj_consume_token(NAME); |
1046 | - jj_consume_token(NUMERAL); |
1047 | - jj_consume_token(NUMERAL); |
1048 | - jj_consume_token(NUMERAL); |
1049 | - jj_consume_token(NUMERAL); |
1050 | - jj_consume_token(NUMERAL); |
1051 | - jj_consume_token(NUMERAL); |
1052 | + trace_call("parseControl"); |
1053 | + try { |
1054 | + jj_consume_token(CONTROL); |
1055 | + jj_consume_token(NAME); |
1056 | + jj_consume_token(NUMERAL); |
1057 | + jj_consume_token(NUMERAL); |
1058 | + jj_consume_token(NUMERAL); |
1059 | + jj_consume_token(NUMERAL); |
1060 | + jj_consume_token(NUMERAL); |
1061 | + jj_consume_token(NUMERAL); |
1062 | + } finally { |
1063 | + trace_return("parseControl"); |
1064 | + } |
1065 | } |
1066 | |
1067 | final public void parseConstraint() throws ParseException { |
1068 | - jj_consume_token(CONSTRAINT); |
1069 | - jj_consume_token(NAME); |
1070 | - jj_consume_token(NUMERAL); |
1071 | - jj_consume_token(NUMERAL); |
1072 | + trace_call("parseConstraint"); |
1073 | + try { |
1074 | + jj_consume_token(CONSTRAINT); |
1075 | + jj_consume_token(NAME); |
1076 | + jj_consume_token(NUMERAL); |
1077 | + jj_consume_token(NUMERAL); |
1078 | + } finally { |
1079 | + trace_return("parseConstraint"); |
1080 | + } |
1081 | } |
1082 | |
1083 | /** Generated Token Manager. */ |
1084 | @@ -348,6 +398,7 @@ |
1085 | jj_ntk = -1; |
1086 | if (token.kind == kind) { |
1087 | jj_gen++; |
1088 | + trace_token(token, ""); |
1089 | return token; |
1090 | } |
1091 | token = oldToken; |
1092 | @@ -362,6 +413,7 @@ |
1093 | else token = token.next = token_source.getNextToken(); |
1094 | jj_ntk = -1; |
1095 | jj_gen++; |
1096 | + trace_token(token, " (in getNextToken)"); |
1097 | return token; |
1098 | } |
1099 | |
1100 | @@ -417,12 +469,55 @@ |
1101 | return new ParseException(token, exptokseq, tokenImage); |
1102 | } |
1103 | |
1104 | - /** Enable tracing. */ |
1105 | + private int trace_indent = 0; |
1106 | + private boolean trace_enabled = true; |
1107 | + |
1108 | +/** Enable tracing. */ |
1109 | final public void enable_tracing() { |
1110 | + trace_enabled = true; |
1111 | } |
1112 | |
1113 | - /** Disable tracing. */ |
1114 | +/** Disable tracing. */ |
1115 | final public void disable_tracing() { |
1116 | + trace_enabled = false; |
1117 | + } |
1118 | + |
1119 | + private void trace_call(String s) { |
1120 | + if (trace_enabled) { |
1121 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1122 | + System.out.println("Call: " + s); |
1123 | + } |
1124 | + trace_indent = trace_indent + 2; |
1125 | + } |
1126 | + |
1127 | + private void trace_return(String s) { |
1128 | + trace_indent = trace_indent - 2; |
1129 | + if (trace_enabled) { |
1130 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1131 | + System.out.println("Return: " + s); |
1132 | + } |
1133 | + } |
1134 | + |
1135 | + private void trace_token(Token t, String where) { |
1136 | + if (trace_enabled) { |
1137 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1138 | + System.out.print("Consumed token: <" + tokenImage[t.kind]); |
1139 | + if (t.kind != 0 && !tokenImage[t.kind].equals("\"" + t.image + "\"")) { |
1140 | + System.out.print(": \"" + t.image + "\""); |
1141 | + } |
1142 | + System.out.println(" at line " + t.beginLine + " column " + t.beginColumn + ">" + where); |
1143 | + } |
1144 | + } |
1145 | + |
1146 | + private void trace_scan(Token t1, int t2) { |
1147 | + if (trace_enabled) { |
1148 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1149 | + System.out.print("Visited token: <" + tokenImage[t1.kind]); |
1150 | + if (t1.kind != 0 && !tokenImage[t1.kind].equals("\"" + t1.image + "\"")) { |
1151 | + System.out.print(": \"" + t1.image + "\""); |
1152 | + } |
1153 | + System.out.println(" at line " + t1.beginLine + " column " + t1.beginColumn + ">; Expected token: <" + tokenImage[t2] + ">"); |
1154 | + } |
1155 | } |
1156 | |
1157 | } |
1158 | |
1159 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.jj' |
1160 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.jj 2015-10-19 17:34:06 +0000 |
1161 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/GenlibParser.jj 2015-11-09 09:38:45 +0000 |
1162 | @@ -6,7 +6,9 @@ |
1163 | JDK_VERSION = "1.7"; |
1164 | LOOKAHEAD = 1; |
1165 | STATIC = false; |
1166 | - DEBUG_PARSER = false; |
1167 | + DEBUG_PARSER = true; |
1168 | + DEBUG_LOOKAHEAD = false; |
1169 | + DEBUG_TOKEN_MANAGER = false; |
1170 | } |
1171 | |
1172 | PARSER_BEGIN(GenlibParser) |
1173 | |
1174 | === added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.java' |
1175 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.java 1970-01-01 00:00:00 +0000 |
1176 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.java 2015-11-09 09:38:45 +0000 |
1177 | @@ -0,0 +1,315 @@ |
1178 | +/* Generated By:JavaCC: Do not edit this line. SubstitutionParser.java */ |
1179 | +package org.workcraft.plugins.circuit.javacc; |
1180 | + |
1181 | +import java.util.List; |
1182 | +import java.util.LinkedList; |
1183 | +import java.util.Map; |
1184 | +import java.util.HashMap; |
1185 | + |
1186 | +import org.workcraft.util.Pair; |
1187 | +import org.workcraft.plugins.circuit.verilog.SubstitutionRule; |
1188 | + |
1189 | +public class SubstitutionParser implements SubstitutionParserConstants { |
1190 | + |
1191 | + final public List<SubstitutionRule> parseSubstitutionRules() throws ParseException { |
1192 | + trace_call("parseSubstitutionRules"); |
1193 | + try { |
1194 | + SubstitutionRule rule; |
1195 | + List<SubstitutionRule> rules = new LinkedList<SubstitutionRule>(); |
1196 | + label_1: |
1197 | + while (true) { |
1198 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
1199 | + case EXTENDED_NAME: |
1200 | + ; |
1201 | + break; |
1202 | + default: |
1203 | + jj_la1[0] = jj_gen; |
1204 | + break label_1; |
1205 | + } |
1206 | + rule = parseSubstitutionRule(); |
1207 | + rules.add(rule); |
1208 | + } |
1209 | + {if (true) return rules;} |
1210 | + throw new Error("Missing return statement in function"); |
1211 | + } finally { |
1212 | + trace_return("parseSubstitutionRules"); |
1213 | + } |
1214 | + } |
1215 | + |
1216 | + final public SubstitutionRule parseSubstitutionRule() throws ParseException { |
1217 | + trace_call("parseSubstitutionRule"); |
1218 | + try { |
1219 | + Pair<String, String> gateSubstitution; |
1220 | + Pair<String, String> portSubstitution; |
1221 | + Map<String, String> portSubstitutions = new HashMap<String, String>(); |
1222 | + gateSubstitution = parseSubstitution(); |
1223 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
1224 | + case 8: |
1225 | + jj_consume_token(8); |
1226 | + label_2: |
1227 | + while (true) { |
1228 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
1229 | + case EXTENDED_NAME: |
1230 | + ; |
1231 | + break; |
1232 | + default: |
1233 | + jj_la1[1] = jj_gen; |
1234 | + break label_2; |
1235 | + } |
1236 | + portSubstitution = parseSubstitution(); |
1237 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
1238 | + case 10: |
1239 | + jj_consume_token(10); |
1240 | + break; |
1241 | + default: |
1242 | + jj_la1[2] = jj_gen; |
1243 | + ; |
1244 | + } |
1245 | + String oldPortName = portSubstitution.getFirst(); |
1246 | + String newPortName = portSubstitution.getSecond(); |
1247 | + portSubstitutions.put(oldPortName, newPortName); |
1248 | + } |
1249 | + jj_consume_token(9); |
1250 | + break; |
1251 | + default: |
1252 | + jj_la1[3] = jj_gen; |
1253 | + ; |
1254 | + } |
1255 | + String oldGateName = gateSubstitution.getFirst(); |
1256 | + String newGateName = gateSubstitution.getSecond(); |
1257 | + {if (true) return new SubstitutionRule(oldGateName, newGateName, portSubstitutions);} |
1258 | + throw new Error("Missing return statement in function"); |
1259 | + } finally { |
1260 | + trace_return("parseSubstitutionRule"); |
1261 | + } |
1262 | + } |
1263 | + |
1264 | + final public Pair<String, String> parseSubstitution() throws ParseException { |
1265 | + trace_call("parseSubstitution"); |
1266 | + try { |
1267 | + Token oldName; |
1268 | + Token newName; |
1269 | + oldName = jj_consume_token(EXTENDED_NAME); |
1270 | + jj_consume_token(11); |
1271 | + newName = jj_consume_token(EXTENDED_NAME); |
1272 | + {if (true) return new Pair(oldName.image, newName.image);} |
1273 | + throw new Error("Missing return statement in function"); |
1274 | + } finally { |
1275 | + trace_return("parseSubstitution"); |
1276 | + } |
1277 | + } |
1278 | + |
1279 | + /** Generated Token Manager. */ |
1280 | + public SubstitutionParserTokenManager token_source; |
1281 | + SimpleCharStream jj_input_stream; |
1282 | + /** Current token. */ |
1283 | + public Token token; |
1284 | + /** Next token. */ |
1285 | + public Token jj_nt; |
1286 | + private int jj_ntk; |
1287 | + private int jj_gen; |
1288 | + final private int[] jj_la1 = new int[4]; |
1289 | + static private int[] jj_la1_0; |
1290 | + static { |
1291 | + jj_la1_init_0(); |
1292 | + } |
1293 | + private static void jj_la1_init_0() { |
1294 | + jj_la1_0 = new int[] {0x80,0x80,0x400,0x100,}; |
1295 | + } |
1296 | + |
1297 | + /** Constructor with InputStream. */ |
1298 | + public SubstitutionParser(java.io.InputStream stream) { |
1299 | + this(stream, null); |
1300 | + } |
1301 | + /** Constructor with InputStream and supplied encoding */ |
1302 | + public SubstitutionParser(java.io.InputStream stream, String encoding) { |
1303 | + try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } |
1304 | + token_source = new SubstitutionParserTokenManager(jj_input_stream); |
1305 | + token = new Token(); |
1306 | + jj_ntk = -1; |
1307 | + jj_gen = 0; |
1308 | + for (int i = 0; i < 4; i++) jj_la1[i] = -1; |
1309 | + } |
1310 | + |
1311 | + /** Reinitialise. */ |
1312 | + public void ReInit(java.io.InputStream stream) { |
1313 | + ReInit(stream, null); |
1314 | + } |
1315 | + /** Reinitialise. */ |
1316 | + public void ReInit(java.io.InputStream stream, String encoding) { |
1317 | + try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } |
1318 | + token_source.ReInit(jj_input_stream); |
1319 | + token = new Token(); |
1320 | + jj_ntk = -1; |
1321 | + jj_gen = 0; |
1322 | + for (int i = 0; i < 4; i++) jj_la1[i] = -1; |
1323 | + } |
1324 | + |
1325 | + /** Constructor. */ |
1326 | + public SubstitutionParser(java.io.Reader stream) { |
1327 | + jj_input_stream = new SimpleCharStream(stream, 1, 1); |
1328 | + token_source = new SubstitutionParserTokenManager(jj_input_stream); |
1329 | + token = new Token(); |
1330 | + jj_ntk = -1; |
1331 | + jj_gen = 0; |
1332 | + for (int i = 0; i < 4; i++) jj_la1[i] = -1; |
1333 | + } |
1334 | + |
1335 | + /** Reinitialise. */ |
1336 | + public void ReInit(java.io.Reader stream) { |
1337 | + jj_input_stream.ReInit(stream, 1, 1); |
1338 | + token_source.ReInit(jj_input_stream); |
1339 | + token = new Token(); |
1340 | + jj_ntk = -1; |
1341 | + jj_gen = 0; |
1342 | + for (int i = 0; i < 4; i++) jj_la1[i] = -1; |
1343 | + } |
1344 | + |
1345 | + /** Constructor with generated Token Manager. */ |
1346 | + public SubstitutionParser(SubstitutionParserTokenManager tm) { |
1347 | + token_source = tm; |
1348 | + token = new Token(); |
1349 | + jj_ntk = -1; |
1350 | + jj_gen = 0; |
1351 | + for (int i = 0; i < 4; i++) jj_la1[i] = -1; |
1352 | + } |
1353 | + |
1354 | + /** Reinitialise. */ |
1355 | + public void ReInit(SubstitutionParserTokenManager tm) { |
1356 | + token_source = tm; |
1357 | + token = new Token(); |
1358 | + jj_ntk = -1; |
1359 | + jj_gen = 0; |
1360 | + for (int i = 0; i < 4; i++) jj_la1[i] = -1; |
1361 | + } |
1362 | + |
1363 | + private Token jj_consume_token(int kind) throws ParseException { |
1364 | + Token oldToken; |
1365 | + if ((oldToken = token).next != null) token = token.next; |
1366 | + else token = token.next = token_source.getNextToken(); |
1367 | + jj_ntk = -1; |
1368 | + if (token.kind == kind) { |
1369 | + jj_gen++; |
1370 | + trace_token(token, ""); |
1371 | + return token; |
1372 | + } |
1373 | + token = oldToken; |
1374 | + jj_kind = kind; |
1375 | + throw generateParseException(); |
1376 | + } |
1377 | + |
1378 | + |
1379 | +/** Get the next Token. */ |
1380 | + final public Token getNextToken() { |
1381 | + if (token.next != null) token = token.next; |
1382 | + else token = token.next = token_source.getNextToken(); |
1383 | + jj_ntk = -1; |
1384 | + jj_gen++; |
1385 | + trace_token(token, " (in getNextToken)"); |
1386 | + return token; |
1387 | + } |
1388 | + |
1389 | +/** Get the specific Token. */ |
1390 | + final public Token getToken(int index) { |
1391 | + Token t = token; |
1392 | + for (int i = 0; i < index; i++) { |
1393 | + if (t.next != null) t = t.next; |
1394 | + else t = t.next = token_source.getNextToken(); |
1395 | + } |
1396 | + return t; |
1397 | + } |
1398 | + |
1399 | + private int jj_ntk() { |
1400 | + if ((jj_nt=token.next) == null) |
1401 | + return (jj_ntk = (token.next=token_source.getNextToken()).kind); |
1402 | + else |
1403 | + return (jj_ntk = jj_nt.kind); |
1404 | + } |
1405 | + |
1406 | + private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>(); |
1407 | + private int[] jj_expentry; |
1408 | + private int jj_kind = -1; |
1409 | + |
1410 | + /** Generate ParseException. */ |
1411 | + public ParseException generateParseException() { |
1412 | + jj_expentries.clear(); |
1413 | + boolean[] la1tokens = new boolean[12]; |
1414 | + if (jj_kind >= 0) { |
1415 | + la1tokens[jj_kind] = true; |
1416 | + jj_kind = -1; |
1417 | + } |
1418 | + for (int i = 0; i < 4; i++) { |
1419 | + if (jj_la1[i] == jj_gen) { |
1420 | + for (int j = 0; j < 32; j++) { |
1421 | + if ((jj_la1_0[i] & (1<<j)) != 0) { |
1422 | + la1tokens[j] = true; |
1423 | + } |
1424 | + } |
1425 | + } |
1426 | + } |
1427 | + for (int i = 0; i < 12; i++) { |
1428 | + if (la1tokens[i]) { |
1429 | + jj_expentry = new int[1]; |
1430 | + jj_expentry[0] = i; |
1431 | + jj_expentries.add(jj_expentry); |
1432 | + } |
1433 | + } |
1434 | + int[][] exptokseq = new int[jj_expentries.size()][]; |
1435 | + for (int i = 0; i < jj_expentries.size(); i++) { |
1436 | + exptokseq[i] = jj_expentries.get(i); |
1437 | + } |
1438 | + return new ParseException(token, exptokseq, tokenImage); |
1439 | + } |
1440 | + |
1441 | + private int trace_indent = 0; |
1442 | + private boolean trace_enabled = true; |
1443 | + |
1444 | +/** Enable tracing. */ |
1445 | + final public void enable_tracing() { |
1446 | + trace_enabled = true; |
1447 | + } |
1448 | + |
1449 | +/** Disable tracing. */ |
1450 | + final public void disable_tracing() { |
1451 | + trace_enabled = false; |
1452 | + } |
1453 | + |
1454 | + private void trace_call(String s) { |
1455 | + if (trace_enabled) { |
1456 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1457 | + System.out.println("Call: " + s); |
1458 | + } |
1459 | + trace_indent = trace_indent + 2; |
1460 | + } |
1461 | + |
1462 | + private void trace_return(String s) { |
1463 | + trace_indent = trace_indent - 2; |
1464 | + if (trace_enabled) { |
1465 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1466 | + System.out.println("Return: " + s); |
1467 | + } |
1468 | + } |
1469 | + |
1470 | + private void trace_token(Token t, String where) { |
1471 | + if (trace_enabled) { |
1472 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1473 | + System.out.print("Consumed token: <" + tokenImage[t.kind]); |
1474 | + if (t.kind != 0 && !tokenImage[t.kind].equals("\"" + t.image + "\"")) { |
1475 | + System.out.print(": \"" + t.image + "\""); |
1476 | + } |
1477 | + System.out.println(" at line " + t.beginLine + " column " + t.beginColumn + ">" + where); |
1478 | + } |
1479 | + } |
1480 | + |
1481 | + private void trace_scan(Token t1, int t2) { |
1482 | + if (trace_enabled) { |
1483 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
1484 | + System.out.print("Visited token: <" + tokenImage[t1.kind]); |
1485 | + if (t1.kind != 0 && !tokenImage[t1.kind].equals("\"" + t1.image + "\"")) { |
1486 | + System.out.print(": \"" + t1.image + "\""); |
1487 | + } |
1488 | + System.out.println(" at line " + t1.beginLine + " column " + t1.beginColumn + ">; Expected token: <" + tokenImage[t2] + ">"); |
1489 | + } |
1490 | + } |
1491 | + |
1492 | +} |
1493 | |
1494 | === added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.jj' |
1495 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.jj 1970-01-01 00:00:00 +0000 |
1496 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParser.jj 2015-11-09 09:38:45 +0000 |
1497 | @@ -0,0 +1,100 @@ |
1498 | +/** |
1499 | + * JavaCC file |
1500 | + */ |
1501 | + |
1502 | +options { |
1503 | + JDK_VERSION = "1.7"; |
1504 | + LOOKAHEAD = 1; |
1505 | + STATIC = false; |
1506 | + DEBUG_PARSER = true; |
1507 | + DEBUG_LOOKAHEAD = false; |
1508 | + DEBUG_TOKEN_MANAGER = false; |
1509 | +} |
1510 | + |
1511 | +PARSER_BEGIN(SubstitutionParser) |
1512 | +package org.workcraft.plugins.circuit.javacc; |
1513 | + |
1514 | +import java.util.List; |
1515 | +import java.util.LinkedList; |
1516 | +import java.util.Map; |
1517 | +import java.util.HashMap; |
1518 | + |
1519 | +import org.workcraft.util.Pair; |
1520 | +import org.workcraft.plugins.circuit.verilog.SubstitutionRule; |
1521 | + |
1522 | +public class SubstitutionParser { |
1523 | +} |
1524 | +PARSER_END(SubstitutionParser) |
1525 | + |
1526 | +SKIP: |
1527 | +{ |
1528 | + " " |
1529 | +| "\t" |
1530 | +| "\r" |
1531 | +| "\n" |
1532 | +| <"//" (~["\r", "\n"])*> |
1533 | +| < "`" (~["\r", "\n"])*> |
1534 | +} |
1535 | + |
1536 | +TOKEN : |
1537 | +{ |
1538 | + <EXTENDED_NAME : ["A"-"Z", "a"-"z", "_", "/" ] ([ "A"-"Z", "a"-"z", "_", "0"-"9", ":", "/", "\\", "-"])*> |
1539 | +| "(" |
1540 | +| ")" |
1541 | +| "," |
1542 | +} |
1543 | + |
1544 | +List<SubstitutionRule> parseSubstitutionRules() : |
1545 | +{ |
1546 | + SubstitutionRule rule; |
1547 | + List<SubstitutionRule> rules = new LinkedList<SubstitutionRule>(); |
1548 | +} |
1549 | +{ |
1550 | + ( |
1551 | + rule = parseSubstitutionRule() |
1552 | + { |
1553 | + rules.add(rule); |
1554 | + } |
1555 | + )* |
1556 | + { |
1557 | + return rules; |
1558 | + } |
1559 | +} |
1560 | + |
1561 | +SubstitutionRule parseSubstitutionRule() : |
1562 | +{ |
1563 | + Pair<String, String> gateSubstitution; |
1564 | + Pair<String, String> portSubstitution; |
1565 | + Map<String, String> portSubstitutions = new HashMap<String, String>(); |
1566 | +} |
1567 | +{ |
1568 | + gateSubstitution = parseSubstitution() |
1569 | + [ "(" |
1570 | + ( |
1571 | + portSubstitution = parseSubstitution() [","] |
1572 | + { |
1573 | + String oldPortName = portSubstitution.getFirst(); |
1574 | + String newPortName = portSubstitution.getSecond(); |
1575 | + portSubstitutions.put(oldPortName, newPortName); |
1576 | + } |
1577 | + )* |
1578 | + ")" |
1579 | + ] |
1580 | + { |
1581 | + String oldGateName = gateSubstitution.getFirst(); |
1582 | + String newGateName = gateSubstitution.getSecond(); |
1583 | + return new SubstitutionRule(oldGateName, newGateName, portSubstitutions); |
1584 | + } |
1585 | +} |
1586 | + |
1587 | +Pair<String, String> parseSubstitution(): |
1588 | +{ |
1589 | + Token oldName; |
1590 | + Token newName; |
1591 | +} |
1592 | +{ |
1593 | + oldName = <EXTENDED_NAME> "=" newName = <EXTENDED_NAME> |
1594 | + { |
1595 | + return new Pair(oldName.image, newName.image); |
1596 | + } |
1597 | +} |
1598 | |
1599 | === added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserConstants.java' |
1600 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserConstants.java 1970-01-01 00:00:00 +0000 |
1601 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserConstants.java 2015-11-09 09:38:45 +0000 |
1602 | @@ -0,0 +1,35 @@ |
1603 | +/* Generated By:JavaCC: Do not edit this line. SubstitutionParserConstants.java */ |
1604 | +package org.workcraft.plugins.circuit.javacc; |
1605 | + |
1606 | + |
1607 | +/** |
1608 | + * Token literal values and constants. |
1609 | + * Generated by org.javacc.parser.OtherFilesGen#start() |
1610 | + */ |
1611 | +public interface SubstitutionParserConstants { |
1612 | + |
1613 | + /** End of File. */ |
1614 | + int EOF = 0; |
1615 | + /** RegularExpression Id. */ |
1616 | + int EXTENDED_NAME = 7; |
1617 | + |
1618 | + /** Lexical state. */ |
1619 | + int DEFAULT = 0; |
1620 | + |
1621 | + /** Literal token values. */ |
1622 | + String[] tokenImage = { |
1623 | + "<EOF>", |
1624 | + "\" \"", |
1625 | + "\"\\t\"", |
1626 | + "\"\\r\"", |
1627 | + "\"\\n\"", |
1628 | + "<token of kind 5>", |
1629 | + "<token of kind 6>", |
1630 | + "<EXTENDED_NAME>", |
1631 | + "\"(\"", |
1632 | + "\")\"", |
1633 | + "\",\"", |
1634 | + "\"=\"", |
1635 | + }; |
1636 | + |
1637 | +} |
1638 | |
1639 | === added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserTokenManager.java' |
1640 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserTokenManager.java 1970-01-01 00:00:00 +0000 |
1641 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/SubstitutionParserTokenManager.java 2015-11-09 09:38:45 +0000 |
1642 | @@ -0,0 +1,399 @@ |
1643 | +/* Generated By:JavaCC: Do not edit this line. SubstitutionParserTokenManager.java */ |
1644 | +package org.workcraft.plugins.circuit.javacc; |
1645 | +import java.util.List; |
1646 | +import java.util.LinkedList; |
1647 | +import java.util.Map; |
1648 | +import java.util.HashMap; |
1649 | +import org.workcraft.util.Pair; |
1650 | +import org.workcraft.plugins.circuit.verilog.SubstitutionRule; |
1651 | + |
1652 | +/** Token Manager. */ |
1653 | +public class SubstitutionParserTokenManager implements SubstitutionParserConstants |
1654 | +{ |
1655 | + |
1656 | + /** Debug output. */ |
1657 | + public java.io.PrintStream debugStream = System.out; |
1658 | + /** Set debug output. */ |
1659 | + public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } |
1660 | +private final int jjStopStringLiteralDfa_0(int pos, long active0) |
1661 | +{ |
1662 | + switch (pos) |
1663 | + { |
1664 | + default : |
1665 | + return -1; |
1666 | + } |
1667 | +} |
1668 | +private final int jjStartNfa_0(int pos, long active0) |
1669 | +{ |
1670 | + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); |
1671 | +} |
1672 | +private int jjStopAtPos(int pos, int kind) |
1673 | +{ |
1674 | + jjmatchedKind = kind; |
1675 | + jjmatchedPos = pos; |
1676 | + return pos + 1; |
1677 | +} |
1678 | +private int jjMoveStringLiteralDfa0_0() |
1679 | +{ |
1680 | + switch(curChar) |
1681 | + { |
1682 | + case 40: |
1683 | + return jjStopAtPos(0, 8); |
1684 | + case 41: |
1685 | + return jjStopAtPos(0, 9); |
1686 | + case 44: |
1687 | + return jjStopAtPos(0, 10); |
1688 | + case 61: |
1689 | + return jjStopAtPos(0, 11); |
1690 | + default : |
1691 | + return jjMoveNfa_0(2, 0); |
1692 | + } |
1693 | +} |
1694 | +static final long[] jjbitVec0 = { |
1695 | + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL |
1696 | +}; |
1697 | +private int jjMoveNfa_0(int startState, int curPos) |
1698 | +{ |
1699 | + int startsAt = 0; |
1700 | + jjnewStateCnt = 7; |
1701 | + int i = 1; |
1702 | + jjstateSet[0] = startState; |
1703 | + int kind = 0x7fffffff; |
1704 | + for (;;) |
1705 | + { |
1706 | + if (++jjround == 0x7fffffff) |
1707 | + ReInitRounds(); |
1708 | + if (curChar < 64) |
1709 | + { |
1710 | + long l = 1L << curChar; |
1711 | + do |
1712 | + { |
1713 | + switch(jjstateSet[--i]) |
1714 | + { |
1715 | + case 2: |
1716 | + if (curChar == 47) |
1717 | + { |
1718 | + if (kind > 7) |
1719 | + kind = 7; |
1720 | + jjCheckNAdd(6); |
1721 | + } |
1722 | + if (curChar == 47) |
1723 | + jjstateSet[jjnewStateCnt++] = 0; |
1724 | + break; |
1725 | + case 0: |
1726 | + if (curChar != 47) |
1727 | + break; |
1728 | + if (kind > 5) |
1729 | + kind = 5; |
1730 | + jjCheckNAdd(1); |
1731 | + break; |
1732 | + case 1: |
1733 | + if ((0xffffffffffffdbffL & l) == 0L) |
1734 | + break; |
1735 | + if (kind > 5) |
1736 | + kind = 5; |
1737 | + jjCheckNAdd(1); |
1738 | + break; |
1739 | + case 4: |
1740 | + if ((0xffffffffffffdbffL & l) == 0L) |
1741 | + break; |
1742 | + if (kind > 6) |
1743 | + kind = 6; |
1744 | + jjstateSet[jjnewStateCnt++] = 4; |
1745 | + break; |
1746 | + case 5: |
1747 | + if (curChar != 47) |
1748 | + break; |
1749 | + if (kind > 7) |
1750 | + kind = 7; |
1751 | + jjCheckNAdd(6); |
1752 | + break; |
1753 | + case 6: |
1754 | + if ((0x7ffa00000000000L & l) == 0L) |
1755 | + break; |
1756 | + if (kind > 7) |
1757 | + kind = 7; |
1758 | + jjCheckNAdd(6); |
1759 | + break; |
1760 | + default : break; |
1761 | + } |
1762 | + } while(i != startsAt); |
1763 | + } |
1764 | + else if (curChar < 128) |
1765 | + { |
1766 | + long l = 1L << (curChar & 077); |
1767 | + do |
1768 | + { |
1769 | + switch(jjstateSet[--i]) |
1770 | + { |
1771 | + case 2: |
1772 | + if ((0x7fffffe87fffffeL & l) != 0L) |
1773 | + { |
1774 | + if (kind > 7) |
1775 | + kind = 7; |
1776 | + jjCheckNAdd(6); |
1777 | + } |
1778 | + else if (curChar == 96) |
1779 | + { |
1780 | + if (kind > 6) |
1781 | + kind = 6; |
1782 | + jjCheckNAdd(4); |
1783 | + } |
1784 | + break; |
1785 | + case 1: |
1786 | + if (kind > 5) |
1787 | + kind = 5; |
1788 | + jjstateSet[jjnewStateCnt++] = 1; |
1789 | + break; |
1790 | + case 3: |
1791 | + if (curChar != 96) |
1792 | + break; |
1793 | + if (kind > 6) |
1794 | + kind = 6; |
1795 | + jjCheckNAdd(4); |
1796 | + break; |
1797 | + case 4: |
1798 | + if (kind > 6) |
1799 | + kind = 6; |
1800 | + jjCheckNAdd(4); |
1801 | + break; |
1802 | + case 5: |
1803 | + if ((0x7fffffe87fffffeL & l) == 0L) |
1804 | + break; |
1805 | + if (kind > 7) |
1806 | + kind = 7; |
1807 | + jjCheckNAdd(6); |
1808 | + break; |
1809 | + case 6: |
1810 | + if ((0x7fffffe97fffffeL & l) == 0L) |
1811 | + break; |
1812 | + if (kind > 7) |
1813 | + kind = 7; |
1814 | + jjCheckNAdd(6); |
1815 | + break; |
1816 | + default : break; |
1817 | + } |
1818 | + } while(i != startsAt); |
1819 | + } |
1820 | + else |
1821 | + { |
1822 | + int i2 = (curChar & 0xff) >> 6; |
1823 | + long l2 = 1L << (curChar & 077); |
1824 | + do |
1825 | + { |
1826 | + switch(jjstateSet[--i]) |
1827 | + { |
1828 | + case 1: |
1829 | + if ((jjbitVec0[i2] & l2) == 0L) |
1830 | + break; |
1831 | + if (kind > 5) |
1832 | + kind = 5; |
1833 | + jjstateSet[jjnewStateCnt++] = 1; |
1834 | + break; |
1835 | + case 4: |
1836 | + if ((jjbitVec0[i2] & l2) == 0L) |
1837 | + break; |
1838 | + if (kind > 6) |
1839 | + kind = 6; |
1840 | + jjstateSet[jjnewStateCnt++] = 4; |
1841 | + break; |
1842 | + default : break; |
1843 | + } |
1844 | + } while(i != startsAt); |
1845 | + } |
1846 | + if (kind != 0x7fffffff) |
1847 | + { |
1848 | + jjmatchedKind = kind; |
1849 | + jjmatchedPos = curPos; |
1850 | + kind = 0x7fffffff; |
1851 | + } |
1852 | + ++curPos; |
1853 | + if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt))) |
1854 | + return curPos; |
1855 | + try { curChar = input_stream.readChar(); } |
1856 | + catch(java.io.IOException e) { return curPos; } |
1857 | + } |
1858 | +} |
1859 | +static final int[] jjnextStates = { |
1860 | +}; |
1861 | + |
1862 | +/** Token literal values. */ |
1863 | +public static final String[] jjstrLiteralImages = { |
1864 | +"", null, null, null, null, null, null, null, "\50", "\51", "\54", "\75", }; |
1865 | + |
1866 | +/** Lexer state names. */ |
1867 | +public static final String[] lexStateNames = { |
1868 | + "DEFAULT", |
1869 | +}; |
1870 | +static final long[] jjtoToken = { |
1871 | + 0xf81L, |
1872 | +}; |
1873 | +static final long[] jjtoSkip = { |
1874 | + 0x7eL, |
1875 | +}; |
1876 | +protected SimpleCharStream input_stream; |
1877 | +private final int[] jjrounds = new int[7]; |
1878 | +private final int[] jjstateSet = new int[14]; |
1879 | +protected char curChar; |
1880 | +/** Constructor. */ |
1881 | +public SubstitutionParserTokenManager(SimpleCharStream stream){ |
1882 | + if (SimpleCharStream.staticFlag) |
1883 | + throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); |
1884 | + input_stream = stream; |
1885 | +} |
1886 | + |
1887 | +/** Constructor. */ |
1888 | +public SubstitutionParserTokenManager(SimpleCharStream stream, int lexState){ |
1889 | + this(stream); |
1890 | + SwitchTo(lexState); |
1891 | +} |
1892 | + |
1893 | +/** Reinitialise parser. */ |
1894 | +public void ReInit(SimpleCharStream stream) |
1895 | +{ |
1896 | + jjmatchedPos = jjnewStateCnt = 0; |
1897 | + curLexState = defaultLexState; |
1898 | + input_stream = stream; |
1899 | + ReInitRounds(); |
1900 | +} |
1901 | +private void ReInitRounds() |
1902 | +{ |
1903 | + int i; |
1904 | + jjround = 0x80000001; |
1905 | + for (i = 7; i-- > 0;) |
1906 | + jjrounds[i] = 0x80000000; |
1907 | +} |
1908 | + |
1909 | +/** Reinitialise parser. */ |
1910 | +public void ReInit(SimpleCharStream stream, int lexState) |
1911 | +{ |
1912 | + ReInit(stream); |
1913 | + SwitchTo(lexState); |
1914 | +} |
1915 | + |
1916 | +/** Switch to specified lex state. */ |
1917 | +public void SwitchTo(int lexState) |
1918 | +{ |
1919 | + if (lexState >= 1 || lexState < 0) |
1920 | + throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE); |
1921 | + else |
1922 | + curLexState = lexState; |
1923 | +} |
1924 | + |
1925 | +protected Token jjFillToken() |
1926 | +{ |
1927 | + final Token t; |
1928 | + final String curTokenImage; |
1929 | + final int beginLine; |
1930 | + final int endLine; |
1931 | + final int beginColumn; |
1932 | + final int endColumn; |
1933 | + String im = jjstrLiteralImages[jjmatchedKind]; |
1934 | + curTokenImage = (im == null) ? input_stream.GetImage() : im; |
1935 | + beginLine = input_stream.getBeginLine(); |
1936 | + beginColumn = input_stream.getBeginColumn(); |
1937 | + endLine = input_stream.getEndLine(); |
1938 | + endColumn = input_stream.getEndColumn(); |
1939 | + t = Token.newToken(jjmatchedKind, curTokenImage); |
1940 | + |
1941 | + t.beginLine = beginLine; |
1942 | + t.endLine = endLine; |
1943 | + t.beginColumn = beginColumn; |
1944 | + t.endColumn = endColumn; |
1945 | + |
1946 | + return t; |
1947 | +} |
1948 | + |
1949 | +int curLexState = 0; |
1950 | +int defaultLexState = 0; |
1951 | +int jjnewStateCnt; |
1952 | +int jjround; |
1953 | +int jjmatchedPos; |
1954 | +int jjmatchedKind; |
1955 | + |
1956 | +/** Get the next Token. */ |
1957 | +public Token getNextToken() |
1958 | +{ |
1959 | + Token matchedToken; |
1960 | + int curPos = 0; |
1961 | + |
1962 | + EOFLoop : |
1963 | + for (;;) |
1964 | + { |
1965 | + try |
1966 | + { |
1967 | + curChar = input_stream.BeginToken(); |
1968 | + } |
1969 | + catch(java.io.IOException e) |
1970 | + { |
1971 | + jjmatchedKind = 0; |
1972 | + matchedToken = jjFillToken(); |
1973 | + return matchedToken; |
1974 | + } |
1975 | + |
1976 | + try { input_stream.backup(0); |
1977 | + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) |
1978 | + curChar = input_stream.BeginToken(); |
1979 | + } |
1980 | + catch (java.io.IOException e1) { continue EOFLoop; } |
1981 | + jjmatchedKind = 0x7fffffff; |
1982 | + jjmatchedPos = 0; |
1983 | + curPos = jjMoveStringLiteralDfa0_0(); |
1984 | + if (jjmatchedKind != 0x7fffffff) |
1985 | + { |
1986 | + if (jjmatchedPos + 1 < curPos) |
1987 | + input_stream.backup(curPos - jjmatchedPos - 1); |
1988 | + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) |
1989 | + { |
1990 | + matchedToken = jjFillToken(); |
1991 | + return matchedToken; |
1992 | + } |
1993 | + else |
1994 | + { |
1995 | + continue EOFLoop; |
1996 | + } |
1997 | + } |
1998 | + int error_line = input_stream.getEndLine(); |
1999 | + int error_column = input_stream.getEndColumn(); |
2000 | + String error_after = null; |
2001 | + boolean EOFSeen = false; |
2002 | + try { input_stream.readChar(); input_stream.backup(1); } |
2003 | + catch (java.io.IOException e1) { |
2004 | + EOFSeen = true; |
2005 | + error_after = curPos <= 1 ? "" : input_stream.GetImage(); |
2006 | + if (curChar == '\n' || curChar == '\r') { |
2007 | + error_line++; |
2008 | + error_column = 0; |
2009 | + } |
2010 | + else |
2011 | + error_column++; |
2012 | + } |
2013 | + if (!EOFSeen) { |
2014 | + input_stream.backup(1); |
2015 | + error_after = curPos <= 1 ? "" : input_stream.GetImage(); |
2016 | + } |
2017 | + throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR); |
2018 | + } |
2019 | +} |
2020 | + |
2021 | +private void jjCheckNAdd(int state) |
2022 | +{ |
2023 | + if (jjrounds[state] != jjround) |
2024 | + { |
2025 | + jjstateSet[jjnewStateCnt++] = state; |
2026 | + jjrounds[state] = jjround; |
2027 | + } |
2028 | +} |
2029 | +private void jjAddStates(int start, int end) |
2030 | +{ |
2031 | + do { |
2032 | + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; |
2033 | + } while (start++ != end); |
2034 | +} |
2035 | +private void jjCheckNAddTwoStates(int state1, int state2) |
2036 | +{ |
2037 | + jjCheckNAdd(state1); |
2038 | + jjCheckNAdd(state2); |
2039 | +} |
2040 | + |
2041 | +} |
2042 | |
2043 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.java' |
2044 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.java 2015-11-02 12:32:29 +0000 |
2045 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.java 2015-11-09 09:38:45 +0000 |
2046 | @@ -17,33 +17,45 @@ |
2047 | public class VerilogParser implements VerilogParserConstants { |
2048 | |
2049 | final public List<Module> parseCircuit() throws ParseException { |
2050 | + trace_call("parseCircuit"); |
2051 | + try { |
2052 | List<Module> modules; |
2053 | - modules = parseModules(); |
2054 | + modules = parseModules(); |
2055 | {if (true) return modules;} |
2056 | throw new Error("Missing return statement in function"); |
2057 | + } finally { |
2058 | + trace_return("parseCircuit"); |
2059 | + } |
2060 | } |
2061 | |
2062 | final public List<Module> parseModules() throws ParseException { |
2063 | + trace_call("parseModules"); |
2064 | + try { |
2065 | Module module; |
2066 | List<Module> modules = new LinkedList<Module>(); |
2067 | - label_1: |
2068 | - while (true) { |
2069 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2070 | - case MODULE: |
2071 | - ; |
2072 | - break; |
2073 | - default: |
2074 | - jj_la1[0] = jj_gen; |
2075 | - break label_1; |
2076 | - } |
2077 | - module = parseModule(); |
2078 | + label_1: |
2079 | + while (true) { |
2080 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2081 | + case MODULE: |
2082 | + ; |
2083 | + break; |
2084 | + default: |
2085 | + jj_la1[0] = jj_gen; |
2086 | + break label_1; |
2087 | + } |
2088 | + module = parseModule(); |
2089 | modules.add(module); |
2090 | - } |
2091 | + } |
2092 | {if (true) return modules;} |
2093 | throw new Error("Missing return statement in function"); |
2094 | + } finally { |
2095 | + trace_return("parseModules"); |
2096 | + } |
2097 | } |
2098 | |
2099 | final public Module parseModule() throws ParseException { |
2100 | + trace_call("parseModule"); |
2101 | + try { |
2102 | String name; |
2103 | List<Port> ports; |
2104 | List<Assign> assigns; |
2105 | @@ -51,169 +63,199 @@ |
2106 | List<Instance> group; |
2107 | Set<List<Instance>> groups = new HashSet<List<Instance>>(); |
2108 | Map<String, Boolean> signalStates = null; |
2109 | - jj_consume_token(MODULE); |
2110 | - name = parseModuleName(); |
2111 | - ports = parsePorts(); |
2112 | - assigns = parseAssigns(); |
2113 | - instances = parseInstances(); |
2114 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2115 | - case PETRIFY_UNMAPPED: |
2116 | - jj_consume_token(PETRIFY_UNMAPPED); |
2117 | - label_2: |
2118 | - while (true) { |
2119 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2120 | - case PETRIFY_EQUATION: |
2121 | - ; |
2122 | - break; |
2123 | - default: |
2124 | - jj_la1[1] = jj_gen; |
2125 | - break label_2; |
2126 | - } |
2127 | - jj_consume_token(PETRIFY_EQUATION); |
2128 | - group = parseInstances(); |
2129 | + jj_consume_token(MODULE); |
2130 | + name = parseModuleName(); |
2131 | + ports = parsePorts(); |
2132 | + assigns = parseAssigns(); |
2133 | + instances = parseInstances(); |
2134 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2135 | + case PETRIFY_UNMAPPED: |
2136 | + jj_consume_token(PETRIFY_UNMAPPED); |
2137 | + label_2: |
2138 | + while (true) { |
2139 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2140 | + case PETRIFY_EQUATION: |
2141 | + ; |
2142 | + break; |
2143 | + default: |
2144 | + jj_la1[1] = jj_gen; |
2145 | + break label_2; |
2146 | + } |
2147 | + jj_consume_token(PETRIFY_EQUATION); |
2148 | + group = parseInstances(); |
2149 | instances.addAll(group); |
2150 | groups.add(group); |
2151 | + } |
2152 | + break; |
2153 | + default: |
2154 | + jj_la1[2] = jj_gen; |
2155 | + ; |
2156 | } |
2157 | - break; |
2158 | - default: |
2159 | - jj_la1[2] = jj_gen; |
2160 | - ; |
2161 | - } |
2162 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2163 | - case PETRIFY_INIT_STATE: |
2164 | - case MPSAT_INIT_STATE: |
2165 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2166 | case PETRIFY_INIT_STATE: |
2167 | - jj_consume_token(PETRIFY_INIT_STATE); |
2168 | - break; |
2169 | case MPSAT_INIT_STATE: |
2170 | - jj_consume_token(MPSAT_INIT_STATE); |
2171 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2172 | + case PETRIFY_INIT_STATE: |
2173 | + jj_consume_token(PETRIFY_INIT_STATE); |
2174 | + break; |
2175 | + case MPSAT_INIT_STATE: |
2176 | + jj_consume_token(MPSAT_INIT_STATE); |
2177 | + break; |
2178 | + default: |
2179 | + jj_la1[3] = jj_gen; |
2180 | + jj_consume_token(-1); |
2181 | + throw new ParseException(); |
2182 | + } |
2183 | + signalStates = parseInitialState(); |
2184 | break; |
2185 | default: |
2186 | - jj_la1[3] = jj_gen; |
2187 | - jj_consume_token(-1); |
2188 | - throw new ParseException(); |
2189 | + jj_la1[4] = jj_gen; |
2190 | + ; |
2191 | } |
2192 | - signalStates = parseInitialState(); |
2193 | - break; |
2194 | - default: |
2195 | - jj_la1[4] = jj_gen; |
2196 | - ; |
2197 | - } |
2198 | - jj_consume_token(ENDMODULE); |
2199 | + jj_consume_token(ENDMODULE); |
2200 | {if (true) return new Module(name, ports, assigns, instances, signalStates, groups);} |
2201 | throw new Error("Missing return statement in function"); |
2202 | + } finally { |
2203 | + trace_return("parseModule"); |
2204 | + } |
2205 | } |
2206 | |
2207 | final public String parseModuleName() throws ParseException { |
2208 | + trace_call("parseModuleName"); |
2209 | + try { |
2210 | Token nameToken; |
2211 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2212 | - case NAME: |
2213 | - nameToken = jj_consume_token(NAME); |
2214 | - break; |
2215 | - case PETRIFY_NAME: |
2216 | - nameToken = jj_consume_token(PETRIFY_NAME); |
2217 | - break; |
2218 | - default: |
2219 | - jj_la1[5] = jj_gen; |
2220 | - jj_consume_token(-1); |
2221 | - throw new ParseException(); |
2222 | - } |
2223 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2224 | + case NAME: |
2225 | + nameToken = jj_consume_token(NAME); |
2226 | + break; |
2227 | + case PETRIFY_NAME: |
2228 | + nameToken = jj_consume_token(PETRIFY_NAME); |
2229 | + break; |
2230 | + default: |
2231 | + jj_la1[5] = jj_gen; |
2232 | + jj_consume_token(-1); |
2233 | + throw new ParseException(); |
2234 | + } |
2235 | {if (true) return nameToken.image;} |
2236 | throw new Error("Missing return statement in function"); |
2237 | + } finally { |
2238 | + trace_return("parseModuleName"); |
2239 | + } |
2240 | } |
2241 | |
2242 | final public List<Port> parsePorts() throws ParseException { |
2243 | + trace_call("parsePorts"); |
2244 | + try { |
2245 | List<Port> ports; |
2246 | - if (jj_2_1(2147483647)) { |
2247 | - ports = parseCompactPorts(); |
2248 | - } else { |
2249 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2250 | - case 38: |
2251 | - case 44: |
2252 | - ports = parseComplexPorts(); |
2253 | - break; |
2254 | - default: |
2255 | - jj_la1[6] = jj_gen; |
2256 | - jj_consume_token(-1); |
2257 | - throw new ParseException(); |
2258 | + if (jj_2_1(2147483647)) { |
2259 | + ports = parseCompactPorts(); |
2260 | + } else { |
2261 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2262 | + case 38: |
2263 | + case 44: |
2264 | + ports = parseComplexPorts(); |
2265 | + break; |
2266 | + default: |
2267 | + jj_la1[6] = jj_gen; |
2268 | + jj_consume_token(-1); |
2269 | + throw new ParseException(); |
2270 | + } |
2271 | } |
2272 | - } |
2273 | {if (true) return ports;} |
2274 | throw new Error("Missing return statement in function"); |
2275 | + } finally { |
2276 | + trace_return("parsePorts"); |
2277 | + } |
2278 | } |
2279 | |
2280 | final public List<Port> parseCompactPorts() throws ParseException { |
2281 | + trace_call("parseCompactPorts"); |
2282 | + try { |
2283 | Port port; |
2284 | List<Port> ports = new LinkedList<Port>(); |
2285 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2286 | - case 38: |
2287 | - jj_consume_token(38); |
2288 | - label_3: |
2289 | - while (true) { |
2290 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2291 | - case INPUT: |
2292 | - case OUTPUT: |
2293 | - ; |
2294 | - break; |
2295 | - default: |
2296 | - jj_la1[7] = jj_gen; |
2297 | - break label_3; |
2298 | - } |
2299 | - port = parseCompactPort(); |
2300 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2301 | - case 42: |
2302 | - jj_consume_token(42); |
2303 | - break; |
2304 | - default: |
2305 | - jj_la1[8] = jj_gen; |
2306 | - ; |
2307 | - } |
2308 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2309 | + case 38: |
2310 | + jj_consume_token(38); |
2311 | + label_3: |
2312 | + while (true) { |
2313 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2314 | + case INPUT: |
2315 | + case OUTPUT: |
2316 | + ; |
2317 | + break; |
2318 | + default: |
2319 | + jj_la1[7] = jj_gen; |
2320 | + break label_3; |
2321 | + } |
2322 | + port = parseCompactPort(); |
2323 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2324 | + case 42: |
2325 | + jj_consume_token(42); |
2326 | + break; |
2327 | + default: |
2328 | + jj_la1[8] = jj_gen; |
2329 | + ; |
2330 | + } |
2331 | ports.add(port); |
2332 | + } |
2333 | + jj_consume_token(39); |
2334 | + break; |
2335 | + default: |
2336 | + jj_la1[9] = jj_gen; |
2337 | + ; |
2338 | } |
2339 | - jj_consume_token(39); |
2340 | - break; |
2341 | - default: |
2342 | - jj_la1[9] = jj_gen; |
2343 | - ; |
2344 | - } |
2345 | - jj_consume_token(44); |
2346 | + jj_consume_token(44); |
2347 | {if (true) return ports;} |
2348 | throw new Error("Missing return statement in function"); |
2349 | + } finally { |
2350 | + trace_return("parseCompactPorts"); |
2351 | + } |
2352 | } |
2353 | |
2354 | final public Port parseCompactPort() throws ParseException { |
2355 | + trace_call("parseCompactPort"); |
2356 | + try { |
2357 | Port.Type type; |
2358 | Token nameToken; |
2359 | - type = parsePortType(); |
2360 | - nameToken = jj_consume_token(NAME); |
2361 | + type = parsePortType(); |
2362 | + nameToken = jj_consume_token(NAME); |
2363 | {if (true) return new Port(nameToken.image, type);} |
2364 | throw new Error("Missing return statement in function"); |
2365 | + } finally { |
2366 | + trace_return("parseCompactPort"); |
2367 | + } |
2368 | } |
2369 | |
2370 | final public Port.Type parsePortType() throws ParseException { |
2371 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2372 | - case INPUT: |
2373 | - jj_consume_token(INPUT); |
2374 | + trace_call("parsePortType"); |
2375 | + try { |
2376 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2377 | + case INPUT: |
2378 | + jj_consume_token(INPUT); |
2379 | {if (true) return Port.Type.INPUT;} |
2380 | - break; |
2381 | - case OUTPUT: |
2382 | - jj_consume_token(OUTPUT); |
2383 | + break; |
2384 | + case OUTPUT: |
2385 | + jj_consume_token(OUTPUT); |
2386 | {if (true) return Port.Type.OUTPUT;} |
2387 | - break; |
2388 | - default: |
2389 | - jj_la1[10] = jj_gen; |
2390 | - jj_consume_token(-1); |
2391 | - throw new ParseException(); |
2392 | + break; |
2393 | + default: |
2394 | + jj_la1[10] = jj_gen; |
2395 | + jj_consume_token(-1); |
2396 | + throw new ParseException(); |
2397 | + } |
2398 | + throw new Error("Missing return statement in function"); |
2399 | + } finally { |
2400 | + trace_return("parsePortType"); |
2401 | } |
2402 | - throw new Error("Missing return statement in function"); |
2403 | } |
2404 | |
2405 | final public List<Port> parseComplexPorts() throws ParseException { |
2406 | + trace_call("parseComplexPorts"); |
2407 | + try { |
2408 | List<String> declarations; |
2409 | List<Port> definitions; |
2410 | - declarations = parsePortsDeclaration(); |
2411 | - definitions = parsePortsDefinitions(); |
2412 | + declarations = parsePortsDeclaration(); |
2413 | + definitions = parsePortsDefinitions(); |
2414 | HashMap<String, Port.Type> nameToType = new HashMap<String, Port.Type>(); |
2415 | for (Port port: definitions) { |
2416 | nameToType.put(port.name, port.type); |
2417 | @@ -225,335 +267,403 @@ |
2418 | } |
2419 | {if (true) return ports;} |
2420 | throw new Error("Missing return statement in function"); |
2421 | + } finally { |
2422 | + trace_return("parseComplexPorts"); |
2423 | + } |
2424 | } |
2425 | |
2426 | final public List<String> parsePortsDeclaration() throws ParseException { |
2427 | + trace_call("parsePortsDeclaration"); |
2428 | + try { |
2429 | List<String> names = null; |
2430 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2431 | - case 38: |
2432 | - jj_consume_token(38); |
2433 | - names = parseNames(); |
2434 | - jj_consume_token(39); |
2435 | - break; |
2436 | - default: |
2437 | - jj_la1[11] = jj_gen; |
2438 | - ; |
2439 | - } |
2440 | - jj_consume_token(44); |
2441 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2442 | + case 38: |
2443 | + jj_consume_token(38); |
2444 | + names = parseNames(); |
2445 | + jj_consume_token(39); |
2446 | + break; |
2447 | + default: |
2448 | + jj_la1[11] = jj_gen; |
2449 | + ; |
2450 | + } |
2451 | + jj_consume_token(44); |
2452 | List<String> ports = new LinkedList<String>(); |
2453 | if (names != null) { |
2454 | ports.addAll(names); |
2455 | } |
2456 | {if (true) return ports;} |
2457 | throw new Error("Missing return statement in function"); |
2458 | + } finally { |
2459 | + trace_return("parsePortsDeclaration"); |
2460 | + } |
2461 | } |
2462 | |
2463 | final public List<Port> parsePortsDefinitions() throws ParseException { |
2464 | + trace_call("parsePortsDefinitions"); |
2465 | + try { |
2466 | List<Port> ports; |
2467 | List<Port> allPorts = new LinkedList<Port>(); |
2468 | - label_4: |
2469 | - while (true) { |
2470 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2471 | - case INPUT: |
2472 | - case OUTPUT: |
2473 | - case INOUT: |
2474 | - case REG: |
2475 | - case WIRE: |
2476 | - ; |
2477 | - break; |
2478 | - default: |
2479 | - jj_la1[12] = jj_gen; |
2480 | - break label_4; |
2481 | - } |
2482 | - ports = parsePortsDefinition(); |
2483 | + label_4: |
2484 | + while (true) { |
2485 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2486 | + case INPUT: |
2487 | + case OUTPUT: |
2488 | + case INOUT: |
2489 | + case REG: |
2490 | + case WIRE: |
2491 | + ; |
2492 | + break; |
2493 | + default: |
2494 | + jj_la1[12] = jj_gen; |
2495 | + break label_4; |
2496 | + } |
2497 | + ports = parsePortsDefinition(); |
2498 | if (ports != null) { |
2499 | allPorts.addAll(ports); |
2500 | } |
2501 | - } |
2502 | + } |
2503 | {if (true) return allPorts;} |
2504 | throw new Error("Missing return statement in function"); |
2505 | + } finally { |
2506 | + trace_return("parsePortsDefinitions"); |
2507 | + } |
2508 | } |
2509 | |
2510 | final public List<Port> parsePortsDefinition() throws ParseException { |
2511 | + trace_call("parsePortsDefinition"); |
2512 | + try { |
2513 | List<String> names; |
2514 | Port.Type type; |
2515 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2516 | - case INPUT: |
2517 | - case OUTPUT: |
2518 | - type = parsePortType(); |
2519 | - names = parseNames(); |
2520 | - jj_consume_token(44); |
2521 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2522 | + case INPUT: |
2523 | + case OUTPUT: |
2524 | + type = parsePortType(); |
2525 | + names = parseNames(); |
2526 | + jj_consume_token(44); |
2527 | List<Port> ports = new LinkedList<Port>(); |
2528 | for (String name: names) { |
2529 | Port port = new Port(name, type); |
2530 | ports.add(port); |
2531 | } |
2532 | {if (true) return ports;} |
2533 | - break; |
2534 | - case INOUT: |
2535 | - case REG: |
2536 | - case WIRE: |
2537 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2538 | - case WIRE: |
2539 | - jj_consume_token(WIRE); |
2540 | break; |
2541 | case INOUT: |
2542 | - jj_consume_token(INOUT); |
2543 | - break; |
2544 | case REG: |
2545 | - jj_consume_token(REG); |
2546 | - break; |
2547 | - default: |
2548 | - jj_la1[13] = jj_gen; |
2549 | - jj_consume_token(-1); |
2550 | - throw new ParseException(); |
2551 | - } |
2552 | - parseNames(); |
2553 | - jj_consume_token(44); |
2554 | + case WIRE: |
2555 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2556 | + case WIRE: |
2557 | + jj_consume_token(WIRE); |
2558 | + break; |
2559 | + case INOUT: |
2560 | + jj_consume_token(INOUT); |
2561 | + break; |
2562 | + case REG: |
2563 | + jj_consume_token(REG); |
2564 | + break; |
2565 | + default: |
2566 | + jj_la1[13] = jj_gen; |
2567 | + jj_consume_token(-1); |
2568 | + throw new ParseException(); |
2569 | + } |
2570 | + parseNames(); |
2571 | + jj_consume_token(44); |
2572 | {if (true) return null;} |
2573 | - break; |
2574 | - default: |
2575 | - jj_la1[14] = jj_gen; |
2576 | - jj_consume_token(-1); |
2577 | - throw new ParseException(); |
2578 | + break; |
2579 | + default: |
2580 | + jj_la1[14] = jj_gen; |
2581 | + jj_consume_token(-1); |
2582 | + throw new ParseException(); |
2583 | + } |
2584 | + throw new Error("Missing return statement in function"); |
2585 | + } finally { |
2586 | + trace_return("parsePortsDefinition"); |
2587 | } |
2588 | - throw new Error("Missing return statement in function"); |
2589 | } |
2590 | |
2591 | final public List<String> parseNames() throws ParseException { |
2592 | + trace_call("parseNames"); |
2593 | + try { |
2594 | Token nameToken; |
2595 | List<String> names = new LinkedList<String>(); |
2596 | - label_5: |
2597 | - while (true) { |
2598 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2599 | - case NAME: |
2600 | - ; |
2601 | - break; |
2602 | - default: |
2603 | - jj_la1[15] = jj_gen; |
2604 | - break label_5; |
2605 | - } |
2606 | - nameToken = jj_consume_token(NAME); |
2607 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2608 | - case 42: |
2609 | - jj_consume_token(42); |
2610 | - break; |
2611 | - default: |
2612 | - jj_la1[16] = jj_gen; |
2613 | - ; |
2614 | - } |
2615 | + label_5: |
2616 | + while (true) { |
2617 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2618 | + case NAME: |
2619 | + ; |
2620 | + break; |
2621 | + default: |
2622 | + jj_la1[15] = jj_gen; |
2623 | + break label_5; |
2624 | + } |
2625 | + nameToken = jj_consume_token(NAME); |
2626 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2627 | + case 42: |
2628 | + jj_consume_token(42); |
2629 | + break; |
2630 | + default: |
2631 | + jj_la1[16] = jj_gen; |
2632 | + ; |
2633 | + } |
2634 | String name = nameToken.image; |
2635 | names.add(name); |
2636 | - } |
2637 | + } |
2638 | {if (true) return names;} |
2639 | throw new Error("Missing return statement in function"); |
2640 | + } finally { |
2641 | + trace_return("parseNames"); |
2642 | + } |
2643 | } |
2644 | |
2645 | final public Map<String, Boolean> parseInitialState() throws ParseException { |
2646 | + trace_call("parseInitialState"); |
2647 | + try { |
2648 | Boolean state; |
2649 | Token nameToken; |
2650 | Map<String, Boolean> signalStates = new HashMap<String, Boolean>(); |
2651 | - label_6: |
2652 | - while (true) { |
2653 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2654 | - case NAME: |
2655 | - case 43: |
2656 | - ; |
2657 | - break; |
2658 | - default: |
2659 | - jj_la1[17] = jj_gen; |
2660 | - break label_6; |
2661 | - } |
2662 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2663 | - case 43: |
2664 | - jj_consume_token(43); |
2665 | - nameToken = jj_consume_token(NAME); |
2666 | + label_6: |
2667 | + while (true) { |
2668 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2669 | + case NAME: |
2670 | + case 43: |
2671 | + ; |
2672 | + break; |
2673 | + default: |
2674 | + jj_la1[17] = jj_gen; |
2675 | + break label_6; |
2676 | + } |
2677 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2678 | + case 43: |
2679 | + jj_consume_token(43); |
2680 | + nameToken = jj_consume_token(NAME); |
2681 | state = false; |
2682 | - break; |
2683 | - case NAME: |
2684 | - nameToken = jj_consume_token(NAME); |
2685 | + break; |
2686 | + case NAME: |
2687 | + nameToken = jj_consume_token(NAME); |
2688 | state = true; |
2689 | - break; |
2690 | - default: |
2691 | - jj_la1[18] = jj_gen; |
2692 | - jj_consume_token(-1); |
2693 | - throw new ParseException(); |
2694 | - } |
2695 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2696 | - case 42: |
2697 | - jj_consume_token(42); |
2698 | - break; |
2699 | - default: |
2700 | - jj_la1[19] = jj_gen; |
2701 | - ; |
2702 | - } |
2703 | + break; |
2704 | + default: |
2705 | + jj_la1[18] = jj_gen; |
2706 | + jj_consume_token(-1); |
2707 | + throw new ParseException(); |
2708 | + } |
2709 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2710 | + case 42: |
2711 | + jj_consume_token(42); |
2712 | + break; |
2713 | + default: |
2714 | + jj_la1[19] = jj_gen; |
2715 | + ; |
2716 | + } |
2717 | String name = nameToken.image; |
2718 | signalStates.put(name, state); |
2719 | - } |
2720 | + } |
2721 | {if (true) return signalStates;} |
2722 | throw new Error("Missing return statement in function"); |
2723 | + } finally { |
2724 | + trace_return("parseInitialState"); |
2725 | + } |
2726 | } |
2727 | |
2728 | final public List<Assign> parseAssigns() throws ParseException { |
2729 | + trace_call("parseAssigns"); |
2730 | + try { |
2731 | Assign assign; |
2732 | List<Assign> assigns = new LinkedList<Assign>(); |
2733 | - label_7: |
2734 | - while (true) { |
2735 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2736 | - case ASSIGN: |
2737 | - ; |
2738 | - break; |
2739 | - default: |
2740 | - jj_la1[20] = jj_gen; |
2741 | - break label_7; |
2742 | - } |
2743 | - assign = parseAssign(); |
2744 | + label_7: |
2745 | + while (true) { |
2746 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2747 | + case ASSIGN: |
2748 | + ; |
2749 | + break; |
2750 | + default: |
2751 | + jj_la1[20] = jj_gen; |
2752 | + break label_7; |
2753 | + } |
2754 | + assign = parseAssign(); |
2755 | assigns.add(assign); |
2756 | - } |
2757 | + } |
2758 | {if (true) return assigns;} |
2759 | throw new Error("Missing return statement in function"); |
2760 | + } finally { |
2761 | + trace_return("parseAssigns"); |
2762 | + } |
2763 | } |
2764 | |
2765 | final public Assign parseAssign() throws ParseException { |
2766 | + trace_call("parseAssign"); |
2767 | + try { |
2768 | Token nameToken; |
2769 | Token formulaToken; |
2770 | - jj_consume_token(ASSIGN); |
2771 | - nameToken = jj_consume_token(NAME); |
2772 | - formulaToken = jj_consume_token(FORMULA); |
2773 | + jj_consume_token(ASSIGN); |
2774 | + nameToken = jj_consume_token(NAME); |
2775 | + formulaToken = jj_consume_token(FORMULA); |
2776 | String formula = formulaToken.image.replaceAll("^=", "").replaceAll(";$", ""); |
2777 | {if (true) return new Assign(nameToken.image, formula);} |
2778 | throw new Error("Missing return statement in function"); |
2779 | + } finally { |
2780 | + trace_return("parseAssign"); |
2781 | + } |
2782 | } |
2783 | |
2784 | final public List<Instance> parseInstances() throws ParseException { |
2785 | + trace_call("parseInstances"); |
2786 | + try { |
2787 | Instance instance; |
2788 | List<Instance> instances = new LinkedList<Instance>(); |
2789 | - label_8: |
2790 | - while (true) { |
2791 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2792 | - case NAME: |
2793 | - case PETRIFY_NAME: |
2794 | - case PETRIFY_ZERO_DELAY: |
2795 | - case MPSAT_ZERO_DELAY: |
2796 | - ; |
2797 | - break; |
2798 | - default: |
2799 | - jj_la1[21] = jj_gen; |
2800 | - break label_8; |
2801 | - } |
2802 | - instance = parseInstance(); |
2803 | + label_8: |
2804 | + while (true) { |
2805 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2806 | + case NAME: |
2807 | + case PETRIFY_NAME: |
2808 | + case PETRIFY_ZERO_DELAY: |
2809 | + case MPSAT_ZERO_DELAY: |
2810 | + ; |
2811 | + break; |
2812 | + default: |
2813 | + jj_la1[21] = jj_gen; |
2814 | + break label_8; |
2815 | + } |
2816 | + instance = parseInstance(); |
2817 | instances.add(instance); |
2818 | - } |
2819 | + } |
2820 | {if (true) return instances;} |
2821 | throw new Error("Missing return statement in function"); |
2822 | + } finally { |
2823 | + trace_return("parseInstances"); |
2824 | + } |
2825 | } |
2826 | |
2827 | final public Instance parseInstance() throws ParseException { |
2828 | + trace_call("parseInstance"); |
2829 | + try { |
2830 | boolean zeroDelay = false; |
2831 | String moduleName; |
2832 | Token nameToken = null; |
2833 | List<String> parameters; |
2834 | List<Pin> pins; |
2835 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2836 | - case PETRIFY_ZERO_DELAY: |
2837 | - case MPSAT_ZERO_DELAY: |
2838 | switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2839 | case PETRIFY_ZERO_DELAY: |
2840 | - jj_consume_token(PETRIFY_ZERO_DELAY); |
2841 | - break; |
2842 | case MPSAT_ZERO_DELAY: |
2843 | - jj_consume_token(MPSAT_ZERO_DELAY); |
2844 | - break; |
2845 | - default: |
2846 | - jj_la1[22] = jj_gen; |
2847 | - jj_consume_token(-1); |
2848 | - throw new ParseException(); |
2849 | - } |
2850 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2851 | + case PETRIFY_ZERO_DELAY: |
2852 | + jj_consume_token(PETRIFY_ZERO_DELAY); |
2853 | + break; |
2854 | + case MPSAT_ZERO_DELAY: |
2855 | + jj_consume_token(MPSAT_ZERO_DELAY); |
2856 | + break; |
2857 | + default: |
2858 | + jj_la1[22] = jj_gen; |
2859 | + jj_consume_token(-1); |
2860 | + throw new ParseException(); |
2861 | + } |
2862 | zeroDelay = true; |
2863 | - break; |
2864 | - default: |
2865 | - jj_la1[23] = jj_gen; |
2866 | - ; |
2867 | - } |
2868 | - moduleName = parseModuleName(); |
2869 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2870 | - case NAME: |
2871 | - nameToken = jj_consume_token(NAME); |
2872 | - break; |
2873 | - default: |
2874 | - jj_la1[24] = jj_gen; |
2875 | - ; |
2876 | - } |
2877 | - jj_consume_token(38); |
2878 | - pins = parsePins(); |
2879 | - jj_consume_token(39); |
2880 | - jj_consume_token(44); |
2881 | + break; |
2882 | + default: |
2883 | + jj_la1[23] = jj_gen; |
2884 | + ; |
2885 | + } |
2886 | + moduleName = parseModuleName(); |
2887 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2888 | + case NAME: |
2889 | + nameToken = jj_consume_token(NAME); |
2890 | + break; |
2891 | + default: |
2892 | + jj_la1[24] = jj_gen; |
2893 | + ; |
2894 | + } |
2895 | + jj_consume_token(38); |
2896 | + pins = parsePins(); |
2897 | + jj_consume_token(39); |
2898 | + jj_consume_token(44); |
2899 | String name = (nameToken == null ? null : nameToken.image); |
2900 | {if (true) return new Instance(name, moduleName, pins, zeroDelay);} |
2901 | throw new Error("Missing return statement in function"); |
2902 | + } finally { |
2903 | + trace_return("parseInstance"); |
2904 | + } |
2905 | } |
2906 | |
2907 | final public List<Pin> parsePins() throws ParseException { |
2908 | + trace_call("parsePins"); |
2909 | + try { |
2910 | List<Pin> pins; |
2911 | - if (jj_2_2(2147483647)) { |
2912 | - pins = parseNamedPins(); |
2913 | - } else { |
2914 | - pins = parseOrderedPins(); |
2915 | - } |
2916 | + if (jj_2_2(2147483647)) { |
2917 | + pins = parseNamedPins(); |
2918 | + } else { |
2919 | + pins = parseOrderedPins(); |
2920 | + } |
2921 | {if (true) return pins;} |
2922 | throw new Error("Missing return statement in function"); |
2923 | + } finally { |
2924 | + trace_return("parsePins"); |
2925 | + } |
2926 | } |
2927 | |
2928 | final public List<Pin> parseNamedPins() throws ParseException { |
2929 | + trace_call("parseNamedPins"); |
2930 | + try { |
2931 | Pin pin; |
2932 | List<Pin> pins = new LinkedList<Pin>(); |
2933 | - label_9: |
2934 | - while (true) { |
2935 | - pin = parseNamedPin(); |
2936 | + label_9: |
2937 | + while (true) { |
2938 | + pin = parseNamedPin(); |
2939 | pins.add(pin); |
2940 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2941 | - case 45: |
2942 | - ; |
2943 | - break; |
2944 | - default: |
2945 | - jj_la1[25] = jj_gen; |
2946 | - break label_9; |
2947 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2948 | + case 45: |
2949 | + ; |
2950 | + break; |
2951 | + default: |
2952 | + jj_la1[25] = jj_gen; |
2953 | + break label_9; |
2954 | + } |
2955 | } |
2956 | - } |
2957 | {if (true) return pins;} |
2958 | throw new Error("Missing return statement in function"); |
2959 | + } finally { |
2960 | + trace_return("parseNamedPins"); |
2961 | + } |
2962 | } |
2963 | |
2964 | final public Pin parseNamedPin() throws ParseException { |
2965 | + trace_call("parseNamedPin"); |
2966 | + try { |
2967 | Token portName; |
2968 | Token netName; |
2969 | - jj_consume_token(45); |
2970 | - portName = jj_consume_token(NAME); |
2971 | - jj_consume_token(38); |
2972 | - netName = jj_consume_token(NAME); |
2973 | - jj_consume_token(39); |
2974 | - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2975 | - case 42: |
2976 | - jj_consume_token(42); |
2977 | - break; |
2978 | - default: |
2979 | - jj_la1[26] = jj_gen; |
2980 | - ; |
2981 | - } |
2982 | + jj_consume_token(45); |
2983 | + portName = jj_consume_token(NAME); |
2984 | + jj_consume_token(38); |
2985 | + netName = jj_consume_token(NAME); |
2986 | + jj_consume_token(39); |
2987 | + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { |
2988 | + case 42: |
2989 | + jj_consume_token(42); |
2990 | + break; |
2991 | + default: |
2992 | + jj_la1[26] = jj_gen; |
2993 | + ; |
2994 | + } |
2995 | {if (true) return new Pin(portName.image, netName.image);} |
2996 | throw new Error("Missing return statement in function"); |
2997 | + } finally { |
2998 | + trace_return("parseNamedPin"); |
2999 | + } |
3000 | } |
3001 | |
3002 | final public List<Pin> parseOrderedPins() throws ParseException { |
3003 | + trace_call("parseOrderedPins"); |
3004 | + try { |
3005 | List<String> wires; |
3006 | List<Pin> pins = new LinkedList<Pin>(); |
3007 | - wires = parseNames(); |
3008 | + wires = parseNames(); |
3009 | for (String wire: wires) { |
3010 | Pin pin = new Pin(null, wire); |
3011 | pins.add(pin); |
3012 | } |
3013 | {if (true) return pins;} |
3014 | throw new Error("Missing return statement in function"); |
3015 | + } finally { |
3016 | + trace_return("parseOrderedPins"); |
3017 | + } |
3018 | } |
3019 | |
3020 | private boolean jj_2_1(int xla) { |
3021 | @@ -777,6 +887,7 @@ |
3022 | } |
3023 | } |
3024 | } |
3025 | + trace_token(token, ""); |
3026 | return token; |
3027 | } |
3028 | token = oldToken; |
3029 | @@ -814,6 +925,7 @@ |
3030 | else token = token.next = token_source.getNextToken(); |
3031 | jj_ntk = -1; |
3032 | jj_gen++; |
3033 | + trace_token(token, " (in getNextToken)"); |
3034 | return token; |
3035 | } |
3036 | |
3037 | @@ -902,12 +1014,55 @@ |
3038 | return new ParseException(token, exptokseq, tokenImage); |
3039 | } |
3040 | |
3041 | - /** Enable tracing. */ |
3042 | + private int trace_indent = 0; |
3043 | + private boolean trace_enabled = true; |
3044 | + |
3045 | +/** Enable tracing. */ |
3046 | final public void enable_tracing() { |
3047 | + trace_enabled = true; |
3048 | } |
3049 | |
3050 | - /** Disable tracing. */ |
3051 | +/** Disable tracing. */ |
3052 | final public void disable_tracing() { |
3053 | + trace_enabled = false; |
3054 | + } |
3055 | + |
3056 | + private void trace_call(String s) { |
3057 | + if (trace_enabled) { |
3058 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
3059 | + System.out.println("Call: " + s); |
3060 | + } |
3061 | + trace_indent = trace_indent + 2; |
3062 | + } |
3063 | + |
3064 | + private void trace_return(String s) { |
3065 | + trace_indent = trace_indent - 2; |
3066 | + if (trace_enabled) { |
3067 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
3068 | + System.out.println("Return: " + s); |
3069 | + } |
3070 | + } |
3071 | + |
3072 | + private void trace_token(Token t, String where) { |
3073 | + if (trace_enabled) { |
3074 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
3075 | + System.out.print("Consumed token: <" + tokenImage[t.kind]); |
3076 | + if (t.kind != 0 && !tokenImage[t.kind].equals("\"" + t.image + "\"")) { |
3077 | + System.out.print(": \"" + t.image + "\""); |
3078 | + } |
3079 | + System.out.println(" at line " + t.beginLine + " column " + t.beginColumn + ">" + where); |
3080 | + } |
3081 | + } |
3082 | + |
3083 | + private void trace_scan(Token t1, int t2) { |
3084 | + if (trace_enabled) { |
3085 | + for (int i = 0; i < trace_indent; i++) { System.out.print(" "); } |
3086 | + System.out.print("Visited token: <" + tokenImage[t1.kind]); |
3087 | + if (t1.kind != 0 && !tokenImage[t1.kind].equals("\"" + t1.image + "\"")) { |
3088 | + System.out.print(": \"" + t1.image + "\""); |
3089 | + } |
3090 | + System.out.println(" at line " + t1.beginLine + " column " + t1.beginColumn + ">; Expected token: <" + tokenImage[t2] + ">"); |
3091 | + } |
3092 | } |
3093 | |
3094 | private void jj_rescan_token() { |
3095 | |
3096 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.jj' |
3097 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.jj 2015-11-03 23:05:25 +0000 |
3098 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/javacc/VerilogParser.jj 2015-11-09 09:38:45 +0000 |
3099 | @@ -6,7 +6,7 @@ |
3100 | JDK_VERSION = "1.7"; |
3101 | LOOKAHEAD = 1; |
3102 | STATIC = false; |
3103 | - DEBUG_PARSER = false; |
3104 | + DEBUG_PARSER = true; |
3105 | DEBUG_LOOKAHEAD = false; |
3106 | DEBUG_TOKEN_MANAGER = false; |
3107 | } |
3108 | |
3109 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/serialisation/VerilogSerialiser.java' |
3110 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/serialisation/VerilogSerialiser.java 2015-07-30 13:49:01 +0000 |
3111 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/serialisation/VerilogSerialiser.java 2015-11-09 09:38:45 +0000 |
3112 | @@ -21,18 +21,30 @@ |
3113 | |
3114 | package org.workcraft.plugins.circuit.serialisation; |
3115 | |
3116 | +import java.io.File; |
3117 | +import java.io.FileInputStream; |
3118 | +import java.io.FileNotFoundException; |
3119 | +import java.io.InputStream; |
3120 | import java.io.OutputStream; |
3121 | import java.io.PrintWriter; |
3122 | import java.util.HashMap; |
3123 | +import java.util.HashSet; |
3124 | +import java.util.List; |
3125 | import java.util.UUID; |
3126 | |
3127 | +import org.workcraft.Framework; |
3128 | import org.workcraft.dom.Model; |
3129 | import org.workcraft.dom.hierarchy.NamespaceHelper; |
3130 | import org.workcraft.exceptions.ArgumentException; |
3131 | import org.workcraft.plugins.circuit.Circuit; |
3132 | -import org.workcraft.plugins.circuit.CircuitComponent; |
3133 | +import org.workcraft.plugins.circuit.CircuitSettings; |
3134 | import org.workcraft.plugins.circuit.CircuitUtils; |
3135 | import org.workcraft.plugins.circuit.Contact; |
3136 | +import org.workcraft.plugins.circuit.FunctionComponent; |
3137 | +import org.workcraft.plugins.circuit.javacc.ParseException; |
3138 | +import org.workcraft.plugins.circuit.javacc.SubstitutionParser; |
3139 | +import org.workcraft.plugins.circuit.verilog.SubstitutionRule; |
3140 | +import org.workcraft.plugins.shared.CommonDebugSettings; |
3141 | import org.workcraft.serialisation.Format; |
3142 | import org.workcraft.serialisation.ModelSerialiser; |
3143 | import org.workcraft.serialisation.ReferenceProducer; |
3144 | @@ -45,7 +57,7 @@ |
3145 | private static final String KEYWORD_INPUT = "input"; |
3146 | private static final String KEYWORD_MODULE = "module "; |
3147 | private static final String KEYWORD_ENDMODULE = "endmodule"; |
3148 | - |
3149 | + |
3150 | class ReferenceResolver implements ReferenceProducer { |
3151 | HashMap<Object, String> refMap = new HashMap<Object, String>(); |
3152 | |
3153 | @@ -94,6 +106,7 @@ |
3154 | private void writeCircuit(PrintWriter out, Circuit circuit) { |
3155 | writeHeader(out, circuit); |
3156 | writeInstances(out, circuit); |
3157 | + writeInitialState(out, circuit); |
3158 | out.println(KEYWORD_ENDMODULE); |
3159 | } |
3160 | |
3161 | @@ -130,7 +143,8 @@ |
3162 | } |
3163 | |
3164 | private void writeInstances(PrintWriter out, Circuit circuit) { |
3165 | - for (CircuitComponent component: Hierarchy.getDescendantsOfType(circuit.getRoot(), CircuitComponent.class)) { |
3166 | + HashMap<String, SubstitutionRule> substitutionRules = readSubsritutionRules(); |
3167 | + for (FunctionComponent component: Hierarchy.getDescendantsOfType(circuit.getRoot(), FunctionComponent.class)) { |
3168 | String moduleName = component.getModule(); |
3169 | String instanceRef = circuit.getNodeReference(component); |
3170 | String instanceFlatName = NamespaceHelper.hierarchicalToFlatName(instanceRef); |
3171 | @@ -138,6 +152,17 @@ |
3172 | System.out.println(" Warning: component '" + instanceFlatName + "' is not associated to a module."); |
3173 | moduleName = ""; |
3174 | } |
3175 | + SubstitutionRule substitutionRule = substitutionRules.get(moduleName); |
3176 | + if (substitutionRule != null) { |
3177 | + String newModuleName = substitutionRule.newName; |
3178 | + if (newModuleName != null) { |
3179 | + System.out.println("Info: in component '" + instanceFlatName + "' renaming module '" + moduleName + "' to '" + newModuleName + "'."); |
3180 | + moduleName = newModuleName; |
3181 | + } |
3182 | + } |
3183 | + if (component.getIsZeroDelay() && (component.isBuffer() || component.isInverter())) { |
3184 | + out.println(" // This inverter should have a short delay"); |
3185 | + } |
3186 | out.print(" " + moduleName + " " + instanceFlatName + " ("); |
3187 | boolean first = true; |
3188 | for (Contact contact: component.getContacts()) { |
3189 | @@ -149,13 +174,77 @@ |
3190 | String contactName = contact.getName(); |
3191 | String wireName = CircuitUtils.getWireName(circuit, contact); |
3192 | if ((wireName == null) || wireName.isEmpty()) { |
3193 | - System.out.println(" Warning: contact '" + contactName + "' of component '"+ instanceFlatName + "' is disconnected."); |
3194 | + System.out.println(" Warning: in component '" + instanceFlatName + "' contact '" + contactName + "' is disconnected."); |
3195 | wireName = ""; |
3196 | } |
3197 | + if (substitutionRule != null) { |
3198 | + String newContactName = substitutionRule.substitutions.get(contactName); |
3199 | + if (newContactName != null) { |
3200 | + System.out.println("Info: in component '" + instanceFlatName + "' renaming contact '" + contactName + "' to '" + newContactName + "'."); |
3201 | + contactName = newContactName; |
3202 | + } |
3203 | + } |
3204 | out.print("." + contactName + "(" + wireName + ")"); |
3205 | } |
3206 | out.print(");\n"); |
3207 | } |
3208 | } |
3209 | |
3210 | + private HashMap<String, SubstitutionRule> readSubsritutionRules() { |
3211 | + HashMap<String, SubstitutionRule> result = new HashMap<>(); |
3212 | + String substitutionsFileName = CircuitSettings.getSubstitutionLibrary(); |
3213 | + if ((substitutionsFileName == null) || substitutionsFileName.isEmpty()) { |
3214 | + System.out.println("Warning: file of substitutions is not specified."); |
3215 | + } else { |
3216 | + File libraryFile = new File(substitutionsFileName); |
3217 | + final Framework framework = Framework.getInstance(); |
3218 | + if (framework.checkFile(libraryFile, "Access error for the file of substitutions")) { |
3219 | + try { |
3220 | + InputStream genlibInputStream = new FileInputStream(substitutionsFileName); |
3221 | + SubstitutionParser substitutionParser = new SubstitutionParser(genlibInputStream); |
3222 | + if (CommonDebugSettings.getParserTracing()) { |
3223 | + substitutionParser.enable_tracing(); |
3224 | + } else { |
3225 | + substitutionParser.disable_tracing(); |
3226 | + } |
3227 | + List<SubstitutionRule> rules = substitutionParser.parseSubstitutionRules(); |
3228 | + for (SubstitutionRule rule: rules) { |
3229 | + result.put(rule.oldName, rule); |
3230 | + } |
3231 | + System.out.println("Info: renaming gates and pins using the file of substitutions '" + substitutionsFileName + "'."); |
3232 | + } catch (FileNotFoundException e) { |
3233 | + } catch (ParseException e) { |
3234 | + System.out.println("Warning: could not parse the file of substitutions '" + substitutionsFileName + "'."); |
3235 | + } |
3236 | + } |
3237 | + } |
3238 | + return result; |
3239 | + } |
3240 | + |
3241 | + private void writeInitialState(PrintWriter out, Circuit circuit) { |
3242 | + HashSet<Contact> contacts = new HashSet<>(); |
3243 | + for (Contact contact: Hierarchy.getDescendantsOfType(circuit.getRoot(), Contact.class, new Func<Contact, Boolean>() { |
3244 | + @Override |
3245 | + public Boolean eval(Contact arg) { |
3246 | + return (arg.isPort() != arg.isOutput()); |
3247 | + } |
3248 | + })) { |
3249 | + contacts.add(contact); |
3250 | + } |
3251 | + out.println(); |
3252 | + out.println(" // signal values at the initial state:"); |
3253 | + out.print(" //"); |
3254 | + for (Contact contact: contacts) { |
3255 | + String wireName = CircuitUtils.getWireName(circuit, contact); |
3256 | + if ((wireName != null) && !wireName.isEmpty()) { |
3257 | + out.print(" "); |
3258 | + if ( !contact.getInitToOne() ) { |
3259 | + out.print("!"); |
3260 | + } |
3261 | + out.print(wireName); |
3262 | + } |
3263 | + } |
3264 | + out.println(); |
3265 | + } |
3266 | + |
3267 | } |
3268 | |
3269 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/stg/CircuitToStgConverter.java' |
3270 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/stg/CircuitToStgConverter.java 2015-11-02 12:32:29 +0000 |
3271 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/stg/CircuitToStgConverter.java 2015-11-09 09:38:45 +0000 |
3272 | @@ -212,7 +212,7 @@ |
3273 | private TwoWayMap<VisualContact, SignalStg> convertDriversToStgs(HashSet<VisualContact> drivers) { |
3274 | TwoWayMap<VisualContact, SignalStg> result = new TwoWayMap<>(); |
3275 | for (VisualContact driver: drivers) { |
3276 | - VisualContact signal = CircuitUtils.findSignal(circuit, driver); |
3277 | + VisualContact signal = CircuitUtils.findSignal(circuit, driver, true); |
3278 | Container container = getContainer(signal); |
3279 | String signalName = CircuitUtils.getSignalName(circuit, signal); |
3280 | |
3281 | @@ -276,7 +276,7 @@ |
3282 | |
3283 | clauses.addAll(dnf.getClauses()); |
3284 | |
3285 | - VisualContact signal = CircuitUtils.findSignal(circuit, driver); |
3286 | + VisualContact signal = CircuitUtils.findSignal(circuit, driver, true); |
3287 | Container container = getContainer(signal); |
3288 | String signalName = CircuitUtils.getSignalName(circuit, signal); |
3289 | SignalTransition.Type signalType = CircuitUtils.getSignalType(circuit, signal); |
3290 | @@ -459,7 +459,7 @@ |
3291 | for (VisualContact driver: drivers) { |
3292 | SignalStg signalStg = driverToStgMap.getValue(driver); |
3293 | if (signalStg != null) { |
3294 | - VisualContact signal = CircuitUtils.findSignal(circuit, driver); |
3295 | + VisualContact signal = CircuitUtils.findSignal(circuit, driver, true); |
3296 | Point2D centerPosition = getPosition(signal); |
3297 | setPosition(signalStg.zero, Geometry.add(centerPosition, OFFSET_P0)); |
3298 | setPosition(signalStg.one, Geometry.add(centerPosition, OFFSET_P1)); |
3299 | |
3300 | === added file 'CircuitPlugin/src/org/workcraft/plugins/circuit/verilog/SubstitutionRule.java' |
3301 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/verilog/SubstitutionRule.java 1970-01-01 00:00:00 +0000 |
3302 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/verilog/SubstitutionRule.java 2015-11-09 09:38:45 +0000 |
3303 | @@ -0,0 +1,16 @@ |
3304 | +package org.workcraft.plugins.circuit.verilog; |
3305 | + |
3306 | +import java.util.Map; |
3307 | + |
3308 | +public class SubstitutionRule { |
3309 | + public final String oldName; |
3310 | + public final String newName; |
3311 | + public final Map<String, String> substitutions; |
3312 | + |
3313 | + public SubstitutionRule(String oldName, String newName, Map<String, String> substitutions) { |
3314 | + this.oldName = oldName; |
3315 | + this.newName = newName; |
3316 | + this.substitutions = substitutions; |
3317 | + } |
3318 | + |
3319 | +} |
3320 | |
3321 | === modified file 'WorkcraftCore/src/org/workcraft/plugins/shared/CommonDebugSettings.java' |
3322 | --- WorkcraftCore/src/org/workcraft/plugins/shared/CommonDebugSettings.java 2015-10-13 17:22:00 +0000 |
3323 | +++ WorkcraftCore/src/org/workcraft/plugins/shared/CommonDebugSettings.java 2015-11-09 09:38:45 +0000 |
3324 | @@ -35,14 +35,17 @@ |
3325 | private static final String keyCopyModelOnChange = prefix + ".copyModelOnChange"; |
3326 | private static final String keyKeepTemporaryFiles = prefix + ".keepTemporaryFiles"; |
3327 | private static final String keyVerboseImport = prefix + ".verboseImport"; |
3328 | + private static final String keyParserTracing = prefix + ".parserTracing"; |
3329 | |
3330 | private static final boolean defaultCopyModelOnChange = false; |
3331 | private static final Boolean defaultKeepTemporaryFiles = true; |
3332 | private static final Boolean defaultVerboseImport = false; |
3333 | + private static final Boolean defaultParserTracing = false; |
3334 | |
3335 | private static boolean copyModelOnChange = defaultCopyModelOnChange; |
3336 | private static Boolean keepTemporaryFiles = defaultKeepTemporaryFiles; |
3337 | private static Boolean verboseImport = defaultVerboseImport; |
3338 | + private static Boolean parserTracing = defaultParserTracing; |
3339 | |
3340 | public CommonDebugSettings() { |
3341 | properties.add(new PropertyDeclaration<CommonDebugSettings, Boolean>( |
3342 | @@ -74,6 +77,16 @@ |
3343 | return getVerboseImport(); |
3344 | } |
3345 | }); |
3346 | + |
3347 | + properties.add(new PropertyDeclaration<CommonDebugSettings, Boolean>( |
3348 | + this, "Log tracing information from parsers", Boolean.class, true, false, false) { |
3349 | + protected void setter(CommonDebugSettings object, Boolean value) { |
3350 | + setParserTracing(value); |
3351 | + } |
3352 | + protected Boolean getter(CommonDebugSettings object) { |
3353 | + return getParserTracing(); |
3354 | + } |
3355 | + }); |
3356 | } |
3357 | |
3358 | @Override |
3359 | @@ -86,6 +99,7 @@ |
3360 | setCopyModelOnChange(config.getBoolean(keyCopyModelOnChange, defaultCopyModelOnChange)); |
3361 | setKeepTemporaryFiles(config.getBoolean(keyKeepTemporaryFiles, defaultKeepTemporaryFiles)); |
3362 | setVerboseImport(config.getBoolean(keyVerboseImport, defaultVerboseImport)); |
3363 | + setParserTracing(config.getBoolean(keyParserTracing, defaultParserTracing)); |
3364 | } |
3365 | |
3366 | @Override |
3367 | @@ -93,6 +107,7 @@ |
3368 | config.setBoolean(keyCopyModelOnChange, getCopyModelOnChange()); |
3369 | config.setBoolean(keyKeepTemporaryFiles, getKeepTemporaryFiles()); |
3370 | config.setBoolean(keyVerboseImport, getVerboseImport()); |
3371 | + config.setBoolean(keyParserTracing, getParserTracing()); |
3372 | } |
3373 | |
3374 | @Override |
3375 | @@ -128,5 +143,13 @@ |
3376 | public static void setVerboseImport(Boolean value) { |
3377 | verboseImport = value; |
3378 | } |
3379 | + |
3380 | + public static Boolean getParserTracing() { |
3381 | + return parserTracing; |
3382 | + } |
3383 | + |
3384 | + public static void setParserTracing(Boolean value) { |
3385 | + parserTracing = value; |
3386 | + } |
3387 | |
3388 | } |