mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 14:56:29 -04:00
fixes #858
This commit is contained in:
parent
15cc82145b
commit
058bf2d9ad
@ -18,8 +18,8 @@ import java.util.TreeMap;
|
|||||||
*/
|
*/
|
||||||
public class ModelAnalyserInfo {
|
public class ModelAnalyserInfo {
|
||||||
private final String clockPin;
|
private final String clockPin;
|
||||||
private final HashMap<String, ArrayList<String>> inputBusMap;
|
private final ArrayList<Bus> inputBusList;
|
||||||
private final HashMap<String, ArrayList<String>> outputBusMap;
|
private final ArrayList<Bus> outputBusList;
|
||||||
private final HashMap<String, Long> initValueMap;
|
private final HashMap<String, Long> initValueMap;
|
||||||
private final boolean isSequential;
|
private final boolean isSequential;
|
||||||
private TreeMap<String, String> pins;
|
private TreeMap<String, String> pins;
|
||||||
@ -41,8 +41,8 @@ public class ModelAnalyserInfo {
|
|||||||
|
|
||||||
isSequential = model != null && !model.findNode(Node::hasState).isEmpty();
|
isSequential = model != null && !model.findNode(Node::hasState).isEmpty();
|
||||||
|
|
||||||
inputBusMap = new HashMap<>();
|
inputBusList = new ArrayList<>();
|
||||||
outputBusMap = new HashMap<>();
|
outputBusList = new ArrayList<>();
|
||||||
|
|
||||||
initValueMap = new HashMap<>();
|
initValueMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ public class ModelAnalyserInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void addInputBus(String name, ArrayList<String> names) {
|
void addInputBus(String name, ArrayList<String> names) {
|
||||||
inputBusMap.put(name, names);
|
inputBusList.add(new Bus(name, names));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,21 +118,21 @@ public class ModelAnalyserInfo {
|
|||||||
* @param names the individual names in the truth table
|
* @param names the individual names in the truth table
|
||||||
*/
|
*/
|
||||||
public void addOutputBus(String name, ArrayList<String> names) {
|
public void addOutputBus(String name, ArrayList<String> names) {
|
||||||
outputBusMap.put(name, names);
|
outputBusList.add(new Bus(name, names));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return input bus map
|
* @return input bus map
|
||||||
*/
|
*/
|
||||||
public HashMap<String, ArrayList<String>> getInputBusMap() {
|
public ArrayList<Bus> getInputBusList() {
|
||||||
return inputBusMap;
|
return inputBusList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return output bus map
|
* @return output bus map
|
||||||
*/
|
*/
|
||||||
public HashMap<String, ArrayList<String>> getOutputBusMap() {
|
public ArrayList<Bus> getOutputBusList() {
|
||||||
return outputBusMap;
|
return outputBusList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,4 +180,31 @@ public class ModelAnalyserInfo {
|
|||||||
public void setStateSignalName(String stateSignalName) {
|
public void setStateSignalName(String stateSignalName) {
|
||||||
this.stateSignalName = stateSignalName;
|
this.stateSignalName = stateSignalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of a bus used as input or output of the circuit
|
||||||
|
*/
|
||||||
|
public static final class Bus {
|
||||||
|
private final String busName;
|
||||||
|
private final ArrayList<String> signalNames;
|
||||||
|
|
||||||
|
private Bus(String busName, ArrayList<String> signalNames) {
|
||||||
|
this.busName = busName;
|
||||||
|
this.signalNames = signalNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the name of the bus
|
||||||
|
*/
|
||||||
|
public String getBusName() {
|
||||||
|
return busName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of names of the signals the bus is made of
|
||||||
|
*/
|
||||||
|
public ArrayList<String> getSignalNames() {
|
||||||
|
return signalNames;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import de.neemann.digital.analyse.quinemc.ThreeStateValue;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a test case which represents the truth table
|
* Creates a test case which represents the truth table
|
||||||
@ -22,8 +21,8 @@ import java.util.Map;
|
|||||||
public class TruthTableFormatterTestCase implements TruthTableFormatter {
|
public class TruthTableFormatterTestCase implements TruthTableFormatter {
|
||||||
private enum Type {NORMAL, FIRSTBIN, BIN}
|
private enum Type {NORMAL, FIRSTBIN, BIN}
|
||||||
|
|
||||||
private final HashMap<String, ArrayList<String>> inputBusMap;
|
private final ArrayList<ModelAnalyserInfo.Bus> inputBusList;
|
||||||
private final HashMap<String, ArrayList<String>> outputBusMap;
|
private final ArrayList<ModelAnalyserInfo.Bus> outputBusList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
@ -32,11 +31,11 @@ public class TruthTableFormatterTestCase implements TruthTableFormatter {
|
|||||||
*/
|
*/
|
||||||
public TruthTableFormatterTestCase(ModelAnalyserInfo modelAnalyzerInfo) {
|
public TruthTableFormatterTestCase(ModelAnalyserInfo modelAnalyzerInfo) {
|
||||||
if (modelAnalyzerInfo == null) {
|
if (modelAnalyzerInfo == null) {
|
||||||
inputBusMap = new HashMap<>();
|
inputBusList = new ArrayList<>();
|
||||||
outputBusMap = new HashMap<>();
|
outputBusList = new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
inputBusMap = modelAnalyzerInfo.getInputBusMap();
|
inputBusList = modelAnalyzerInfo.getInputBusList();
|
||||||
outputBusMap = modelAnalyzerInfo.getOutputBusMap();
|
outputBusList = modelAnalyzerInfo.getOutputBusList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,12 +46,12 @@ public class TruthTableFormatterTestCase implements TruthTableFormatter {
|
|||||||
ArrayList<String> inputs = new ArrayList<>();
|
ArrayList<String> inputs = new ArrayList<>();
|
||||||
for (Variable v : truthTable.getVars())
|
for (Variable v : truthTable.getVars())
|
||||||
inputs.add(v.getIdentifier());
|
inputs.add(v.getIdentifier());
|
||||||
ArrayList<Type> inputOutType = outVars(sb, inputs, inputBusMap);
|
ArrayList<Type> inputOutType = outVars(sb, inputs, inputBusList);
|
||||||
|
|
||||||
ArrayList<String> outputs = new ArrayList<>();
|
ArrayList<String> outputs = new ArrayList<>();
|
||||||
for (int i = 0; i < truthTable.getResultCount(); i++)
|
for (int i = 0; i < truthTable.getResultCount(); i++)
|
||||||
outputs.add(truthTable.getResultName(i));
|
outputs.add(truthTable.getResultName(i));
|
||||||
ArrayList<Type> outputOutType = outVars(sb, outputs, outputBusMap);
|
ArrayList<Type> outputOutType = outVars(sb, outputs, outputBusList);
|
||||||
|
|
||||||
sb.append("\n\n");
|
sb.append("\n\n");
|
||||||
|
|
||||||
@ -86,16 +85,16 @@ public class TruthTableFormatterTestCase implements TruthTableFormatter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Type> outVars(StringBuilder sb, ArrayList<String> vars, HashMap<String, ArrayList<String>> busMap) {
|
private ArrayList<Type> outVars(StringBuilder sb, ArrayList<String> vars, ArrayList<ModelAnalyserInfo.Bus> busList) {
|
||||||
ArrayList<Type> types = new ArrayList<>(vars.size());
|
ArrayList<Type> types = new ArrayList<>(vars.size());
|
||||||
HashMap<String, String> map = new HashMap<>();
|
HashMap<String, String> map = new HashMap<>();
|
||||||
for (Map.Entry<String, ArrayList<String>> e : busMap.entrySet()) {
|
for (ModelAnalyserInfo.Bus b : busList) {
|
||||||
String last = null;
|
String last = null;
|
||||||
for (String s : e.getValue()) {
|
for (String s : b.getSignalNames()) {
|
||||||
map.put(s, "");
|
map.put(s, "");
|
||||||
last = s;
|
last = s;
|
||||||
}
|
}
|
||||||
map.put(last, e.getKey());
|
map.put(last, b.getBusName());
|
||||||
}
|
}
|
||||||
for (String n : vars) {
|
for (String n : vars) {
|
||||||
String r = map.get(n);
|
String r = map.get(n);
|
||||||
|
@ -517,10 +517,10 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
private void checkForInputBus(Collection<Variable> variables, int splitterXPos, Circuit circuit) {
|
private void checkForInputBus(Collection<Variable> variables, int splitterXPos, Circuit circuit) {
|
||||||
StringBuilder pinString = new StringBuilder();
|
StringBuilder pinString = new StringBuilder();
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (Map.Entry<String, ArrayList<String>> e : mai.getInputBusMap().entrySet()) {
|
for (ModelAnalyserInfo.Bus b : mai.getInputBusList()) {
|
||||||
pinString.setLength(0);
|
pinString.setLength(0);
|
||||||
int found = 0;
|
int found = 0;
|
||||||
final ArrayList<String> inputs = e.getValue();
|
final ArrayList<String> inputs = b.getSignalNames();
|
||||||
for (String n : inputs) {
|
for (String n : inputs) {
|
||||||
if (variables.contains(new Variable(n))) {
|
if (variables.contains(new Variable(n))) {
|
||||||
found++;
|
found++;
|
||||||
@ -541,7 +541,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
.setPos(new Vector(splitterXPos, y))
|
.setPos(new Vector(splitterXPos, y))
|
||||||
.setShapeFactory(shapeFactory));
|
.setShapeFactory(shapeFactory));
|
||||||
circuit.add(new VisualElement(In.DESCRIPTION.getName())
|
circuit.add(new VisualElement(In.DESCRIPTION.getName())
|
||||||
.setAttribute(Keys.LABEL, e.getKey())
|
.setAttribute(Keys.LABEL, b.getBusName())
|
||||||
.setAttribute(Keys.BITS, inputs.size())
|
.setAttribute(Keys.BITS, inputs.size())
|
||||||
.setAttribute(Keys.PINNUMBER, pinString.toString())
|
.setAttribute(Keys.PINNUMBER, pinString.toString())
|
||||||
.setPos(new Vector(splitterXPos - 2 * SIZE, y))
|
.setPos(new Vector(splitterXPos - 2 * SIZE, y))
|
||||||
@ -570,10 +570,10 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
private int checkForOutputBus(int splitterXPos, Circuit circuit) {
|
private int checkForOutputBus(int splitterXPos, Circuit circuit) {
|
||||||
StringBuilder pinString = new StringBuilder();
|
StringBuilder pinString = new StringBuilder();
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (Map.Entry<String, ArrayList<String>> e : mai.getOutputBusMap().entrySet()) {
|
for (ModelAnalyserInfo.Bus b : mai.getOutputBusList()) {
|
||||||
pinString.setLength(0);
|
pinString.setLength(0);
|
||||||
int found = 0;
|
int found = 0;
|
||||||
final ArrayList<String> outputs = e.getValue();
|
final ArrayList<String> outputs = b.getSignalNames();
|
||||||
for (String n : outputs) {
|
for (String n : outputs) {
|
||||||
if (combinatorialOutputs.containsKey(n)) {
|
if (combinatorialOutputs.containsKey(n)) {
|
||||||
found++;
|
found++;
|
||||||
@ -593,7 +593,7 @@ public class CircuitBuilder implements BuilderInterface<CircuitBuilder> {
|
|||||||
.setPos(new Vector(splitterXPos, y))
|
.setPos(new Vector(splitterXPos, y))
|
||||||
.setShapeFactory(shapeFactory));
|
.setShapeFactory(shapeFactory));
|
||||||
circuit.add(new VisualElement(Out.DESCRIPTION.getName())
|
circuit.add(new VisualElement(Out.DESCRIPTION.getName())
|
||||||
.setAttribute(Keys.LABEL, e.getKey())
|
.setAttribute(Keys.LABEL, b.getBusName())
|
||||||
.setAttribute(Keys.BITS, outputs.size())
|
.setAttribute(Keys.BITS, outputs.size())
|
||||||
.setAttribute(Keys.PINNUMBER, pinString.toString())
|
.setAttribute(Keys.PINNUMBER, pinString.toString())
|
||||||
.setPos(new Vector(splitterXPos + 3 * SIZE, y))
|
.setPos(new Vector(splitterXPos + 3 * SIZE, y))
|
||||||
|
@ -24,13 +24,13 @@ import junit.framework.TestCase;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import static de.neemann.digital.analyse.quinemc.ThreeStateValue.one;
|
import static de.neemann.digital.analyse.quinemc.ThreeStateValue.one;
|
||||||
import static de.neemann.digital.analyse.quinemc.ThreeStateValue.zero;
|
import static de.neemann.digital.analyse.quinemc.ThreeStateValue.zero;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class ModelAnalyserTest extends TestCase {
|
public class ModelAnalyserTest extends TestCase {
|
||||||
|
|
||||||
@ -269,20 +269,19 @@ public class ModelAnalyserTest extends TestCase {
|
|||||||
Model model = createModel("dig/analyze/multiBitInOutXOr.dig");
|
Model model = createModel("dig/analyze/multiBitInOutXOr.dig");
|
||||||
ModelAnalyserInfo mai = new ModelAnalyser(model).analyse().getModelAnalyzerInfo();
|
ModelAnalyserInfo mai = new ModelAnalyser(model).analyse().getModelAnalyzerInfo();
|
||||||
|
|
||||||
assertEquals(2, mai.getInputBusMap().size());
|
assertEquals(2, mai.getInputBusList().size());
|
||||||
checkBus(mai.getInputBusMap(), "A", "A_0", "A_1", "A_2", "A_3");
|
checkBus(mai.getInputBusList().get(0), "A", "A_0", "A_1", "A_2", "A_3");
|
||||||
checkBus(mai.getInputBusMap(), "B", "B_0", "B_1", "B_2", "B_3");
|
checkBus(mai.getInputBusList().get(1), "B", "B_0", "B_1", "B_2", "B_3");
|
||||||
|
|
||||||
assertEquals(1, mai.getOutputBusMap().size());
|
assertEquals(1, mai.getOutputBusList().size());
|
||||||
checkBus(mai.getOutputBusMap(), "S", "S_0", "S_1", "S_2", "S_3");
|
checkBus(mai.getOutputBusList().get(0), "S", "S_0", "S_1", "S_2", "S_3");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBus(HashMap<String, ArrayList<String>> busMap, String name, String... names) {
|
private void checkBus(ModelAnalyserInfo.Bus bus, String name, String... names) {
|
||||||
ArrayList<String> n = busMap.get(name);
|
assertEquals(name, bus.getBusName());
|
||||||
assertNotNull(n);
|
assertEquals(names.length, bus.getSignalNames().size());
|
||||||
assertEquals(names.length, n.size());
|
|
||||||
for (int i = 0; i < names.length; i++)
|
for (int i = 0; i < names.length; i++)
|
||||||
assertEquals(names[i], n.get(i));
|
assertEquals(names[i], bus.getSignalNames().get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import de.neemann.digital.analyse.ModelAnalyserInfo;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class ValueParserTest extends TestCase {
|
public class ValueParserTest extends TestCase {
|
||||||
@ -38,10 +37,11 @@ public class ValueParserTest extends TestCase {
|
|||||||
ModelAnalyserInfo mai = new ModelAnalyserInfo(null);
|
ModelAnalyserInfo mai = new ModelAnalyserInfo(null);
|
||||||
TreeMap<String, Integer> v = new ValueParser("A=1101").setModelAnalyzerInfo(mai).parse();
|
TreeMap<String, Integer> v = new ValueParser("A=1101").setModelAnalyzerInfo(mai).parse();
|
||||||
assertEquals(4, v.size());
|
assertEquals(4, v.size());
|
||||||
HashMap<String, ArrayList<String>> om = mai.getOutputBusMap();
|
ArrayList<ModelAnalyserInfo.Bus> om = mai.getOutputBusList();
|
||||||
assertEquals(1, om.size());
|
assertEquals(1, om.size());
|
||||||
ArrayList<String> list = om.get("A");
|
ModelAnalyserInfo.Bus bus = om.get(0);
|
||||||
assertNotNull(list);
|
assertEquals("A", bus.getBusName());
|
||||||
|
ArrayList<String> list = bus.getSignalNames();
|
||||||
assertEquals(4, list.size());
|
assertEquals(4, list.size());
|
||||||
assertEquals("A0", list.get(0));
|
assertEquals("A0", list.get(0));
|
||||||
assertEquals("A1", list.get(1));
|
assertEquals("A1", list.get(1));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user