-
Notifications
You must be signed in to change notification settings - Fork 157
field array support #400
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
field array support #400
Conversation
r? @Disasm (rust_highfive has picked a reviewer for you, use r? to override) |
bors try |
tryBuild succeeded |
5b77117
to
bedc69f
Compare
bors try |
tryBuild succeeded |
ce572bd
to
ff56f52
Compare
Rebased. bors try |
tryBuild succeeded |
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.
Thank you! I've found a few things to discuss and/or change.
I checked this change on riscv-rust/k210-pac#33, the output looks good for me despite some pin%s
strings in doc comments.
Sorry for the delay.
src/generate/register.rs
Outdated
@@ -737,6 +856,7 @@ struct F<'a> { | |||
ty: Ident, | |||
width: u32, | |||
write_constraint: Option<&'a WriteConstraint>, | |||
dim: Option<(u32, u32, u32, Vec<String>)>, |
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.
I believe it will be useful to add a struct
to describe these inner tuple fields
src/generate/register.rs
Outdated
#_pc_r::new ( #value ) | ||
} | ||
}); | ||
|
||
let doc = format!("Reader of field `{}`", f.name); |
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.
One of these constructions generates #[doc = "Reader of field `pin%s`"]
. Same for the _W
type.
src/generate/register.rs
Outdated
@@ -306,10 +325,10 @@ pub fn fields( | |||
let _pc_r = &f._pc_r; | |||
let _pc_w = &f._pc_w; | |||
let description = &f.description; | |||
let description_with_bits = &f.description_with_bits; | |||
let width = f.width; |
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.
Why do you need this separate variable? It isn't referenced from quote!
blocks as far as I can see.
src/generate/register.rs
Outdated
let sequential_indexes = dim_index | ||
.iter() | ||
.map(|element| element.parse::<u32>()) | ||
.eq((first..de.dim+first).map(Ok)); |
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.
According to the spec dimIndex
has 0..1 occurrence and these calculations are redundant.
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 check is to ensure that dim_index
consist of correct sequence (e.g. 4,5,6,7
)
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.
Oh, indeed, I misunderstood the spec.
src/generate/register.rs
Outdated
r_impl_items.push(quote! { | ||
#[doc = #doc] | ||
#[inline(always)] | ||
pub fn #sc(&self) -> #_pc_r { | ||
#_pc_r::new( #value ) | ||
} | ||
}); |
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 construction was under if let Some((evs, base)) = lookup_filter(&lookup_results, Usage::Read) {
, now it's under } else {
. Please check if this is correct, I don't quite understand what's going on here.
1ca7988
to
5a2cbea
Compare
Rebased and fixed. |
@@ -216,26 +213,19 @@ pub fn fields( | |||
let can_write = access != Access::ReadOnly; | |||
|
|||
// TODO enumeratedValues | |||
let inline = quote! { #[inline(always)] }; |
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.
Have you checked whether this is worth the harder to read quote sections below? If we do something like this we ideally wouldn't repeat the quoting for each register we process but do it exactly once and then reuse it.
I'd rather prefer readability over speed, because we already have relatively fast processing, but the code is quite difficult to understand. |
I agree. Also we could do a lot better explaining what the code is doing, especially for the more obscure and less common parts. |
425: replace_suffix r=therealprof a=burrbull Part of #400 Co-authored-by: Andrey Zgarbul <[email protected]>
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.
Overall LGTM. I think we can merge this after discussion on the last two comments (with or without corresponding fixes).
src/generate/register.rs
Outdated
@@ -246,7 +239,6 @@ pub fn fields( | |||
let fty = width.to_ty()?; | |||
let evs = &f.enumerated_values; | |||
let quotedfield = String::from("`") + &f.name + "`"; |
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.
Maybe this let quotedfield
line should be moved too. @therealprof could you comment on this?
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.
No preference. I planned to do something with it but that plan is already gone out the window with this PR anyway. 😅
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.
Ok! @burrbull, could you move it then to line 296?
src/generate/register.rs
Outdated
let pc = base.field.to_sanitized_upper_case(); | ||
let pc = util::replace_suffix(base.field, "") | ||
.to_sanitized_upper_case() | ||
.to_string(); |
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.
Do you need this .to_string();
?
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.
CH_ABORT_R
This field does not contain <dim>
https://github.com/riscv-rust/k210-pac/blob/4f7330528951b6d1f54ed5030d7f17b0078cdce5/k210.svd#L1123
Please add there:
<dim>6</dim>
<dimIncrement>1</dimIncrement>
<dimIndex>1-6</dimIndex>
Hmm, there are still buggy doc comments: #[doc = "Reader of field `ch%s_abort`"]
pub type CH_ABORT_R = crate::R<bool, bool>;
#[doc = "Write proxy for field `ch%s_abort`"]
pub struct CH_ABORT_W<'a> {
w: &'a mut W,
} |
Also ( #[doc = "Reader of fields `ch_abort_we(1-6)`"]
pub type CH_ABORT_WE_R = crate::R<bool, bool>;
#[doc = "Write proxy for fields `ch_abort_we(1-6)`"]
pub struct CH_ABORT_WE_W<'a> {
w: &'a mut W,
offset: usize,
} But sometimes it generates correct docs: #[doc = "Enable write to ch(1-6)_susp bit"]
#[inline(always)]
pub unsafe fn ch_susp_we(&self, n: usize) -> CH_SUSP_WE_R {
CH_SUSP_WE_R::new(((self.bits >> n - 1 + 24) & 0x01) != 0)
} |
I've already shut down my PC. But you can do it yourself. :) |
Indeed! |
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.
Thank you @burrbull!
bors r+ |
400: field array support r=Disasm a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]> Co-authored-by: Zgarbul Andrey <[email protected]> Co-authored-by: Vadim Kaushan <[email protected]>
Build failed |
|
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.
bors r+
400: field array support r=Disasm a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
Build succeeded |
No description provided.