@@ -551,35 +551,81 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
551
551
}
552
552
}
553
553
554
+ #[ derive( Clone ) ]
555
+ pub enum DisassembleMode {
556
+ All ,
557
+ Function ( String ) ,
558
+ Entry ( String ) ,
559
+ Globals ,
560
+ }
561
+
554
562
#[ derive( Default , Clone ) ]
555
563
pub struct CodegenArgs {
556
564
pub nvvm_options : Vec < NvvmOption > ,
557
565
pub override_libm : bool ,
558
566
pub use_constant_memory_space : bool ,
559
567
pub final_module_path : Option < PathBuf > ,
568
+ pub disassemble : Option < DisassembleMode > ,
560
569
}
561
570
562
571
impl CodegenArgs {
563
572
pub fn from_session ( sess : & Session ) -> Self {
564
- Self :: parse ( & sess. opts . cg . llvm_args )
573
+ Self :: parse ( & sess. opts . cg . llvm_args , sess )
565
574
}
566
575
567
576
// we may want to use rustc's own option parsing facilities to have better errors in the future.
568
- pub fn parse ( args : & [ String ] ) -> Self {
577
+ pub fn parse ( args : & [ String ] , sess : & Session ) -> Self {
569
578
// TODO: replace this with a "proper" arg parser.
570
579
let mut cg_args = Self :: default ( ) ;
571
580
581
+ let mut skip_next = false ;
572
582
for ( idx, arg) in args. iter ( ) . enumerate ( ) {
583
+ if skip_next {
584
+ skip_next = false ;
585
+ continue ;
586
+ }
587
+
573
588
if let Ok ( flag) = NvvmOption :: from_str ( arg) {
574
589
cg_args. nvvm_options . push ( flag) ;
575
590
} else if arg == "--override-libm" {
576
591
cg_args. override_libm = true ;
577
592
} else if arg == "--use-constant-memory-space" {
578
593
cg_args. use_constant_memory_space = true ;
579
594
} else if arg == "--final-module-path" {
580
- cg_args. final_module_path = Some ( PathBuf :: from (
581
- args. get ( idx + 1 ) . expect ( "No path for --final-module-path" ) ,
582
- ) ) ;
595
+ let path = match args. get ( idx + 1 ) {
596
+ Some ( p) => p,
597
+ None => sess
598
+ . dcx ( )
599
+ . fatal ( "--final-module-path requires a path argument" ) ,
600
+ } ;
601
+ cg_args. final_module_path = Some ( PathBuf :: from ( path) ) ;
602
+ skip_next = true ;
603
+ } else if arg == "--disassemble" {
604
+ cg_args. disassemble = Some ( DisassembleMode :: All ) ;
605
+ } else if arg == "--disassemble-globals" {
606
+ cg_args. disassemble = Some ( DisassembleMode :: Globals ) ;
607
+ } else if arg == "--disassemble-fn" {
608
+ let func_name = match args. get ( idx + 1 ) {
609
+ Some ( name) => name. clone ( ) ,
610
+ None => sess
611
+ . dcx ( )
612
+ . fatal ( "--disassemble-fn requires a function name argument" ) ,
613
+ } ;
614
+ cg_args. disassemble = Some ( DisassembleMode :: Function ( func_name) ) ;
615
+ skip_next = true ;
616
+ } else if let Some ( func) = arg. strip_prefix ( "--disassemble-fn=" ) {
617
+ cg_args. disassemble = Some ( DisassembleMode :: Function ( func. to_string ( ) ) ) ;
618
+ } else if arg == "--disassemble-entry" {
619
+ let entry_name = match args. get ( idx + 1 ) {
620
+ Some ( name) => name. clone ( ) ,
621
+ None => sess
622
+ . dcx ( )
623
+ . fatal ( "--disassemble-entry requires an entry name argument" ) ,
624
+ } ;
625
+ cg_args. disassemble = Some ( DisassembleMode :: Entry ( entry_name) ) ;
626
+ skip_next = true ;
627
+ } else if let Some ( entry) = arg. strip_prefix ( "--disassemble-entry=" ) {
628
+ cg_args. disassemble = Some ( DisassembleMode :: Entry ( entry. to_string ( ) ) ) ;
583
629
}
584
630
}
585
631
0 commit comments