From b5ece94f084012c348b5b6b3ea8ac6594e466e2f Mon Sep 17 00:00:00 2001 From: Charlotte Fulham Date: Thu, 6 Aug 2026 11:46:47 +1000 Subject: [PATCH] tool: separate sdf tree parsing Separate XML specific parsing details into `parse_xml`, so that `parse` can be reused Signed-off-by: Charlotte Fulham --- tool/microkit/src/main.rs | 4 ++-- tool/microkit/src/sdf.rs | 32 ++++++++++++++++++++++---------- tool/microkit/tests/test.rs | 4 ++-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tool/microkit/src/main.rs b/tool/microkit/src/main.rs index 6f4f88bbf..a461a454d 100644 --- a/tool/microkit/src/main.rs +++ b/tool/microkit/src/main.rs @@ -10,7 +10,7 @@ use microkit_tool::argparse; use microkit_tool::argparse::{Args, ArgsError}; use microkit_tool::build::build_system; -use microkit_tool::sdf::parse; +use microkit_tool::sdf::parse_xml; use microkit_tool::sdk::Sdk; use microkit_tool::sel4::Config; use microkit_tool::util::bail_if_not_exists; @@ -54,7 +54,7 @@ fn main() -> Result<(), String> { let xml: String = fs::read_to_string(system_path).unwrap(); - let mut system = match parse( + let mut system = match parse_xml( system_path.as_path(), &xml, &kernel_config, diff --git a/tool/microkit/src/sdf.rs b/tool/microkit/src/sdf.rs index 407af6576..84dd251af 100644 --- a/tool/microkit/src/sdf.rs +++ b/tool/microkit/src/sdf.rs @@ -61,6 +61,7 @@ pub struct SdfLocation { pub col: u32, } +#[derive(Clone, Copy)] pub struct SdfAttribute<'a> { pub name: &'a str, pub value: &'a str, @@ -125,7 +126,7 @@ impl<'a> SdfNode<'a> for roxmltree::Node<'a, '_> { } } -pub(crate) struct SystemDescriptionFile<'a> { +pub struct SystemDescriptionFile<'a> { filename: &'a Path, } @@ -138,7 +139,7 @@ pub struct SystemDescription { pub domains: Domains, } -pub fn parse( +pub fn parse_xml( filename: &Path, xml: &str, config: &Config, @@ -151,14 +152,6 @@ pub fn parse( let xml_sdf = SystemDescriptionFile { filename }; - let mut root_pds = vec![]; - let mut mrs = vec![]; - let mut iomaps = vec![]; - let mut io_address_space_names = HashSet::new(); - let mut iommu_domain_ids = HashSet::new(); - let mut iommu_device_identifiers = Vec::new(); - let mut channels = vec![]; - let mut domains = Domains::default(); let system = doc .root() .children() @@ -170,6 +163,25 @@ pub fn parse( let system: &dyn SdfNode = &system; + parse(xml_sdf, system, config, search_paths) +} + +pub fn parse( + xml_sdf: SystemDescriptionFile, + system: &dyn SdfNode, + config: &Config, + search_paths: &Vec, +) -> Result { + let mut root_pds = vec![]; + let mut mrs = vec![]; + let mut iomaps = vec![]; + let mut io_address_space_names = HashSet::new(); + let mut iommu_domain_ids = HashSet::new(); + let mut iommu_device_identifiers = Vec::new(); + let mut channels = vec![]; + let mut domains = Domains::default(); + let filename = xml_sdf.filename; + // Channels cannot be parsed immediately as they refer to a particular protection domain // via an index in the list of PDs. This means that we have to parse all PDs first and // then parse the channels. diff --git a/tool/microkit/tests/test.rs b/tool/microkit/tests/test.rs index 1f1442588..33758ba24 100644 --- a/tool/microkit/tests/test.rs +++ b/tool/microkit/tests/test.rs @@ -107,7 +107,7 @@ fn check_success(kernel_config: &sel4::Config, test_name: &str) { path.push("tests/sdf/"); path.push(test_name); let sdf = std::fs::read_to_string(path).unwrap(); - let parse = sdf::parse( + let parse = sdf::parse_xml( Path::new(test_name), &sdf, kernel_config, @@ -131,7 +131,7 @@ fn check_error(kernel_config: &sel4::Config, test_name: &str, expected_err: &str sdf_path.push("tests/sdf/"); sdf_path.push(test_name); let sdf = std::fs::read_to_string(sdf_path).unwrap(); - let parse_err = sdf::parse( + let parse_err = sdf::parse_xml( Path::new(test_name), &sdf, kernel_config,