mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
disabled const optimization on DT switches, see #255
This commit is contained in:
parent
610f00bad9
commit
12adf74a2b
@ -18,7 +18,7 @@ public final class PlainSwitch implements NodeInterface {
|
|||||||
/**
|
/**
|
||||||
* Defines a direction for the switch. NO means no direction is given, the switch is bidirectional.
|
* Defines a direction for the switch. NO means no direction is given, the switch is bidirectional.
|
||||||
*/
|
*/
|
||||||
public enum Unidirectional { NO, FROM1TO2, FROM2TO1 }
|
public enum Unidirectional {NO, FROM1TO2, FROM2TO1}
|
||||||
|
|
||||||
private final ObservableValue output1;
|
private final ObservableValue output1;
|
||||||
private final ObservableValue output2;
|
private final ObservableValue output2;
|
||||||
@ -67,7 +67,7 @@ public final class PlainSwitch implements NodeInterface {
|
|||||||
input2.addObserverToValue(this).checkBits(bits, null);
|
input2.addObserverToValue(this).checkBits(bits, null);
|
||||||
switch (unidirectional) {
|
switch (unidirectional) {
|
||||||
case NO:
|
case NO:
|
||||||
switchModel = createSwitchModel(input1, input2, output1, output2, true);
|
switchModel = createSwitchModel(input1, input2, output1, output2, true, true);
|
||||||
break;
|
break;
|
||||||
case FROM1TO2:
|
case FROM1TO2:
|
||||||
switchModel = new UniDirectionalSwitch(input1, output2);
|
switchModel = new UniDirectionalSwitch(input1, output2);
|
||||||
@ -82,22 +82,25 @@ public final class PlainSwitch implements NodeInterface {
|
|||||||
static SwitchModel createSwitchModel(
|
static SwitchModel createSwitchModel(
|
||||||
ObservableValue input1, ObservableValue input2,
|
ObservableValue input1, ObservableValue input2,
|
||||||
ObservableValue output1, ObservableValue output2,
|
ObservableValue output1, ObservableValue output2,
|
||||||
boolean setOpenContactToHighZ) throws NodeException {
|
boolean setOpenContactToHighZ, boolean optimizeConstants) throws NodeException {
|
||||||
|
|
||||||
if (input1 instanceof CommonBusValue) {
|
if (input1 instanceof CommonBusValue) {
|
||||||
if (input2 instanceof CommonBusValue) {
|
if (input2 instanceof CommonBusValue) {
|
||||||
final CommonBusValue in1 = (CommonBusValue) input1;
|
final CommonBusValue in1 = (CommonBusValue) input1;
|
||||||
final CommonBusValue in2 = (CommonBusValue) input2;
|
final CommonBusValue in2 = (CommonBusValue) input2;
|
||||||
ObservableValue constant = in1.searchConstant();
|
if (optimizeConstants) {
|
||||||
if (constant != null)
|
ObservableValue constant = in1.searchConstant();
|
||||||
return new UniDirectionalSwitch(constant, output2);
|
|
||||||
else {
|
|
||||||
constant = in2.searchConstant();
|
|
||||||
if (constant != null)
|
if (constant != null)
|
||||||
return new UniDirectionalSwitch(constant, output1);
|
return new UniDirectionalSwitch(constant, output2);
|
||||||
else
|
else {
|
||||||
return new RealSwitch(in1, in2);
|
constant = in2.searchConstant();
|
||||||
}
|
if (constant != null)
|
||||||
|
return new UniDirectionalSwitch(constant, output1);
|
||||||
|
else
|
||||||
|
return new RealSwitch(in1, in2);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
return new RealSwitch(in1, in2);
|
||||||
} else
|
} else
|
||||||
return new UniDirectionalSwitch(input1, output2);
|
return new UniDirectionalSwitch(input1, output2);
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,11 +42,11 @@ public final class PlainSwitchDT implements NodeInterface {
|
|||||||
|
|
||||||
if (inA != null && inB != null) {
|
if (inA != null && inB != null) {
|
||||||
inB.addObserverToValue(this).checkBits(bits, null);
|
inB.addObserverToValue(this).checkBits(bits, null);
|
||||||
s1 = PlainSwitch.createSwitchModel(inA, inB, outputA, outputB, inC == null);
|
s1 = PlainSwitch.createSwitchModel(inA, inB, outputA, outputB, inC == null, false);
|
||||||
}
|
}
|
||||||
if (inA != null && inC != null) {
|
if (inA != null && inC != null) {
|
||||||
inC.addObserverToValue(this).checkBits(bits, null);
|
inC.addObserverToValue(this).checkBits(bits, null);
|
||||||
s2 = PlainSwitch.createSwitchModel(inA, inC, outputA, outputC, inB == null);
|
s2 = PlainSwitch.createSwitchModel(inA, inC, outputA, outputC, inB == null, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ public class TestExamples extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testTestExamples() throws Exception {
|
public void testTestExamples() throws Exception {
|
||||||
File examples = new File(Resources.getRoot(), "/dig/test");
|
File examples = new File(Resources.getRoot(), "/dig/test");
|
||||||
assertEquals(152, new FileScanner(this::check).scan(examples));
|
assertEquals(153, new FileScanner(this::check).scan(examples));
|
||||||
assertEquals(150, testCasesInFiles);
|
assertEquals(152, testCasesInFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
242
src/test/resources/dig/test/switch/const3.dig
Normal file
242
src/test/resources/dig/test/switch/const3.dig
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<circuit>
|
||||||
|
<version>1</version>
|
||||||
|
<attributes/>
|
||||||
|
<visualElements>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Text</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Description</string>
|
||||||
|
<string>see issue #255</string>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="560" y="320"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Const</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="980" y="400"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>RelayDT</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>rotation</string>
|
||||||
|
<rotation rotation="1"/>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="1000" y="480"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Ground</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="960" y="500"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>In</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Label</string>
|
||||||
|
<string>A_2</string>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="920" y="420"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Testcase</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Testdata</string>
|
||||||
|
<testData>
|
||||||
|
<dataString>A_2 Y_2
|
||||||
|
0 0
|
||||||
|
1 1
|
||||||
|
0 0
|
||||||
|
1 1
|
||||||
|
</dataString>
|
||||||
|
</testData>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="860" y="500"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Out</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Label</string>
|
||||||
|
<string>Y_2</string>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="1080" y="500"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Const</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>rotation</string>
|
||||||
|
<rotation rotation="2"/>
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<string>Value</string>
|
||||||
|
<long>0</long>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="1040" y="400"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>PullDown</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="1000" y="520"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Const</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="680" y="400"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>RelayDT</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>rotation</string>
|
||||||
|
<rotation rotation="1"/>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="700" y="480"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Ground</elementName>
|
||||||
|
<elementAttributes/>
|
||||||
|
<pos x="660" y="500"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>In</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Label</string>
|
||||||
|
<string>A_1</string>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="620" y="420"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Testcase</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Testdata</string>
|
||||||
|
<testData>
|
||||||
|
<dataString>A_1 Y_1
|
||||||
|
0 0
|
||||||
|
1 1
|
||||||
|
0 0
|
||||||
|
1 1
|
||||||
|
</dataString>
|
||||||
|
</testData>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="560" y="500"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Out</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>Label</string>
|
||||||
|
<string>Y_1</string>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="780" y="500"/>
|
||||||
|
</visualElement>
|
||||||
|
<visualElement>
|
||||||
|
<elementName>Const</elementName>
|
||||||
|
<elementAttributes>
|
||||||
|
<entry>
|
||||||
|
<string>rotation</string>
|
||||||
|
<rotation rotation="2"/>
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<string>Value</string>
|
||||||
|
<long>0</long>
|
||||||
|
</entry>
|
||||||
|
</elementAttributes>
|
||||||
|
<pos x="740" y="400"/>
|
||||||
|
</visualElement>
|
||||||
|
</visualElements>
|
||||||
|
<wires>
|
||||||
|
<wire>
|
||||||
|
<p1 x="980" y="400"/>
|
||||||
|
<p2 x="1000" y="400"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="1020" y="400"/>
|
||||||
|
<p2 x="1040" y="400"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="680" y="400"/>
|
||||||
|
<p2 x="700" y="400"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="720" y="400"/>
|
||||||
|
<p2 x="740" y="400"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="920" y="420"/>
|
||||||
|
<p2 x="960" y="420"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="620" y="420"/>
|
||||||
|
<p2 x="660" y="420"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="1000" y="500"/>
|
||||||
|
<p2 x="1080" y="500"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="700" y="500"/>
|
||||||
|
<p2 x="780" y="500"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="960" y="480"/>
|
||||||
|
<p2 x="960" y="500"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="960" y="420"/>
|
||||||
|
<p2 x="960" y="440"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="720" y="400"/>
|
||||||
|
<p2 x="720" y="440"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="660" y="480"/>
|
||||||
|
<p2 x="660" y="500"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="660" y="420"/>
|
||||||
|
<p2 x="660" y="440"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="1000" y="400"/>
|
||||||
|
<p2 x="1000" y="440"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="1000" y="480"/>
|
||||||
|
<p2 x="1000" y="500"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="1000" y="500"/>
|
||||||
|
<p2 x="1000" y="520"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="1020" y="400"/>
|
||||||
|
<p2 x="1020" y="440"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="700" y="400"/>
|
||||||
|
<p2 x="700" y="440"/>
|
||||||
|
</wire>
|
||||||
|
<wire>
|
||||||
|
<p1 x="700" y="480"/>
|
||||||
|
<p2 x="700" y="500"/>
|
||||||
|
</wire>
|
||||||
|
</wires>
|
||||||
|
</circuit>
|
Loading…
x
Reference in New Issue
Block a user