@@ -568,124 +568,205 @@ impl FromStr for SplitDwarfKind {
568568 }
569569}
570570
571- #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , PartialOrd , Ord , HashStable_Generic ) ]
572- #[ derive( Encodable , Decodable ) ]
573- pub enum OutputType {
574- /// This is the optimized bitcode, which could be either pre-LTO or non-LTO bitcode,
575- /// depending on the specific request type.
576- Bitcode ,
577- /// This is the summary or index data part of the ThinLTO bitcode.
578- ThinLinkBitcode ,
579- Assembly ,
580- LlvmAssembly ,
581- Mir ,
582- Metadata ,
583- Object ,
584- Exe ,
585- DepInfo ,
586- }
571+ macro_rules! define_output_types {
572+ (
573+ $(
574+ $( #[ doc = $doc: expr] ) *
575+ $Variant: ident => {
576+ shorthand: $shorthand: expr,
577+ extension: $extension: expr,
578+ description: $description: expr,
579+ default_filename: $default_filename: expr,
580+ is_text: $is_text: expr,
581+ compatible_with_cgus_and_single_output: $compatible: expr
582+ }
583+ ) ,* $( , ) ?
584+ ) => {
585+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug , PartialOrd , Ord , HashStable_Generic ) ]
586+ #[ derive( Encodable , Decodable ) ]
587+ pub enum OutputType {
588+ $(
589+ $( #[ doc = $doc] ) *
590+ $Variant,
591+ ) *
592+ }
587593
588- impl StableOrd for OutputType {
589- const CAN_USE_UNSTABLE_SORT : bool = true ;
590594
591- // Trivial C-Style enums have a stable sort order across compilation sessions.
592- const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED : ( ) = ( ) ;
593- }
595+ impl StableOrd for OutputType {
596+ const CAN_USE_UNSTABLE_SORT : bool = true ;
594597
595- impl < HCX : HashStableContext > ToStableHashKey < HCX > for OutputType {
596- type KeyType = Self ;
598+ // Trivial C-Style enums have a stable sort order across compilation sessions.
599+ const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED : ( ) = ( ) ;
600+ }
597601
598- fn to_stable_hash_key ( & self , _: & HCX ) -> Self :: KeyType {
599- * self
600- }
601- }
602+ impl <HCX : HashStableContext > ToStableHashKey <HCX > for OutputType {
603+ type KeyType = Self ;
602604
603- impl OutputType {
604- fn is_compatible_with_codegen_units_and_single_output_file ( & self ) -> bool {
605- match * self {
606- OutputType :: Exe | OutputType :: DepInfo | OutputType :: Metadata => true ,
607- OutputType :: Bitcode
608- | OutputType :: ThinLinkBitcode
609- | OutputType :: Assembly
610- | OutputType :: LlvmAssembly
611- | OutputType :: Mir
612- | OutputType :: Object => false ,
605+ fn to_stable_hash_key( & self , _: & HCX ) -> Self :: KeyType {
606+ * self
607+ }
613608 }
614- }
615609
616- pub fn shorthand ( & self ) -> & ' static str {
617- match * self {
618- OutputType :: Bitcode => "llvm-bc" ,
619- OutputType :: ThinLinkBitcode => "thin-link-bitcode" ,
620- OutputType :: Assembly => "asm" ,
621- OutputType :: LlvmAssembly => "llvm-ir" ,
622- OutputType :: Mir => "mir" ,
623- OutputType :: Object => "obj" ,
624- OutputType :: Metadata => "metadata" ,
625- OutputType :: Exe => "link" ,
626- OutputType :: DepInfo => "dep-info" ,
627- }
628- }
629-
630- fn from_shorthand ( shorthand : & str ) -> Option < Self > {
631- Some ( match shorthand {
632- "asm" => OutputType :: Assembly ,
633- "llvm-ir" => OutputType :: LlvmAssembly ,
634- "mir" => OutputType :: Mir ,
635- "llvm-bc" => OutputType :: Bitcode ,
636- "thin-link-bitcode" => OutputType :: ThinLinkBitcode ,
637- "obj" => OutputType :: Object ,
638- "metadata" => OutputType :: Metadata ,
639- "link" => OutputType :: Exe ,
640- "dep-info" => OutputType :: DepInfo ,
641- _ => return None ,
642- } )
643- }
644610
645- fn shorthands_display ( ) -> String {
646- format ! (
647- "`{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`" ,
648- OutputType :: Bitcode . shorthand( ) ,
649- OutputType :: ThinLinkBitcode . shorthand( ) ,
650- OutputType :: Assembly . shorthand( ) ,
651- OutputType :: LlvmAssembly . shorthand( ) ,
652- OutputType :: Mir . shorthand( ) ,
653- OutputType :: Object . shorthand( ) ,
654- OutputType :: Metadata . shorthand( ) ,
655- OutputType :: Exe . shorthand( ) ,
656- OutputType :: DepInfo . shorthand( ) ,
657- )
658- }
611+ impl OutputType {
612+ pub fn iter_all( ) -> impl Iterator <Item = OutputType > {
613+ static ALL_VARIANTS : & [ OutputType ] = & [
614+ $(
615+ OutputType :: $Variant,
616+ ) *
617+ ] ;
618+ ALL_VARIANTS . iter( ) . copied( )
619+ }
620+
621+ fn is_compatible_with_codegen_units_and_single_output_file( & self ) -> bool {
622+ match * self {
623+ $(
624+ OutputType :: $Variant => $compatible,
625+ ) *
626+ }
627+ }
628+
629+ pub fn shorthand( & self ) -> & ' static str {
630+ match * self {
631+ $(
632+ OutputType :: $Variant => $shorthand,
633+ ) *
634+ }
635+ }
636+
637+ fn from_shorthand( shorthand: & str ) -> Option <Self > {
638+ match shorthand {
639+ $(
640+ s if s == $shorthand => Some ( OutputType :: $Variant) ,
641+ ) *
642+ _ => None ,
643+ }
644+ }
645+
646+ fn shorthands_display( ) -> String {
647+ let shorthands = vec![
648+ $(
649+ format!( "`{}`" , $shorthand) ,
650+ ) *
651+ ] ;
652+ shorthands. join( ", " )
653+ }
654+
655+ pub fn extension( & self ) -> & ' static str {
656+ match * self {
657+ $(
658+ OutputType :: $Variant => $extension,
659+ ) *
660+ }
661+ }
662+
663+ pub fn is_text_output( & self ) -> bool {
664+ match * self {
665+ $(
666+ OutputType :: $Variant => $is_text,
667+ ) *
668+ }
669+ }
670+
671+ pub fn description( & self ) -> & ' static str {
672+ match * self {
673+ $(
674+ OutputType :: $Variant => $description,
675+ ) *
676+ }
677+ }
678+
679+ pub fn default_filename( & self ) -> & ' static str {
680+ match * self {
681+ $(
682+ OutputType :: $Variant => $default_filename,
683+ ) *
684+ }
685+ }
659686
660- pub fn extension ( & self ) -> & ' static str {
661- match * self {
662- OutputType :: Bitcode => "bc" ,
663- OutputType :: ThinLinkBitcode => "indexing.o" ,
664- OutputType :: Assembly => "s" ,
665- OutputType :: LlvmAssembly => "ll" ,
666- OutputType :: Mir => "mir" ,
667- OutputType :: Object => "o" ,
668- OutputType :: Metadata => "rmeta" ,
669- OutputType :: DepInfo => "d" ,
670- OutputType :: Exe => "" ,
671- }
672- }
673687
674- pub fn is_text_output ( & self ) -> bool {
675- match * self {
676- OutputType :: Assembly
677- | OutputType :: LlvmAssembly
678- | OutputType :: Mir
679- | OutputType :: DepInfo => true ,
680- OutputType :: Bitcode
681- | OutputType :: ThinLinkBitcode
682- | OutputType :: Object
683- | OutputType :: Metadata
684- | OutputType :: Exe => false ,
685688 }
686689 }
687690}
688691
692+ define_output_types ! {
693+ Assembly => {
694+ shorthand: "asm" ,
695+ extension: "s" ,
696+ description: "Generates a file with the crate's assembly code" ,
697+ default_filename: "CRATE_NAME.s" ,
698+ is_text: true ,
699+ compatible_with_cgus_and_single_output: false
700+ } ,
701+ #[ doc = "This is the optimized bitcode, which could be either pre-LTO or non-LTO bitcode," ]
702+ #[ doc = "depending on the specific request type." ]
703+ Bitcode => {
704+ shorthand: "llvm-bc" ,
705+ extension: "bc" ,
706+ description: "Generates a binary file containing the LLVM bitcode" ,
707+ default_filename: "CRATE_NAME.bc" ,
708+ is_text: false ,
709+ compatible_with_cgus_and_single_output: false
710+ } ,
711+ DepInfo => {
712+ shorthand: "dep-info" ,
713+ extension: "d" ,
714+ description: "Generates a file with Makefile syntax that indicates all the source files that were loaded to generate the crate" ,
715+ default_filename: "CRATE_NAME.d" ,
716+ is_text: true ,
717+ compatible_with_cgus_and_single_output: true
718+ } ,
719+ Exe => {
720+ shorthand: "link" ,
721+ extension: "" ,
722+ description: "Generates the crates specified by --crate-type. This is the default if --emit is not specified" ,
723+ default_filename: "(platform and crate-type dependent)" ,
724+ is_text: false ,
725+ compatible_with_cgus_and_single_output: true
726+ } ,
727+ LlvmAssembly => {
728+ shorthand: "llvm-ir" ,
729+ extension: "ll" ,
730+ description: "Generates a file containing LLVM IR" ,
731+ default_filename: "CRATE_NAME.ll" ,
732+ is_text: true ,
733+ compatible_with_cgus_and_single_output: false
734+ } ,
735+ Metadata => {
736+ shorthand: "metadata" ,
737+ extension: "rmeta" ,
738+ description: "Generates a file containing metadata about the crate" ,
739+ default_filename: "libCRATE_NAME.rmeta" ,
740+ is_text: false ,
741+ compatible_with_cgus_and_single_output: true
742+ } ,
743+ Mir => {
744+ shorthand: "mir" ,
745+ extension: "mir" ,
746+ description: "Generates a file containing rustc's mid-level intermediate representation" ,
747+ default_filename: "CRATE_NAME.mir" ,
748+ is_text: true ,
749+ compatible_with_cgus_and_single_output: false
750+ } ,
751+ Object => {
752+ shorthand: "obj" ,
753+ extension: "o" ,
754+ description: "Generates a native object file" ,
755+ default_filename: "CRATE_NAME.o" ,
756+ is_text: false ,
757+ compatible_with_cgus_and_single_output: false
758+ } ,
759+ #[ doc = "This is the summary or index data part of the ThinLTO bitcode." ]
760+ ThinLinkBitcode => {
761+ shorthand: "thin-link-bitcode" ,
762+ extension: "indexing.o" ,
763+ description: "Generates the ThinLTO summary as bitcode" ,
764+ default_filename: "CRATE_NAME.indexing.o" ,
765+ is_text: false ,
766+ compatible_with_cgus_and_single_output: false
767+ } ,
768+ }
769+
689770/// The type of diagnostics output to generate.
690771#[ derive( Clone , Copy , Debug , PartialEq , Eq , Default ) ]
691772pub enum ErrorOutputType {
@@ -1570,6 +1651,18 @@ static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
15701651 )
15711652} ) ;
15721653
1654+ static EMIT_HELP : LazyLock < String > = LazyLock :: new ( || {
1655+ let mut result =
1656+ String :: from ( "Comma separated list of types of output for the compiler to emit.\n " ) ;
1657+ result. push_str ( "Each TYPE has the default FILE name:\n " ) ;
1658+
1659+ for output in OutputType :: iter_all ( ) {
1660+ result. push_str ( & format ! ( "* {} - {}\n " , output. shorthand( ) , output. default_filename( ) ) ) ;
1661+ }
1662+
1663+ result
1664+ } ) ;
1665+
15731666/// Returns all rustc command line options, including metadata for
15741667/// each option, such as whether the option is stable.
15751668pub fn rustc_optgroups ( ) -> Vec < RustcOptGroup > {
@@ -1616,14 +1709,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16161709 make_crate_type_option( ) ,
16171710 opt( Stable , Opt , "" , "crate-name" , "Specify the name of the crate being built" , "NAME" ) ,
16181711 opt( Stable , Opt , "" , "edition" , & EDITION_STRING , EDITION_NAME_LIST ) ,
1619- opt(
1620- Stable ,
1621- Multi ,
1622- "" ,
1623- "emit" ,
1624- "Comma separated list of types of output for the compiler to emit" ,
1625- "[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]" ,
1626- ) ,
1712+ opt( Stable , Multi , "" , "emit" , & EMIT_HELP , "TYPE[=FILE]" ) ,
16271713 opt( Stable , Multi , "" , "print" , & PRINT_HELP , "INFO[=FILE]" ) ,
16281714 opt( Stable , FlagMulti , "g" , "" , "Equivalent to -C debuginfo=2" , "" ) ,
16291715 opt( Stable , FlagMulti , "O" , "" , "Equivalent to -C opt-level=3" , "" ) ,
0 commit comments