Construct OutputType using macro and print [=FILENAME] help info
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
parent
4c20d17365
commit
6fe881c788
7 changed files with 243 additions and 127 deletions
|
@ -568,122 +568,203 @@ impl FromStr for SplitDwarfKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, HashStable_Generic)]
|
macro_rules! define_output_types {
|
||||||
#[derive(Encodable, Decodable)]
|
(
|
||||||
pub enum OutputType {
|
$(
|
||||||
/// This is the optimized bitcode, which could be either pre-LTO or non-LTO bitcode,
|
$(#[doc = $doc:expr])*
|
||||||
/// depending on the specific request type.
|
$Variant:ident => {
|
||||||
Bitcode,
|
shorthand: $shorthand:expr,
|
||||||
/// This is the summary or index data part of the ThinLTO bitcode.
|
extension: $extension:expr,
|
||||||
ThinLinkBitcode,
|
description: $description:expr,
|
||||||
Assembly,
|
default_filename: $default_filename:expr,
|
||||||
LlvmAssembly,
|
is_text: $is_text:expr,
|
||||||
Mir,
|
compatible_with_cgus_and_single_output: $compatible:expr
|
||||||
Metadata,
|
}
|
||||||
Object,
|
),* $(,)?
|
||||||
Exe,
|
) => {
|
||||||
DepInfo,
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, HashStable_Generic)]
|
||||||
}
|
#[derive(Encodable, Decodable)]
|
||||||
|
pub enum OutputType {
|
||||||
|
$(
|
||||||
|
$(#[doc = $doc])*
|
||||||
|
$Variant,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
impl StableOrd for OutputType {
|
|
||||||
const CAN_USE_UNSTABLE_SORT: bool = true;
|
|
||||||
|
|
||||||
// Trivial C-Style enums have a stable sort order across compilation sessions.
|
impl StableOrd for OutputType {
|
||||||
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
|
const CAN_USE_UNSTABLE_SORT: bool = true;
|
||||||
}
|
|
||||||
|
|
||||||
impl<HCX: HashStableContext> ToStableHashKey<HCX> for OutputType {
|
// Trivial C-Style enums have a stable sort order across compilation sessions.
|
||||||
type KeyType = Self;
|
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
|
||||||
|
}
|
||||||
|
|
||||||
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
|
impl<HCX: HashStableContext> ToStableHashKey<HCX> for OutputType {
|
||||||
*self
|
type KeyType = Self;
|
||||||
|
|
||||||
|
fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl OutputType {
|
||||||
|
pub fn iter_all() -> impl Iterator<Item = OutputType> {
|
||||||
|
static ALL_VARIANTS: &[OutputType] = &[
|
||||||
|
$(
|
||||||
|
OutputType::$Variant,
|
||||||
|
)*
|
||||||
|
];
|
||||||
|
ALL_VARIANTS.iter().copied()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
$(
|
||||||
|
OutputType::$Variant => $compatible,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shorthand(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
$(
|
||||||
|
OutputType::$Variant => $shorthand,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_shorthand(shorthand: &str) -> Option<Self> {
|
||||||
|
match shorthand {
|
||||||
|
$(
|
||||||
|
s if s == $shorthand => Some(OutputType::$Variant),
|
||||||
|
)*
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shorthands_display() -> String {
|
||||||
|
let shorthands = vec![
|
||||||
|
$(
|
||||||
|
format!("`{}`", $shorthand),
|
||||||
|
)*
|
||||||
|
];
|
||||||
|
shorthands.join(", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn extension(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
$(
|
||||||
|
OutputType::$Variant => $extension,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_text_output(&self) -> bool {
|
||||||
|
match *self {
|
||||||
|
$(
|
||||||
|
OutputType::$Variant => $is_text,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn description(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
$(
|
||||||
|
OutputType::$Variant => $description,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn default_filename(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
$(
|
||||||
|
OutputType::$Variant => $default_filename,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutputType {
|
define_output_types! {
|
||||||
fn is_compatible_with_codegen_units_and_single_output_file(&self) -> bool {
|
Assembly => {
|
||||||
match *self {
|
shorthand: "asm",
|
||||||
OutputType::Exe | OutputType::DepInfo | OutputType::Metadata => true,
|
extension: "s",
|
||||||
OutputType::Bitcode
|
description: "Generates a file with the crate's assembly code",
|
||||||
| OutputType::ThinLinkBitcode
|
default_filename: "CRATE_NAME.s",
|
||||||
| OutputType::Assembly
|
is_text: true,
|
||||||
| OutputType::LlvmAssembly
|
compatible_with_cgus_and_single_output: false
|
||||||
| OutputType::Mir
|
},
|
||||||
| OutputType::Object => false,
|
#[doc = "This is the optimized bitcode, which could be either pre-LTO or non-LTO bitcode,"]
|
||||||
}
|
#[doc = "depending on the specific request type."]
|
||||||
}
|
Bitcode => {
|
||||||
|
shorthand: "llvm-bc",
|
||||||
pub fn shorthand(&self) -> &'static str {
|
extension: "bc",
|
||||||
match *self {
|
description: "Generates a binary file containing the LLVM bitcode",
|
||||||
OutputType::Bitcode => "llvm-bc",
|
default_filename: "CRATE_NAME.bc",
|
||||||
OutputType::ThinLinkBitcode => "thin-link-bitcode",
|
is_text: false,
|
||||||
OutputType::Assembly => "asm",
|
compatible_with_cgus_and_single_output: false
|
||||||
OutputType::LlvmAssembly => "llvm-ir",
|
},
|
||||||
OutputType::Mir => "mir",
|
DepInfo => {
|
||||||
OutputType::Object => "obj",
|
shorthand: "dep-info",
|
||||||
OutputType::Metadata => "metadata",
|
extension: "d",
|
||||||
OutputType::Exe => "link",
|
description: "Generates a file with Makefile syntax that indicates all the source files that were loaded to generate the crate",
|
||||||
OutputType::DepInfo => "dep-info",
|
default_filename: "CRATE_NAME.d",
|
||||||
}
|
is_text: true,
|
||||||
}
|
compatible_with_cgus_and_single_output: true
|
||||||
|
},
|
||||||
fn from_shorthand(shorthand: &str) -> Option<Self> {
|
Exe => {
|
||||||
Some(match shorthand {
|
shorthand: "link",
|
||||||
"asm" => OutputType::Assembly,
|
extension: "",
|
||||||
"llvm-ir" => OutputType::LlvmAssembly,
|
description: "Generates the crates specified by --crate-type. This is the default if --emit is not specified",
|
||||||
"mir" => OutputType::Mir,
|
default_filename: "(platform and crate-type dependent)",
|
||||||
"llvm-bc" => OutputType::Bitcode,
|
is_text: false,
|
||||||
"thin-link-bitcode" => OutputType::ThinLinkBitcode,
|
compatible_with_cgus_and_single_output: true
|
||||||
"obj" => OutputType::Object,
|
},
|
||||||
"metadata" => OutputType::Metadata,
|
LlvmAssembly => {
|
||||||
"link" => OutputType::Exe,
|
shorthand: "llvm-ir",
|
||||||
"dep-info" => OutputType::DepInfo,
|
extension: "ll",
|
||||||
_ => return None,
|
description: "Generates a file containing LLVM IR",
|
||||||
})
|
default_filename: "CRATE_NAME.ll",
|
||||||
}
|
is_text: true,
|
||||||
|
compatible_with_cgus_and_single_output: false
|
||||||
fn shorthands_display() -> String {
|
},
|
||||||
format!(
|
Metadata => {
|
||||||
"`{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`",
|
shorthand: "metadata",
|
||||||
OutputType::Bitcode.shorthand(),
|
extension: "rmeta",
|
||||||
OutputType::ThinLinkBitcode.shorthand(),
|
description: "Generates a file containing metadata about the crate",
|
||||||
OutputType::Assembly.shorthand(),
|
default_filename: "libCRATE_NAME.rmeta",
|
||||||
OutputType::LlvmAssembly.shorthand(),
|
is_text: false,
|
||||||
OutputType::Mir.shorthand(),
|
compatible_with_cgus_and_single_output: true
|
||||||
OutputType::Object.shorthand(),
|
},
|
||||||
OutputType::Metadata.shorthand(),
|
Mir => {
|
||||||
OutputType::Exe.shorthand(),
|
shorthand: "mir",
|
||||||
OutputType::DepInfo.shorthand(),
|
extension: "mir",
|
||||||
)
|
description: "Generates a file containing rustc's mid-level intermediate representation",
|
||||||
}
|
default_filename: "CRATE_NAME.mir",
|
||||||
|
is_text: true,
|
||||||
pub fn extension(&self) -> &'static str {
|
compatible_with_cgus_and_single_output: false
|
||||||
match *self {
|
},
|
||||||
OutputType::Bitcode => "bc",
|
Object => {
|
||||||
OutputType::ThinLinkBitcode => "indexing.o",
|
shorthand: "obj",
|
||||||
OutputType::Assembly => "s",
|
extension: "o",
|
||||||
OutputType::LlvmAssembly => "ll",
|
description: "Generates a native object file",
|
||||||
OutputType::Mir => "mir",
|
default_filename: "CRATE_NAME.o",
|
||||||
OutputType::Object => "o",
|
is_text: false,
|
||||||
OutputType::Metadata => "rmeta",
|
compatible_with_cgus_and_single_output: false
|
||||||
OutputType::DepInfo => "d",
|
},
|
||||||
OutputType::Exe => "",
|
#[doc = "This is the summary or index data part of the ThinLTO bitcode."]
|
||||||
}
|
ThinLinkBitcode => {
|
||||||
}
|
shorthand: "thin-link-bitcode",
|
||||||
|
extension: "indexing.o",
|
||||||
pub fn is_text_output(&self) -> bool {
|
description: "Generates the ThinLTO summary as bitcode",
|
||||||
match *self {
|
default_filename: "CRATE_NAME.indexing.o",
|
||||||
OutputType::Assembly
|
is_text: false,
|
||||||
| OutputType::LlvmAssembly
|
compatible_with_cgus_and_single_output: false
|
||||||
| OutputType::Mir
|
},
|
||||||
| OutputType::DepInfo => true,
|
|
||||||
OutputType::Bitcode
|
|
||||||
| OutputType::ThinLinkBitcode
|
|
||||||
| OutputType::Object
|
|
||||||
| OutputType::Metadata
|
|
||||||
| OutputType::Exe => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type of diagnostics output to generate.
|
/// The type of diagnostics output to generate.
|
||||||
|
@ -1570,6 +1651,18 @@ static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static EMIT_HELP: LazyLock<String> = LazyLock::new(|| {
|
||||||
|
let mut result =
|
||||||
|
String::from("Comma separated list of types of output for the compiler to emit.\n");
|
||||||
|
result.push_str("Each TYPE has the default FILE name:\n");
|
||||||
|
|
||||||
|
for output in OutputType::iter_all() {
|
||||||
|
result.push_str(&format!("* {} - {}\n", output.shorthand(), output.default_filename()));
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
});
|
||||||
|
|
||||||
/// Returns all rustc command line options, including metadata for
|
/// Returns all rustc command line options, including metadata for
|
||||||
/// each option, such as whether the option is stable.
|
/// each option, such as whether the option is stable.
|
||||||
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
||||||
|
@ -1616,14 +1709,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
|
||||||
make_crate_type_option(),
|
make_crate_type_option(),
|
||||||
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"),
|
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"),
|
||||||
opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST),
|
opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST),
|
||||||
opt(
|
opt(Stable, Multi, "", "emit", &EMIT_HELP, "TYPE[=FILE]"),
|
||||||
Stable,
|
|
||||||
Multi,
|
|
||||||
"",
|
|
||||||
"emit",
|
|
||||||
"Comma separated list of types of output for the compiler to emit",
|
|
||||||
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]",
|
|
||||||
),
|
|
||||||
opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"),
|
opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"),
|
||||||
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
|
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
|
||||||
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
|
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
libdash_separated_something-extra.rmeta: dash-separated.rs
|
|
||||||
|
|
||||||
dash-separated_something-extra.d: dash-separated.rs
|
dash-separated_something-extra.d: dash-separated.rs
|
||||||
|
|
||||||
|
libdash_separated_something-extra.rmeta: dash-separated.rs
|
||||||
|
|
||||||
dash-separated.rs:
|
dash-separated.rs:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
@@ -53,10 +53,27 @@
|
@@ -63,10 +63,27 @@
|
||||||
Set a codegen option
|
Set a codegen option
|
||||||
-V, --version Print version info and exit
|
-V, --version Print version info and exit
|
||||||
-v, --verbose Use verbose output
|
-v, --verbose Use verbose output
|
||||||
|
|
|
@ -26,9 +26,19 @@ Options:
|
||||||
Specify which edition of the compiler to use when
|
Specify which edition of the compiler to use when
|
||||||
compiling code. The default is 2015 and the latest
|
compiling code. The default is 2015 and the latest
|
||||||
stable edition is 2024.
|
stable edition is 2024.
|
||||||
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
|
--emit TYPE[=FILE]
|
||||||
Comma separated list of types of output for the
|
Comma separated list of types of output for the
|
||||||
compiler to emit
|
compiler to emit.
|
||||||
|
Each TYPE has the default FILE name:
|
||||||
|
* asm - CRATE_NAME.s
|
||||||
|
* llvm-bc - CRATE_NAME.bc
|
||||||
|
* dep-info - CRATE_NAME.d
|
||||||
|
* link - (platform and crate-type dependent)
|
||||||
|
* llvm-ir - CRATE_NAME.ll
|
||||||
|
* metadata - libCRATE_NAME.rmeta
|
||||||
|
* mir - CRATE_NAME.mir
|
||||||
|
* obj - CRATE_NAME.o
|
||||||
|
* thin-link-bitcode - CRATE_NAME.indexing.o
|
||||||
--print INFO[=FILE]
|
--print INFO[=FILE]
|
||||||
Compiler information to print on stdout (or to a file)
|
Compiler information to print on stdout (or to a file)
|
||||||
INFO may be one of
|
INFO may be one of
|
||||||
|
|
|
@ -26,9 +26,19 @@ Options:
|
||||||
Specify which edition of the compiler to use when
|
Specify which edition of the compiler to use when
|
||||||
compiling code. The default is 2015 and the latest
|
compiling code. The default is 2015 and the latest
|
||||||
stable edition is 2024.
|
stable edition is 2024.
|
||||||
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
|
--emit TYPE[=FILE]
|
||||||
Comma separated list of types of output for the
|
Comma separated list of types of output for the
|
||||||
compiler to emit
|
compiler to emit.
|
||||||
|
Each TYPE has the default FILE name:
|
||||||
|
* asm - CRATE_NAME.s
|
||||||
|
* llvm-bc - CRATE_NAME.bc
|
||||||
|
* dep-info - CRATE_NAME.d
|
||||||
|
* link - (platform and crate-type dependent)
|
||||||
|
* llvm-ir - CRATE_NAME.ll
|
||||||
|
* metadata - libCRATE_NAME.rmeta
|
||||||
|
* mir - CRATE_NAME.mir
|
||||||
|
* obj - CRATE_NAME.o
|
||||||
|
* thin-link-bitcode - CRATE_NAME.indexing.o
|
||||||
--print INFO[=FILE]
|
--print INFO[=FILE]
|
||||||
Compiler information to print on stdout (or to a file)
|
Compiler information to print on stdout (or to a file)
|
||||||
INFO may be one of
|
INFO may be one of
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
//@ compile-flags: --emit
|
//@ compile-flags: --emit
|
||||||
|
//@ error-pattern: Argument to option 'emit' missing
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
error: Argument to option 'emit' missing
|
error: Argument to option 'emit' missing
|
||||||
Usage:
|
Usage:
|
||||||
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
|
--emit TYPE[=FILE] Comma separated list of types of output for the
|
||||||
Comma separated list of types of output for the
|
compiler to emit.
|
||||||
compiler to emit
|
Each TYPE has the default FILE name:
|
||||||
|
* asm - CRATE_NAME.s
|
||||||
|
* llvm-bc - CRATE_NAME.bc
|
||||||
|
* dep-info - CRATE_NAME.d
|
||||||
|
* link - (platform and crate-type dependent)
|
||||||
|
* llvm-ir - CRATE_NAME.ll
|
||||||
|
* metadata - libCRATE_NAME.rmeta
|
||||||
|
* mir - CRATE_NAME.mir
|
||||||
|
* obj - CRATE_NAME.o
|
||||||
|
* thin-link-bitcode - CRATE_NAME.indexing.o
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue