Search in sources :

Example 1 with HDLNet

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;
}
Also used : ExprVar(de.neemann.digital.hdl.model2.expression.ExprVar) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ExprNot(de.neemann.digital.hdl.model2.expression.ExprNot)

Example 2 with HDLNet

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;
}
Also used : Expression(de.neemann.digital.hdl.model2.expression.Expression)

Example 3 with HDLNet

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);
}
Also used : HDLNet(de.neemann.digital.hdl.model2.HDLNet) ArrayList(java.util.ArrayList) HDLNode(de.neemann.digital.hdl.model2.HDLNode) HDLPort(de.neemann.digital.hdl.model2.HDLPort) HashSet(java.util.HashSet)

Example 4 with HDLNet

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));
        }
    }
}
Also used : ExprConstant(de.neemann.digital.hdl.model2.expression.ExprConstant)

Example 5 with HDLNet

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++;
    }
}
Also used : ExprVarRange(de.neemann.digital.hdl.model2.expression.ExprVarRange) Splitter(de.neemann.digital.core.wiring.Splitter)

Aggregations

ExprVar (de.neemann.digital.hdl.model2.expression.ExprVar)2 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Splitter (de.neemann.digital.core.wiring.Splitter)1 HDLNet (de.neemann.digital.hdl.model2.HDLNet)1 HDLNode (de.neemann.digital.hdl.model2.HDLNode)1 HDLPort (de.neemann.digital.hdl.model2.HDLPort)1 ExprConstant (de.neemann.digital.hdl.model2.expression.ExprConstant)1 ExprNot (de.neemann.digital.hdl.model2.expression.ExprNot)1 ExprVarRange (de.neemann.digital.hdl.model2.expression.ExprVarRange)1 Expression (de.neemann.digital.hdl.model2.expression.Expression)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1