-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add DeleteRegisters, FixRegisterBitSizes.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::common::*; | ||
use crate::ir::*; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct DeleteRegisters { | ||
pub block: String, | ||
pub from: String, | ||
} | ||
|
||
impl DeleteRegisters { | ||
pub fn run(&self, ir: &mut IR) -> anyhow::Result<()> { | ||
let path_re = make_regex(&self.block)?; | ||
let re = make_regex(&self.from)?; | ||
for id in match_all(ir.blocks.keys().cloned(), &path_re) { | ||
let b = ir.blocks.get_mut(&id).unwrap(); | ||
b.items.retain(|i| !re.is_match(&i.name)); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::ir::*; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct FixRegisterBitSizes {} | ||
|
||
impl FixRegisterBitSizes { | ||
pub fn run(&self, ir: &mut IR) -> anyhow::Result<()> { | ||
for (_, b) in &mut ir.blocks { | ||
for i in &mut b.items { | ||
if let BlockItemInner::Register(r) = &mut i.inner { | ||
let orig_bit_size = r.bit_size; | ||
let good_bit_size = match r.bit_size { | ||
..=8 => 8, | ||
..=16 => 16, | ||
..=32 => 32, | ||
..=64 => 64, | ||
_ => panic!("Invalid register bit size {}", r.bit_size), | ||
}; | ||
if r.bit_size != good_bit_size { | ||
r.bit_size = good_bit_size; | ||
match &r.fieldset { | ||
None => { | ||
// create a new fieldset, with a single field with the original bit size. | ||
r.fieldset = Some(i.name.clone()); | ||
let fs = FieldSet { | ||
bit_size: good_bit_size, | ||
fields: vec![Field { | ||
name: "val".to_string(), | ||
bit_offset: BitOffset::Regular(0), | ||
bit_size: orig_bit_size, | ||
description: None, | ||
enumm: None, | ||
array: None, | ||
}], | ||
description: None, | ||
extends: None, | ||
}; | ||
if ir.fieldsets.insert(i.name.clone(), fs).is_some() { | ||
panic!("dup fieldset {}", i.name); | ||
} | ||
} | ||
Some(fs) => { | ||
// expand the size of the existing fieldset. | ||
let fs = ir.fieldsets.get_mut(fs).unwrap(); | ||
fs.bit_size = good_bit_size; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters