diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f66dd98..366c9b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] -- Implement `riscv-pac` traits via experimental `riscv` element in SVD. - You must use the `unstable-riscv` feature to use this. +- Use standard `riscv-peripheral` peripherals via experimental `riscv.yaml` configuration file. + You must compile `svd2rust` with the `unstable-riscv` feature to use this. +- Implement `riscv-pac` traits via experimental `riscv.yaml` configuration file. + You must compile `svd2rust` with the `unstable-riscv` feature to use this. - Fix `enumeratedValues` with `isDefault` only ## [v0.33.4] - 2024-06-16 diff --git a/Cargo.toml b/Cargo.toml index 6e3239a1..d4592d8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ default = ["bin", "json", "yaml"] bin = ["dep:clap", "dep:env_logger", "serde", "dep:irx-config"] json = ["dep:serde_json"] yaml = ["dep:serde_yaml"] -unstable-riscv = [] +unstable-riscv = ["irx-config/yaml"] [dependencies] clap = { version = "4.0", optional = true } diff --git a/src/main.rs b/src/main.rs index aabec8f6..526e8e72 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ #![recursion_limit = "128"] use log::{debug, error, info, warn}; +#[cfg(feature = "unstable-riscv")] +use svd2rust::config::RiscvConfig; use svd2rust::config::{IdentFormatError, IdentFormats, IdentFormatsTheme}; use svd2rust::util::IdentFormat; @@ -18,6 +20,8 @@ use svd2rust::{ }; fn parse_configs(app: Command) -> Result { + #[cfg(feature = "unstable-riscv")] + use irx_config::parsers::yaml; use irx_config::parsers::{cmd, toml}; use irx_config::ConfigBuilder; let ident_formats = app.clone().get_matches(); @@ -29,10 +33,24 @@ fn parse_configs(app: Command) -> Result { .path_option("config") .ignore_missing_file(true) .build()?, - ) - .load()?; + ); + #[cfg(feature = "unstable-riscv")] + let irxconfig = irxconfig.append_parser( + yaml::ParserBuilder::default() + .default_path("riscv.yaml") + .path_option("riscv_cfg") + .ignore_missing_file(true) + .build()?, + ); + let irxconfig = irxconfig.load()?; let mut config: Config = irxconfig.get()?; + + #[cfg(feature = "unstable-riscv")] + if let Ok(riscv_config) = irxconfig.get::() { + config.riscv_config = Some(riscv_config); + } + let mut idf = match config.ident_formats_theme { Some(IdentFormatsTheme::Legacy) => IdentFormats::legacy_theme(), _ => IdentFormats::default_theme(), @@ -290,6 +308,15 @@ Ignore this option if you are not building your own FPGA based soft-cores."), env!("CARGO_PKG_VERSION"), include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")) )); + #[cfg(feature = "unstable-riscv")] + let app = app.arg( + Arg::new("riscv_cfg") + .long("riscv_config") + .help("RISC-V Config YAML file") + .short('r') + .action(ArgAction::Set) + .value_name("YAML_FILE"), + ); let mut config = match parse_configs(app) { Ok(config) => {