Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 28 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,

Expand All @@ -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<convert_cli::InputFormat>,

/// Format of output file (XML, JSON or YAML)
#[clap(long = "output-format")]
output_format: Option<convert_cli::OutputFormat>,

/// Expand arrays, clusters and derived values
#[clap(long)]
expand: bool,

/// Skip enumeratedValues and writeConstraints during parsing (XML input only)
#[clap(long)]
ignore_enums: bool,
},
}

Expand All @@ -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(())
}
Expand Down
12 changes: 11 additions & 1 deletion src/convert/convert_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub fn convert(
out_path: &Path,
input_format: Option<InputFormat>,
output_format: Option<OutputFormat>,
expand: bool,
ignore_enums: bool,
) -> Result<()> {
let input_format = match input_format {
None => match in_path.extension().and_then(|e| e.to_str()) {
Expand All @@ -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)?,
Expand Down