use of de.neemann.digital.hdl.model2.HDLNet in project Digital by hneemann.
the class HDLCircuit method createNot.
private HDLNode createNot(HDLPort p, HDLNode node) throws HDLException, NodeException, PinException {
final ElementAttributes attr = new ElementAttributes().setBits(p.getBits());
HDLNodeAssignment n = new HDLNodeAssignment(Not.DESCRIPTION.getName(), attr, name -> p.getBits());
HDLNet outNet = new HDLNet(null);
listOfNets.add(outNet);
HDLNet inNet = p.getNet();
inNet.remove(p);
n.addPort(new HDLPort(Not.DESCRIPTION.getInputDescription(attr).get(0).getName(), inNet, HDLPort.Direction.IN, p.getBits()));
n.addPort(new HDLPort(Not.DESCRIPTION.getOutputDescriptions(attr).get(0).getName(), outNet, HDLPort.Direction.OUT, p.getBits()));
p.setNet(outNet);
node.replaceNet(inNet, outNet);
n.setExpression(new ExprNot(new ExprVar(n.getInputs().get(0).getNet())));
return n;
}
use of de.neemann.digital.hdl.model2.HDLNet in project Digital by hneemann.
the class MergeAssignements method merge.
private HDLNodeAssignment merge(HDLNodeAssignment host, HDLNodeAssignment include) {
final Expression expression = host.getExpression();
final HDLNet obsoleteNet = include.getOutput().getNet();
expression.replace(obsoleteNet, include.getExpression());
HDLNodeAssignment node = new HDLNodeAssignment("merged expression", null, name -> host.getOutput().getBits());
node.setExpression(expression);
circuit.removeNet(obsoleteNet);
node.addPort(host.getOutput());
for (HDLPort i : host.getInputs()) if (i.getNet() != obsoleteNet)
node.addPort(i);
for (HDLPort i : include.getInputs()) if (!node.hasInput(i))
node.addPort(i);
else
i.getNet().remove(i);
return node;
}
use of de.neemann.digital.hdl.model2.HDLNet in project Digital by hneemann.
the class NodeSorterExpressionBased method optimize.
@Override
public void optimize(HDLCircuit circuit) {
ArrayList<HDLNode> nodes = circuit.getNodes();
ArrayList<HDLNode> nodesAvail = new ArrayList<>(nodes);
nodes.clear();
HashSet<HDLNet> nets = new HashSet<>();
for (HDLPort p : circuit.getInputs()) nets.add(p.getNet());
// all nodes without an input at top!
for (HDLNode n : nodesAvail) if (n.getInputs().isEmpty()) {
nodes.add(n);
for (HDLPort p : n.getOutputs()) if (p.getNet() != null)
nets.add(p.getNet());
}
nodesAvail.removeAll(nodes);
// then a layer sorting
while (!nodesAvail.isEmpty()) {
ArrayList<HDLNode> layer = new ArrayList<>();
for (HDLNode n : nodesAvail) {
if (n.traverseExpressions(new DependsOnlyOn(nets)).ok())
layer.add(n);
}
if (layer.isEmpty()) {
// circular dependency detected
for (HDLNode n : nodesAvail) if (n.traverseExpressions(new DependsAtLeastOnOneOf(nets)).ok())
layer.add(n);
}
if (layer.isEmpty())
break;
nodes.addAll(layer);
nodesAvail.removeAll(layer);
for (HDLNode n : layer) for (HDLPort p : n.getOutputs()) if (p.getNet() != null)
nets.add(p.getNet());
}
// if there are unsolvable circular dependencies, keep old order
if (!nodesAvail.isEmpty())
nodes.addAll(nodesAvail);
}
use of de.neemann.digital.hdl.model2.HDLNet in project Digital by hneemann.
the class RemoveConstantSignals method optimize.
@Override
public void optimize(HDLCircuit circuit) {
Iterator<HDLNet> it = circuit.getNets().iterator();
while (it.hasNext()) {
HDLNet net = it.next();
final ExprConstant constant = net.isConstant();
if (constant != null && isOnlyUsedInSupportedNodes(net)) {
circuit.getNodes().remove(net.getOutput().getParent());
it.remove();
circuit.replaceNetByExpression(net, new ExprConstant(constant));
}
}
}
use of de.neemann.digital.hdl.model2.HDLNet in project Digital by hneemann.
the class ReplaceOneToMany method replace.
private void replace(HDLNodeSplitterOneToMany n, ArrayList<HDLNodeAssignment> newNodes) throws HDLException {
final HDLPort inPort = n.getInputs().get(0);
HDLNet inNet = inPort.getNet();
inPort.setNet(null);
int i = 0;
for (Splitter.Port p : n.getOutputSplit()) {
final HDLPort outPort = n.getOutputs().get(i);
if (outPort.getNet() != null) {
ExprVarRange exp = new ExprVarRange(inNet, p.getPos() + p.getBits() - 1, p.getPos());
HDLNodeAssignment node = new HDLNodeAssignment("splitter", null, null);
node.setExpression(exp);
node.addPort(new HDLPort("in", inNet, HDLPort.Direction.IN, inPort.getBits()));
node.addPort(outPort);
newNodes.add(node);
}
i++;
}
}
Aggregations