From a229c17f55763ec130e3d52df422b3b3d686371f Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Fri, 7 Jan 2022 22:21:11 +0300 Subject: [PATCH] expand --- Cargo.toml | 4 ++-- src/cli.rs | 29 ++++++++++++++++++++++++++++- src/convert/convert_cli.rs | 12 +++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4b064ec8..346391ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,8 @@ edition = "2021" clap = { version = "3.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } quick-xml = { version = "0.18", features = ["serialize"] } -svd-rs = { version = "0.13.1", features = ["serde"] } -svd-parser = "0.13.1" +svd-rs = { version = "0.13.2", features = ["serde", "derive-from"] } +svd-parser = { version = "0.13.2", features = ["expand"] } svd-encoder = "0.13.1" yaml-rust = "0.4" serde_yaml = "0.8.23" diff --git a/src/cli.rs b/src/cli.rs index 605ec9a0..333a26a2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,6 +12,7 @@ use svdtools::{ enum Command { /// Patches an SVD file as specified by a YAML file Patch { + /// Path to input SVD file #[clap(parse(from_os_str))] svd_file: PathBuf, }, @@ -27,6 +28,7 @@ enum Command { }, /// Print list of all interrupts described by an SVD file Interrupts { + /// Path to input SVD file #[clap(parse(from_os_str))] svd_file: PathBuf, @@ -36,19 +38,35 @@ enum Command { }, /// Generate text-based memory map of an SVD file. Mmap { + /// Path to input SVD file #[clap(parse(from_os_str))] svd_file: PathBuf, }, /// Convert SVD representation between file formats Convert { + /// Path to input file #[clap(parse(from_os_str))] in_path: PathBuf, + + /// Path to output file #[clap(parse(from_os_str))] out_path: PathBuf, + + /// Format of input file (XML, JSON or YAML) #[clap(long = "input-format")] input_format: Option, + + /// Format of output file (XML, JSON or YAML) #[clap(long = "output-format")] output_format: Option, + + /// Expand arrays, clusters and derived values + #[clap(long)] + expand: bool, + + /// Skip enumeratedValues and writeConstraints during parsing (XML input only) + #[clap(long)] + ignore_enums: bool, }, } @@ -69,7 +87,16 @@ impl Command { out_path, input_format, output_format, - } => convert_cli::convert(in_path, out_path, *input_format, *output_format)?, + expand, + ignore_enums, + } => convert_cli::convert( + in_path, + out_path, + *input_format, + *output_format, + *expand, + *ignore_enums, + )?, } Ok(()) } diff --git a/src/convert/convert_cli.rs b/src/convert/convert_cli.rs index 61535974..1f1ca4af 100644 --- a/src/convert/convert_cli.rs +++ b/src/convert/convert_cli.rs @@ -48,6 +48,8 @@ pub fn convert( out_path: &Path, input_format: Option, output_format: Option, + expand: bool, + ignore_enums: bool, ) -> Result<()> { let input_format = match input_format { None => match in_path.extension().and_then(|e| e.to_str()) { @@ -68,10 +70,18 @@ pub fn convert( File::open(in_path)?.read_to_string(&mut input)?; let device = match input_format { - InputFormat::Xml => svd_parser::parse(&input)?, + InputFormat::Xml => svd_parser::parse_with_config( + &input, + &svd_parser::Config::default().ignore_enums(ignore_enums), + )?, InputFormat::Yaml => serde_yaml::from_str(&input)?, InputFormat::Json => serde_json::from_str(&input)?, }; + let device = if expand { + svd_parser::expand(&device)? + } else { + device + }; let output = match output_format { OutputFormat::Xml => svd_encoder::encode(&device)?,