use of de.neemann.digital.core.NodeException in project Digital by hneemann.
the class Monoflop method init.
@Override
public void init(Model model) throws NodeException {
ArrayList<Clock> clockList = model.getClocks();
if (clockList.size() != 1)
throw new NodeException(Lang.get("err_monoflopRequiresOneClock"));
final ObservableValue clock = clockList.get(0).getClockOutput();
clock.addObserver(() -> {
if (clock.getBool()) {
if (counter > 0) {
counter--;
if (counter == 0) {
setOut(false);
Monoflop.this.hasChanged();
}
}
}
});
}
use of de.neemann.digital.core.NodeException 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.core.NodeException in project Digital by hneemann.
the class BitExtenderTest method testSignExtendError2.
public void testSignExtendError2() throws Exception {
try {
ObservableValue in = new ObservableValue("in", 5);
new BitExtender(new ElementAttributes().set(Keys.OUTPUT_BITS, 4)).setInputs(in.asList());
fail();
} catch (NodeException e) {
}
}
use of de.neemann.digital.core.NodeException in project Digital by hneemann.
the class RomLoader method preInit.
@Override
public void preInit(Model model) throws NodeException {
List<ROM> roms = model.findNode(ROM.class, ROM::isProgramMemory);
if (roms.isEmpty())
throw new NodeException(Lang.get("msg_noRomFound"));
if (roms.size() > 1)
throw new NodeException(Lang.get("msg_moreThenOneRomFound"));
try {
roms.get(0).setData(new DataField(romHex));
roms.get(0).provideRomAdress(model);
} catch (IOException e) {
throw new NodeException(e.getMessage());
}
}
use of de.neemann.digital.core.NodeException 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);
}
}
Aggregations