Digital
Digital copied to clipboard
Option to export HDL files from CLI
I think it would be a nice idea to add the possibility to export to HDL from the CLI. It would allow the integration of Digital in Makefile or build scripts.
I did a quick test with Verilog and it seems to work. Since I'm not a Java developer, I'm not sure about integrating VHDL and providing test coverage, so I'm not going to create a PR.
File: src/main/java/de/neemann/digital/cli/HDLExport.java
package de.neemann.digital.cli;
import de.neemann.digital.hdl.verilog2.VerilogGenerator;
import de.neemann.digital.cli.cli.Argument;
import de.neemann.digital.cli.cli.CLIException;
import de.neemann.digital.cli.cli.BasicCommand;
import de.neemann.digital.hdl.printer.CodePrinter;
import java.io.File;
import java.io.IOException;
public class HDLExport extends BasicCommand {
private final Argument<String> digFile;
private final Argument<String> verilogFile;
public HDLExport() {
super("hdl");
digFile = addArgument(new Argument<>("dig", "", false));
verilogFile = addArgument(new Argument<>("verilog", "", true));
}
@Override
public void execute() throws CLIException {
String digFilePath = digFile.get();
String verilogFilePath = verilogFile.get();
File verilogFile = new File(verilogFilePath);
try {
CircuitLoader circuitLoader = new CircuitLoader(digFilePath, false);
VerilogGenerator verilogGenerator = new VerilogGenerator(circuitLoader.getLibrary(), new CodePrinter(verilogFile));
verilogGenerator.export(circuitLoader.getCircuit());
System.out.println("Verilog export completed successfully.");
} catch (IOException e) {
throw new CLIException("Failed to export Verilog: " + e.getMessage(), e);
}
}
}
Good idea!