all tests are running again

This commit is contained in:
hneemann 2018-03-24 17:59:27 +01:00
parent 3c04f78d0f
commit 812302bcf7
5 changed files with 76 additions and 30 deletions

View File

@ -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);
}

View File

@ -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(");");
}
}
}

View File

@ -8,24 +8,21 @@ USE ieee.std_logic_1164.all;
outputs:=1<<elem.'Selector Bits';
?>
entity <?=entityName?> is
<? vhdl.beginGenericPort();?>
<? if (elem.Bits>1) { ?>
<?- if (elem.Bits>1) { ?>
generic ( Bits : integer );<? vhdl.registerGeneric("Bits");?>
<? } ?>
<?- } ?>
port (
<? for (i:=0;i<outputs;i++) {?>
PORT_out_<?=i?>: out <?= vhdl.genericType(elem.Bits)?>;
<? } ?>
PORT_sel: in <?= vhdl.type(elem.'Selector Bits')?>;
PORT_in: in <?= vhdl.genericType(elem.Bits)?> );
<? vhdl.endGenericPort();?>
<?- for (i:=0;i<outputs;i++) {?>
out_<?=i?>: out <?= vhdl.genericType(elem.Bits)?>;
<?- } ?>
sel: in <?= vhdl.type(elem.'Selector Bits')?>;
p_in: in <?= vhdl.genericType(elem.Bits)?> );
end <?=entityName?>;
architecture <?=entityName?>_arch of <?=entityName?> is
begin
<? for (i:=0;i<outputs;i++) {?>
PORT_out_<?=i?> <= PORT_in when PORT_sel = <?= vhdl.value(i,elem.'Selector Bits')?> else <?= vhdl.zero(elem.Bits)?>;
<? } ?>
<?- for (i:=0;i<outputs;i++) {?>
out_<?=i?> <= p_in when sel = <?= vhdl.value(i,elem.'Selector Bits')?> else <?= vhdl.zero(elem.Bits)?>;
<?- } ?>
end <?=entityName?>_arch;

View File

@ -0,0 +1,8 @@
<?=elem.Code;
entityName:=elem.Label;
if (elem.applicationType!="GHDL")
panic("only GHDL components are supported for VHDL export! Found: "+elem.applicationType);
?>

View File

@ -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 {