Skip to content

Commit 0c4b34e

Browse files
bors[bot]burrbull
andauthored
Merge #104
104: expand r=adamgreig a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents 713e960 + a229c17 commit 0c4b34e

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ edition = "2021"
2727
clap = { version = "3.0", features = ["derive"] }
2828
serde = { version = "1.0", features = ["derive"] }
2929
quick-xml = { version = "0.18", features = ["serialize"] }
30-
svd-rs = { version = "0.13.1", features = ["serde"] }
31-
svd-parser = "0.13.1"
30+
svd-rs = { version = "0.13.2", features = ["serde", "derive-from"] }
31+
svd-parser = { version = "0.13.2", features = ["expand"] }
3232
svd-encoder = "0.13.1"
3333
yaml-rust = "0.4"
3434
serde_yaml = "0.8.23"

src/cli.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use svdtools::{
1212
enum Command {
1313
/// Patches an SVD file as specified by a YAML file
1414
Patch {
15+
/// Path to input SVD file
1516
#[clap(parse(from_os_str))]
1617
svd_file: PathBuf,
1718
},
@@ -27,6 +28,7 @@ enum Command {
2728
},
2829
/// Print list of all interrupts described by an SVD file
2930
Interrupts {
31+
/// Path to input SVD file
3032
#[clap(parse(from_os_str))]
3133
svd_file: PathBuf,
3234

@@ -36,19 +38,35 @@ enum Command {
3638
},
3739
/// Generate text-based memory map of an SVD file.
3840
Mmap {
41+
/// Path to input SVD file
3942
#[clap(parse(from_os_str))]
4043
svd_file: PathBuf,
4144
},
4245
/// Convert SVD representation between file formats
4346
Convert {
47+
/// Path to input file
4448
#[clap(parse(from_os_str))]
4549
in_path: PathBuf,
50+
51+
/// Path to output file
4652
#[clap(parse(from_os_str))]
4753
out_path: PathBuf,
54+
55+
/// Format of input file (XML, JSON or YAML)
4856
#[clap(long = "input-format")]
4957
input_format: Option<convert_cli::InputFormat>,
58+
59+
/// Format of output file (XML, JSON or YAML)
5060
#[clap(long = "output-format")]
5161
output_format: Option<convert_cli::OutputFormat>,
62+
63+
/// Expand arrays, clusters and derived values
64+
#[clap(long)]
65+
expand: bool,
66+
67+
/// Skip enumeratedValues and writeConstraints during parsing (XML input only)
68+
#[clap(long)]
69+
ignore_enums: bool,
5270
},
5371
}
5472

@@ -69,7 +87,16 @@ impl Command {
6987
out_path,
7088
input_format,
7189
output_format,
72-
} => convert_cli::convert(in_path, out_path, *input_format, *output_format)?,
90+
expand,
91+
ignore_enums,
92+
} => convert_cli::convert(
93+
in_path,
94+
out_path,
95+
*input_format,
96+
*output_format,
97+
*expand,
98+
*ignore_enums,
99+
)?,
73100
}
74101
Ok(())
75102
}

src/convert/convert_cli.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub fn convert(
4848
out_path: &Path,
4949
input_format: Option<InputFormat>,
5050
output_format: Option<OutputFormat>,
51+
expand: bool,
52+
ignore_enums: bool,
5153
) -> Result<()> {
5254
let input_format = match input_format {
5355
None => match in_path.extension().and_then(|e| e.to_str()) {
@@ -68,10 +70,18 @@ pub fn convert(
6870
File::open(in_path)?.read_to_string(&mut input)?;
6971

7072
let device = match input_format {
71-
InputFormat::Xml => svd_parser::parse(&input)?,
73+
InputFormat::Xml => svd_parser::parse_with_config(
74+
&input,
75+
&svd_parser::Config::default().ignore_enums(ignore_enums),
76+
)?,
7277
InputFormat::Yaml => serde_yaml::from_str(&input)?,
7378
InputFormat::Json => serde_json::from_str(&input)?,
7479
};
80+
let device = if expand {
81+
svd_parser::expand(&device)?
82+
} else {
83+
device
84+
};
7585

7686
let output = match output_format {
7787
OutputFormat::Xml => svd_encoder::encode(&device)?,

0 commit comments

Comments
 (0)