diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 919259cb..6e5c3d69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,8 +56,8 @@ jobs: include: - { rust: stable, vendor: Atmel, options: all } - { rust: stable, vendor: Atmel, options: "" } - - { rust: stable, vendor: Freescale, options: all } - - { rust: stable, vendor: Freescale, options: "" } + - { rust: stable, vendor: Freescale, options: "--strict --atomics --ident-format register::c:" } + - { rust: stable, vendor: Freescale, options: "--ident-format register::c:" } - { rust: stable, vendor: Fujitsu, options: "" } - { rust: stable, vendor: Fujitsu, options: "--atomics" } - { rust: stable, vendor: GD32, options: all } diff --git a/CHANGELOG.md b/CHANGELOG.md index 01223973..10564a51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] - Add `base-address-shift` config flag -- Use `PascalCase` for type idents, fix case changing bugs +- Use `PascalCase` for type idents, fix case changing bugs, add `--ident-format` (`-f`) option flag ## [v0.31.5] - 2024-01-04 diff --git a/src/main.rs b/src/main.rs index f8ace936..756bdb1c 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,13 @@ #![recursion_limit = "128"] use log::{debug, error, info}; +use svd2rust::util::{Case, IdentFormat}; use std::io::Write; use std::process; use std::{fs::File, path::Path}; -use anyhow::{Context, Result}; +use anyhow::{anyhow, Context, Result}; use clap::{Arg, ArgAction, Command}; use svd2rust::{ @@ -18,6 +19,8 @@ use svd2rust::{ fn parse_configs(app: Command) -> Result { use irx_config::parsers::{cmd, toml}; use irx_config::ConfigBuilder; + let ident_formats = app.clone().get_matches(); + dbg!(&ident_formats); let irxconfig = ConfigBuilder::default() .append_parser(cmd::ParserBuilder::new(app).exit_on_error(true).build()?) .append_parser( @@ -29,7 +32,81 @@ fn parse_configs(app: Command) -> Result { ) .load()?; - irxconfig.get().map_err(Into::into) + let mut config: Config = irxconfig.get()?; + if let Some(ident_formats) = ident_formats.get_many::("ident_format") { + for f in ident_formats { + let mut f = f.split(":"); + dbg!(f.clone().count()); + if let (Some(n), Some(p), Some(c), Some(s)) = (f.next(), f.next(), f.next(), f.next()) { + let fmts = &mut config.ident_formats; + let case = match c { + "" => None, + "p" | "pascal" | "type" => Some(Case::Pascal), + "s" | "snake" | "lower" => Some(Case::Snake), + "c" | "constant" | "upper" => Some(Case::Constant), + _ => return Err(anyhow!("Unknown case")), + }; + let id_f = IdentFormat { + case, + prefix: p.into(), + suffix: s.into(), + }; + dbg!(&id_f); + match n { + "field_reader" => { + fmts.field_reader = id_f; + } + "enum_name" => { + fmts.enum_name = id_f; + } + "enum_write_name" => { + fmts.enum_write_name = id_f; + } + "enum_value" => { + fmts.enum_value = id_f; + } + "interrupt" => { + fmts.interrupt = id_f; + } + "cluster" => { + fmts.cluster = id_f; + } + "cluster_accessor" => { + fmts.cluster_accessor = id_f; + } + //"cluster_mod" => { + // fmts.cluster_mod = id_f; + //}, + "register" => { + fmts.register = id_f; + } + "register_spec" => { + fmts.register_spec = id_f; + } + "register_accessor" => { + fmts.register_accessor = id_f; + } + //"register_mod" => { + // fmts.register_mod = id_f; + //}, + "peripheral" => { + fmts.peripheral = id_f; + } + "peripheral_sigleton" => { + fmts.peripheral_sigleton = id_f; + } + //"peripheral_mod" => { + // fmts.peripheral_mod = id_f; + //}, + "peripheral_feature" => { + fmts.peripheral_feature = id_f; + } + _ => {} + } + } + } + } + Ok(config) } fn run() -> Result<()> { @@ -119,6 +196,14 @@ fn run() -> Result<()> { .action(ArgAction::SetTrue) .help("Use independent cfg feature flags for each peripheral"), ) + .arg( + Arg::new("ident_format") + .long("ident-format") + .short('f') + .alias("ident_format") + .action(ArgAction::Append) + .help("Specify prefix, case and suffix for identifier type"), + ) .arg( Arg::new("max_cluster_size") .long("max-cluster-size")