1
1
//! Conversions from backend-independent data types to/from LLVM FFI types.
2
2
3
- use rustc_codegen_ssa:: common:: { AtomicRmwBinOp , IntPredicate , RealPredicate } ;
3
+ use rustc_codegen_ssa:: common:: { AtomicRmwBinOp , IntPredicate , RealPredicate , TypeKind } ;
4
4
use rustc_middle:: ty:: AtomicOrdering ;
5
5
use rustc_session:: config:: DebugInfo ;
6
6
use rustc_target:: spec:: SymbolVisibility ;
@@ -9,10 +9,22 @@ use crate::llvm;
9
9
10
10
/// Helper trait for converting backend-independent types to LLVM-specific
11
11
/// types, for FFI purposes.
12
+ ///
13
+ /// FIXME(#147327): These trait/method names were chosen to avoid churn in
14
+ /// existing code, but are not great and could probably be made clearer.
12
15
pub ( crate ) trait FromGeneric < T > {
13
16
fn from_generic ( other : T ) -> Self ;
14
17
}
15
18
19
+ /// Helper trait for converting LLVM-specific types to backend-independent
20
+ /// types, for FFI purposes.
21
+ ///
22
+ /// FIXME(#147327): These trait/method names were chosen to avoid churn in
23
+ /// existing code, but are not great and could probably be made clearer.
24
+ pub ( crate ) trait ToGeneric < T > {
25
+ fn to_generic ( & self ) -> T ;
26
+ }
27
+
16
28
impl FromGeneric < SymbolVisibility > for llvm:: Visibility {
17
29
fn from_generic ( visibility : SymbolVisibility ) -> Self {
18
30
match visibility {
@@ -113,3 +125,29 @@ impl FromGeneric<DebugInfo> for llvm::debuginfo::DebugEmissionKind {
113
125
}
114
126
}
115
127
}
128
+
129
+ impl ToGeneric < TypeKind > for llvm:: TypeKind {
130
+ fn to_generic ( & self ) -> TypeKind {
131
+ match self {
132
+ Self :: Void => TypeKind :: Void ,
133
+ Self :: Half => TypeKind :: Half ,
134
+ Self :: Float => TypeKind :: Float ,
135
+ Self :: Double => TypeKind :: Double ,
136
+ Self :: X86_FP80 => TypeKind :: X86_FP80 ,
137
+ Self :: FP128 => TypeKind :: FP128 ,
138
+ Self :: PPC_FP128 => TypeKind :: PPC_FP128 ,
139
+ Self :: Label => TypeKind :: Label ,
140
+ Self :: Integer => TypeKind :: Integer ,
141
+ Self :: Function => TypeKind :: Function ,
142
+ Self :: Struct => TypeKind :: Struct ,
143
+ Self :: Array => TypeKind :: Array ,
144
+ Self :: Pointer => TypeKind :: Pointer ,
145
+ Self :: Vector => TypeKind :: Vector ,
146
+ Self :: Metadata => TypeKind :: Metadata ,
147
+ Self :: Token => TypeKind :: Token ,
148
+ Self :: ScalableVector => TypeKind :: ScalableVector ,
149
+ Self :: BFloat => TypeKind :: BFloat ,
150
+ Self :: X86_AMX => TypeKind :: X86_AMX ,
151
+ }
152
+ }
153
+ }
0 commit comments