use of de.neemann.digital.hdl.model2.HDLNode 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.HDLNode in project Digital by hneemann.
the class VHDLLibrary method getEntity.
/**
* Gets the entity of the given node
*
* @param node the node
* @return the entity
* @throws HDLException HDLException
*/
public VHDLEntity getEntity(HDLNode node) throws HDLException {
String elementName = node.getElementName();
VHDLEntity e = map.get(elementName);
if (e == null) {
try {
e = new VHDLTemplate(elementName);
map.put(elementName, e);
} catch (IOException ex) {
ex.printStackTrace();
LOGGER.info("could not load '" + VHDLTemplate.neededFileName(elementName) + "'");
}
}
if (e == null)
throw new HDLException(Lang.get("err_vhdlNoEntity_N", elementName));
return e;
}
use of de.neemann.digital.hdl.model2.HDLNode in project Digital by hneemann.
the class MergeConstants method optimize.
@Override
public void optimize(HDLCircuit circuit) throws HDLException {
this.circuit = circuit;
ArrayList<HDLNode> nodes = circuit.getNodes();
int n1 = 0;
while (n1 < nodes.size()) {
final HDLNode node1 = nodes.get(n1);
ExprConstant con1 = ExprConstant.isConstant(node1);
if (con1 != null) {
// CHECKSTYLE.OFF: ModifiedControlVariable
for (int n2 = n1 + 1; n2 < nodes.size(); n2++) {
final HDLNode node2 = nodes.get(n2);
ExprConstant con2 = ExprConstant.isConstant(node2);
if (con2 != null) {
if (con1.isEqualTo(con2)) {
merge(node1, node2);
nodes.remove(n2);
n2--;
}
}
}
// CHECKSTYLE.ON: ModifiedControlVariable
}
n1++;
}
}
use of de.neemann.digital.hdl.model2.HDLNode 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);
}
Aggregations