Skip to content

Commit 34f7364

Browse files
committed
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.
1 parent 32c5613 commit 34f7364

File tree

2 files changed

+40
-79
lines changed

2 files changed

+40
-79
lines changed

mk/llvm.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ $(foreach host,$(CFG_HOST), \
102102
define LLVM_LINKAGE_DEPS
103103
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.rustc_llvm: $$(LLVM_LINKAGE_PATH_$(2))
104104
RUSTFLAGS$(1)_rustc_llvm_T_$(2) += $$(shell echo $$(LLVM_ALL_COMPONENTS_$(2)) | tr '-' '_' |\
105-
sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg have_component_\1/g')
105+
sed -e 's/^ //;s/\([^ ]*\)/\-\-cfg "llvm_component=\\"\1\\""/g')
106106
endef
107107

108108
$(foreach source,$(CFG_HOST), \

src/librustc_llvm/lib.rs

Lines changed: 39 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,53 +2166,6 @@ extern {
21662166
pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
21672167
}
21682168

2169-
#[cfg(have_component_x86)]
2170-
extern {
2171-
pub fn LLVMInitializeX86TargetInfo();
2172-
pub fn LLVMInitializeX86Target();
2173-
pub fn LLVMInitializeX86TargetMC();
2174-
pub fn LLVMInitializeX86AsmPrinter();
2175-
pub fn LLVMInitializeX86AsmParser();
2176-
}
2177-
#[cfg(have_component_arm)]
2178-
extern {
2179-
pub fn LLVMInitializeARMTargetInfo();
2180-
pub fn LLVMInitializeARMTarget();
2181-
pub fn LLVMInitializeARMTargetMC();
2182-
pub fn LLVMInitializeARMAsmPrinter();
2183-
pub fn LLVMInitializeARMAsmParser();
2184-
}
2185-
#[cfg(have_component_aarch64)]
2186-
extern {
2187-
pub fn LLVMInitializeAArch64TargetInfo();
2188-
pub fn LLVMInitializeAArch64Target();
2189-
pub fn LLVMInitializeAArch64TargetMC();
2190-
pub fn LLVMInitializeAArch64AsmPrinter();
2191-
pub fn LLVMInitializeAArch64AsmParser();
2192-
}
2193-
#[cfg(have_component_mips)]
2194-
extern {
2195-
pub fn LLVMInitializeMipsTargetInfo();
2196-
pub fn LLVMInitializeMipsTarget();
2197-
pub fn LLVMInitializeMipsTargetMC();
2198-
pub fn LLVMInitializeMipsAsmPrinter();
2199-
pub fn LLVMInitializeMipsAsmParser();
2200-
}
2201-
#[cfg(have_component_powerpc)]
2202-
extern {
2203-
pub fn LLVMInitializePowerPCTargetInfo();
2204-
pub fn LLVMInitializePowerPCTarget();
2205-
pub fn LLVMInitializePowerPCTargetMC();
2206-
pub fn LLVMInitializePowerPCAsmPrinter();
2207-
pub fn LLVMInitializePowerPCAsmParser();
2208-
}
2209-
#[cfg(have_component_pnacl)]
2210-
extern {
2211-
pub fn LLVMInitializePNaClTargetInfo();
2212-
pub fn LLVMInitializePNaClTarget();
2213-
pub fn LLVMInitializePNaClTargetMC();
2214-
}
2215-
22162169
// LLVM requires symbols from this library, but apparently they're not printed
22172170
// during llvm-config?
22182171
#[cfg(windows)]
@@ -2399,47 +2352,55 @@ pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
23992352

24002353
pub fn initialize_available_targets() {
24012354
macro_rules! init_target(
2402-
($cfg:ident $arch:ident) => { {
2355+
($cfg:meta, $($method:ident),*) => { {
24032356
#[cfg($cfg)]
24042357
fn init() {
2358+
extern {
2359+
$(fn $method();)*
2360+
}
24052361
unsafe {
2406-
let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2407-
f();
2408-
let f = concat_idents!(LLVMInitialize, $arch, Target);
2409-
f();
2410-
let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2411-
f();
2412-
let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2413-
f();
2414-
let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2415-
f();
2362+
$($method();)*
24162363
}
24172364
}
24182365
#[cfg(not($cfg))]
24192366
fn init() { }
24202367
init();
24212368
} }
24222369
);
2423-
2424-
init_target!(have_component_powerpc PowerPC);
2425-
init_target!(have_component_mips Mips);
2426-
init_target!(have_component_aarch64 AArch64);
2427-
init_target!(have_component_arm ARM);
2428-
init_target!(have_component_x86 X86);
2429-
2430-
// PNaCl doesn't provide some of the optional target components, so we
2431-
// manually initialize it here.
2432-
#[cfg(have_component_pnacl)]
2433-
fn init_pnacl() {
2434-
unsafe {
2435-
LLVMInitializePNaClTargetInfo();
2436-
LLVMInitializePNaClTarget();
2437-
LLVMInitializePNaClTargetMC();
2438-
}
2439-
}
2440-
#[cfg(not(have_component_pnacl))]
2441-
fn init_pnacl() { }
2442-
init_pnacl();
2370+
init_target!(llvm_component = "x86",
2371+
LLVMInitializeX86TargetInfo,
2372+
LLVMInitializeX86Target,
2373+
LLVMInitializeX86TargetMC,
2374+
LLVMInitializeX86AsmPrinter,
2375+
LLVMInitializeX86AsmParser);
2376+
init_target!(llvm_component = "arm",
2377+
LLVMInitializeARMTargetInfo,
2378+
LLVMInitializeARMTarget,
2379+
LLVMInitializeARMTargetMC,
2380+
LLVMInitializeARMAsmPrinter,
2381+
LLVMInitializeARMAsmParser);
2382+
init_target!(llvm_component = "aarch64",
2383+
LLVMInitializeAArch64TargetInfo,
2384+
LLVMInitializeAArch64Target,
2385+
LLVMInitializeAArch64TargetMC,
2386+
LLVMInitializeAArch64AsmPrinter,
2387+
LLVMInitializeAArch64AsmParser);
2388+
init_target!(llvm_component = "mips",
2389+
LLVMInitializeMipsTargetInfo,
2390+
LLVMInitializeMipsTarget,
2391+
LLVMInitializeMipsTargetMC,
2392+
LLVMInitializeMipsAsmPrinter,
2393+
LLVMInitializeMipsAsmParser);
2394+
init_target!(llvm_component = "powerpc",
2395+
LLVMInitializePowerPCTargetInfo,
2396+
LLVMInitializePowerPCTarget,
2397+
LLVMInitializePowerPCTargetMC,
2398+
LLVMInitializePowerPCAsmPrinter,
2399+
LLVMInitializePowerPCAsmParser);
2400+
init_target!(llvm_component = "pnacl",
2401+
LLVMInitializePNaClTargetInfo,
2402+
LLVMInitializePNaClTarget,
2403+
LLVMInitializePNaClTargetMC);
24432404
}
24442405

24452406
pub fn last_error() -> Option<String> {

0 commit comments

Comments
 (0)