Compare commits

..

No commits in common. "2c1afd1cd63f8da01300bf866c510f5db313da2b" and "5835b995a96450c2dcc4d6448fcb7d75df6716b8" have entirely different histories.

3 changed files with 194 additions and 784 deletions

File diff suppressed because it is too large Load diff

View file

@ -66,8 +66,8 @@ pub(crate) struct ModuleFn {
vis: Visibility,
sig: Signature,
block: Box<Block>,
io: Vec<ModuleIO>,
struct_generics: ParsedGenerics,
the_struct: TokenStream,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
@ -224,41 +224,6 @@ impl Parse for ModuleFn {
errors.finish()?;
let struct_generics = struct_generics.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 {
attrs,
config_options,
@ -266,8 +231,8 @@ impl Parse for ModuleFn {
vis,
sig,
block,
io,
struct_generics,
the_struct,
})
}
}
@ -281,8 +246,8 @@ impl ModuleFn {
vis,
sig,
block,
io,
struct_generics,
the_struct,
} = self;
let ConfigOptions {
outline_generated: _,
@ -314,7 +279,7 @@ impl ModuleFn {
ModuleKind::Normal => quote! { ::fayalite::module::ModuleKind::Normal },
};
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();
let struct_ty = quote! {#fn_name #struct_type_generics};
body_sig.ident = parse_quote! {__body};
@ -329,6 +294,17 @@ impl ModuleFn {
};
outer_sig.output =
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 (_, body_type_generics, _) = body_fn.sig.generics.split_for_impl();
let body_turbofish_type_generics = body_type_generics.as_turbofish();
@ -340,6 +316,15 @@ impl ModuleFn {
|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 {
attrs,
vis,
@ -347,7 +332,7 @@ impl ModuleFn {
block,
};
let mut retval = outer_fn.into_token_stream();
retval.extend(the_struct);
retval.extend(crate::hdl_bundle::hdl_bundle(the_struct).unwrap());
retval
}
}

View file

@ -6,7 +6,6 @@ use fayalite::{
intern::Intern,
module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
prelude::*,
ty::StaticType,
};
use serde_json::json;
@ -134,11 +133,9 @@ circuit my_module:
};
}
#[cfg(todo)]
#[hdl_module(outline_generated)]
pub fn check_array_repeat<const N: usize>()
where
ConstUsize<N>: KnownSize,
{
pub fn check_array_repeat<const N: usize>() {
#[hdl]
let i: UInt<8> = m.input();
#[hdl]
@ -150,6 +147,7 @@ where
);
}
#[cfg(todo)]
#[test]
fn test_array_repeat() {
let _n = SourceLocation::normalize_files_for_tests();
@ -190,21 +188,21 @@ circuit check_array_repeat_1:
};
}
#[cfg(todo)]
#[hdl_module(outline_generated)]
pub fn check_skipped_generics<T, #[hdl(skip)] U, const N: usize, #[hdl(skip)] const M: usize>(v: U)
where
T: StaticType,
ConstUsize<N>: KnownSize,
T: StaticValue,
U: std::fmt::Display,
{
dbg!(M);
#[hdl]
let i: T = m.input();
#[hdl]
let o: Array<T, N> = m.output();
let o: Array<[T; N]> = m.output();
let bytes = v.to_string().as_bytes().to_expr();
#[hdl]
let o2: Array<UInt<8>> = m.output(Expr::ty(bytes));
let o2: Array<[UInt<8>]> = m.output(bytes.ty());
connect(
o,
#[hdl]
@ -213,6 +211,7 @@ where
connect(o2, bytes);
}
#[cfg(todo)]
#[test]
fn test_skipped_generics() {
let _n = SourceLocation::normalize_files_for_tests();