forked from libre-chip/fayalite
		
	change default to --simplify-enums=replace-with-bundle-of-uints
This commit is contained in:
		
							parent
							
								
									9d66fcc548
								
							
						
					
					
						commit
						d089095667
					
				
					 2 changed files with 80 additions and 36 deletions
				
			
		| 
						 | 
				
			
			@ -2616,7 +2616,7 @@ pub struct ExportOptionsPrivate(());
 | 
			
		|||
pub struct ExportOptions {
 | 
			
		||||
    #[clap(long = "no-simplify-memories", action = clap::ArgAction::SetFalse)]
 | 
			
		||||
    pub simplify_memories: bool,
 | 
			
		||||
    #[clap(long, value_parser = OptionSimplifyEnumsKindValueParser, default_value = OptionSimplifyEnumsKindValueParser::NONE_NAME)]
 | 
			
		||||
    #[clap(long, value_parser = OptionSimplifyEnumsKindValueParser, default_value = "replace-with-bundle-of-uints")]
 | 
			
		||||
    pub simplify_enums: std::option::Option<SimplifyEnumsKind>,
 | 
			
		||||
    #[doc(hidden)]
 | 
			
		||||
    #[clap(skip = ExportOptionsPrivate(()))]
 | 
			
		||||
| 
						 | 
				
			
			@ -2688,7 +2688,7 @@ impl Default for ExportOptions {
 | 
			
		|||
    fn default() -> Self {
 | 
			
		||||
        Self {
 | 
			
		||||
            simplify_memories: true,
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithBundleOfUInts),
 | 
			
		||||
            __private: ExportOptionsPrivate(()),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,8 @@
 | 
			
		|||
// SPDX-License-Identifier: LGPL-3.0-or-later
 | 
			
		||||
// See Notices.txt for copyright information
 | 
			
		||||
use fayalite::{
 | 
			
		||||
    annotations::CustomFirrtlAnnotation,
 | 
			
		||||
    assert_export_firrtl,
 | 
			
		||||
    intern::Intern,
 | 
			
		||||
    module::transform::simplify_enums::{simplify_enums, SimplifyEnumsKind},
 | 
			
		||||
    prelude::*,
 | 
			
		||||
    annotations::CustomFirrtlAnnotation, assert_export_firrtl, firrtl::ExportOptions,
 | 
			
		||||
    intern::Intern, module::transform::simplify_enums::SimplifyEnumsKind, prelude::*,
 | 
			
		||||
    ty::StaticType,
 | 
			
		||||
};
 | 
			
		||||
use serde_json::json;
 | 
			
		||||
| 
						 | 
				
			
			@ -86,6 +83,10 @@ fn test_mymodule() {
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/my_module.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit my_module:
 | 
			
		||||
    type Ty0 = {`0`: UInt<32>, `1`: SInt<5>}
 | 
			
		||||
| 
						 | 
				
			
			@ -481,6 +482,10 @@ fn test_enum_literals() {
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_literals.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_literals:
 | 
			
		||||
    type Ty0 = {|HdlNone, HdlSome: UInt<8>|}
 | 
			
		||||
| 
						 | 
				
			
			@ -502,12 +507,13 @@ circuit check_enum_literals:
 | 
			
		|||
            connect o2, {|A, B: UInt<8>, C: UInt<1>[3]|}(C, _array_literal_expr) @[module-XXXXXXXXXX.rs 10:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let orig_m = m.canonical().intern();
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::SimplifyToEnumsWithNoBody).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::SimplifyToEnumsWithNoBody),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_literals.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_literals:
 | 
			
		||||
    type Ty0 = {|HdlNone, HdlSome|}
 | 
			
		||||
| 
						 | 
				
			
			@ -549,11 +555,13 @@ circuit check_enum_literals:
 | 
			
		|||
            connect o2, _bundle_literal_expr_3 @[module-XXXXXXXXXX.rs 10:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithBundleOfUInts).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithBundleOfUInts),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_literals.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_literals:
 | 
			
		||||
    type Ty0 = {tag: UInt<1>, body: UInt<8>}
 | 
			
		||||
| 
						 | 
				
			
			@ -593,11 +601,13 @@ circuit check_enum_literals:
 | 
			
		|||
            connect o2, _bundle_literal_expr_3 @[module-XXXXXXXXXX.rs 10:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithUInt).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithUInt),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_literals.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_literals:
 | 
			
		||||
    type Ty0 = {tag: UInt<1>, body: UInt<8>}
 | 
			
		||||
| 
						 | 
				
			
			@ -708,6 +718,10 @@ fn test_struct_enum_match() {
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_struct_enum_match.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_struct_enum_match:
 | 
			
		||||
    type Ty0 = {|HdlNone, HdlSome: UInt<8>|}
 | 
			
		||||
| 
						 | 
				
			
			@ -764,12 +778,13 @@ circuit check_struct_enum_match:
 | 
			
		|||
                connect o[4], _match_arm_value_9[2] @[module-XXXXXXXXXX.rs 24:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let orig_m = m.canonical().intern();
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::SimplifyToEnumsWithNoBody).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::SimplifyToEnumsWithNoBody),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_struct_enum_match.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_struct_enum_match:
 | 
			
		||||
    type Ty0 = {|HdlNone, HdlSome|}
 | 
			
		||||
| 
						 | 
				
			
			@ -844,11 +859,13 @@ circuit check_struct_enum_match:
 | 
			
		|||
                connect o[4], _cast_bits_to_array_expr_1[2] @[module-XXXXXXXXXX.rs 24:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithBundleOfUInts).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithBundleOfUInts),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_struct_enum_match.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_struct_enum_match:
 | 
			
		||||
    type Ty0 = {tag: UInt<1>, body: UInt<8>}
 | 
			
		||||
| 
						 | 
				
			
			@ -915,11 +932,13 @@ circuit check_struct_enum_match:
 | 
			
		|||
            connect o[4], _cast_bits_to_array_expr_1[2] @[module-XXXXXXXXXX.rs 24:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithUInt).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithUInt),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_struct_enum_match.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_struct_enum_match:
 | 
			
		||||
    module check_struct_enum_match: @[module-XXXXXXXXXX.rs 1:1]
 | 
			
		||||
| 
						 | 
				
			
			@ -2419,6 +2438,10 @@ fn test_memory_of_enum() {
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_memory_of_enum.fir": r#"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_memory_of_enum: %[[
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			@ -2524,12 +2547,13 @@ circuit check_memory_of_enum: %[[
 | 
			
		|||
0000111101
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let orig_m = m.canonical().intern();
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::SimplifyToEnumsWithNoBody).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::SimplifyToEnumsWithNoBody),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_memory_of_enum.fir": r#"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_memory_of_enum: %[[
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			@ -2671,11 +2695,12 @@ circuit check_memory_of_enum: %[[
 | 
			
		|||
01
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithBundleOfUInts).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_memory_of_enum.fir": r#"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_memory_of_enum: %[[
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			@ -2801,11 +2826,13 @@ circuit check_memory_of_enum: %[[
 | 
			
		|||
01
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithUInt).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithUInt),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_memory_of_enum.fir": r#"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_memory_of_enum: %[[
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			@ -2906,6 +2933,10 @@ fn test_memory_of_array_of_enum() {
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_memory_of_array_of_enum.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_memory_of_array_of_enum:
 | 
			
		||||
    type Ty0 = {|A, B: UInt<8>, C: UInt<1>[3]|}
 | 
			
		||||
| 
						 | 
				
			
			@ -3227,6 +3258,10 @@ circuit check_uninit:
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_uninit_1.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_uninit_1:
 | 
			
		||||
    type Ty0 = {}
 | 
			
		||||
| 
						 | 
				
			
			@ -3329,6 +3364,10 @@ fn test_enum_connect_any() {
 | 
			
		|||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: None,
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_connect_any.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_connect_any:
 | 
			
		||||
    type Ty0 = {|HdlNone, HdlSome: SInt<1>|}
 | 
			
		||||
| 
						 | 
				
			
			@ -3357,12 +3396,13 @@ circuit check_enum_connect_any:
 | 
			
		|||
            connect o2, i2 @[module-XXXXXXXXXX.rs 11:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let orig_m = m.canonical().intern();
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::SimplifyToEnumsWithNoBody).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::SimplifyToEnumsWithNoBody),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_connect_any.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_connect_any:
 | 
			
		||||
    type Ty0 = {|A, B, C|}
 | 
			
		||||
| 
						 | 
				
			
			@ -3577,11 +3617,13 @@ circuit check_enum_connect_any:
 | 
			
		|||
            connect o2, i2 @[module-XXXXXXXXXX.rs 11:1]
 | 
			
		||||
",
 | 
			
		||||
    };
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithBundleOfUInts).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithBundleOfUInts),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_connect_any.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_connect_any:
 | 
			
		||||
    type Ty0 = {tag: UInt<2>, body: UInt<2>}
 | 
			
		||||
| 
						 | 
				
			
			@ -3732,12 +3774,14 @@ circuit check_enum_connect_any:
 | 
			
		|||
            connect o1, i1 @[module-XXXXXXXXXX.rs 10:1]
 | 
			
		||||
            connect o2, i2 @[module-XXXXXXXXXX.rs 11:1]
 | 
			
		||||
",
 | 
			
		||||
    }
 | 
			
		||||
    let m = simplify_enums(orig_m, SimplifyEnumsKind::ReplaceWithUInt).unwrap();
 | 
			
		||||
    dbg!(m);
 | 
			
		||||
    };
 | 
			
		||||
    #[rustfmt::skip] // work around https://github.com/rust-lang/rustfmt/issues/6161
 | 
			
		||||
    assert_export_firrtl! {
 | 
			
		||||
        m =>
 | 
			
		||||
        options: ExportOptions {
 | 
			
		||||
            simplify_enums: Some(SimplifyEnumsKind::ReplaceWithUInt),
 | 
			
		||||
            ..ExportOptions::default()
 | 
			
		||||
        },
 | 
			
		||||
        "/test/check_enum_connect_any.fir": r"FIRRTL version 3.2.0
 | 
			
		||||
circuit check_enum_connect_any:
 | 
			
		||||
    type Ty0 = {tag: UInt<2>, body: UInt<2>}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue