-
Notifications
You must be signed in to change notification settings - Fork 53
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
Backend for listing instantiations of primitives #1860
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heck yes!!! This seems perfect! Wahoo! Just have a couple of code-level suggestions within.
As for the name, maybe something like primitive-uses
or primitives-used
something would be nice and clear? We could even call the source file primitive_uses.rs
.
calyx-backend/src/primitives.rs
Outdated
let mut curr_params = Vec::new(); | ||
for (param_name, param_size) in param_binding.iter() { | ||
let param = PrimitiveParam { | ||
param_name: param_name.to_string(), | ||
param_value: *param_size, | ||
}; | ||
curr_params.push(param); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that this matters very much, but this is probably possible to write in a functional way (and eliminate mut
, in favor of collect
). I think it would look something like this (although I haven't tested it):
let curr_params: Vec<_> = param_binding.iter().map(|param_name, param_size| {
PrimitiveParam {
// unchanged
}
}).collect();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super cool! Thanks for the suggestion :)
Wonderful; looks great! Merge at will, I say. 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, left a few minor notes that you can take or leave
calyx-backend/src/primitive_uses.rs
Outdated
let main_comp = ctx | ||
.components | ||
.iter() | ||
.find(|comp| comp.name == ctx.entrypoint) | ||
.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a method on Context
called entrypoint
which does this exact thing.
It's functionally the same but might as well make use of it
calyx-backend/src/primitive_uses.rs
Outdated
|
||
gen_primitive_set(ctx, main_comp, primitive_set); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a more idiomatic way of writing it. Better when you might want to use
something as more than a mutable reference down the line
gen_primitive_set(ctx, main_comp, primitive_set); | |
let mut primitive_set: HashSet<PrimitiveUse> = HashSet::new(); | |
gen_primitive_set(ctx, main_comp, &mut primitive_set); |
* First pass for backend to produce json file containing primitive instantiation info * pretty print the json * Map from param names to values * Fix clippy error * usage message * Fix doc comments * Change JSON format for parameter names and values * Fix formatting error * Changed naming and fixed unchanged name * Make parameter collection functional * Make fixes from PR comments
This PR contains a new backend that lists all of the unique instantiations of primitives within a program into a JSON file. This is necessary for my Calyx-FIRRTL efforts because FIRRTL does not support parameterization of modules, and therefore I have to generate individual FIRRTL modules that each correspond to a specific primitive instantiation in Calyx. This backend is the first step, and the produced JSON file will be processed by a script that I will write next. I'll also add fud2 support for this backend soon.
As a side note, this backend would also be similarly useful for the BTOR2-Cider efforts as described in #1845 under Generation Scaffolding.
This backend borrowed a lot of code from the Resource Estimation backend, which I'm very thankful for 🙂
Please let me know if there's any points I can improve here!! Also, I'm personally not a fan of the namings I used (
primitive-inst
,primtives.rs
, etc) but didn't have any better ideas, so I'd really appreciate any suggestions on that front 🙂Usage
You can run the backend by using the
-b primitive-inst
flag, and the optional-o <OUTPUT_FILE>
flag to write the JSON to a file.ex) Running with
language-tutorial-mem
:we get in
p.json
...