Skip to content

Conversation

therealprof
Copy link
Contributor

The two main reasons behind this change are ensuring that the numbers
(mostly addresses, masks and default values) line up with the datasheet
for easier searching and verification since those are pretty much always
expressed in hexadecimal. The other reason being clippy now complains
about long numeric literals (without seperators) being hard to read -- I
agree.

Signed-off-by: Daniel Egger daniel@eggers-club.de

@therealprof
Copy link
Contributor Author

@japaric Mind having a look?

Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @therealprof.

I agree this is an improvement for "big" 32 bit literals like addresses but not so much for small numbers (<100) so I have proposed some tweaks. What do you think?

I'd be interested in hearing other people's opinions as well. @jonas-schievink, care to chime in?

src/generate.rs Outdated

if let Some(cpu) = d.cpu.as_ref() {
let bits = util::unsuffixed(cpu.nvic_priority_bits as u64);
let bits = util::hex(cpu.nvic_priority_bits);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think writing this one in hex is going to make it more readable as the value is always in the range from 1 to 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to have everything base 2/16 (as implied by the word "bits" here) related written in hex but I do agree it makes little sense for small numbers. I can get rid of that.

src/generate.rs Outdated
mask: util::hex_or_bool((((1 as u64) << width) - 1) as u32, width),
name: &f.name,
offset: util::unsuffixed(u64(f.bit_range.offset)),
offset: util::hex(f.bit_range.offset),
Copy link
Member

Choose a reason for hiding this comment

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

This value will in the range 0..32. TBH, I personally would find it easier to read it in decimal since it appears in the RHS of expressions like value << offset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, will change that back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@japaric Actually I can't change that back because offset now takes a Token while util::unsuffixed() produces a Lit. If you want I can add some more code to produce a decimal token to be fed into offset.

Copy link
Member

Choose a reason for hiding this comment

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

Or, maybe, unsuffixed could return Tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, it's done.

src/util.rs Outdated
}

/// Turns `n` into an unsuffixed separated hex ident
pub fn hex(n: u32) -> Ident {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Ident is for (parsed) identifiers. I see that there's no Lit variant for hexadecimal so we can't use that. I think returning Tokens would be the most correct choice after Lit. Could you change this to Tokens? (I think you would have to do something like let mut ts = Tokens::new(); ts.append("0xdead_beef"); ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try that.

@jonas-schievink
Copy link
Contributor

The general idea makes sense to me, as do @japaric's comments. I don't know enough about ARM to have any real insight here :)

@homunkulus
Copy link
Contributor

☔ The latest upstream changes (presumably #121) made this pull request unmergeable. Please resolve the merge conflicts.

The two main reasons behind this change are ensuring that the numbers
(mostly addresses, masks and default values) line up with the datasheet
for easier searching and verification since those are pretty much always
expressed in hexadecimal. The other reason being clippy now complains
about long numeric literals (without seperators) being hard to read -- I
agree.

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
@therealprof
Copy link
Contributor Author

@japaric Except for the one change requested which I commented above the other requests have been addressed now.

src/util.rs Outdated
/// Turns `n` into an unsuffixed token
pub fn unsuffixed(n: u64) -> Tokens {
let mut t = Tokens::new();
t.append (format!("{}", n));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: stray whitespace between append and (

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'll find a lot more nits if you run rustfmt over it, which is preventing me from doing it all the time. 😉

This changes the util::unsuffixed() and util::unsuffixed_or_bool()
functions to return a quote::Tokens instead of a syn::Lit.

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
@japaric
Copy link
Member

japaric commented Sep 23, 2017

Thanks, @therealprof.

@homunkulus r+

@homunkulus
Copy link
Contributor

📌 Commit b5756e8 has been approved by japaric

@homunkulus
Copy link
Contributor

⌛ Testing commit b5756e8 with merge b5756e8...

@homunkulus
Copy link
Contributor

💔 Test failed - status-travis

@homunkulus
Copy link
Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: japaric
Pushing b5756e8 to master...

@homunkulus homunkulus merged commit b5756e8 into rust-embedded:master Sep 23, 2017
@therealprof therealprof deleted the hex-literals branch September 23, 2017 21:53
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.

4 participants