mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-28 15:32:40 -04:00
better ordering of input bus in generated circuits
This commit is contained in:
parent
68193f3156
commit
df554b1d97
@ -40,7 +40,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
private final ArrayList<FragmentVariable> fragmentVariables;
|
private final ArrayList<FragmentVariable> fragmentVariables;
|
||||||
private final ArrayList<Fragment> fragments;
|
private final ArrayList<Fragment> fragments;
|
||||||
private final HashSet<String> combinatorialOutputs;
|
private final HashSet<String> combinatorialOutputs;
|
||||||
private final HashSet<String> createdNets;
|
private final ArrayList<Variable> sequentialVars;
|
||||||
private final ArrayList<FragmentVisualElement> flipflops;
|
private final ArrayList<FragmentVisualElement> flipflops;
|
||||||
private final boolean useJKff;
|
private final boolean useJKff;
|
||||||
private int pos;
|
private int pos;
|
||||||
@ -69,7 +69,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
fragments = new ArrayList<>();
|
fragments = new ArrayList<>();
|
||||||
flipflops = new ArrayList<>();
|
flipflops = new ArrayList<>();
|
||||||
combinatorialOutputs = new HashSet<>();
|
combinatorialOutputs = new HashSet<>();
|
||||||
createdNets = new HashSet<>();
|
sequentialVars = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,8 +118,6 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
flipflops.add(ff);
|
flipflops.add(ff);
|
||||||
FragmentSameInValue fsv = new FragmentSameInValue(ff);
|
FragmentSameInValue fsv = new FragmentSameInValue(ff);
|
||||||
FragmentExpression fe = new FragmentExpression(fsv, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
|
FragmentExpression fe = new FragmentExpression(fsv, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
|
||||||
createdNets.add(name);
|
|
||||||
|
|
||||||
fragments.add(new FragmentExpression(frJ, fe));
|
fragments.add(new FragmentExpression(frJ, fe));
|
||||||
} else {
|
} else {
|
||||||
Fragment frJ = createFragment(jk.getSimplifiedJ());
|
Fragment frJ = createFragment(jk.getSimplifiedJ());
|
||||||
@ -127,7 +125,6 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
FragmentVisualElement ff = new FragmentVisualElement(FlipflopJK.DESCRIPTION, shapeFactory).ignoreInput(1).setAttr(Keys.LABEL, name);
|
FragmentVisualElement ff = new FragmentVisualElement(FlipflopJK.DESCRIPTION, shapeFactory).ignoreInput(1).setAttr(Keys.LABEL, name);
|
||||||
flipflops.add(ff);
|
flipflops.add(ff);
|
||||||
FragmentExpression fe = new FragmentExpression(ff, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
|
FragmentExpression fe = new FragmentExpression(ff, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
|
||||||
createdNets.add(name);
|
|
||||||
fragments.add(new FragmentExpression(Arrays.asList(frJ, frK), fe));
|
fragments.add(new FragmentExpression(Arrays.asList(frJ, frK), fe));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,10 +137,10 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
FragmentVisualElement ff = new FragmentVisualElement(FlipflopD.DESCRIPTION, shapeFactory).setAttr(Keys.LABEL, name);
|
FragmentVisualElement ff = new FragmentVisualElement(FlipflopD.DESCRIPTION, shapeFactory).setAttr(Keys.LABEL, name);
|
||||||
flipflops.add(ff);
|
flipflops.add(ff);
|
||||||
FragmentExpression fe = new FragmentExpression(ff, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
|
FragmentExpression fe = new FragmentExpression(ff, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
|
||||||
createdNets.add(name);
|
|
||||||
fragments.add(new FragmentExpression(fr, fe));
|
fragments.add(new FragmentExpression(fr, fe));
|
||||||
}
|
}
|
||||||
expression.traverse(variableVisitor);
|
expression.traverse(variableVisitor);
|
||||||
|
sequentialVars.add(new Variable(name));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +199,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
pos -= SIZE;
|
pos -= SIZE;
|
||||||
for (Variable v : inputs) {
|
for (Variable v : inputs) {
|
||||||
VisualElement visualElement;
|
VisualElement visualElement;
|
||||||
if (createdNets.contains(v.getIdentifier())) {
|
if (sequentialVars.contains(v)) {
|
||||||
visualElement = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
|
visualElement = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
|
||||||
visualElement.getElementAttributes()
|
visualElement.getElementAttributes()
|
||||||
.set(Keys.ROTATE, new Rotation(1))
|
.set(Keys.ROTATE, new Rotation(1))
|
||||||
@ -271,7 +268,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
if (maxWidth < b.getWidth()) maxWidth = b.getWidth();
|
if (maxWidth < b.getWidth()) maxWidth = b.getWidth();
|
||||||
}
|
}
|
||||||
// add space for clock wire!
|
// add space for clock wire!
|
||||||
if (!createdNets.isEmpty())
|
if (!sequentialVars.isEmpty())
|
||||||
maxWidth += SIZE * 2;
|
maxWidth += SIZE * 2;
|
||||||
|
|
||||||
// set width to fragments
|
// set width to fragments
|
||||||
@ -288,18 +285,9 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
|
|
||||||
// order bus variables
|
// order bus variables
|
||||||
Collection<Variable> variables = variableVisitor.getVariables();
|
Collection<Variable> variables = variableVisitor.getVariables();
|
||||||
if (!createdNets.isEmpty()) {
|
if (!sequentialVars.isEmpty())
|
||||||
ArrayList<Variable> c1 = new ArrayList<>();
|
variables = order(variables, sequentialVars);
|
||||||
ArrayList<Variable> c2 = new ArrayList<>();
|
|
||||||
for (Variable v : variables)
|
|
||||||
if (createdNets.contains(v.getIdentifier()))
|
|
||||||
c2.add(v);
|
|
||||||
else
|
|
||||||
c1.add(v);
|
|
||||||
|
|
||||||
c1.addAll(c2);
|
|
||||||
variables = c1;
|
|
||||||
}
|
|
||||||
|
|
||||||
createInputBus(variables, circuit);
|
createInputBus(variables, circuit);
|
||||||
|
|
||||||
@ -307,13 +295,31 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
if (!flipflops.isEmpty())
|
if (!flipflops.isEmpty())
|
||||||
addClockTpFlipFlops(circuit);
|
addClockTpFlipFlops(circuit);
|
||||||
|
|
||||||
if (!createdNets.isEmpty())
|
if (!sequentialVars.isEmpty())
|
||||||
addNetConnections(circuit, maxWidth + SIZE * 5);
|
addNetConnections(circuit, maxWidth + SIZE * 5);
|
||||||
|
|
||||||
circuit.setNotModified();
|
circuit.setNotModified();
|
||||||
return circuit;
|
return circuit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the lastItems to the end of the variables list.
|
||||||
|
* Items which are not in lastItems are placed at the beginning of the result list
|
||||||
|
*
|
||||||
|
* @param variables the variables to order
|
||||||
|
* @param lastItems the items to be placed at the end of the list
|
||||||
|
* @return the ordered list
|
||||||
|
*/
|
||||||
|
private static <T> ArrayList<T> order(Collection<T> variables, ArrayList<T> lastItems) {
|
||||||
|
ArrayList<T> vars = new ArrayList<>(variables);
|
||||||
|
for (T seq : lastItems)
|
||||||
|
if (vars.contains(seq)) {
|
||||||
|
vars.remove(seq); // move to end
|
||||||
|
vars.add(seq);
|
||||||
|
}
|
||||||
|
return vars;
|
||||||
|
}
|
||||||
|
|
||||||
private void addClockTpFlipFlops(Circuit circuit) {
|
private void addClockTpFlipFlops(Circuit circuit) {
|
||||||
int x = Integer.MAX_VALUE;
|
int x = Integer.MAX_VALUE;
|
||||||
int yMin = Integer.MAX_VALUE;
|
int yMin = Integer.MAX_VALUE;
|
||||||
@ -349,14 +355,15 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
|
|
||||||
private void addNetConnections(Circuit circuit, int xPos) {
|
private void addNetConnections(Circuit circuit, int xPos) {
|
||||||
int y = -SIZE * 5;
|
int y = -SIZE * 5;
|
||||||
ArrayList<String> list = new ArrayList<>(createdNets);
|
for (Variable name : sequentialVars) {
|
||||||
Collections.sort(list);
|
String oName = name.getIdentifier();
|
||||||
for (String name : list) {
|
if (oName.endsWith("n")) {
|
||||||
String oName = name;
|
oName = oName.substring(0, oName.length() - 1);
|
||||||
if (name.endsWith("n")) oName = name.substring(0, name.length() - 1);
|
if (oName.endsWith("_")) oName = oName.substring(0, oName.length() - 1);
|
||||||
|
}
|
||||||
if (!combinatorialOutputs.contains(oName)) {
|
if (!combinatorialOutputs.contains(oName)) {
|
||||||
VisualElement t = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
|
VisualElement t = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
|
||||||
t.getElementAttributes().set(Keys.NETNAME, name);
|
t.getElementAttributes().set(Keys.NETNAME, name.getIdentifier());
|
||||||
t.setPos(new Vector(xPos, y));
|
t.setPos(new Vector(xPos, y));
|
||||||
t.setRotation(2);
|
t.setRotation(2);
|
||||||
circuit.add(t);
|
circuit.add(t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user