From 0b2cebe3d7fa4a8904432d5d061ae8ccd112ed00 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Nov 2024 22:07:50 +0100 Subject: [PATCH] add RenameInterrupts. --- src/transform/mod.rs | 1 + src/transform/rename_interrupts.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/transform/rename_interrupts.rs diff --git a/src/transform/mod.rs b/src/transform/mod.rs index 38bf2b0..a083b3c 100644 --- a/src/transform/mod.rs +++ b/src/transform/mod.rs @@ -255,4 +255,5 @@ transforms!( make_block::MakeBlock, modify_byte_offset::ModifyByteOffset, fix_register_bit_sizes::FixRegisterBitSizes, + rename_interrupts::RenameInterrupts, ); diff --git a/src/transform/rename_interrupts.rs b/src/transform/rename_interrupts.rs new file mode 100644 index 0000000..273ab46 --- /dev/null +++ b/src/transform/rename_interrupts.rs @@ -0,0 +1,25 @@ +use serde::{Deserialize, Serialize}; + +use super::common::*; +use crate::ir::*; + +#[derive(Debug, Serialize, Deserialize)] +pub struct RenameInterrupts { + pub from: String, + pub to: String, +} + +impl RenameInterrupts { + pub fn run(&self, ir: &mut IR) -> anyhow::Result<()> { + let re = make_regex(&self.from)?; + + for d in ir.devices.values_mut() { + for i in &mut d.interrupts { + if let Some(name) = match_expand(&i.name, &re, &self.to) { + i.name = name; + } + } + } + Ok(()) + } +}