@@ -29,7 +29,7 @@ object HasCliOptions {
2929 * @tparam the internal type of the option. This is what the `<value>` will
3030 * be converted to.
3131 */
32- case class CliOption [A ](
32+ case class CliOption [A ] private (
3333 name : String ,
3434 help : String ,
3535 convert : (String ) => A ,
@@ -66,13 +66,40 @@ object HasCliOptions {
6666
6767 @ deprecated(" avoid use of copy" , " Chisel 7.1.0" )
6868 def copy [A ](
69- name : String ,
70- help : String ,
71- convert : (String ) => A ,
72- updateChiselOptions : (A , Array [String ]) => Array [String ],
73- updateFirtoolOptions : (A , Array [String ]) => Array [String ],
74- updateCommonSettings : (A , CommonCompilationSettings ) => CommonCompilationSettings ,
75- updateBackendSettings : (A , Backend .Settings ) => Backend .Settings
69+ name : String = name,
70+ help : String = help,
71+ convert : (String ) => A = convert,
72+ updateChiselOptions : (A , Array [String ]) => Array [String ] = updateChiselOptions,
73+ updateFirtoolOptions : (A , Array [String ]) => Array [String ] = updateFirtoolOptions,
74+ updateCommonSettings : (A , CommonCompilationSettings ) => CommonCompilationSettings = updateCommonSettings,
75+ updateBackendSettings : (A , Backend .Settings ) => Backend .Settings = updateBackendSettings
76+ ): CliOption [A ] = CliOption [A ](
77+ name = name,
78+ help = help,
79+ convert = convert,
80+ updateChiselOptions = updateChiselOptions,
81+ updateFirtoolOptions = updateFirtoolOptions,
82+ updateCommonSettings = updateCommonSettings,
83+ updateBackendSettings = updateBackendSettings,
84+ updateUnsetChiselOptions = updateUnsetChiselOptions,
85+ updateUnsetFirtoolOptions = updateUnsetFirtoolOptions,
86+ updateUnsetCommonSettings = updateUnsetCommonSettings,
87+ updateUnsetBackendSettings = updateUnsetBackendSettings
88+ )
89+
90+ // Suppress generation of private copy with default arguments by Scala 3
91+ private def copy [A ](
92+ name : String ,
93+ help : String ,
94+ convert : (String ) => A ,
95+ updateChiselOptions : (A , Array [String ]) => Array [String ],
96+ updateFirtoolOptions : (A , Array [String ]) => Array [String ],
97+ updateCommonSettings : (A , CommonCompilationSettings ) => CommonCompilationSettings ,
98+ updateBackendSettings : (A , Backend .Settings ) => Backend .Settings ,
99+ updateUnsetChiselOptions : (Array [String ]) => Array [String ],
100+ updateUnsetFirtoolOptions : (Array [String ]) => Array [String ],
101+ updateUnsetCommonSettings : (CommonCompilationSettings ) => CommonCompilationSettings ,
102+ updateUnsetBackendSettings : (Backend .Settings ) => Backend .Settings
76103 ): CliOption [A ] = CliOption [A ](
77104 name = name,
78105 help = help,
@@ -90,6 +117,34 @@ object HasCliOptions {
90117
91118 object CliOption {
92119
120+ def apply [A ](
121+ name : String ,
122+ help : String ,
123+ convert : (String ) => A ,
124+ updateChiselOptions : (A , Array [String ]) => Array [String ],
125+ updateFirtoolOptions : (A , Array [String ]) => Array [String ],
126+ updateCommonSettings : (A , CommonCompilationSettings ) => CommonCompilationSettings ,
127+ updateBackendSettings : (A , Backend .Settings ) => Backend .Settings ,
128+ updateUnsetChiselOptions : (Array [String ]) => Array [String ],
129+ updateUnsetFirtoolOptions : (Array [String ]) => Array [String ],
130+ updateUnsetCommonSettings : (CommonCompilationSettings ) => CommonCompilationSettings ,
131+ updateUnsetBackendSettings : (Backend .Settings ) => Backend .Settings
132+ ): CliOption [A ] = {
133+ new CliOption [A ](
134+ name = name,
135+ help = help,
136+ convert = convert,
137+ updateChiselOptions = updateChiselOptions,
138+ updateFirtoolOptions = updateFirtoolOptions,
139+ updateCommonSettings = updateCommonSettings,
140+ updateBackendSettings = updateBackendSettings,
141+ updateUnsetChiselOptions = updateUnsetChiselOptions,
142+ updateUnsetFirtoolOptions = updateUnsetFirtoolOptions,
143+ updateUnsetCommonSettings = updateUnsetCommonSettings,
144+ updateUnsetBackendSettings = updateUnsetBackendSettings
145+ )
146+ }
147+
93148 @ deprecated(" use newer CliOption case class apply" , " Chisel 7.1.0" )
94149 def apply [A ](
95150 name : String ,
@@ -216,6 +271,35 @@ object HasCliOptions {
216271 convert = identity
217272 )
218273
274+ /** Add a flag option to a test.
275+ *
276+ * This is an option which can only take one of two "truthy" values: `1` or
277+ * `true`. Any "falsey" values are not allowed. This option is a stand-in
278+ * for any option which is supposed to be a flag to a test which has some
279+ * effect if set.
280+ *
281+ * This option exists because Scalatest forces options to have a value. It
282+ * is illegal to pass an option like `-Dfoo`. This [[flag ]] option exists
283+ * to problem a single flag-style option as opposed to having users roll
284+ * their own.
285+ *
286+ * @param name the name of the option
287+ * @param help help text to show to tell the user how to use this option
288+ */
289+ def flag (name : String , help : String ): CliOption [Unit ] =
290+ flag(
291+ name = name,
292+ help = help,
293+ updateChiselOptions = identity,
294+ updateFirtoolOptions = identity,
295+ updateCommonSettings = identity,
296+ updateBackendSettings = identity,
297+ updateUnsetChiselOptions = identity,
298+ updateUnsetFirtoolOptions = identity,
299+ updateUnsetCommonSettings = identity,
300+ updateUnsetBackendSettings = identity
301+ )
302+
219303 /** Add a flag option to a test.
220304 *
221305 * This is an option which can only take one of two "truthy" values: `1` or
0 commit comments