mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-29 07:50:29 -04:00
pin assignment is stored in truth table now
This commit is contained in:
parent
7fbc46323c
commit
fa6fc4dd7e
@ -136,6 +136,11 @@ public class ModelAnalyser {
|
|||||||
for (Signal s : inputs)
|
for (Signal s : inputs)
|
||||||
tt.addVariable(s.getName());
|
tt.addVariable(s.getName());
|
||||||
|
|
||||||
|
for (Signal s : inputs)
|
||||||
|
tt.addPinNumber(s);
|
||||||
|
for (Signal s : outputs)
|
||||||
|
tt.addPinNumber(s);
|
||||||
|
|
||||||
ArrayList<BoolTableByteArray> data = new ArrayList<>();
|
ArrayList<BoolTableByteArray> data = new ArrayList<>();
|
||||||
for (Signal s : outputs) {
|
for (Signal s : outputs) {
|
||||||
BoolTableByteArray e = new BoolTableByteArray(rows);
|
BoolTableByteArray e = new BoolTableByteArray(rows);
|
||||||
|
@ -10,9 +10,12 @@ import de.neemann.digital.analyse.expression.Variable;
|
|||||||
import de.neemann.digital.analyse.quinemc.BoolTable;
|
import de.neemann.digital.analyse.quinemc.BoolTable;
|
||||||
import de.neemann.digital.analyse.quinemc.BoolTableByteArray;
|
import de.neemann.digital.analyse.quinemc.BoolTableByteArray;
|
||||||
import de.neemann.digital.analyse.quinemc.ThreeStateValue;
|
import de.neemann.digital.analyse.quinemc.ThreeStateValue;
|
||||||
|
import de.neemann.digital.core.NodeException;
|
||||||
|
import de.neemann.digital.core.Signal;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of a truth table.
|
* The description of a truth table.
|
||||||
@ -23,6 +26,7 @@ public class TruthTable {
|
|||||||
|
|
||||||
private final ArrayList<Variable> variables;
|
private final ArrayList<Variable> variables;
|
||||||
private final ArrayList<Result> results;
|
private final ArrayList<Result> results;
|
||||||
|
private final TreeMap<String, Integer> pins;
|
||||||
private transient BitSetter bitSetter;
|
private transient BitSetter bitSetter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,6 +127,7 @@ public class TruthTable {
|
|||||||
public TruthTable(ArrayList<Variable> vars) {
|
public TruthTable(ArrayList<Variable> vars) {
|
||||||
this.variables = vars;
|
this.variables = vars;
|
||||||
results = new ArrayList<>();
|
results = new ArrayList<>();
|
||||||
|
pins = new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -425,6 +430,24 @@ public class TruthTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ats the signals pindescription to the table
|
||||||
|
*
|
||||||
|
* @param s the signal
|
||||||
|
* @throws NodeException NodeException
|
||||||
|
*/
|
||||||
|
public void addPinNumber(Signal s) throws NodeException {
|
||||||
|
int p = s.getPinNumber();
|
||||||
|
if (p >= 0) pins.put(s.getName(), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the assigned pins
|
||||||
|
*/
|
||||||
|
public TreeMap<String, Integer> getPins() {
|
||||||
|
return pins;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A single result column
|
* A single result column
|
||||||
*/
|
*/
|
||||||
|
@ -2,8 +2,6 @@ package de.neemann.digital.builder;
|
|||||||
|
|
||||||
import de.neemann.digital.analyse.expression.Expression;
|
import de.neemann.digital.analyse.expression.Expression;
|
||||||
import de.neemann.digital.analyse.expression.Variable;
|
import de.neemann.digital.analyse.expression.Variable;
|
||||||
import de.neemann.digital.core.Model;
|
|
||||||
import de.neemann.digital.core.Signal;
|
|
||||||
import de.neemann.digital.core.element.PinDescription;
|
import de.neemann.digital.core.element.PinDescription;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
@ -29,41 +27,6 @@ public class PinMap {
|
|||||||
availPins = new ArrayList<>();
|
availPins = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the pin assignments from the given model
|
|
||||||
*
|
|
||||||
* @param model the model
|
|
||||||
* @return this for chained calls
|
|
||||||
* @throws PinMapException PinMapException
|
|
||||||
*/
|
|
||||||
public PinMap addModel(Model model) throws PinMapException {
|
|
||||||
for (Signal p : model.getInputs())
|
|
||||||
addSignal(p);
|
|
||||||
for (Signal p : model.getOutputs())
|
|
||||||
addSignal(p);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addSignal(Signal signal) throws PinMapException {
|
|
||||||
if (signal.getDescription() != null && signal.getDescription().length() > 0) {
|
|
||||||
StringTokenizer st = new StringTokenizer(signal.getDescription(), "\n\r");
|
|
||||||
while (st.hasMoreTokens()) {
|
|
||||||
String line = st.nextToken();
|
|
||||||
if (line.toLowerCase().startsWith("pin ")) {
|
|
||||||
String intStr = line.substring(4).trim();
|
|
||||||
try {
|
|
||||||
int pin = Integer.parseInt(intStr);
|
|
||||||
assignPin(signal.getName(), pin);
|
|
||||||
return;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new PinMapException("invalid assignment " + signal.getName() + "=" + intStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the available input pin numbers
|
* Sets the available input pin numbers
|
||||||
*
|
*
|
||||||
@ -190,9 +153,9 @@ public class PinMap {
|
|||||||
* @return this for chained calls
|
* @return this for chained calls
|
||||||
* @throws PinMapException PinMapException
|
* @throws PinMapException PinMapException
|
||||||
*/
|
*/
|
||||||
public PinMap addAll(PinMap pinMap) throws PinMapException {
|
public PinMap addAll(Map<String, Integer> pinMap) throws PinMapException {
|
||||||
if (pinMap != null)
|
if (pinMap != null)
|
||||||
for (Map.Entry<String, Integer> e : pinMap.pinMap.entrySet())
|
for (Map.Entry<String, Integer> e : pinMap.entrySet())
|
||||||
assignPin(e.getKey(), e.getValue());
|
assignPin(e.getKey(), e.getValue());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.neemann.digital.core;
|
package de.neemann.digital.core;
|
||||||
|
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple storage bean for signals
|
* A simple storage bean for signals
|
||||||
*/
|
*/
|
||||||
@ -86,4 +88,29 @@ public final class Signal implements Comparable<Signal> {
|
|||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return name != null && name.length() > 0 && value != null;
|
return name != null && name.length() > 0 && value != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of this pin.
|
||||||
|
*
|
||||||
|
* @return the pin number of -1 if no pin is given
|
||||||
|
* @throws NodeException invalid pin number
|
||||||
|
*/
|
||||||
|
public int getPinNumber() throws NodeException {
|
||||||
|
if (getDescription() != null && getDescription().length() > 0) {
|
||||||
|
StringTokenizer st = new StringTokenizer(getDescription(), "\n\r");
|
||||||
|
while (st.hasMoreTokens()) {
|
||||||
|
String line = st.nextToken();
|
||||||
|
if (line.toLowerCase().startsWith("pin ")) {
|
||||||
|
String intStr = line.substring(4).trim();
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(intStr);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new NodeException("invalid pin assignment " + getName() + "=" + intStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ import de.neemann.digital.analyse.AnalyseException;
|
|||||||
import de.neemann.digital.analyse.ModelAnalyser;
|
import de.neemann.digital.analyse.ModelAnalyser;
|
||||||
import de.neemann.digital.analyse.TruthTable;
|
import de.neemann.digital.analyse.TruthTable;
|
||||||
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
import de.neemann.digital.analyse.expression.format.FormatToExpression;
|
||||||
import de.neemann.digital.builder.PinMap;
|
|
||||||
import de.neemann.digital.builder.PinMapException;
|
|
||||||
import de.neemann.digital.core.*;
|
import de.neemann.digital.core.*;
|
||||||
import de.neemann.digital.core.element.ElementAttributes;
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
import de.neemann.digital.core.element.Key;
|
import de.neemann.digital.core.element.Key;
|
||||||
@ -631,10 +629,9 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
|||||||
try {
|
try {
|
||||||
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
|
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
|
||||||
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), shapeFactory, filename)
|
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), shapeFactory, filename)
|
||||||
.setPinMap(new PinMap().addModel(model))
|
|
||||||
.setVisible(true);
|
.setVisible(true);
|
||||||
stoppedState.enter();
|
stoppedState.enter();
|
||||||
} catch (PinException | PinMapException | NodeException | AnalyseException | ElementNotFoundException e1) {
|
} catch (PinException | NodeException | AnalyseException | ElementNotFoundException e1) {
|
||||||
showErrorAndStopModel(Lang.get("msg_annalyseErr"), e1);
|
showErrorAndStopModel(Lang.get("msg_annalyseErr"), e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,6 @@ public class TableDialog extends JDialog {
|
|||||||
private TableColumn column;
|
private TableColumn column;
|
||||||
private int columnIndex;
|
private int columnIndex;
|
||||||
private AllSolutionsDialog allSolutionsDialog;
|
private AllSolutionsDialog allSolutionsDialog;
|
||||||
private PinMap pinMap;
|
|
||||||
private ExpressionListenerStore lastGeneratedExpressions;
|
private ExpressionListenerStore lastGeneratedExpressions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -482,7 +481,7 @@ public class TableDialog extends JDialog {
|
|||||||
fileChooser.setSelectedFile(filename);
|
fileChooser.setSelectedFile(filename);
|
||||||
if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
|
if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
try {
|
try {
|
||||||
expressionExporter.getPinMapping().addAll(pinMap);
|
expressionExporter.getPinMapping().addAll(model.getTable().getPins());
|
||||||
new BuilderExpressionCreator(expressionExporter.getBuilder(), ExpressionModifier.IDENTITY).create(lastGeneratedExpressions);
|
new BuilderExpressionCreator(expressionExporter.getBuilder(), ExpressionModifier.IDENTITY).create(lastGeneratedExpressions);
|
||||||
expressionExporter.export(Main.checkSuffix(fileChooser.getSelectedFile(), suffix));
|
expressionExporter.export(Main.checkSuffix(fileChooser.getSelectedFile(), suffix));
|
||||||
} catch (ExpressionException | FormatterException | IOException | FuseMapFillerException | PinMapException e) {
|
} catch (ExpressionException | FormatterException | IOException | FuseMapFillerException | PinMapException e) {
|
||||||
@ -536,7 +535,7 @@ public class TableDialog extends JDialog {
|
|||||||
|
|
||||||
File f = new File(cuplPath, "CUPL.PLD");
|
File f = new File(cuplPath, "CUPL.PLD");
|
||||||
cupl.setProjectName(filename.getName());
|
cupl.setProjectName(filename.getName());
|
||||||
cupl.getPinMapping().addAll(pinMap);
|
cupl.getPinMapping().addAll(model.getTable().getPins());
|
||||||
new BuilderExpressionCreator(cupl.getBuilder(), ExpressionModifier.IDENTITY).create(lastGeneratedExpressions);
|
new BuilderExpressionCreator(cupl.getBuilder(), ExpressionModifier.IDENTITY).create(lastGeneratedExpressions);
|
||||||
try (FileOutputStream out = new FileOutputStream(f)) {
|
try (FileOutputStream out = new FileOutputStream(f)) {
|
||||||
cupl.writeTo(out);
|
cupl.writeTo(out);
|
||||||
@ -570,17 +569,6 @@ public class TableDialog extends JDialog {
|
|||||||
calculateExpressions();
|
calculateExpressions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a pin map
|
|
||||||
*
|
|
||||||
* @param pinMap the pin description
|
|
||||||
* @return this for chained calls
|
|
||||||
*/
|
|
||||||
public TableDialog setPinMap(PinMap pinMap) {
|
|
||||||
this.pinMap = pinMap;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CalculationTableModelListener implements TableModelListener {
|
private class CalculationTableModelListener implements TableModelListener {
|
||||||
@Override
|
@Override
|
||||||
public void tableChanged(TableModelEvent tableModelEvent) {
|
public void tableChanged(TableModelEvent tableModelEvent) {
|
||||||
|
@ -165,7 +165,7 @@ public class PinMapTest extends TestCase {
|
|||||||
public void testToString() throws PinMapException {
|
public void testToString() throws PinMapException {
|
||||||
pinMap.assignPin("A", 1);
|
pinMap.assignPin("A", 1);
|
||||||
pinMap.assignPin("B", 4);
|
pinMap.assignPin("B", 4);
|
||||||
String pinStr=pinMap.toString();
|
String pinStr = pinMap.toString();
|
||||||
|
|
||||||
assertTrue(pinStr.contains("Pin 1: A\n"));
|
assertTrue(pinStr.contains("Pin 1: A\n"));
|
||||||
assertTrue(pinStr.contains("Pin 4: B\n"));
|
assertTrue(pinStr.contains("Pin 4: B\n"));
|
||||||
@ -181,25 +181,4 @@ public class PinMapTest extends TestCase {
|
|||||||
"Pin 6: nicht verwendet\n", );*/
|
"Pin 6: nicht verwendet\n", );*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testModelInputs() throws PinMapException {
|
|
||||||
Model m = new Model();
|
|
||||||
m.addInput(new Signal("A_1", new ObservableValue("A_1", 1)).setDescription("Pin 3"));
|
|
||||||
m.addInput(new Signal("A_2", new ObservableValue("A_2", 1)).setDescription("Pin 1"));
|
|
||||||
pinMap.addModel(m);
|
|
||||||
|
|
||||||
assertEquals(3, pinMap.getInputFor("A_1"));
|
|
||||||
assertEquals(1, pinMap.getInputFor("A_2"));
|
|
||||||
assertEquals(2, pinMap.getInputFor("A_3"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testModelOutputs() throws PinMapException {
|
|
||||||
Model m = new Model();
|
|
||||||
m.addOutput(new Signal("A_1", new ObservableValue("A_1", 1)).setDescription("Pin 6\nTest documentation"));
|
|
||||||
m.addOutput(new Signal("A_2", new ObservableValue("A_2", 1)).setDescription("Test documentation\nPin 4"));
|
|
||||||
pinMap.addModel(m);
|
|
||||||
|
|
||||||
assertEquals(6, pinMap.getOutputFor("A_1"));
|
|
||||||
assertEquals(4, pinMap.getOutputFor("A_2"));
|
|
||||||
assertEquals(5, pinMap.getOutputFor("A_3"));
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user