mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Use LLVM-C APIs for getting/setting visibility
This commit is contained in:
parent
96993a9b5e
commit
d976ca8701
@ -161,9 +161,9 @@ pub enum Linkage {
|
|||||||
LinkerPrivateWeakLinkage = 16,
|
LinkerPrivateWeakLinkage = 16,
|
||||||
}
|
}
|
||||||
|
|
||||||
// LLVMRustVisibility
|
/// Must match the layout of `LLVMVisibility`.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq, TryFromU32)]
|
||||||
pub enum Visibility {
|
pub enum Visibility {
|
||||||
Default = 0,
|
Default = 0,
|
||||||
Hidden = 1,
|
Hidden = 1,
|
||||||
@ -984,6 +984,8 @@ unsafe extern "C" {
|
|||||||
pub fn LLVMGetLinkage(Global: &Value) -> RawEnum<Linkage>;
|
pub fn LLVMGetLinkage(Global: &Value) -> RawEnum<Linkage>;
|
||||||
pub fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage);
|
pub fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage);
|
||||||
pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
|
pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
|
||||||
|
pub fn LLVMGetVisibility(Global: &Value) -> RawEnum<Visibility>;
|
||||||
|
pub fn LLVMSetVisibility(Global: &Value, Viz: Visibility);
|
||||||
pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
|
pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
|
||||||
pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
|
pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
|
||||||
pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
|
pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
|
||||||
@ -1559,8 +1561,6 @@ unsafe extern "C" {
|
|||||||
) -> bool;
|
) -> bool;
|
||||||
|
|
||||||
// Operations on global variables, functions, and aliases (globals)
|
// Operations on global variables, functions, and aliases (globals)
|
||||||
pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
|
|
||||||
pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
|
|
||||||
pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
|
pub fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
|
||||||
|
|
||||||
// Operations on global variables
|
// Operations on global variables
|
||||||
|
@ -243,12 +243,12 @@ pub fn set_linkage(llglobal: &Value, linkage: Linkage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_visibility(llglobal: &Value) -> Visibility {
|
pub fn get_visibility(llglobal: &Value) -> Visibility {
|
||||||
unsafe { LLVMRustGetVisibility(llglobal) }
|
unsafe { LLVMGetVisibility(llglobal) }.to_rust()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_visibility(llglobal: &Value, visibility: Visibility) {
|
pub fn set_visibility(llglobal: &Value, visibility: Visibility) {
|
||||||
unsafe {
|
unsafe {
|
||||||
LLVMRustSetVisibility(llglobal, visibility);
|
LLVMSetVisibility(llglobal, visibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1646,45 +1646,6 @@ extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class LLVMRustVisibility {
|
|
||||||
Default = 0,
|
|
||||||
Hidden = 1,
|
|
||||||
Protected = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
static LLVMRustVisibility toRust(LLVMVisibility Vis) {
|
|
||||||
switch (Vis) {
|
|
||||||
case LLVMDefaultVisibility:
|
|
||||||
return LLVMRustVisibility::Default;
|
|
||||||
case LLVMHiddenVisibility:
|
|
||||||
return LLVMRustVisibility::Hidden;
|
|
||||||
case LLVMProtectedVisibility:
|
|
||||||
return LLVMRustVisibility::Protected;
|
|
||||||
}
|
|
||||||
report_fatal_error("Invalid LLVMRustVisibility value!");
|
|
||||||
}
|
|
||||||
|
|
||||||
static LLVMVisibility fromRust(LLVMRustVisibility Vis) {
|
|
||||||
switch (Vis) {
|
|
||||||
case LLVMRustVisibility::Default:
|
|
||||||
return LLVMDefaultVisibility;
|
|
||||||
case LLVMRustVisibility::Hidden:
|
|
||||||
return LLVMHiddenVisibility;
|
|
||||||
case LLVMRustVisibility::Protected:
|
|
||||||
return LLVMProtectedVisibility;
|
|
||||||
}
|
|
||||||
report_fatal_error("Invalid LLVMRustVisibility value!");
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" LLVMRustVisibility LLVMRustGetVisibility(LLVMValueRef V) {
|
|
||||||
return toRust(LLVMGetVisibility(V));
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMRustSetVisibility(LLVMValueRef V,
|
|
||||||
LLVMRustVisibility RustVisibility) {
|
|
||||||
LLVMSetVisibility(V, fromRust(RustVisibility));
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void LLVMRustSetDSOLocal(LLVMValueRef Global, bool is_dso_local) {
|
extern "C" void LLVMRustSetDSOLocal(LLVMValueRef Global, bool is_dso_local) {
|
||||||
unwrap<GlobalValue>(Global)->setDSOLocal(is_dso_local);
|
unwrap<GlobalValue>(Global)->setDSOLocal(is_dso_local);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ pub(crate) fn try_from_u32(s: Structure<'_>) -> TokenStream {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.construct(|_, _| -> TokenStream { unreachable!() }))
|
.map(|v| v.construct(|_, _| -> TokenStream { unreachable!() }))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
|
||||||
|
#[allow(keyword_idents_2024)]
|
||||||
s.gen_impl(quote! {
|
s.gen_impl(quote! {
|
||||||
// The surrounding code might have shadowed these identifiers.
|
// The surrounding code might have shadowed these identifiers.
|
||||||
use ::core::convert::TryFrom;
|
use ::core::convert::TryFrom;
|
||||||
|
Loading…
Reference in New Issue
Block a user