use of de.neemann.digital.draw.elements.PinException in project Digital by hneemann.
the class HDLModel method createNode.
/**
* Creates a isolated node
*
* @param v the VisualElement of the node
* @param parent the parrents circuit
* @return the node
* @throws HDLException HDLException
*/
public HDLNode createNode(VisualElement v, HDLCircuit parent) throws HDLException {
try {
ElementTypeDescription td = elementLibrary.getElementType(v.getElementName());
if (td instanceof ElementLibrary.ElementTypeDescriptionCustom) {
ElementLibrary.ElementTypeDescriptionCustom tdc = (ElementLibrary.ElementTypeDescriptionCustom) td;
HDLCircuit c = circuitMap.get(tdc.getCircuit());
if (c == null) {
c = new HDLCircuit(tdc.getCircuit(), v.getElementName(), this);
circuitMap.put(tdc.getCircuit(), c);
}
return addInputsOutputs(new HDLNodeCustom(v.getElementName(), v.getElementAttributes(), c), v, parent).createExpressions();
} else if (v.equalsDescription(Const.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprConstant(node.getElementAttributes().get(Keys.VALUE), node.getOutput().getBits()));
return node;
} else if (v.equalsDescription(DipSwitch.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprConstant(node.getElementAttributes().get(Keys.DIP_DEFAULT) ? 1 : 0, node.getOutput().getBits()));
return node;
} else if (v.equalsDescription(Ground.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprConstant(0, node.getOutput().getBits()));
return node;
} else if (v.equalsDescription(VDD.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprConstant(-1, node.getOutput().getBits()));
return node;
} else if (v.equalsDescription(Not.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprNot(new ExprVar(node.getInputs().get(0).getNet())));
return node;
} else if (v.equalsDescription(Or.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(createOperation(node.getInputs(), ExprOperate.Operation.OR));
return node;
} else if (v.equalsDescription(And.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(createOperation(node.getInputs(), ExprOperate.Operation.AND));
return node;
} else if (v.equalsDescription(XOr.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(createOperation(node.getInputs(), ExprOperate.Operation.XOR));
return node;
} else if (v.equalsDescription(NOr.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprNot(createOperation(node.getInputs(), ExprOperate.Operation.OR)));
return node;
} else if (v.equalsDescription(NAnd.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprNot(createOperation(node.getInputs(), ExprOperate.Operation.AND)));
return node;
} else if (v.equalsDescription(XNOr.DESCRIPTION)) {
final HDLNodeAssignment node = createExpression(v, parent, td);
node.setExpression(new ExprNot(createOperation(node.getInputs(), ExprOperate.Operation.XOR)));
return node;
} else
return addInputsOutputs(new HDLNodeBuildIn(v.getElementName(), v.getElementAttributes(), new ObservableValuesBitsProvider(td.createElement(v.getElementAttributes()).getOutputs())), v, parent).createExpressions();
} catch (ElementNotFoundException | PinException | NodeException e) {
throw new HDLException("error creating node", e);
}
}
use of de.neemann.digital.draw.elements.PinException in project Digital by hneemann.
the class ElementLibrary method importElement.
/**
* Imports the given file
*
* @param file the file to load
* @return the description
* @throws IOException IOException
*/
ElementTypeDescription importElement(File file) throws IOException {
try {
LOGGER.debug("load element " + file);
Circuit circuit;
try {
circuit = Circuit.loadCircuit(file, shapeFactory);
} catch (FileNotFoundException e) {
throw new IOException(Lang.get("err_couldNotFindIncludedFile_N0", file));
}
ElementTypeDescriptionCustom description = new ElementTypeDescriptionCustom(file, attributes -> new CustomElement(circuit, ElementLibrary.this), circuit);
description.setShortName(createShortName(file));
String descriptionText = circuit.getAttributes().get(Keys.DESCRIPTION);
if (descriptionText != null && descriptionText.length() > 0) {
description.setDescription(descriptionText);
}
return description;
} catch (PinException e) {
throw new IOException(Lang.get("msg_errorImportingModel_N0", file), e);
}
}
use of de.neemann.digital.draw.elements.PinException 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);
}
}
use of de.neemann.digital.draw.elements.PinException in project Digital by hneemann.
the class Net method interconnect.
/**
* Do the interconnection.
* All inputs and outputs in the net are connected together.
* If there is no output an exception is thrown.
* If there is one single output, all input {@link ObservableValue}s are set to this output
* If there are more then one output a {@link DataBus} is created.
* <p>
* At the end all wires get a reference to the {@link ObservableValue} the represent
*
* @param m the model is needed to create the {@link DataBus}
* @param attachWires if true, the values are attached to the wires
* @throws PinException PinException
*/
public void interconnect(Model m, boolean attachWires) throws PinException {
ArrayList<Pin> inputs = new ArrayList<>();
ArrayList<Pin> outputs = new ArrayList<>();
for (Pin p : pins) {
if (p.getDirection() == Pin.Direction.input)
inputs.add(p);
else
outputs.add(p);
}
if (outputs.size() == 0)
throw new PinException(Lang.get("err_noOutConnectedToWire", this.toString()), this);
ObservableValue value = null;
if (outputs.size() == 1 && outputs.get(0).getPullResistor() == PinDescription.PullResistor.none) {
value = outputs.get(0).getValue();
} else {
value = new DataBus(this, m, outputs).getReadableOutput();
}
if (value == null)
throw new PinException(Lang.get("err_output_N_notDefined", outputs.get(0)), this);
for (Pin i : inputs) i.setValue(value);
for (// set also the reader for bidirectional pins
Pin o : // set also the reader for bidirectional pins
outputs) o.setReaderValue(value);
if (wires != null && attachWires)
for (Wire w : wires) w.setValue(value);
}
Aggregations