Skip to content

Conversation

@romancardenas
Copy link
Contributor

This is part of the work for improving the procedural macros used in this repo.

I reduced to the minimum the amount of code in riscv-macros/src/lib.rs. The idea is leaving there only the public macros, and all the auxiliary code will be in clean modules.

Currently, riscv-macros only contain the pac_enum macro, which works in tandem with the riscv crate. Thus, the auxiliary code has been moved to the riscv module.

If the rt feature is active, pac_enum may also produce code required by riscv-rt. This additional code is now isolated in the riscv::rt module.

Next steps will be moving code from riscv-rt/macros to riscv-macros, under a new riscv_rt module.

@romancardenas romancardenas requested a review from a team as a code owner November 26, 2025 11:30
Copy link
Contributor

@KushalMeghani1644 KushalMeghani1644 left a comment

Choose a reason for hiding this comment

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

Most the codes are great! but I have a few concerns here! take my reviews with a grain of salt since I am not a official maintainer of this crate... thanks :)

Comment on lines +94 to +120
impl PacEnumItem {
pub fn new(input: &DeriveInput) -> Self {
let name = input.ident.clone();
let (mut numbers, mut max_number) = (HashMap::new(), 0);

let variants = match &input.data {
Data::Enum(data) => &data.variants,
_ => panic!("Input is not an enum"),
};
for v in variants.iter() {
let ident = v.ident.clone();
let value = match v.discriminant.as_ref() {
Some((_, syn::Expr::Lit(expr_lit))) => match &expr_lit.lit {
syn::Lit::Int(lit_int) => {
lit_int.base10_parse::<usize>().unwrap_or_else(|_| {
panic!("All variant discriminants must be unsigned integers")
})
}
_ => panic!("All variant discriminants must be unsigned integers"),
},
None => panic!("Variant must have a discriminant"),
_ => panic!("All variant discriminants must be literal expressions"),
};

if numbers.insert(value, ident).is_some() {
panic!("Duplicate discriminant value");
}
Copy link
Contributor

@KushalMeghani1644 KushalMeghani1644 Dec 7, 2025

Choose a reason for hiding this comment

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

Hey! @romancardenas looking at the codes, all of them are mostly great! the only thing that concerns me here is the use of panic!() macro for things like missing discriminants and duplicate discriminant. I feel like it would be better to use something like syn::Error what do you think?

take my reviews with a grain of salt since I am not a actual maintainer of these crate.
Thank you :)

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