update(docs): add docs on validator

This commit is contained in:
Wataru Otsubo 2025-03-31 17:53:44 +09:00
parent cba5b8594b
commit ccfd443e5d
3 changed files with 7 additions and 1 deletions

View file

@ -14,7 +14,8 @@
//!
//! 1. Convert [`roxmltree::Document`] to register map represented with types defined in
//! [`types`], filling missing parameters. See [`converter`].
//! 2. Generate [`proc_macro2::TokenStream`] from register map produced in the previous step. See
//! 2. Validate the register map. See [`types::Module::validate`] in [`validator`].
//! 3. Generate [`proc_macro2::TokenStream`] from register map produced in the previous step. See
//! [`generator`].
//!
//! # modules
@ -22,6 +23,7 @@
//! - [`converter`]: DOM to internal representation
//! - [`generator`]: internal representation to rust code
//! - [`io`]: formatting and printing
//! - [`validator`]: validate the register map and generate flattened register map
pub mod converter;
pub mod generator;

View file

@ -16,6 +16,8 @@ struct Args {
#[derive(Debug, Subcommand)]
enum Commands {
/// Generate register interface code.
///
/// Also run validation before generation.
Generate {
/// Output directory.
out: path::PathBuf,

View file

@ -20,6 +20,8 @@ type FlattenedRegisterMap<'a> = Vec<Option<FlattenedRegisterEntry<'a>>>;
impl Module {
/// Validate the address assignment, generating a flatten register map.
/// Returns a tuple of [`FlattenedRegisterMap`] and [`ValidationError`]s vector.
/// Empty errors vector means there is no errors in the register map.
pub fn validate(&self) -> (FlattenedRegisterMap, Vec<ValidationError>) {
let mut mapping = Vec::new();
mapping.resize(self.size.try_into().unwrap(), None);