11//! Conversions from backend-independent data types to/from LLVM FFI types.
22
3- use rustc_codegen_ssa:: common:: { AtomicRmwBinOp , IntPredicate , RealPredicate } ;
3+ use rustc_codegen_ssa:: common:: { AtomicRmwBinOp , IntPredicate , RealPredicate , TypeKind } ;
44use rustc_middle:: ty:: AtomicOrdering ;
55use rustc_session:: config:: DebugInfo ;
66use rustc_target:: spec:: SymbolVisibility ;
@@ -9,10 +9,22 @@ use crate::llvm;
99
1010/// Helper trait for converting backend-independent types to LLVM-specific
1111/// 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.
1215pub ( crate ) trait FromGeneric < T > {
1316 fn from_generic ( other : T ) -> Self ;
1417}
1518
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+
1628impl FromGeneric < SymbolVisibility > for llvm:: Visibility {
1729 fn from_generic ( visibility : SymbolVisibility ) -> Self {
1830 match visibility {
@@ -113,3 +125,29 @@ impl FromGeneric<DebugInfo> for llvm::debuginfo::DebugEmissionKind {
113125 }
114126 }
115127}
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