fixed an model analyser issue concerning non zero default values in multi bit flip-flops.

This commit is contained in:
hneemann 2017-06-26 17:47:01 +02:00
parent 04de28b577
commit faf4844b63
4 changed files with 24 additions and 12 deletions

View File

@ -158,11 +158,11 @@ public class ModelAnalyser {
String label = ff.getLabel();
if (label.length() == 0)
label = createUniqueName(ff);
for (int i = 0; i < ff.getBits(); i++) {
for (int i = ff.getBits() - 1; i >= 0; i--) {
ObservableValue qn = new ObservableValue("", 1);
ObservableValue nqn = new ObservableValue("", 1);
FlipflopD newff = new FlipflopD(label + i, qn, nqn);
spinput.add(qn);
spinput.addAtTop(qn);
model.add(newff);
newff.setInputs(new ObservableValues(insp.getOutputs().get(i), getClock()));
out.add(newff);
@ -182,6 +182,7 @@ public class ModelAnalyser {
nqout.setValue(~value);
}
});
spq.fireHasChanged();
} catch (NodeException e) {
throw new AnalyseException(e);

View File

@ -47,6 +47,17 @@ public class ObservableValues extends ImmutableList<ObservableValue> {
return this;
}
/**
* Adds a value at top of list
*
* @param val the value to add
* @return the builder
*/
public Builder addAtTop(ObservableValue val) {
values.add(0, val);
return this;
}
/**
* @return the {@link ObservableValues} instance
*/

View File

@ -103,16 +103,16 @@ public class ModelAnalyserTest extends TestCase {
public void testAnalyzerMultiBit() throws Exception {
Model model = new ToBreakRunner("dig/analyze/multiBitCounter.dig", false).getModel();
TruthTable tt = new ModelAnalyser(model).analyse();
assertEquals("Q0n+1", tt.getResultName(0));
final BoolTable r0 = tt.getResult(0);
assertEquals("Q0n+1", tt.getResultName(1));
final BoolTable r0 = tt.getResult(1);
assertEquals(4, r0.size());
assertEquals(one, r0.get(0));
assertEquals(one, r0.get(1));
assertEquals(zero, r0.get(2));
assertEquals(zero, r0.get(1));
assertEquals(one, r0.get(2));
assertEquals(zero, r0.get(3));
assertEquals("Q1n+1", tt.getResultName(1));
final BoolTable r1 = tt.getResult(1);
assertEquals("Q1n+1", tt.getResultName(0));
final BoolTable r1 = tt.getResult(0);
assertEquals(4, r1.size());
assertEquals(zero, r1.get(0));
assertEquals(one, r1.get(1));
@ -124,8 +124,8 @@ public class ModelAnalyserTest extends TestCase {
final BoolTable y0 = tt.getResult(2);
final BoolTable y1 = tt.getResult(3);
for (int i = 0; i < 4; i++) {
assertEquals((i & 2) > 0, y0.get(i).invert().bool());
assertEquals((i & 1) > 0, y1.get(i).invert().bool());
assertEquals((i & 1) > 0, y0.get(i).invert().bool());
assertEquals((i & 2) > 0, y1.get(i).invert().bool());
}
}

View File

@ -15,8 +15,8 @@
<int>2</int>
</entry>
<entry>
<string>Default</string>
<int>1</int>
<string>InDefault</string>
<value v="1" z="false"/>
</entry>
</elementAttributes>
<pos x="280" y="220"/>