-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring of input don't care handling
- Loading branch information
Showing
5 changed files
with
129 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/de/neemann/digital/testing/LineListenerResolveDontCare.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.neemann.digital.testing; | ||
|
||
import de.neemann.digital.testing.parser.LineListener; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Resolves don't cares in the inputs list | ||
* Created by hneemann on 19.04.17. | ||
*/ | ||
public class LineListenerResolveDontCare implements LineListener { | ||
|
||
private final LineListener parent; | ||
private final ArrayList<TestResult.TestSignal> inputs; | ||
|
||
/** | ||
* Create a new instance | ||
* | ||
* @param parent the parent listener | ||
* @param inputs the input test signals | ||
*/ | ||
public LineListenerResolveDontCare(LineListener parent, ArrayList<TestResult.TestSignal> inputs) { | ||
this.parent = parent; | ||
this.inputs = inputs; | ||
} | ||
|
||
@Override | ||
public void add(Value[] rowWithDontCare) { | ||
ArrayList<Integer> dcIndex = null; | ||
for (TestResult.TestSignal in : inputs) { | ||
if (rowWithDontCare[in.getIndex()].getType() == Value.Type.DONTCARE) { | ||
if (dcIndex == null) | ||
dcIndex = new ArrayList<>(); | ||
dcIndex.add(in.getIndex()); | ||
} | ||
} | ||
if (dcIndex == null) | ||
parent.add(rowWithDontCare); | ||
else { | ||
int count = 1 << dcIndex.size(); | ||
for (int n = 0; n < count; n++) { | ||
int mask = 1; | ||
for (int in : dcIndex) { | ||
boolean val = (n & mask) != 0; | ||
rowWithDontCare[in] = new Value(val ? 1 : 0); | ||
mask *= 2; | ||
} | ||
parent.add(rowWithDontCare); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters