use of de.neemann.digital.analyse.DetermineJKStateMachine in project Digital by hneemann.
the class CircuitBuilder method addSequential.
/**
* Add a transition function of a state machine
*
* @param name name of the state
* @param expression the expression describing next state
* @return this for chained calls
* @throws BuilderException BuilderException
*/
@Override
public CircuitBuilder addSequential(String name, Expression expression) throws BuilderException {
boolean useDff = true;
if (useJKff) {
try {
DetermineJKStateMachine jk = new DetermineJKStateMachine(name, expression);
useDff = jk.isDFF();
if (!useDff) {
boolean isJequalK = new Equals(jk.getSimplifiedJ(), jk.getSimplifiedK()).isEqual();
if (isJequalK) {
Fragment frJ = createFragment(jk.getSimplifiedJ());
FragmentVisualElement ff = new FragmentVisualElement(FlipflopJK.DESCRIPTION, shapeFactory).ignoreInput(1).setAttr(Keys.LABEL, name);
flipflops.add(ff);
FragmentSameInValue fsv = new FragmentSameInValue(ff);
FragmentExpression fe = new FragmentExpression(fsv, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
fragments.add(new FragmentExpression(frJ, fe));
} else {
Fragment frJ = createFragment(jk.getSimplifiedJ());
Fragment frK = createFragment(jk.getSimplifiedK());
FragmentVisualElement ff = new FragmentVisualElement(FlipflopJK.DESCRIPTION, shapeFactory).ignoreInput(1).setAttr(Keys.LABEL, name);
flipflops.add(ff);
FragmentExpression fe = new FragmentExpression(ff, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
fragments.add(new FragmentExpression(Arrays.asList(frJ, frK), fe));
}
}
} catch (ExpressionException | FormatterException e) {
throw new BuilderException(e.getMessage());
}
}
if (useDff) {
Fragment fr = createFragment(expression);
FragmentVisualElement ff = new FragmentVisualElement(FlipflopD.DESCRIPTION, shapeFactory).setAttr(Keys.LABEL, name);
flipflops.add(ff);
FragmentExpression fe = new FragmentExpression(ff, new FragmentVisualElement(Tunnel.DESCRIPTION, shapeFactory).setAttr(Keys.NETNAME, name));
fragments.add(new FragmentExpression(fr, fe));
}
expression.traverse(variableVisitor);
sequentialVars.add(new Variable(name));
return this;
}
use of de.neemann.digital.analyse.DetermineJKStateMachine in project Digital by hneemann.
the class ExpressionListenerOptimizeJK method resultFound.
@Override
public void resultFound(String name, Expression expression) throws FormatterException, ExpressionException {
if (name.endsWith("n+1")) {
String varName = name.substring(0, name.length() - 2);
if (name.equals(lastName)) {
int c = new DetermineJKStateMachine(varName, expression).getComplexity();
if (c < lastComplexity) {
lastName = name;
lastExpression = expression;
lastComplexity = c;
}
} else {
handlePending();
lastName = name;
lastExpression = expression;
lastComplexity = new DetermineJKStateMachine(varName, expression).getComplexity();
}
} else {
handlePending();
parent.resultFound(name, expression);
}
}
use of de.neemann.digital.analyse.DetermineJKStateMachine in project Digital by hneemann.
the class ExpressionListenerJK method resultFound.
@Override
public void resultFound(String name, Expression expression) throws FormatterException, ExpressionException {
parent.resultFound(name, expression);
if (name.endsWith("n+1")) {
String detName = name.substring(0, name.length() - 2);
DetermineJKStateMachine jk = new DetermineJKStateMachine(detName, expression);
Expression j = jk.getJ();
parent.resultFound("J_" + detName, j);
Expression s = jk.getSimplifiedJ();
if (!s.toString().equals(j.toString())) {
parent.resultFound("", s);
}
Expression k = jk.getK();
parent.resultFound("K_" + detName, k);
s = jk.getSimplifiedK();
if (!s.toString().equals(k.toString())) {
parent.resultFound("", s);
}
}
}
Aggregations