mirror of
https://gitlab.cern.ch/wotsubo/endcap-sl-software-ri-generator.git
synced 2025-02-23 00:57:08 +09:00
finish: impl CodeGen for Register
This commit is contained in:
parent
48215049e8
commit
1ed3843508
2 changed files with 41 additions and 27 deletions
|
@ -212,6 +212,7 @@ impl CodeGen for Block {
|
|||
}
|
||||
|
||||
mod codegen_register;
|
||||
mod codegen_registerspec_impl;
|
||||
|
||||
impl CodeGen for Register {
|
||||
fn generate_register_interface(self) -> Result<proc_macro2::TokenStream, CodeGenError> {
|
||||
|
@ -226,7 +227,8 @@ impl CodeGen for Register {
|
|||
proc_macro2::Ident,
|
||||
) = codegen_register::reg_type_def(&self, &upper_camel_name)?;
|
||||
|
||||
let code_reg_def: proc_macro2::TokenStream = todo!();
|
||||
let code_reg_def: proc_macro2::TokenStream =
|
||||
codegen_registerspec_impl::gen_registerspec_impl(reg_name.clone(), self.modf, type_t, type_ux);
|
||||
|
||||
Ok(quote! {
|
||||
pub mod #snake_case_name {
|
||||
|
@ -250,33 +252,9 @@ impl CodeGen for Register {
|
|||
}
|
||||
}
|
||||
|
||||
impl RegisterSpec for #reg_name<'_> {
|
||||
type Ux = u32;
|
||||
type T = SlId;
|
||||
#code_reg_def
|
||||
|
||||
fn as_ptr(&self) -> *mut Self::Ux {
|
||||
self.mem_ptr
|
||||
}
|
||||
}
|
||||
impl Readable for #reg_name<'_> {}
|
||||
impl Writable for #reg_name<'_> {}
|
||||
impl Modifiable for #reg_name<'_> {}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct SlId(pub u32);
|
||||
impl TryFrom<u32> for SlId {
|
||||
type Error = DataConversionError<u32, Self>;
|
||||
|
||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||
let mask = 0x0000003f;
|
||||
Ok(SlId(value & mask))
|
||||
}
|
||||
}
|
||||
impl From<SlId> for u32 {
|
||||
fn from(val: SlId) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
#code_t_def
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
36
src/generator/codegen_registerspec_impl.rs
Normal file
36
src/generator/codegen_registerspec_impl.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use proc_macro2::{Ident, TokenStream};
|
||||
use quote::quote;
|
||||
|
||||
use crate::types::RwSpecifier;
|
||||
|
||||
pub(super) fn gen_registerspec_impl(
|
||||
reg_name: Ident,
|
||||
modf: RwSpecifier,
|
||||
type_t: Ident,
|
||||
type_ux: Ident,
|
||||
) -> TokenStream {
|
||||
let impl_rw = match modf {
|
||||
RwSpecifier::R => quote! {
|
||||
impl Readable for #reg_name<'_> {}
|
||||
},
|
||||
RwSpecifier::W => quote! {
|
||||
impl Writable for #reg_name<'_> {}
|
||||
},
|
||||
RwSpecifier::RW => quote! {
|
||||
impl Readable for #reg_name<'_> {}
|
||||
impl Writable for #reg_name<'_> {}
|
||||
impl Modifiable for #reg_name<'_> {}
|
||||
},
|
||||
};
|
||||
quote! {
|
||||
impl RegisterSpec for #reg_name<'_> {
|
||||
type Ux = #type_ux;
|
||||
type T = #type_t;
|
||||
|
||||
fn as_ptr(&self) -> *mut Self::Ux {
|
||||
self.mem_ptr
|
||||
}
|
||||
}
|
||||
#impl_rw
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue