mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-27 23:18:02 -04:00
better error checking while optimizing expressions
This commit is contained in:
parent
1aeb54b513
commit
8464e72cf7
@ -186,7 +186,13 @@ public class TruthTable {
|
||||
* Adds a new variable
|
||||
*/
|
||||
public void addVariable() {
|
||||
addVariable("A");
|
||||
char v = 'A';
|
||||
Variable var;
|
||||
do {
|
||||
var = new Variable("" + v);
|
||||
v++;
|
||||
} while (variables.contains(var) && v <= 'Z');
|
||||
addVariable(var);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,7 +201,16 @@ public class TruthTable {
|
||||
* @param name name of the variable
|
||||
*/
|
||||
public void addVariable(String name) {
|
||||
variables.add(new Variable(name));
|
||||
addVariable(new Variable(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a variable
|
||||
*
|
||||
* @param var the variable to add
|
||||
*/
|
||||
public void addVariable(Variable var) {
|
||||
variables.add(var);
|
||||
for (Result r : results)
|
||||
r.setValues(BoolTableByteArray.createDoubledValues(r.getValues()));
|
||||
|
||||
|
@ -28,8 +28,8 @@ import java.util.*;
|
||||
import static de.neemann.digital.draw.shapes.GenericShape.SIZE;
|
||||
|
||||
/**
|
||||
* Builder to create a circuit from a set off expression
|
||||
* Is also able to create a state machine.
|
||||
* Builder to create a circuit from a set of expressions.
|
||||
* Is also able to create a finite state machine.
|
||||
*
|
||||
* @author hneemann
|
||||
*/
|
||||
@ -43,6 +43,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
||||
private final ArrayList<Variable> sequentialVars;
|
||||
private final ArrayList<FragmentVisualElement> flipflops;
|
||||
private final boolean useJKff;
|
||||
private final ArrayList<Variable> desiredVarOrdering;
|
||||
private int pos;
|
||||
|
||||
/**
|
||||
@ -62,8 +63,20 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
||||
* @param useJKff true if JK flip-flops should be used to create state machines instead of D flip-flops.
|
||||
*/
|
||||
public CircuitBuilder(ShapeFactory shapeFactory, boolean useJKff) {
|
||||
this(shapeFactory, useJKff, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new builder.
|
||||
*
|
||||
* @param shapeFactory ShapeFactory which is set to the created VisualElements
|
||||
* @param useJKff true if JK flip-flops should be used to create state machines instead of D flip-flops.
|
||||
* @param varOrdering the desired ordering of the variables, There may be more variables than required. Maybe null.
|
||||
*/
|
||||
public CircuitBuilder(ShapeFactory shapeFactory, boolean useJKff, ArrayList<Variable> varOrdering) {
|
||||
this.shapeFactory = shapeFactory;
|
||||
this.useJKff = useJKff;
|
||||
desiredVarOrdering = varOrdering;
|
||||
variableVisitor = new VariableVisitor();
|
||||
fragmentVariables = new ArrayList<>();
|
||||
fragments = new ArrayList<>();
|
||||
@ -285,6 +298,8 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
||||
|
||||
// order bus variables
|
||||
Collection<Variable> variables = variableVisitor.getVariables();
|
||||
if (desiredVarOrdering != null)
|
||||
variables = order(variables, desiredVarOrdering);
|
||||
if (!sequentialVars.isEmpty())
|
||||
variables = order(variables, sequentialVars);
|
||||
|
||||
|
@ -56,11 +56,11 @@ public class CheckResultListener implements ExpressionListener {
|
||||
return;
|
||||
case one:
|
||||
if (!calculate)
|
||||
throw new ExpressionException("internal minimization error: found false, expected true");
|
||||
throw new ExpressionException(Lang.get("err_minimizationFailed"));
|
||||
break;
|
||||
case zero:
|
||||
if (calculate)
|
||||
throw new ExpressionException("internal minimization error: found true, expected false");
|
||||
throw new ExpressionException(Lang.get("err_minimizationFailed"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -507,7 +507,7 @@ public class TableDialog extends JDialog {
|
||||
|
||||
private void createCircuit(boolean useJKff, ExpressionModifier... modifier) {
|
||||
try {
|
||||
CircuitBuilder circuitBuilder = new CircuitBuilder(shapeFactory, useJKff);
|
||||
CircuitBuilder circuitBuilder = new CircuitBuilder(shapeFactory, useJKff, model.getTable().getVars());
|
||||
new BuilderExpressionCreator(circuitBuilder, modifier).setUseJKOptimizer(useJKff).create(lastGeneratedExpressions);
|
||||
Circuit circuit = circuitBuilder.createCircuit();
|
||||
SwingUtilities.invokeLater(() -> new Main(null, library, circuit).setVisible(true));
|
||||
|
@ -462,6 +462,8 @@ Es sind nur {1} Variablen erlaubt, es wurden jedoch {2} gefunden.</string>
|
||||
<string name="err_varName_N_UsedTwice">Die Variable {0} wird mehrfach verwendet!</string>
|
||||
<string name="err_fileNeedsToBeSaved">Die Datei muss zunächst gespeichert werden!</string>
|
||||
<string name="err_recursiveNestingAt_N0">Die Schaltung {0} bindet sich selbst ein!</string>
|
||||
<string name="err_minimizationFailed">Das Ergebnis der Minimierung ist nicht korrekt!
|
||||
Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
|
||||
<string name="key_AddrBits">Adress-Bits</string>
|
||||
<string name="key_AddrBits_tt">Anzahl der Adress-Bits die verwendet werden.</string>
|
||||
@ -744,7 +746,7 @@ Die Icons stammen aus dem Tango Desktop Project.</string>
|
||||
<string name="msg_fileNotAccessible">Dieser Dateiename ist nicht aus dem aktuellen Projekt importierbar!</string>
|
||||
<string name="msg_fileIsNotUnique">Der Dateiname ist nicht eindeutig!</string>
|
||||
<string name="msg_fileNotImportedYet">Die Datei wurde noch nicht importiert.</string>
|
||||
<string name="msg_fileExists">Die Datei {0} existiert schon!</string>
|
||||
<string name="msg_fileExists">Die Datei {0} existiert schon! Soll die Datei überschrieben werden?</string>
|
||||
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
|
@ -449,6 +449,8 @@ allowed are {1} variables but {2} are found.</string>
|
||||
<string name="err_varName_N_UsedTwice">The variable {0} is used twice!</string>
|
||||
<string name="err_fileNeedsToBeSaved">The file needs to be saved!</string>
|
||||
<string name="err_recursiveNestingAt_N0">The circuit {0} imports itself!</string>
|
||||
<string name="err_minimizationFailed">The result of the minimization is not correct!
|
||||
The names of the variables may not be unique.</string>
|
||||
|
||||
<string name="key_AddrBits">Address Bits</string>
|
||||
<string name="key_AddrBits_tt">Number of address bits used.</string>
|
||||
@ -731,7 +733,7 @@ The icons are taken from the Tango Desktop Project.</string>
|
||||
<string name="msg_fileNotAccessible">The selected file name is not importable from the actual project!</string>
|
||||
<string name="msg_fileIsNotUnique">The file name is not unique!</string>
|
||||
<string name="msg_fileNotImportedYet">The file has not yet been imported.</string>
|
||||
<string name="msg_fileExists">The file {0} already exists!</string>
|
||||
<string name="msg_fileExists">The file {0} already exists! Do you want to overwrite the file?</string>
|
||||
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user