Skip to content

Commit b5756e8

Browse files
committed
Addressed request of expressing the OFFSET in decimal rather than hex
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 <[email protected]>
1 parent e306adf commit b5756e8

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/generate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ pub fn fields(
916916
sc: Ident::new(&*sc),
917917
mask: util::hex_or_bool((((1 as u64) << width) - 1) as u32, width),
918918
name: &f.name,
919-
offset: util::hex(f.bit_range.offset),
919+
offset: util::unsuffixed(u64::from(f.bit_range.offset)),
920920
ty: width.to_ty()?,
921921
write_constraint: f.write_constraint.as_ref(),
922922
})

src/util.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::borrow::Cow;
33
use inflections::Inflect;
44
use svd::{self, Access, EnumeratedValues, Field, Peripheral, Register,
55
Usage};
6-
use syn::{self, Ident, IntTy, Lit};
6+
use syn::{self, Ident};
77
use quote::Tokens;
88

99
use errors::*;
@@ -280,7 +280,7 @@ pub fn access_of(register: &Register) -> Access {
280280
)
281281
}
282282

283-
/// Turns `n` into an unsuffixed separated hex tokens
283+
/// Turns `n` into an unsuffixed separated hex token
284284
pub fn hex(n: u32) -> Tokens {
285285
let mut t = Tokens::new();
286286
let (h2, h1) = ((n >> 16) & 0xffff, n & 0xffff);
@@ -306,18 +306,18 @@ pub fn hex_or_bool(n: u32, width: u32) -> Tokens {
306306
}
307307
}
308308

309-
/// Turns `n` into an unsuffixed literal
310-
pub fn unsuffixed(n: u64) -> Lit {
311-
Lit::Int(n, IntTy::Unsuffixed)
309+
/// Turns `n` into an unsuffixed token
310+
pub fn unsuffixed(n: u64) -> Tokens {
311+
let mut t = Tokens::new();
312+
t.append(format!("{}", n));
313+
t
312314
}
313315

314-
pub fn unsuffixed_or_bool(n: u64, width: u32) -> Lit {
316+
pub fn unsuffixed_or_bool(n: u64, width: u32) -> Tokens {
315317
if width == 1 {
316-
if n == 0 {
317-
Lit::Bool(false)
318-
} else {
319-
Lit::Bool(true)
320-
}
318+
let mut t = Tokens::new();
319+
t.append(if n == 0 { "false" } else { "true" });
320+
t
321321
} else {
322322
unsuffixed(n)
323323
}

0 commit comments

Comments
 (0)