From 2a18fe5fa1972b0841069d2a019c3f29cd4282e0 Mon Sep 17 00:00:00 2001 From: Thanawat Techaumnuaiwit Date: Sat, 16 Dec 2023 17:29:20 -0800 Subject: [PATCH] Allow `write_lakeroad` backend to write output to file instead of stdout. (#9) * Add code to write_lakeroad to file instead of stdout * Fix a bug for writing to stdout as well * Add suggested code --- backends/lakeroad/example.ys | 6 +++++- backends/lakeroad/lakeroad.cc | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backends/lakeroad/example.ys b/backends/lakeroad/example.ys index d73d7680186..f5431b6d917 100644 --- a/backends/lakeroad/example.ys +++ b/backends/lakeroad/example.ys @@ -4,4 +4,8 @@ module test(input [1:0] a, input b, output o); endmodule EOF -write_lakeroad \ No newline at end of file +# Write output to stdout +write_lakeroad +# Write output to file.egg +write_lakeroad file.egg +!rm file.egg diff --git a/backends/lakeroad/lakeroad.cc b/backends/lakeroad/lakeroad.cc index 8e58b83d914..e511c9824d3 100644 --- a/backends/lakeroad/lakeroad.cc +++ b/backends/lakeroad/lakeroad.cc @@ -25,8 +25,8 @@ #include "kernel/rtlil.h" #include "kernel/sigtools.h" #include "kernel/yw.h" -#include #include +#include USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN @@ -1714,11 +1714,22 @@ struct BtorBackend : public Backend { void execute(std::ostream *&f, std::string filename, std::vector args, RTLIL::Design *design) override { log_header(design, "Executing Lakeroad egglog backend.\n"); - RTLIL::Module *topmod = design->top_module(); + // Copied from firrtl code. + size_t argidx = args.size(); + + if (filename == "") { + // The command itself is given as an arg + if (argidx > 1 && args[argidx - 1][0] != '-') { + // extra_args and friends need to see this argument. + argidx -= 1; + filename = args[argidx]; + } + } + // Has to come after other arg parsing. - extra_args(f, filename, args, args.size()); + extra_args(f, filename, args, argidx); if (topmod == nullptr) log_cmd_error("No top module found.\n");