Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow write_lakeroad backend to write output to file instead of stdout. #9

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backends/lakeroad/example.ys

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we run this test, it will generate a "junk" output file. If we run the tests with a clean git directory (that is, no changes made, all changes committed), it will become dirty. This isn't ideal. There are a few ways to fix this:

  • Delete the file after it's written. Unsure if this can be done from within a Yosys script. Sometimes scripting languages let you run shell commands, e.g. by prefixing with ! (like !rm file.egg). Maybe see if this is the case in yosys? (from my simple test on my command line, this is the case!)
  • Generate the file to a temporary directory. This would also require getting the temporary directory within the Yosys script. Normally in a shell script this can be done e.g. with mktemp, but I'm not sure how to make that available in Yosys.
  • Add the generated file to the .gitignore (less ideal).
  • Just add functionality for writing to a file, but don't test it. (Obviously testing everything is ideal, so this is the worst option.)

These are intentionally ordered best to worst. I think the first option should work -- can you try it?

Original file line number Diff line number Diff line change
@@ -4,4 +4,8 @@ module test(input [1:0] a, input b, output o);
endmodule
EOF

write_lakeroad
# Write output to stdout
write_lakeroad
# Write output to file.egg
write_lakeroad file.egg
!rm file.egg
17 changes: 14 additions & 3 deletions backends/lakeroad/lakeroad.cc
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@
#include "kernel/rtlil.h"
#include "kernel/sigtools.h"
#include "kernel/yw.h"
#include <string>
#include <assert.h>
#include <string>

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
@@ -1714,11 +1714,22 @@ struct BtorBackend : public Backend {
void execute(std::ostream *&f, std::string filename, std::vector<std::string> 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");