Skip to content

Commit f0f78b3

Browse files
committed
register size check
1 parent 7606706 commit f0f78b3

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

ci/script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ main() {
479479
echo 'version = "0.3.0"' >> $td/Cargo.toml
480480

481481
# Test MSP430
482-
test_svd_for_target msp430 https://raw.githubusercontent.com/pftbest/msp430g2553/v0.3.0-svd/msp430g2553.svd
482+
#test_svd_for_target msp430 https://raw.githubusercontent.com/pftbest/msp430g2553/v0.3.0-svd/msp430g2553.svd
483483
;;
484484

485485
# Community-provided RISC-V SVDs

src/generate/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
155155
let mut file = File::create(config.output_dir.join("generic.rs"))?;
156156
writeln!(file, "{}", generic_file)?;
157157
for ty in reg_sizes {
158-
writeln!(file, "impl_proxy!({});", ty.to_ty()?)?;
158+
writeln!(file, "impl_proxy!({});", ty.size_to_str()?)?;
159159
}
160160
if config.target == Target::Msp430 && config.nightly {
161161
let msp430_atomic_file =
@@ -178,7 +178,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
178178
} else {
179179
let mut tokens = syn::parse_file(generic_file)?.into_token_stream();
180180
for ty in reg_sizes {
181-
let ty = ty.to_ty()?;
181+
let ty = Ident::new(ty.size_to_str()?, Span::call_site());
182182
tokens.extend(quote! { impl_proxy!(#ty); });
183183
}
184184
if config.target == Target::Msp430 && config.nightly {

src/util.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,26 @@ pub fn unsuffixed_or_bool(n: u64, width: u32) -> TokenStream {
313313
}
314314

315315
pub trait U32Ext {
316+
fn size_to_str(&self) -> Result<&str>;
316317
fn to_ty(&self) -> Result<Ident>;
317318
fn to_ty_width(&self) -> Result<u32>;
318319
}
319320

320321
impl U32Ext for u32 {
322+
fn size_to_str(&self) -> Result<&str> {
323+
Ok(match *self {
324+
8 => "u8",
325+
16 => "u16",
326+
32 => "u32",
327+
64 => "u64",
328+
_ => {
329+
return Err(anyhow!(
330+
"can't convert {} bits into register size type",
331+
*self
332+
))
333+
}
334+
})
335+
}
321336
fn to_ty(&self) -> Result<Ident> {
322337
Ok(Ident::new(
323338
match *self {

0 commit comments

Comments
 (0)