diff --git a/src/main/java/de/neemann/digital/hdl/hgs/Value.java b/src/main/java/de/neemann/digital/hdl/hgs/Value.java index 89ec76137..f9a843e96 100644 --- a/src/main/java/de/neemann/digital/hdl/hgs/Value.java +++ b/src/main/java/de/neemann/digital/hdl/hgs/Value.java @@ -125,6 +125,8 @@ public final class Value { public static boolean equals(Object a, Object b) { if (a instanceof Number && b instanceof Number) return ((Number) a).longValue() == ((Number) b).longValue(); + else if (a instanceof String || b instanceof String) + return a.toString().equals(b.toString()); else return a.equals(b); } diff --git a/src/main/java/de/neemann/digital/hdl/vhdl2/VHDLCreator.java b/src/main/java/de/neemann/digital/hdl/vhdl2/VHDLCreator.java index dacfdb46b..0c1c6cd4b 100644 --- a/src/main/java/de/neemann/digital/hdl/vhdl2/VHDLCreator.java +++ b/src/main/java/de/neemann/digital/hdl/vhdl2/VHDLCreator.java @@ -187,12 +187,14 @@ public class VHDLCreator { int i = 0; for (HDLPort outPort : node.getOutputs()) { Splitter.Port sp = is.getPort(i++); - out.print(outPort.getNet().getName()).print(" <= ").print(source).print("("); - if (outPort.getBits() == 1) - out.print(sp.getPos()); - else - out.print(sp.getPos() + sp.getBits() - 1).print(" downto ").print(sp.getPos()); - out.println(");"); + if (outPort.getNet() != null) { + out.print(outPort.getNet().getName()).print(" <= ").print(source).print("("); + if (outPort.getBits() == 1) + out.print(sp.getPos()); + else + out.print(sp.getPos() + sp.getBits() - 1).print(" downto ").print(sp.getPos()); + out.println(");"); + } } } diff --git a/src/main/resources/vhdl2/DIG_Demultiplexer.tem b/src/main/resources/vhdl2/DIG_Demultiplexer.tem index d779959e8..849fc8417 100644 --- a/src/main/resources/vhdl2/DIG_Demultiplexer.tem +++ b/src/main/resources/vhdl2/DIG_Demultiplexer.tem @@ -8,24 +8,21 @@ USE ieee.std_logic_1164.all; outputs:=1< - entity is - - 1) { ?> + 1) { ?> generic ( Bits : integer ); - + port ( - - PORT_out_: out ; - - PORT_sel: in ; - PORT_in: in ); - + + out_: out ; + + sel: in ; + p_in: in ); end ; architecture _arch of is begin - - PORT_out_ <= PORT_in when PORT_sel = else ; - + + out_ <= p_in when sel = else ; + end _arch; diff --git a/src/main/resources/vhdl2/DIG_External.tem b/src/main/resources/vhdl2/DIG_External.tem new file mode 100644 index 000000000..278a63a6c --- /dev/null +++ b/src/main/resources/vhdl2/DIG_External.tem @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLGeneratorTest.java b/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLGeneratorTest.java index bfd3efead..4c68799fb 100644 --- a/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLGeneratorTest.java +++ b/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLGeneratorTest.java @@ -32,25 +32,21 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import static de.neemann.digital.integration.TestExamples.check; + public class VHDLGeneratorTest extends TestCase { private static final String GHDL = System.getProperty("ghdl", "ghdl"); private int testBenches; - public void testSimple() throws Exception { - File file = new File(Resources.getRoot(), "dig/test/vhdl/reset.dig"); + /* + public void testDebug() throws Exception { + File file = new File(Resources.getRoot(), "dig/hdl/splitter2.dig"); ToBreakRunner br = new ToBreakRunner(file); System.out.println(new VHDLGenerator(br.getLibrary(), new CodePrinterStr(true)).export(br.getCircuit())); - try { - checkVHDLExport(file); - } catch (FileScanner.SkipAllException e) { - // if ghdl is not installed its also ok - } catch (Exception e) { - System.out.println(ExceptionWithOrigin.getOriginOf(e)); - throw e; - } - } + checkVHDLExport(file); + }/**/ public void testInSimulator() throws Exception { File examples = new File(Resources.getRoot(), "/dig/test/vhdl"); @@ -73,7 +69,48 @@ public class VHDLGeneratorTest extends TestCase { } } + public void testDistributedInSimulator() throws Exception { + File examples = new File(Resources.getRoot(), "../../main/dig/vhdl"); + try { + int tested = new FileScanner(this::checkVHDLExport).noOutput().scan(examples); + assertEquals(1, tested); + assertEquals(1, testBenches); + } catch (FileScanner.SkipAllException e) { + // if ghdl is not installed its also ok + } + } + public void testProcessorInSimulator() throws Exception { + File file = new File(Resources.getRoot(), "../../main/dig/processor/VHDLExample.dig"); + try { + checkVHDLExport(file); + } catch (FileScanner.SkipAllException e) { + // if ghdl is not installed its also ok + } catch (Exception e) { + System.out.println(ExceptionWithOrigin.getOriginOf(e)); + throw e; + } + } + + public void testGHDLInSimulator() throws Exception { + try { + ProcessStarter.start(null, GHDL, "--help"); + } catch (IOException e) { + // ghdl is not installed, Ignore Test + return; + } + + Settings.getInstance().getAttributes().set(Keys.SETTINGS_GHDL_PATH, new File(GHDL)); + + File source = new File(Resources.getRoot(), "dig/external/ghdl"); + + int tested = new FileScanner(f -> { + checkVHDLExport(f); + // check simulation in Digital + check(f); + }).noOutput().scan(source); + assertEquals(4, tested); + } private void checkVHDLExport(File file) throws PinException, NodeException, ElementNotFoundException, IOException, FileScanner.SkipAllException, HDLException, de.neemann.digital.hdl.model2.HDLException, HGSEvalException {