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