diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-11-24 00:42:14 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-11-24 00:42:14 +0100 |
| commit | d06cb0a264ac5dd1bbc3f80083438782149c7124 (patch) | |
| tree | a33b52fdbc1541df2dd0d0a8dca256ad55259766 | |
| parent | dfb6d407a1b23f913b7584611099042f36144c5c (diff) | |
stm32-metapac-gen: use actually common `common.rs` instead of emitting it at every single chip file.
| -rw-r--r-- | stm32-metapac-gen/src/lib.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index 876251152..070afb348 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | use chiptool::generate::CommonModule; | 1 | use chiptool::generate::CommonModule; |
| 2 | use chiptool::ir::IR; | 2 | use chiptool::ir::IR; |
| 3 | use proc_macro2::TokenStream; | ||
| 3 | use regex::Regex; | 4 | use regex::Regex; |
| 4 | use std::collections::{BTreeMap, HashMap, HashSet}; | 5 | use std::collections::{BTreeMap, HashMap, HashSet}; |
| 5 | use std::fmt::Write as _; | 6 | use std::fmt::Write as _; |
| @@ -8,6 +9,7 @@ use std::fs::File; | |||
| 8 | use std::io::Write; | 9 | use std::io::Write; |
| 9 | use std::path::Path; | 10 | use std::path::Path; |
| 10 | use std::path::PathBuf; | 11 | use std::path::PathBuf; |
| 12 | use std::str::FromStr; | ||
| 11 | 13 | ||
| 12 | use chiptool::util::ToSanitizedSnakeCase; | 14 | use chiptool::util::ToSanitizedSnakeCase; |
| 13 | use chiptool::{generate, ir, transform}; | 15 | use chiptool::{generate, ir, transform}; |
| @@ -471,10 +473,7 @@ pub fn gen_chip( | |||
| 471 | .join(chip_core_name.to_ascii_lowercase()); | 473 | .join(chip_core_name.to_ascii_lowercase()); |
| 472 | fs::create_dir_all(&chip_dir).unwrap(); | 474 | fs::create_dir_all(&chip_dir).unwrap(); |
| 473 | 475 | ||
| 474 | let generate_opts = generate::Options { | 476 | let items = generate::render(&ir, &gen_opts()).unwrap(); |
| 475 | common_module: CommonModule::Builtin, | ||
| 476 | }; | ||
| 477 | let items = generate::render(&ir, &generate_opts).unwrap(); | ||
| 478 | let mut file = File::create(chip_dir.join("pac.rs")).unwrap(); | 477 | let mut file = File::create(chip_dir.join("pac.rs")).unwrap(); |
| 479 | let data = items.to_string().replace("] ", "]\n"); | 478 | let data = items.to_string().replace("] ", "]\n"); |
| 480 | 479 | ||
| @@ -513,11 +512,13 @@ fn load_chip(options: &Options, name: &str) -> Chip { | |||
| 513 | serde_yaml::from_slice(&chip).unwrap() | 512 | serde_yaml::from_slice(&chip).unwrap() |
| 514 | } | 513 | } |
| 515 | 514 | ||
| 516 | pub fn gen(options: Options) { | 515 | fn gen_opts() -> generate::Options { |
| 517 | let generate_opts = generate::Options { | 516 | generate::Options { |
| 518 | common_module: CommonModule::Builtin, | 517 | common_module: CommonModule::External(TokenStream::from_str("crate::common").unwrap()), |
| 519 | }; | 518 | } |
| 519 | } | ||
| 520 | 520 | ||
| 521 | pub fn gen(options: Options) { | ||
| 521 | fs::create_dir_all(options.out_dir.join("src/peripherals")).unwrap(); | 522 | fs::create_dir_all(options.out_dir.join("src/peripherals")).unwrap(); |
| 522 | fs::create_dir_all(options.out_dir.join("src/chips")).unwrap(); | 523 | fs::create_dir_all(options.out_dir.join("src/chips")).unwrap(); |
| 523 | 524 | ||
| @@ -567,7 +568,7 @@ pub fn gen(options: Options) { | |||
| 567 | transform::sort::Sort {}.run(&mut ir).unwrap(); | 568 | transform::sort::Sort {}.run(&mut ir).unwrap(); |
| 568 | transform::Sanitize {}.run(&mut ir).unwrap(); | 569 | transform::Sanitize {}.run(&mut ir).unwrap(); |
| 569 | 570 | ||
| 570 | let items = generate::render(&ir, &generate_opts).unwrap(); | 571 | let items = generate::render(&ir, &gen_opts()).unwrap(); |
| 571 | let mut file = File::create( | 572 | let mut file = File::create( |
| 572 | options | 573 | options |
| 573 | .out_dir | 574 | .out_dir |
