@@ -242,6 +242,13 @@ fn make_opts() -> getopts::Options
242
242
"q" , "quiet" ,
243
243
"Suppress progress reports." ) ;
244
244
245
+ opts. opt (
246
+ "d" , "define" ,
247
+ "Defines a constant." ,
248
+ "VALUE" ,
249
+ getopts:: HasArg :: Yes ,
250
+ getopts:: Occur :: Multi ) ;
251
+
245
252
opts. opt (
246
253
"" , "color" ,
247
254
"Style the output with colors. [on/off]" ,
@@ -337,6 +344,14 @@ fn parse_command(
337
344
command. show_version |= parsed. opt_present ( "v" ) ;
338
345
command. show_help |= parsed. opt_present ( "h" ) ;
339
346
347
+ for define_arg in parsed. opt_strs ( "d" )
348
+ {
349
+ command. opts . driver_symbol_defs . push (
350
+ parse_define_arg (
351
+ report,
352
+ & define_arg) ?) ;
353
+ }
354
+
340
355
command. opts . debug_iterations |=
341
356
parsed. opt_present ( "debug-iters" ) ;
342
357
@@ -619,6 +634,85 @@ pub fn parse_output_format(
619
634
}
620
635
621
636
637
+ fn parse_define_arg (
638
+ report : & mut diagn:: Report ,
639
+ raw_str : & str )
640
+ -> Result < asm:: DriverSymbolDef , ( ) >
641
+ {
642
+ let split = raw_str
643
+ . split ( '=' )
644
+ . collect :: < Vec < _ > > ( ) ;
645
+
646
+ let name = split[ 0 ] . to_string ( ) ;
647
+
648
+ if split. len ( ) == 1
649
+ {
650
+ return Ok ( asm:: DriverSymbolDef {
651
+ name,
652
+ value : expr:: Value :: make_bool ( true ) ,
653
+ } ) ;
654
+ }
655
+
656
+ if split. len ( ) != 2
657
+ {
658
+ report. error (
659
+ format ! (
660
+ "invalid define argument `{}`" ,
661
+ raw_str) ) ;
662
+
663
+ return Err ( ( ) ) ;
664
+ }
665
+
666
+ let value_str = split[ 1 ] ;
667
+
668
+ let value = {
669
+ if value_str == "true"
670
+ {
671
+ expr:: Value :: make_bool ( true )
672
+ }
673
+ else if value_str == "false"
674
+ {
675
+ expr:: Value :: make_bool ( false )
676
+ }
677
+ else
678
+ {
679
+ let has_negative_sign = split[ 1 ] . chars ( ) . next ( ) == Some ( '-' ) ;
680
+
681
+ let maybe_value = syntax:: excerpt_as_bigint (
682
+ None ,
683
+ diagn:: Span :: new_dummy ( ) ,
684
+ if has_negative_sign { split[ 1 ] . get ( 1 ..) . unwrap ( ) } else { split[ 1 ] } ) ;
685
+
686
+
687
+ use std:: ops:: Neg ;
688
+
689
+ match maybe_value
690
+ {
691
+ Ok ( value) =>
692
+ expr:: Value :: make_integer (
693
+ if has_negative_sign { value. neg ( ) } else { value } ) ,
694
+
695
+ Err ( ( ) ) =>
696
+ {
697
+ report. error (
698
+ format ! (
699
+ "invalid value for define `{}`" ,
700
+ name) ) ;
701
+
702
+ return Err ( ( ) ) ;
703
+ }
704
+ }
705
+ }
706
+ } ;
707
+
708
+
709
+ Ok ( asm:: DriverSymbolDef {
710
+ name,
711
+ value,
712
+ } )
713
+ }
714
+
715
+
622
716
pub fn format_output (
623
717
fileserver : & dyn util:: FileServer ,
624
718
decls : & asm:: ItemDecls ,
0 commit comments