Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[._]*.sw[a-p]
*.org
*.rs.bk
target
target
.DS_Store
15 changes: 11 additions & 4 deletions src/generate/block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{anyhow, bail, Result};
use proc_macro2::TokenStream;
use proc_macro2::{Ident, Span};
use quote::quote;
Expand All @@ -23,15 +23,18 @@ pub fn render(opts: &super::Options, ir: &IR, b: &Block, path: &str) -> Result<T
match &i.inner {
BlockItemInner::Register(r) => {
let reg_ty = if let Some(fieldset_path) = &r.fieldset {
let _f = ir.fieldsets.get(fieldset_path).unwrap();
let _f = ir
.fieldsets
.get(fieldset_path)
.ok_or_else(|| anyhow!("Couldn't find fieldset: {fieldset_path}"))?;
util::relative_path(fieldset_path, path)
} else {
match r.bit_size {
8 => quote!(u8),
16 => quote!(u16),
32 => quote!(u32),
64 => quote!(u64),
_ => panic!("Invalid register bit size {}", r.bit_size),
_ => bail!("Invalid register bit size {}", r.bit_size),
}
};

Expand Down Expand Up @@ -64,7 +67,11 @@ pub fn render(opts: &super::Options, ir: &IR, b: &Block, path: &str) -> Result<T
}
BlockItemInner::Block(b) => {
let block_path = &b.block;
let _b2 = ir.blocks.get(block_path).unwrap();
let _b2 = ir
.blocks
.get(block_path)
.ok_or_else(|| anyhow!("Couldn't find block: {block_path}"))?;

let ty = util::relative_path(block_path, path);
if let Some(array) = &i.array {
let (len, offs_expr) = super::process_array(array);
Expand Down
2 changes: 1 addition & 1 deletion src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{sorted, with_defmt_cfg_attr};
pub fn render_device_x(_ir: &IR, d: &Device) -> Result<String> {
let mut device_x = String::new();
for i in sorted(&d.interrupts, |i| i.value) {
writeln!(&mut device_x, "PROVIDE({} = DefaultHandler);", i.name).unwrap();
writeln!(&mut device_x, "PROVIDE({} = DefaultHandler);", i.name)?;
}
Ok(device_x)
}
Expand Down
4 changes: 2 additions & 2 deletions src/generate/enumm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use anyhow::Result;
use anyhow::{bail, Result};
use proc_macro2::TokenStream;
use proc_macro2::{Ident, Span};
use quote::quote;
Expand All @@ -26,7 +26,7 @@ pub fn render(opts: &super::Options, _ir: &IR, e: &Enum, path: &str) -> Result<T
9..=16 => quote!(u16),
17..=32 => quote!(u32),
33..=64 => quote!(u64),
_ => panic!("Invalid bit_size {}", e.bit_size),
_ => bail!("Invalid bit_size {}", e.bit_size),
};

let (_, name) = super::split_path(path);
Expand Down