forked from libre-chip/fayalite
implement #[hdl] [a; N] -- an array repeat expression
This commit is contained in:
parent
d610858144
commit
c2e5ea8e89
|
@ -221,6 +221,7 @@ forward_fold!(syn::ExprCall => fold_expr_call);
|
||||||
forward_fold!(syn::ExprIf => fold_expr_if);
|
forward_fold!(syn::ExprIf => fold_expr_if);
|
||||||
forward_fold!(syn::ExprMatch => fold_expr_match);
|
forward_fold!(syn::ExprMatch => fold_expr_match);
|
||||||
forward_fold!(syn::ExprPath => fold_expr_path);
|
forward_fold!(syn::ExprPath => fold_expr_path);
|
||||||
|
forward_fold!(syn::ExprRepeat => fold_expr_repeat);
|
||||||
forward_fold!(syn::ExprStruct => fold_expr_struct);
|
forward_fold!(syn::ExprStruct => fold_expr_struct);
|
||||||
forward_fold!(syn::ExprTuple => fold_expr_tuple);
|
forward_fold!(syn::ExprTuple => fold_expr_tuple);
|
||||||
forward_fold!(syn::Ident => fold_ident);
|
forward_fold!(syn::Ident => fold_ident);
|
||||||
|
|
|
@ -1515,6 +1515,7 @@ impl Fold for Visitor {
|
||||||
If => process_hdl_if,
|
If => process_hdl_if,
|
||||||
Match => process_hdl_match,
|
Match => process_hdl_match,
|
||||||
Array => process_hdl_array,
|
Array => process_hdl_array,
|
||||||
|
Repeat => process_hdl_repeat,
|
||||||
Struct => process_hdl_struct,
|
Struct => process_hdl_struct,
|
||||||
Tuple => process_hdl_tuple,
|
Tuple => process_hdl_tuple,
|
||||||
Call => process_hdl_call,
|
Call => process_hdl_call,
|
||||||
|
|
|
@ -9,8 +9,8 @@ use syn::{
|
||||||
punctuated::{Pair, Punctuated},
|
punctuated::{Pair, Punctuated},
|
||||||
spanned::Spanned,
|
spanned::Spanned,
|
||||||
token::{Brace, Paren},
|
token::{Brace, Paren},
|
||||||
Attribute, Expr, ExprArray, ExprCall, ExprGroup, ExprPath, ExprStruct, ExprTuple, FieldValue,
|
Attribute, Expr, ExprArray, ExprCall, ExprGroup, ExprPath, ExprRepeat, ExprStruct, ExprTuple,
|
||||||
Ident, Index, Member, Path, PathArguments, PathSegment, Token, TypePath,
|
FieldValue, Ident, Index, Member, Path, PathArguments, PathSegment, Token, TypePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
options! {
|
options! {
|
||||||
|
@ -351,6 +351,18 @@ impl Visitor {
|
||||||
}
|
}
|
||||||
parse_quote! {::fayalite::expr::ToExpr::to_expr(&#expr_array)}
|
parse_quote! {::fayalite::expr::ToExpr::to_expr(&#expr_array)}
|
||||||
}
|
}
|
||||||
|
pub(crate) fn process_hdl_repeat(
|
||||||
|
&mut self,
|
||||||
|
hdl_attr: HdlAttr<Nothing>,
|
||||||
|
mut expr_repeat: ExprRepeat,
|
||||||
|
) -> Expr {
|
||||||
|
self.require_normal_module(hdl_attr);
|
||||||
|
let repeated_value = &expr_repeat.expr;
|
||||||
|
*expr_repeat.expr = parse_quote_spanned! {repeated_value.span()=>
|
||||||
|
::fayalite::expr::ToExpr::to_expr(&(#repeated_value))
|
||||||
|
};
|
||||||
|
parse_quote! {::fayalite::expr::ToExpr::to_expr(&#expr_repeat)}
|
||||||
|
}
|
||||||
pub(crate) fn process_struct_enum(
|
pub(crate) fn process_struct_enum(
|
||||||
&mut self,
|
&mut self,
|
||||||
hdl_attr: HdlAttr<AggregateLiteralOptions>,
|
hdl_attr: HdlAttr<AggregateLiteralOptions>,
|
||||||
|
|
|
@ -138,6 +138,41 @@ circuit my_module:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[hdl_module(outline_generated)]
|
||||||
|
pub fn check_array_repeat() {
|
||||||
|
#[hdl]
|
||||||
|
let i: UInt<8> = m.input();
|
||||||
|
#[hdl]
|
||||||
|
let o: Array<[UInt<8>; 3]> = m.output();
|
||||||
|
m.connect(
|
||||||
|
o,
|
||||||
|
#[hdl]
|
||||||
|
[i; 3],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_array_repeat() {
|
||||||
|
let _n = SourceLocation::normalize_files_for_tests();
|
||||||
|
let m = check_array_repeat();
|
||||||
|
dbg!(m);
|
||||||
|
#[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
|
||||||
|
assert_export_firrtl! {
|
||||||
|
m =>
|
||||||
|
"/test/check_array_repeat.fir": r"FIRRTL version 3.2.0
|
||||||
|
circuit check_array_repeat:
|
||||||
|
module check_array_repeat: @[module-XXXXXXXXXX.rs 1:1]
|
||||||
|
input i: UInt<8> @[module-XXXXXXXXXX.rs 2:1]
|
||||||
|
output o: UInt<8>[3] @[module-XXXXXXXXXX.rs 3:1]
|
||||||
|
wire _array_literal_expr: UInt<8>[3]
|
||||||
|
connect _array_literal_expr[0], i
|
||||||
|
connect _array_literal_expr[1], i
|
||||||
|
connect _array_literal_expr[2], i
|
||||||
|
connect o, _array_literal_expr @[module-XXXXXXXXXX.rs 4:1]
|
||||||
|
",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[hdl_module(outline_generated)]
|
#[hdl_module(outline_generated)]
|
||||||
pub fn check_partially_written() {
|
pub fn check_partially_written() {
|
||||||
#[hdl]
|
#[hdl]
|
||||||
|
|
Loading…
Reference in a new issue