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

Conversation

thiskappaisgrey
Copy link

@thiskappaisgrey thiskappaisgrey commented Dec 13, 2023

Add code to allow write_lakeroad backend to write to file instead of stdout.

Example (in example.ys):

read_verilog <<EOF
module test(input [1:0] a, input b, output o);
  assign o = a & b;
endmodule
EOF

# Write output to file instead of stdout
write_lakeroad file.egg

@gussmith23

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?

Comment on lines 7 to 10
write_lakeroad file.egg
# Write output to stdout
# write_lakeroad

Choose a reason for hiding this comment

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

Suggested change
# Write output to file instead of stdout
write_lakeroad file.egg
# Write output to stdout
# write_lakeroad
write_lakeroad
write_lakeroad file.egg
!rm file.egg

We might as well test both writing to a file and writing to stdout. Also added code solving my requested change above.

Comment on lines 1719 to 1720
// Copied from firrtl code. Not sure why "filename" is not set ever
// even when I pass "write_lakeroad hello.egg" or something

Choose a reason for hiding this comment

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

Suggested change
// Copied from firrtl code. Not sure why "filename" is not set ever
// even when I pass "write_lakeroad hello.egg" or something
// Copied from firrtl code.

I'll explain to you why filename is not set, and then we can delete this comment (b/c the comment isn't actually relevant to the code). the filename variable isn't set because, when you call write_lakeroad from the Yosys shell (which is how you've been calling it), the Yosys internals call execute without passing filename. I don't know where in the Yosys codebase execute is ever called with a filename, but there must be some place where it's used. When you do write_lakeroad hello.egg, Yosys puts hello.egg into args, not into filename. (that's why this block of code exists: it basically says, if filename isn't set explicitly, then use the last argument as a filename)

@gussmith23
Copy link

Thanks!! A few comments and then we can merge.

@gussmith23
Copy link

Bump on this! Would love to merge it and don't want it to go stale.

@thiskappaisgrey
Copy link
Author

@gussmith23 sorry for forgetting! I was busy with TA duties for the past couple of days (end of quarter is always crazy).

@gussmith23 gussmith23 merged commit 2a18fe5 into uwsampl:gussmith23/lakeroad-backend Dec 17, 2023
11 of 15 checks passed
@gussmith23
Copy link

@gussmith23 sorry for forgetting! I was busy with TA duties for the past couple of days (end of quarter is always crazy).

No problem at all. Classes and TAing is more important! Just wanted to make sure it didn't get forgotten. Congrats on finishing your quarter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants