Search in sources :

Example 6 with HDLCircuit

use of de.neemann.digital.hdl.model2.HDLCircuit 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 7 with HDLCircuit

use of de.neemann.digital.hdl.model2.HDLCircuit 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 8 with HDLCircuit

use of de.neemann.digital.hdl.model2.HDLCircuit in project Digital by hneemann.

the class VHDLGenerator method export.

/**
 * Exports the given circuit
 *
 * @param circuit the circuit to export
 * @return this for chained calls
 * @throws IOException IOException
 */
public VHDLGenerator export(Circuit circuit) throws IOException {
    try {
        if (!circuit.getAttributes().get(Keys.ROMMANAGER).isEmpty())
            throw new HDLException(Lang.get("err_centralDefinedRomsAreNotSupported"));
        BoardInterface board = BoardProvider.getInstance().getBoard(circuit);
        HDLClockIntegrator clockIntegrator = null;
        if (board != null && useClockIntegration)
            clockIntegrator = board.getClockIntegrator();
        HDLModel model = new HDLModel(library).create(circuit, clockIntegrator);
        for (HDLCircuit hdlCircuit : model) hdlCircuit.applyDefaultOptimizations();
        model.renameLabels(new VHDLRenaming());
        out.println("-- generated by Digital. Don't modify this file!");
        out.println("-- Any changes will be lost if this file is regenerated.");
        new VHDLCreator(out).printHDLCircuit(model.getMain());
        File outFile = out.getFile();
        if (outFile != null) {
            testBenches = new VHDLTestBenchCreator(circuit, model).write(outFile).getTestFileWritten();
            if (board != null)
                board.writeFiles(outFile, model);
        }
        return this;
    } catch (PinException | NodeException | HDLException | HGSEvalException e) {
        throw new IOException(Lang.get("err_vhdlExporting"), e);
    }
}
Also used : HDLModel(de.neemann.digital.hdl.model2.HDLModel) NodeException(de.neemann.digital.core.NodeException) HDLCircuit(de.neemann.digital.hdl.model2.HDLCircuit) IOException(java.io.IOException) HDLClockIntegrator(de.neemann.digital.hdl.model2.clock.HDLClockIntegrator) BoardInterface(de.neemann.digital.hdl.vhdl2.boards.BoardInterface) HDLException(de.neemann.digital.hdl.model2.HDLException) PinException(de.neemann.digital.draw.elements.PinException) File(java.io.File) HGSEvalException(de.neemann.digital.hdl.hgs.HGSEvalException)

Aggregations

HDLCircuit (de.neemann.digital.hdl.model2.HDLCircuit)3 HDLModel (de.neemann.digital.hdl.model2.HDLModel)3 CodePrinterStr (de.neemann.digital.hdl.printer.CodePrinterStr)3 ClockIntegratorGeneric (de.neemann.digital.hdl.model2.clock.ClockIntegratorGeneric)2 HDLClockIntegrator (de.neemann.digital.hdl.model2.clock.HDLClockIntegrator)2 ExprConstant (de.neemann.digital.hdl.model2.expression.ExprConstant)2 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)2 ArrayList (java.util.ArrayList)2 NodeException (de.neemann.digital.core.NodeException)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Key (de.neemann.digital.core.element.Key)1 PinException (de.neemann.digital.draw.elements.PinException)1 HGSEvalException (de.neemann.digital.hdl.hgs.HGSEvalException)1 de.neemann.digital.hdl.model2 (de.neemann.digital.hdl.model2)1 HDLException (de.neemann.digital.hdl.model2.HDLException)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 ClockInfo (de.neemann.digital.hdl.model2.clock.ClockInfo)1 CodePrinter (de.neemann.digital.hdl.printer.CodePrinter)1