From 63a3412191d7e8e879d76e1daf9d3ebd7a32519b Mon Sep 17 00:00:00 2001 From: hneemann Date: Wed, 15 May 2019 18:36:00 +0200 Subject: [PATCH] first ide config for basic BASYS3 support. --- .../dig/hdl/{BASYS3.xml => BASYS3_Config.xml} | 9 +- src/main/dig/hdl/TinyFPGA_BX_SOS.dig | 157 ++++++++++++++++++ .../digital/builder/tt2/OSExecute.java | 8 +- .../de/neemann/digital/hdl/hgs/Context.java | 2 - .../hdl/hgs/refs/ReferenceToArray.java | 3 - .../hdl/hgs/refs/ReferenceToStruct.java | 3 - .../java/de/neemann/digital/ide/Command.java | 22 ++- .../de/neemann/digital/ide/Configuration.java | 39 ++++- .../hdl/verilog2/VerilogSimulatorTest.java | 2 +- .../digital/hdl/vhdl2/VHDLSimulatorTest.java | 2 +- .../digital/ide/ConfigurationTest.java | 2 +- .../digital/integration/TestExamples.java | 2 +- 12 files changed, 224 insertions(+), 27 deletions(-) rename src/main/dig/hdl/{BASYS3.xml => BASYS3_Config.xml} (93%) create mode 100644 src/main/dig/hdl/TinyFPGA_BX_SOS.dig diff --git a/src/main/dig/hdl/BASYS3.xml b/src/main/dig/hdl/BASYS3_Config.xml similarity index 93% rename from src/main/dig/hdl/BASYS3.xml rename to src/main/dig/hdl/BASYS3_Config.xml index 680feb56d..e1b5ae737 100644 --- a/src/main/dig/hdl/BASYS3.xml +++ b/src/main/dig/hdl/BASYS3_Config.xml @@ -1,15 +1,16 @@ - + + vivado + vivado/<?=shortname?>.xpr ]]> - + \n");?> diff --git a/src/main/dig/hdl/TinyFPGA_BX_SOS.dig b/src/main/dig/hdl/TinyFPGA_BX_SOS.dig new file mode 100644 index 000000000..9137a8780 --- /dev/null +++ b/src/main/dig/hdl/TinyFPGA_BX_SOS.dig @@ -0,0 +1,157 @@ + + + 1 + + + + Counter + + + Bits + 26 + + + + + + VDD + + + + + Ground + + + + + Clock + + + Label + CLK + + + Frequency + 2147483647 + + + runRealTime + true + + + + + + Splitter + + + Input Splitting + 26 + + + Output Splitting + 21-25 + + + + + + ROM + + + Label + SOS + + + AddrBits + 5 + + + Data + 0,1,0,1,0,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,1,0,1 + + + + + + VDD + + + + + Out + + + Label + LED + + + + + + Out + + + Label + USBPU + + + + + + Ground + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/de/neemann/digital/builder/tt2/OSExecute.java b/src/main/java/de/neemann/digital/builder/tt2/OSExecute.java index e886b540d..b89970f18 100644 --- a/src/main/java/de/neemann/digital/builder/tt2/OSExecute.java +++ b/src/main/java/de/neemann/digital/builder/tt2/OSExecute.java @@ -73,6 +73,8 @@ public class OSExecute { * @return this for chained calls */ public OSExecute setTimeOutSec(int timeOutSec) { + if (timeOutSec == 0) + timeOutSec = Integer.MAX_VALUE; this.timeOutSec = timeOutSec; return this; } @@ -195,9 +197,11 @@ public class OSExecute { public void run() { try { String result = os.startAndWait(); - callback.processTerminated(result); + if (callback != null) + callback.processTerminated(result); } catch (Exception e) { - callback.exception(e); + if (callback != null) + callback.exception(e); } } } diff --git a/src/main/java/de/neemann/digital/hdl/hgs/Context.java b/src/main/java/de/neemann/digital/hdl/hgs/Context.java index 6d61f6a38..2d891ced2 100644 --- a/src/main/java/de/neemann/digital/hdl/hgs/Context.java +++ b/src/main/java/de/neemann/digital/hdl/hgs/Context.java @@ -134,8 +134,6 @@ public class Context { * @throws HGSEvalException HGSEvalException */ public Context declareVar(String name, Object value) throws HGSEvalException { - if (map.containsKey(name)) - throw new HGSEvalException("Variable '" + name + "' already declared!"); map.put(name, value); return this; } diff --git a/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToArray.java b/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToArray.java index 3e157ed56..c06d9adb9 100644 --- a/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToArray.java +++ b/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToArray.java @@ -32,9 +32,6 @@ public class ReferenceToArray implements Reference { final HGSArray array = Value.toArray(parent.get(context)); if (i < 0 || i > array.hgsArraySize()) throw new HGSEvalException("Index out of bounds: " + i); - if (i < array.hgsArraySize()) - throw new HGSEvalException("Array field redeclared: " + i); - array.hgsArrayAdd(initial); } diff --git a/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToStruct.java b/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToStruct.java index cedf2935d..335797021 100644 --- a/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToStruct.java +++ b/src/main/java/de/neemann/digital/hdl/hgs/refs/ReferenceToStruct.java @@ -31,9 +31,6 @@ public class ReferenceToStruct implements Reference { @Override public void declareVar(Context context, Object initial) throws HGSEvalException { final HGSMap hgsMap = Value.toMap(parent.get(context)); - if (hgsMap.hgsMapGet(name) != null) - throw new HGSEvalException("Value '" + name + "' redeclared in struct!"); - hgsMap.hgsMapPut(name, initial); } diff --git a/src/main/java/de/neemann/digital/ide/Command.java b/src/main/java/de/neemann/digital/ide/Command.java index 5006d91d5..f29f81280 100644 --- a/src/main/java/de/neemann/digital/ide/Command.java +++ b/src/main/java/de/neemann/digital/ide/Command.java @@ -11,8 +11,10 @@ package de.neemann.digital.ide; public class Command { private final String name; private final boolean filter; + private final boolean gui; private final String requires; private final String[] args; + private final int timeout; /** * Creates a new command @@ -20,13 +22,17 @@ public class Command { * @param name the name of the command * @param requires the hdl which is required, either "verilog" of "vhdl" * @param filter the true, the commands args are filtered + * @param gui if true the appp has a gui + * @param timeout the timeout value in sec * @param args the arguments */ - public Command(String name, String requires, boolean filter, String... args) { + public Command(String name, String requires, boolean filter, boolean gui, int timeout, String... args) { this.name = name; this.requires = requires; + this.timeout = timeout; this.args = args; this.filter = filter; + this.gui = gui; } /** @@ -63,4 +69,18 @@ public class Command { public boolean isFilter() { return filter; } + + /** + * @return true if application has a gui + */ + public boolean isGui() { + return gui; + } + + /** + * @return timeout in seconds + */ + public int getTimeout() { + return timeout; + } } diff --git a/src/main/java/de/neemann/digital/ide/Configuration.java b/src/main/java/de/neemann/digital/ide/Configuration.java index 9f1859a58..24a9e70b3 100644 --- a/src/main/java/de/neemann/digital/ide/Configuration.java +++ b/src/main/java/de/neemann/digital/ide/Configuration.java @@ -7,7 +7,7 @@ package de.neemann.digital.ide; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.StaxDriver; -import de.neemann.digital.core.extern.ProcessStarter; +import de.neemann.digital.builder.tt2.OSExecute; import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.library.ElementLibrary; import de.neemann.digital.gui.SaveAsHelper; @@ -20,6 +20,8 @@ import de.neemann.digital.hdl.verilog2.VerilogGenerator; import de.neemann.digital.hdl.vhdl2.VHDLGenerator; import de.neemann.digital.lang.Lang; import de.neemann.gui.ErrorMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.swing.*; import java.awt.event.ActionEvent; @@ -30,6 +32,7 @@ import java.util.ArrayList; * Used to create the IDE integration */ public final class Configuration { + private static final Logger LOGGER = LoggerFactory.getLogger(Configuration.class); /** * Loads a configuration @@ -66,6 +69,8 @@ public final class Configuration { xStream.aliasAttribute(Command.class, "name", "name"); xStream.aliasAttribute(Command.class, "requires", "requires"); xStream.aliasAttribute(Command.class, "filter", "filter"); + xStream.aliasAttribute(Command.class, "gui", "gui"); + xStream.aliasAttribute(Command.class, "timeout", "timeout"); xStream.addImplicitCollection(Command.class, "args", "arg", String.class); xStream.alias("file", FileToCreate.class); xStream.aliasAttribute(FileToCreate.class, "name", "name"); @@ -236,7 +241,7 @@ public final class Configuration { } } if (args != null) - getIoInterface().startProcess(digFile.getParentFile(), args); + getIoInterface().startProcess(command, digFile.getParentFile(), command.isGui(), args); } catch (Exception e) { getIoInterface().showError(command, e); } @@ -308,11 +313,13 @@ public final class Configuration { /** * Starts a process * - * @param dir the folder to start the process in - * @param args the arguments + * @param command the command started + * @param dir the folder to start the process in + * @param gui true if app has a gui + * @param args the arguments * @throws IOException IOException */ - void startProcess(File dir, String[] args) throws IOException; + void startProcess(Command command, File dir, boolean gui, String[] args) throws IOException; /** * Shows an error message @@ -330,14 +337,30 @@ public final class Configuration { final File parentFile = filename.getParentFile(); if (!parentFile.exists()) { if (!parentFile.mkdirs()) - throw new IOException("could not create "+parentFile); + throw new IOException("could not create " + parentFile); } return new FileOutputStream(filename); } @Override - public void startProcess(File dir, String[] args) throws IOException { - ProcessStarter.start(dir, args); + public void startProcess(Command command, File dir, boolean gui, String[] args) throws IOException { + OSExecute os = new OSExecute(args) + .setTimeOutSec(command.getTimeout()) + .setWorkingDir(dir); + if (gui) + os.startInThread(new OSExecute.ProcessCallback() { + @Override + public void processTerminated(String consoleOut) { + LOGGER.info("process '" + command.getName() + "' says:\n" + consoleOut); + } + + @Override + public void exception(Exception e) { + showError(command, e); + } + }); + else + os.startAndWait(); } @Override diff --git a/src/test/java/de/neemann/digital/hdl/verilog2/VerilogSimulatorTest.java b/src/test/java/de/neemann/digital/hdl/verilog2/VerilogSimulatorTest.java index b728f375b..37ea3fa55 100644 --- a/src/test/java/de/neemann/digital/hdl/verilog2/VerilogSimulatorTest.java +++ b/src/test/java/de/neemann/digital/hdl/verilog2/VerilogSimulatorTest.java @@ -75,7 +75,7 @@ public class VerilogSimulatorTest extends TestCase { File examples = new File(Resources.getRoot(), "../../main/dig/hdl"); try { int tested = new FileScanner(this::checkVerilogExport).noOutput().scan(examples); - assertEquals(1, tested); + assertEquals(2, tested); assertEquals(1, testBenches); } catch (FileScanner.SkipAllException e) { // if iverilog is not installed its also ok diff --git a/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLSimulatorTest.java b/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLSimulatorTest.java index 0eee083bb..d7cbb838d 100644 --- a/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLSimulatorTest.java +++ b/src/test/java/de/neemann/digital/hdl/vhdl2/VHDLSimulatorTest.java @@ -68,7 +68,7 @@ public class VHDLSimulatorTest extends TestCase { File examples = new File(Resources.getRoot(), "../../main/dig/hdl"); try { int tested = new FileScanner(this::checkVHDLExport).noOutput().scan(examples); - assertEquals(1, tested); + assertEquals(2, tested); assertEquals(1, testBenches); } catch (FileScanner.SkipAllException e) { // if ghdl is not installed its also ok diff --git a/src/test/java/de/neemann/digital/ide/ConfigurationTest.java b/src/test/java/de/neemann/digital/ide/ConfigurationTest.java index 414a3e534..f3ad9c3fe 100644 --- a/src/test/java/de/neemann/digital/ide/ConfigurationTest.java +++ b/src/test/java/de/neemann/digital/ide/ConfigurationTest.java @@ -117,7 +117,7 @@ public class ConfigurationTest extends TestCase { } @Override - public void startProcess(File dir, String[] args) { + public void startProcess(Command command, File dir, boolean gui, String[] args) { commands.add(new StartedCommand(dir, args)); } diff --git a/src/test/java/de/neemann/digital/integration/TestExamples.java b/src/test/java/de/neemann/digital/integration/TestExamples.java index 7c71e0e7e..7323657f2 100644 --- a/src/test/java/de/neemann/digital/integration/TestExamples.java +++ b/src/test/java/de/neemann/digital/integration/TestExamples.java @@ -32,7 +32,7 @@ public class TestExamples extends TestCase { */ public void testDistExamples() throws Exception { File examples = new File(Resources.getRoot().getParentFile().getParentFile(), "/main/dig"); - assertEquals(252, new FileScanner(this::check).scan(examples)); + assertEquals(253, new FileScanner(this::check).scan(examples)); assertEquals(171, testCasesInFiles); }