Skip to content

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

Merged
merged 1 commit into from
Jan 9, 2020
Merged

field array support #400

merged 1 commit into from
Jan 9, 2020

Conversation

burrbull
Copy link
Member

No description provided.

@rust-highfive
Copy link

r? @Disasm

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Dec 14, 2019
@burrbull
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Dec 14, 2019
@bors
Copy link
Contributor

bors bot commented Dec 14, 2019

try

Build succeeded

@burrbull burrbull force-pushed the field-array branch 2 times, most recently from 5b77117 to bedc69f Compare December 14, 2019 19:08
@burrbull
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Dec 14, 2019
@burrbull burrbull changed the title [WIP] field array support field array support Dec 14, 2019
@burrbull burrbull marked this pull request as ready for review December 14, 2019 19:50
@burrbull burrbull requested a review from a team as a code owner December 14, 2019 19:50
@bors
Copy link
Contributor

bors bot commented Dec 14, 2019

try

Build succeeded

@burrbull
Copy link
Member Author

Rebased.

bors try

bors bot added a commit that referenced this pull request Dec 15, 2019
@bors
Copy link
Contributor

bors bot commented Dec 15, 2019

try

Build succeeded

Copy link
Member

@Disasm Disasm left a 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.

@@ -737,6 +856,7 @@ struct F<'a> {
ty: Ident,
width: u32,
write_constraint: Option<&'a WriteConstraint>,
dim: Option<(u32, u32, u32, Vec<String>)>,
Copy link
Member

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

#_pc_r::new ( #value )
}
});

let doc = format!("Reader of field `{}`", f.name);
Copy link
Member

@Disasm Disasm Dec 29, 2019

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.

@@ -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;
Copy link
Member

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.

Comment on lines 248 to 251
let sequential_indexes = dim_index
.iter()
.map(|element| element.parse::<u32>())
.eq((first..de.dim+first).map(Ok));
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member

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.

Comment on lines 383 to 367
r_impl_items.push(quote! {
#[doc = #doc]
#[inline(always)]
pub fn #sc(&self) -> #_pc_r {
#_pc_r::new( #value )
}
});
Copy link
Member

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.

@Disasm Disasm added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 29, 2019
@burrbull burrbull force-pushed the field-array branch 3 times, most recently from 1ca7988 to 5a2cbea Compare January 1, 2020 18:00
@burrbull
Copy link
Member Author

burrbull commented Jan 1, 2020

Rebased and fixed.

@@ -216,26 +213,19 @@ pub fn fields(
let can_write = access != Access::ReadOnly;

// TODO enumeratedValues
let inline = quote! { #[inline(always)] };
Copy link
Contributor

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.

@Disasm
Copy link
Member

Disasm commented Jan 7, 2020

I'd rather prefer readability over speed, because we already have relatively fast processing, but the code is quite difficult to understand.

@therealprof
Copy link
Contributor

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.

@burrbull burrbull mentioned this pull request Jan 7, 2020
bors bot added a commit that referenced this pull request Jan 7, 2020
425: replace_suffix r=therealprof a=burrbull

Part of #400 

Co-authored-by: Andrey Zgarbul <[email protected]>
Copy link
Member

@Disasm Disasm left a 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).

@@ -246,7 +239,6 @@ pub fn fields(
let fty = width.to_ty()?;
let evs = &f.enumerated_values;
let quotedfield = String::from("`") + &f.name + "`";
Copy link
Member

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?

Copy link
Contributor

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. 😅

Copy link
Member

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?

let pc = base.field.to_sanitized_upper_case();
let pc = util::replace_suffix(base.field, "")
.to_sanitized_upper_case()
.to_string();
Copy link
Member

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();?

Copy link
Member Author

@burrbull burrbull Jan 8, 2020

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>

@Disasm
Copy link
Member

Disasm commented Jan 8, 2020

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,
        }

@Disasm
Copy link
Member

Disasm commented Jan 8, 2020

Also (ch_abort_we(1-6) instead of ch(1-6)_abort_we)

        #[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)
            }

@burrbull
Copy link
Member Author

burrbull commented Jan 8, 2020

I've already shut down my PC. But you can do it yourself. :)

@Disasm
Copy link
Member

Disasm commented Jan 8, 2020

Indeed!

Copy link
Member

@Disasm Disasm left a comment

Choose a reason for hiding this comment

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

Thank you @burrbull!

@Disasm
Copy link
Member

Disasm commented Jan 8, 2020

bors r+

bors bot added a commit that referenced this pull request Jan 8, 2020
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]>
@bors
Copy link
Contributor

bors bot commented Jan 8, 2020

Build failed

@burrbull
Copy link
Member Author

burrbull commented Jan 9, 2020

cargo fmt and squash commits

Copy link
Member

@Disasm Disasm left a comment

Choose a reason for hiding this comment

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

bors r+

bors bot added a commit that referenced this pull request Jan 9, 2020
400: field array support r=Disasm a=burrbull



Co-authored-by: Andrey Zgarbul <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jan 9, 2020

Build succeeded

@bors bors bot merged commit abbe720 into master Jan 9, 2020
@bors bors bot deleted the field-array branch January 9, 2020 07:22
@Dirbaio Dirbaio mentioned this pull request Dec 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. T-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants