Skip to content

Commit

Permalink
Add rendering device.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Nov 15, 2024
1 parent 4d62dd5 commit 63e3600
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write as _;

use anyhow::Result;
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
Expand All @@ -7,6 +9,14 @@ use crate::util::{self, StringExt};

use super::sorted;

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();
}
Ok(device_x)
}

pub fn render(_opts: &super::Options, ir: &IR, d: &Device, path: &str) -> Result<TokenStream> {
let mut out = TokenStream::new();
let span = Span::call_site();
Expand Down
2 changes: 2 additions & 0 deletions src/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down

0 comments on commit 63e3600

Please sign in to comment.