mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
allows to use measurement values as signals in a test case
This commit is contained in:
parent
88ac232545
commit
6711cfe4da
@ -66,6 +66,7 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
private final ArrayList<Signal> signals;
|
||||
private final ArrayList<Signal> inputs;
|
||||
private final ArrayList<Signal> outputs;
|
||||
private final ArrayList<Signal> testOutputs;
|
||||
|
||||
private final ArrayList<Node> nodes;
|
||||
private ArrayList<Node> nodesToUpdateAct;
|
||||
@ -92,6 +93,7 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
this.buttonsToMap = new HashMap<>();
|
||||
this.signals = new ArrayList<>();
|
||||
this.outputs = new ArrayList<>();
|
||||
this.testOutputs = new ArrayList<>();
|
||||
this.inputs = new ArrayList<>();
|
||||
this.nodes = new ArrayList<>();
|
||||
this.nodesToUpdateAct = new ArrayList<>();
|
||||
@ -586,8 +588,13 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
* @param signal the signal
|
||||
*/
|
||||
public void addSignal(Signal signal) {
|
||||
if (signal.isValid())
|
||||
if (signal.isValid()) {
|
||||
if (signals.contains(signal))
|
||||
invalidSignal = signal;
|
||||
signals.add(signal);
|
||||
if (signal.isTestOutput())
|
||||
testOutputs.add(signal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -623,6 +630,7 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
invalidSignal = signal;
|
||||
signals.add(signal);
|
||||
outputs.add(signal);
|
||||
testOutputs.add(signal);
|
||||
} else
|
||||
invalidSignal = signal;
|
||||
}
|
||||
@ -649,6 +657,13 @@ public class Model implements Iterable<Node>, SyncAccess {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the models outputs
|
||||
*/
|
||||
public ArrayList<Signal> getTestOutputs() {
|
||||
return testOutputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all registered signals
|
||||
*/
|
||||
|
@ -16,6 +16,7 @@ public final class Signal implements Comparable<Signal> {
|
||||
private String pinNumber;
|
||||
private ObservableValue bidirectionalReader;
|
||||
private boolean showInGraph;
|
||||
private boolean testOutput;
|
||||
|
||||
/**
|
||||
* Creates a new Instance
|
||||
@ -60,6 +61,23 @@ public final class Signal implements Comparable<Signal> {
|
||||
return showInGraph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes this signal to a test output signal
|
||||
*
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public Signal setTestOutput() {
|
||||
testOutput = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this signal is a test output
|
||||
*/
|
||||
public boolean isTestOutput() {
|
||||
return testOutput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
|
@ -86,7 +86,7 @@ abstract class FlipflopBit extends Node implements Element {
|
||||
out = v != 0;
|
||||
q.setBool(out);
|
||||
qn.setBool(!out);
|
||||
}));
|
||||
}).setTestOutput());
|
||||
}
|
||||
|
||||
void setOut(boolean out) {
|
||||
|
@ -120,7 +120,7 @@ public class FlipflopD extends Node implements Element, Countable {
|
||||
value = v;
|
||||
q.setValue(value);
|
||||
qn.setValue(~value);
|
||||
}));
|
||||
}).setTestOutput());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,7 @@ public class Probe implements Element {
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
model.addOutput(new Signal(label, value).setShowInGraph(showInGraph).setFormat(format));
|
||||
model.addSignal(new Signal(label, value).setShowInGraph(showInGraph).setFormat(format).setTestOutput());
|
||||
model.registerGlobalValue(label, value);
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class Counter extends Node implements Element, ProgramCounter {
|
||||
boolean o = (counter == maxValue) && enable.getBool();
|
||||
out.setValue(counter);
|
||||
ovf.setBool(o);
|
||||
}));
|
||||
}).setTestOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,7 +146,7 @@ public class CounterPreset extends Node implements Element, ProgramCounter {
|
||||
boolean o = getOvfValue(counter, dir.getBool(), enable.getBool());
|
||||
out.setValue(counter);
|
||||
ovf.setBool(o);
|
||||
}));
|
||||
}).setTestOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +90,7 @@ public class Register extends Node implements Element, Countable, ProgramCounter
|
||||
model.addSignal(new Signal(label, q, (v, z) -> {
|
||||
value = v;
|
||||
q.setValue(value);
|
||||
}));
|
||||
}).setTestOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -119,7 +119,7 @@ public class TestExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
for (Signal s : model.getOutputs()) {
|
||||
for (Signal s : model.getTestOutputs()) {
|
||||
final int index = getIndexOf(s.getName());
|
||||
if (index >= 0) {
|
||||
outputs.add(new TestSignal(index, s.getValue()));
|
||||
|
@ -49,7 +49,7 @@ public class Context {
|
||||
if (model != null) {
|
||||
// inputs are not supported because there are cases where values
|
||||
// are evaluated and model inputs are not set!
|
||||
for (Signal s : model.getOutputs())
|
||||
for (Signal s : model.getTestOutputs())
|
||||
if (s.getName().equals(name))
|
||||
return s.getValue().getValue();
|
||||
}
|
||||
|
@ -115,10 +115,15 @@ public class Parser {
|
||||
expect(Tokenizer.Token.IDENT);
|
||||
final String sName = tok.getIdent();
|
||||
expect(Tokenizer.Token.EQUAL);
|
||||
int sign = 1;
|
||||
if (tok.peek() == Tokenizer.Token.SUB) {
|
||||
tok.consume();
|
||||
sign = -1;
|
||||
}
|
||||
expect(Tokenizer.Token.NUMBER);
|
||||
long n = convToLong(tok.getIdent());
|
||||
expect(Tokenizer.Token.SEMICOLON);
|
||||
signalInitMap.put(sName, n);
|
||||
signalInitMap.put(sName, sign * n);
|
||||
break;
|
||||
case PROGRAM:
|
||||
tok.consume();
|
||||
|
Loading…
x
Reference in New Issue
Block a user