Merge lp:~danilovesky/workcraft/trunk-import-verilog into lp:workcraft

Proposed by Danil Sokolov
Status: Merged
Merged at revision: 627
Proposed branch: lp:~danilovesky/workcraft/trunk-import-verilog
Merge into: lp:workcraft
Diff against target: 81 lines (+25/-14)
1 file modified
CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java (+25/-14)
To merge this branch: bzr merge lp:~danilovesky/workcraft/trunk-import-verilog
Reviewer Review Type Date Requested Status
Danil Sokolov Pending
Review via email: mp+264059@code.launchpad.net
To post a comment you must log in.
627. By Danil Sokolov

Merge proposal approved.

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/interop/VerilogImporter.java'
2--- CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java 2015-07-04 22:23:12 +0000
3+++ CircuitPlugin/src/org/workcraft/plugins/circuit/interop/VerilogImporter.java 2015-07-07 17:30:53 +0000
4@@ -26,6 +26,7 @@
5 import java.util.Collection;
6 import java.util.HashMap;
7 import java.util.HashSet;
8+import java.util.List;
9
10 import org.workcraft.exceptions.DeserialisationException;
11 import org.workcraft.exceptions.FormatException;
12@@ -35,6 +36,7 @@
13 import org.workcraft.plugins.circuit.CircuitComponent;
14 import org.workcraft.plugins.circuit.CircuitModelDescriptor;
15 import org.workcraft.plugins.circuit.Contact.IOType;
16+import org.workcraft.plugins.circuit.FunctionComponent;
17 import org.workcraft.plugins.circuit.FunctionContact;
18 import org.workcraft.plugins.circuit.javacc.ParseException;
19 import org.workcraft.plugins.circuit.javacc.VerilogParser;
20@@ -61,12 +63,7 @@
21 public Circuit importCircuit(InputStream in) throws DeserialisationException {
22 try {
23 VerilogParser parser = new VerilogParser(in);
24- HashMap<String, Module> modules = new HashMap<>();
25- for (VerilogParser.Module module: parser.parseCircuit()) {
26- if ((module == null) || (module.name == null)) continue;
27- modules.put(module.name, module);
28- }
29-// printDebugInfo(modules);
30+ HashMap<String, Module> modules = getModuleMap(parser.parseCircuit());
31 HashSet<VerilogParser.Module> topModules = getTopModule(modules);
32 if (topModules.size() == 0) {
33 throw new RuntimeException("No top module found.");
34@@ -138,20 +135,15 @@
35 circuit.add(contact);
36 }
37 for (VerilogParser.Instance verilogInstance: topModule.instances) {
38- CircuitComponent component = new CircuitComponent();
39+ FunctionComponent component = new FunctionComponent();
40 component.setModule(verilogInstance.moduleName);
41 circuit.setName(component, verilogInstance.name);
42 circuit.add(component);
43 VerilogParser.Module module = modules.get(verilogInstance.moduleName);
44- HashMap<String, VerilogParser.Port> ports = new HashMap<>();
45- if (module != null) {
46- for (VerilogParser.Port port: module.ports) {
47- ports.put(port.name, port);
48- }
49- }
50+ HashMap<String, VerilogParser.Port> instancePorts = getModulePortMap(module);
51 for (VerilogParser.Connection verilogConnection: verilogInstance.connections) {
52 FunctionContact contact = new FunctionContact();
53- VerilogParser.Port verilogPort = ports.get(verilogConnection.name);
54+ VerilogParser.Port verilogPort = instancePorts.get(verilogConnection.name);
55 Wire wire = wires.get(verilogConnection.netName);
56 if (wire == null) {
57 wire = new Wire();
58@@ -180,4 +172,23 @@
59 return circuit;
60 }
61
62+ private HashMap<String, VerilogParser.Module> getModuleMap(List<VerilogParser.Module> modules) throws ParseException {
63+ HashMap<String, VerilogParser.Module> result = new HashMap<>();
64+ for (VerilogParser.Module module: modules) {
65+ if ((module == null) || (module.name == null)) continue;
66+ result.put(module.name, module);
67+ }
68+ return result;
69+ }
70+
71+ private HashMap<String, VerilogParser.Port> getModulePortMap(VerilogParser.Module module) {
72+ HashMap<String, VerilogParser.Port> result = new HashMap<>();
73+ if (module != null) {
74+ for (VerilogParser.Port port: module.ports) {
75+ result.put(port.name, port);
76+ }
77+ }
78+ return result;
79+ }
80+
81 }

Subscribers

People subscribed via source and target branches