@@ -551,35 +551,81 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
551551 }
552552}
553553
554+ #[ derive( Clone ) ]
555+ pub enum DisassembleMode {
556+ All ,
557+ Function ( String ) ,
558+ Entry ( String ) ,
559+ Globals ,
560+ }
561+
554562#[ derive( Default , Clone ) ]
555563pub struct CodegenArgs {
556564 pub nvvm_options : Vec < NvvmOption > ,
557565 pub override_libm : bool ,
558566 pub use_constant_memory_space : bool ,
559567 pub final_module_path : Option < PathBuf > ,
568+ pub disassemble : Option < DisassembleMode > ,
560569}
561570
562571impl CodegenArgs {
563572 pub fn from_session ( sess : & Session ) -> Self {
564- Self :: parse ( & sess. opts . cg . llvm_args )
573+ Self :: parse ( & sess. opts . cg . llvm_args , sess )
565574 }
566575
567576 // 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 {
569578 // TODO: replace this with a "proper" arg parser.
570579 let mut cg_args = Self :: default ( ) ;
571580
581+ let mut skip_next = false ;
572582 for ( idx, arg) in args. iter ( ) . enumerate ( ) {
583+ if skip_next {
584+ skip_next = false ;
585+ continue ;
586+ }
587+
573588 if let Ok ( flag) = NvvmOption :: from_str ( arg) {
574589 cg_args. nvvm_options . push ( flag) ;
575590 } else if arg == "--override-libm" {
576591 cg_args. override_libm = true ;
577592 } else if arg == "--use-constant-memory-space" {
578593 cg_args. use_constant_memory_space = true ;
579594 } 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 ( ) ) ) ;
583629 }
584630 }
585631
0 commit comments