diff --git a/src/generate/device.rs b/src/generate/device.rs index ac90129..ca8f829 100644 --- a/src/generate/device.rs +++ b/src/generate/device.rs @@ -1,3 +1,5 @@ +use std::fmt::Write as _; + use anyhow::Result; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote; @@ -7,6 +9,14 @@ use crate::util::{self, StringExt}; use super::sorted; +pub fn render_device_x(_ir: &IR, d: &Device) -> Result { + let mut device_x = String::new(); + for i in sorted(&d.interrupts, |i| i.value) { + writeln!(&mut device_x, "PROVIDE({} = DefaultHandler);", i.name).unwrap(); + } + Ok(device_x) +} + pub fn render(_opts: &super::Options, ir: &IR, d: &Device, path: &str) -> Result { let mut out = TokenStream::new(); let span = Span::call_site(); diff --git a/src/generate/mod.rs b/src/generate/mod.rs index 46b7682..ddf659d 100644 --- a/src/generate/mod.rs +++ b/src/generate/mod.rs @@ -11,6 +11,8 @@ use std::str::FromStr; use crate::ir::*; +pub use device::render_device_x; + pub const COMMON_MODULE: &[u8] = include_bytes!("common.rs"); struct Module { diff --git a/src/main.rs b/src/main.rs index d7f98ce..1de1ee0 100755 --- a/src/main.rs +++ b/src/main.rs @@ -282,6 +282,9 @@ fn gen(args: Generate) -> Result<()> { let items = generate::render(&ir, &generate_opts).unwrap(); fs::write("lib.rs", items.to_string())?; + let device_x = generate::render_device_x(&ir, &ir.devices.values().next().unwrap())?; + fs::write("device.x", device_x)?; + Ok(()) }