mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
rustc_llvm: Tweak how initialization is performed
Refactor a bit to have less repetition and #[cfg] and try to bury it all inside of a macro.
This commit is contained in:
parent
32c56138ec
commit
34f7364332
@ -102,7 +102,7 @@ $(foreach host,$(CFG_HOST), \
|
||||
define LLVM_LINKAGE_DEPS
|
||||
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
|
||||
RUSTFLAGS$(1)_rustc_llvm_T_$(2) += $$(shell echo $$(LLVM_ALL_COMPONENTS_$(2)) | tr '-' '_' |\
|
||||
sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg have_component_\1/g')
|
||||
sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg "llvm_component=\\"\1\\""/g')
|
||||
endef
|
||||
|
||||
$(foreach source,$(CFG_HOST), \
|
||||
|
@ -2166,53 +2166,6 @@ extern {
|
||||
pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
|
||||
}
|
||||
|
||||
#[cfg(have_component_x86)]
|
||||
extern {
|
||||
pub fn LLVMInitializeX86TargetInfo();
|
||||
pub fn LLVMInitializeX86Target();
|
||||
pub fn LLVMInitializeX86TargetMC();
|
||||
pub fn LLVMInitializeX86AsmPrinter();
|
||||
pub fn LLVMInitializeX86AsmParser();
|
||||
}
|
||||
#[cfg(have_component_arm)]
|
||||
extern {
|
||||
pub fn LLVMInitializeARMTargetInfo();
|
||||
pub fn LLVMInitializeARMTarget();
|
||||
pub fn LLVMInitializeARMTargetMC();
|
||||
pub fn LLVMInitializeARMAsmPrinter();
|
||||
pub fn LLVMInitializeARMAsmParser();
|
||||
}
|
||||
#[cfg(have_component_aarch64)]
|
||||
extern {
|
||||
pub fn LLVMInitializeAArch64TargetInfo();
|
||||
pub fn LLVMInitializeAArch64Target();
|
||||
pub fn LLVMInitializeAArch64TargetMC();
|
||||
pub fn LLVMInitializeAArch64AsmPrinter();
|
||||
pub fn LLVMInitializeAArch64AsmParser();
|
||||
}
|
||||
#[cfg(have_component_mips)]
|
||||
extern {
|
||||
pub fn LLVMInitializeMipsTargetInfo();
|
||||
pub fn LLVMInitializeMipsTarget();
|
||||
pub fn LLVMInitializeMipsTargetMC();
|
||||
pub fn LLVMInitializeMipsAsmPrinter();
|
||||
pub fn LLVMInitializeMipsAsmParser();
|
||||
}
|
||||
#[cfg(have_component_powerpc)]
|
||||
extern {
|
||||
pub fn LLVMInitializePowerPCTargetInfo();
|
||||
pub fn LLVMInitializePowerPCTarget();
|
||||
pub fn LLVMInitializePowerPCTargetMC();
|
||||
pub fn LLVMInitializePowerPCAsmPrinter();
|
||||
pub fn LLVMInitializePowerPCAsmParser();
|
||||
}
|
||||
#[cfg(have_component_pnacl)]
|
||||
extern {
|
||||
pub fn LLVMInitializePNaClTargetInfo();
|
||||
pub fn LLVMInitializePNaClTarget();
|
||||
pub fn LLVMInitializePNaClTargetMC();
|
||||
}
|
||||
|
||||
// LLVM requires symbols from this library, but apparently they're not printed
|
||||
// during llvm-config?
|
||||
#[cfg(windows)]
|
||||
@ -2399,20 +2352,14 @@ pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
|
||||
|
||||
pub fn initialize_available_targets() {
|
||||
macro_rules! init_target(
|
||||
($cfg:ident $arch:ident) => { {
|
||||
($cfg:meta, $($method:ident),*) => { {
|
||||
#[cfg($cfg)]
|
||||
fn init() {
|
||||
extern {
|
||||
$(fn $method();)*
|
||||
}
|
||||
unsafe {
|
||||
let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
|
||||
f();
|
||||
let f = concat_idents!(LLVMInitialize, $arch, Target);
|
||||
f();
|
||||
let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
|
||||
f();
|
||||
let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
|
||||
f();
|
||||
let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
|
||||
f();
|
||||
$($method();)*
|
||||
}
|
||||
}
|
||||
#[cfg(not($cfg))]
|
||||
@ -2420,26 +2367,40 @@ pub fn initialize_available_targets() {
|
||||
init();
|
||||
} }
|
||||
);
|
||||
|
||||
init_target!(have_component_powerpc PowerPC);
|
||||
init_target!(have_component_mips Mips);
|
||||
init_target!(have_component_aarch64 AArch64);
|
||||
init_target!(have_component_arm ARM);
|
||||
init_target!(have_component_x86 X86);
|
||||
|
||||
// PNaCl doesn't provide some of the optional target components, so we
|
||||
// manually initialize it here.
|
||||
#[cfg(have_component_pnacl)]
|
||||
fn init_pnacl() {
|
||||
unsafe {
|
||||
LLVMInitializePNaClTargetInfo();
|
||||
LLVMInitializePNaClTarget();
|
||||
LLVMInitializePNaClTargetMC();
|
||||
}
|
||||
}
|
||||
#[cfg(not(have_component_pnacl))]
|
||||
fn init_pnacl() { }
|
||||
init_pnacl();
|
||||
init_target!(llvm_component = "x86",
|
||||
LLVMInitializeX86TargetInfo,
|
||||
LLVMInitializeX86Target,
|
||||
LLVMInitializeX86TargetMC,
|
||||
LLVMInitializeX86AsmPrinter,
|
||||
LLVMInitializeX86AsmParser);
|
||||
init_target!(llvm_component = "arm",
|
||||
LLVMInitializeARMTargetInfo,
|
||||
LLVMInitializeARMTarget,
|
||||
LLVMInitializeARMTargetMC,
|
||||
LLVMInitializeARMAsmPrinter,
|
||||
LLVMInitializeARMAsmParser);
|
||||
init_target!(llvm_component = "aarch64",
|
||||
LLVMInitializeAArch64TargetInfo,
|
||||
LLVMInitializeAArch64Target,
|
||||
LLVMInitializeAArch64TargetMC,
|
||||
LLVMInitializeAArch64AsmPrinter,
|
||||
LLVMInitializeAArch64AsmParser);
|
||||
init_target!(llvm_component = "mips",
|
||||
LLVMInitializeMipsTargetInfo,
|
||||
LLVMInitializeMipsTarget,
|
||||
LLVMInitializeMipsTargetMC,
|
||||
LLVMInitializeMipsAsmPrinter,
|
||||
LLVMInitializeMipsAsmParser);
|
||||
init_target!(llvm_component = "powerpc",
|
||||
LLVMInitializePowerPCTargetInfo,
|
||||
LLVMInitializePowerPCTarget,
|
||||
LLVMInitializePowerPCTargetMC,
|
||||
LLVMInitializePowerPCAsmPrinter,
|
||||
LLVMInitializePowerPCAsmParser);
|
||||
init_target!(llvm_component = "pnacl",
|
||||
LLVMInitializePNaClTargetInfo,
|
||||
LLVMInitializePNaClTarget,
|
||||
LLVMInitializePNaClTargetMC);
|
||||
}
|
||||
|
||||
pub fn last_error() -> Option<String> {
|
||||
|
Loading…
Reference in New Issue
Block a user