Compare commits
	
		
			2 commits
		
	
	
		
			5835b995a9
			...
			2c1afd1cd6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2c1afd1cd6 | |||
| 76ea7f82c3 | 
					 3 changed files with 782 additions and 192 deletions
				
			
		
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -66,8 +66,8 @@ pub(crate) struct ModuleFn {
 | 
				
			||||||
    vis: Visibility,
 | 
					    vis: Visibility,
 | 
				
			||||||
    sig: Signature,
 | 
					    sig: Signature,
 | 
				
			||||||
    block: Box<Block>,
 | 
					    block: Box<Block>,
 | 
				
			||||||
    io: Vec<ModuleIO>,
 | 
					 | 
				
			||||||
    struct_generics: ParsedGenerics,
 | 
					    struct_generics: ParsedGenerics,
 | 
				
			||||||
 | 
					    the_struct: TokenStream,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
 | 
					#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
 | 
				
			||||||
| 
						 | 
					@ -224,6 +224,41 @@ impl Parse for ModuleFn {
 | 
				
			||||||
        errors.finish()?;
 | 
					        errors.finish()?;
 | 
				
			||||||
        let struct_generics = struct_generics.unwrap();
 | 
					        let struct_generics = struct_generics.unwrap();
 | 
				
			||||||
        let (block, io) = body_results.unwrap();
 | 
					        let (block, io) = body_results.unwrap();
 | 
				
			||||||
 | 
					        let (_struct_impl_generics, _struct_type_generics, struct_where_clause) =
 | 
				
			||||||
 | 
					            struct_generics.split_for_impl();
 | 
				
			||||||
 | 
					        let struct_where_clause: Option<WhereClause> = parse_quote! { #struct_where_clause };
 | 
				
			||||||
 | 
					        if let Some(struct_where_clause) = &struct_where_clause {
 | 
				
			||||||
 | 
					            sig.generics
 | 
				
			||||||
 | 
					                .where_clause
 | 
				
			||||||
 | 
					                .get_or_insert_with(|| WhereClause {
 | 
				
			||||||
 | 
					                    where_token: struct_where_clause.where_token,
 | 
				
			||||||
 | 
					                    predicates: Default::default(),
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .predicates
 | 
				
			||||||
 | 
					                .extend(struct_where_clause.predicates.clone());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let fn_name = &sig.ident;
 | 
				
			||||||
 | 
					        let io_flips = io
 | 
				
			||||||
 | 
					            .iter()
 | 
				
			||||||
 | 
					            .map(|io| match io.kind.kind {
 | 
				
			||||||
 | 
					                ModuleIOKind::Input((input,)) => quote_spanned! {input.span=>
 | 
				
			||||||
 | 
					                    #[hdl(flip)]
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                ModuleIOKind::Output(_) => quote! {},
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .collect::<Vec<_>>();
 | 
				
			||||||
 | 
					        let io_types = io.iter().map(|io| &io.kind.ty).collect::<Vec<_>>();
 | 
				
			||||||
 | 
					        let io_names = io.iter().map(|io| &io.name).collect::<Vec<_>>();
 | 
				
			||||||
 | 
					        let the_struct: ItemStruct = parse_quote! {
 | 
				
			||||||
 | 
					            #[allow(non_camel_case_types)]
 | 
				
			||||||
 | 
					            #[hdl(no_runtime_generics, no_static)]
 | 
				
			||||||
 | 
					            #vis struct #fn_name #struct_generics #struct_where_clause {
 | 
				
			||||||
 | 
					                #(
 | 
				
			||||||
 | 
					                #io_flips
 | 
				
			||||||
 | 
					                #vis #io_names: #io_types,)*
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        let the_struct = crate::hdl_bundle::hdl_bundle(the_struct)?;
 | 
				
			||||||
        Ok(Self {
 | 
					        Ok(Self {
 | 
				
			||||||
            attrs,
 | 
					            attrs,
 | 
				
			||||||
            config_options,
 | 
					            config_options,
 | 
				
			||||||
| 
						 | 
					@ -231,8 +266,8 @@ impl Parse for ModuleFn {
 | 
				
			||||||
            vis,
 | 
					            vis,
 | 
				
			||||||
            sig,
 | 
					            sig,
 | 
				
			||||||
            block,
 | 
					            block,
 | 
				
			||||||
            io,
 | 
					 | 
				
			||||||
            struct_generics,
 | 
					            struct_generics,
 | 
				
			||||||
 | 
					            the_struct,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -246,8 +281,8 @@ impl ModuleFn {
 | 
				
			||||||
            vis,
 | 
					            vis,
 | 
				
			||||||
            sig,
 | 
					            sig,
 | 
				
			||||||
            block,
 | 
					            block,
 | 
				
			||||||
            io,
 | 
					 | 
				
			||||||
            struct_generics,
 | 
					            struct_generics,
 | 
				
			||||||
 | 
					            the_struct,
 | 
				
			||||||
        } = self;
 | 
					        } = self;
 | 
				
			||||||
        let ConfigOptions {
 | 
					        let ConfigOptions {
 | 
				
			||||||
            outline_generated: _,
 | 
					            outline_generated: _,
 | 
				
			||||||
| 
						 | 
					@ -279,7 +314,7 @@ impl ModuleFn {
 | 
				
			||||||
            ModuleKind::Normal => quote! { ::fayalite::module::ModuleKind::Normal },
 | 
					            ModuleKind::Normal => quote! { ::fayalite::module::ModuleKind::Normal },
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        let fn_name = &outer_sig.ident;
 | 
					        let fn_name = &outer_sig.ident;
 | 
				
			||||||
        let (_struct_impl_generics, struct_type_generics, struct_where_clause) =
 | 
					        let (_struct_impl_generics, struct_type_generics, _struct_where_clause) =
 | 
				
			||||||
            struct_generics.split_for_impl();
 | 
					            struct_generics.split_for_impl();
 | 
				
			||||||
        let struct_ty = quote! {#fn_name #struct_type_generics};
 | 
					        let struct_ty = quote! {#fn_name #struct_type_generics};
 | 
				
			||||||
        body_sig.ident = parse_quote! {__body};
 | 
					        body_sig.ident = parse_quote! {__body};
 | 
				
			||||||
| 
						 | 
					@ -294,17 +329,6 @@ impl ModuleFn {
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        outer_sig.output =
 | 
					        outer_sig.output =
 | 
				
			||||||
            parse_quote! {-> ::fayalite::intern::Interned<::fayalite::module::Module<#struct_ty>>};
 | 
					            parse_quote! {-> ::fayalite::intern::Interned<::fayalite::module::Module<#struct_ty>>};
 | 
				
			||||||
        let io_flips = io
 | 
					 | 
				
			||||||
            .iter()
 | 
					 | 
				
			||||||
            .map(|io| match io.kind.kind {
 | 
					 | 
				
			||||||
                ModuleIOKind::Input((input,)) => quote_spanned! {input.span=>
 | 
					 | 
				
			||||||
                    #[hdl(flip)]
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
                ModuleIOKind::Output(_) => quote! {},
 | 
					 | 
				
			||||||
            })
 | 
					 | 
				
			||||||
            .collect::<Vec<_>>();
 | 
					 | 
				
			||||||
        let io_types = io.iter().map(|io| &io.kind.ty).collect::<Vec<_>>();
 | 
					 | 
				
			||||||
        let io_names = io.iter().map(|io| &io.name).collect::<Vec<_>>();
 | 
					 | 
				
			||||||
        let fn_name_str = fn_name.to_string();
 | 
					        let fn_name_str = fn_name.to_string();
 | 
				
			||||||
        let (_, body_type_generics, _) = body_fn.sig.generics.split_for_impl();
 | 
					        let (_, body_type_generics, _) = body_fn.sig.generics.split_for_impl();
 | 
				
			||||||
        let body_turbofish_type_generics = body_type_generics.as_turbofish();
 | 
					        let body_turbofish_type_generics = body_type_generics.as_turbofish();
 | 
				
			||||||
| 
						 | 
					@ -316,15 +340,6 @@ impl ModuleFn {
 | 
				
			||||||
                |m| __body #body_turbofish_type_generics(m, #(#param_names,)*),
 | 
					                |m| __body #body_turbofish_type_generics(m, #(#param_names,)*),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        }};
 | 
					        }};
 | 
				
			||||||
        let the_struct: ItemStruct = parse_quote! {
 | 
					 | 
				
			||||||
            #[allow(non_camel_case_types)]
 | 
					 | 
				
			||||||
            #[hdl(no_runtime_generics, no_static)]
 | 
					 | 
				
			||||||
            #vis struct #fn_name #struct_generics #struct_where_clause {
 | 
					 | 
				
			||||||
                #(
 | 
					 | 
				
			||||||
                #io_flips
 | 
					 | 
				
			||||||
                #vis #io_names: #io_types,)*
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        };
 | 
					 | 
				
			||||||
        let outer_fn = ItemFn {
 | 
					        let outer_fn = ItemFn {
 | 
				
			||||||
            attrs,
 | 
					            attrs,
 | 
				
			||||||
            vis,
 | 
					            vis,
 | 
				
			||||||
| 
						 | 
					@ -332,7 +347,7 @@ impl ModuleFn {
 | 
				
			||||||
            block,
 | 
					            block,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        let mut retval = outer_fn.into_token_stream();
 | 
					        let mut retval = outer_fn.into_token_stream();
 | 
				
			||||||
        retval.extend(crate::hdl_bundle::hdl_bundle(the_struct).unwrap());
 | 
					        retval.extend(the_struct);
 | 
				
			||||||
        retval
 | 
					        retval
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,7 @@ use fayalite::{
 | 
				
			||||||
    intern::Intern,
 | 
					    intern::Intern,
 | 
				
			||||||
    module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
 | 
					    module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
 | 
				
			||||||
    prelude::*,
 | 
					    prelude::*,
 | 
				
			||||||
 | 
					    ty::StaticType,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use serde_json::json;
 | 
					use serde_json::json;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,9 +134,11 @@ circuit my_module:
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(todo)]
 | 
					 | 
				
			||||||
#[hdl_module(outline_generated)]
 | 
					#[hdl_module(outline_generated)]
 | 
				
			||||||
pub fn check_array_repeat<const N: usize>() {
 | 
					pub fn check_array_repeat<const N: usize>()
 | 
				
			||||||
 | 
					where
 | 
				
			||||||
 | 
					    ConstUsize<N>: KnownSize,
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    #[hdl]
 | 
					    #[hdl]
 | 
				
			||||||
    let i: UInt<8> = m.input();
 | 
					    let i: UInt<8> = m.input();
 | 
				
			||||||
    #[hdl]
 | 
					    #[hdl]
 | 
				
			||||||
| 
						 | 
					@ -147,7 +150,6 @@ pub fn check_array_repeat<const N: usize>() {
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(todo)]
 | 
					 | 
				
			||||||
#[test]
 | 
					#[test]
 | 
				
			||||||
fn test_array_repeat() {
 | 
					fn test_array_repeat() {
 | 
				
			||||||
    let _n = SourceLocation::normalize_files_for_tests();
 | 
					    let _n = SourceLocation::normalize_files_for_tests();
 | 
				
			||||||
| 
						 | 
					@ -188,21 +190,21 @@ circuit check_array_repeat_1:
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(todo)]
 | 
					 | 
				
			||||||
#[hdl_module(outline_generated)]
 | 
					#[hdl_module(outline_generated)]
 | 
				
			||||||
pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U)
 | 
					pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U)
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    T: StaticValue,
 | 
					    T: StaticType,
 | 
				
			||||||
 | 
					    ConstUsize<N>: KnownSize,
 | 
				
			||||||
    U: std::fmt::Display,
 | 
					    U: std::fmt::Display,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    dbg!(M);
 | 
					    dbg!(M);
 | 
				
			||||||
    #[hdl]
 | 
					    #[hdl]
 | 
				
			||||||
    let i: T = m.input();
 | 
					    let i: T = m.input();
 | 
				
			||||||
    #[hdl]
 | 
					    #[hdl]
 | 
				
			||||||
    let o: Array<[T; N]> = m.output();
 | 
					    let o: Array<T, N> = m.output();
 | 
				
			||||||
    let bytes = v.to_string().as_bytes().to_expr();
 | 
					    let bytes = v.to_string().as_bytes().to_expr();
 | 
				
			||||||
    #[hdl]
 | 
					    #[hdl]
 | 
				
			||||||
    let o2: Array<[UInt<8>]> = m.output(bytes.ty());
 | 
					    let o2: Array<UInt<8>> = m.output(Expr::ty(bytes));
 | 
				
			||||||
    connect(
 | 
					    connect(
 | 
				
			||||||
        o,
 | 
					        o,
 | 
				
			||||||
        #[hdl]
 | 
					        #[hdl]
 | 
				
			||||||
| 
						 | 
					@ -211,7 +213,6 @@ where
 | 
				
			||||||
    connect(o2, bytes);
 | 
					    connect(o2, bytes);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(todo)]
 | 
					 | 
				
			||||||
#[test]
 | 
					#[test]
 | 
				
			||||||
fn test_skipped_generics() {
 | 
					fn test_skipped_generics() {
 | 
				
			||||||
    let _n = SourceLocation::normalize_files_for_tests();
 | 
					    let _n = SourceLocation::normalize_files_for_tests();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue