@@ -41,24 +41,24 @@ use super::MirContext;
41
41
/// The LLVM type might not be the same for a single Rust type,
42
42
/// e.g. each enum variant would have its own LLVM struct type.
43
43
#[ derive( Copy , Clone ) ]
44
- struct Const < ' tcx > {
45
- llval : ValueRef ,
46
- ty : Ty < ' tcx >
44
+ pub struct Const < ' tcx > {
45
+ pub llval : ValueRef ,
46
+ pub ty : Ty < ' tcx >
47
47
}
48
48
49
49
impl < ' tcx > Const < ' tcx > {
50
- fn new ( llval : ValueRef , ty : Ty < ' tcx > ) -> Const < ' tcx > {
50
+ pub fn new ( llval : ValueRef , ty : Ty < ' tcx > ) -> Const < ' tcx > {
51
51
Const {
52
52
llval : llval,
53
53
ty : ty
54
54
}
55
55
}
56
56
57
57
/// Translate ConstVal into a LLVM constant value.
58
- fn from_constval < ' a > ( ccx : & CrateContext < ' a , ' tcx > ,
59
- cv : ConstVal ,
60
- ty : Ty < ' tcx > )
61
- -> Const < ' tcx > {
58
+ pub fn from_constval < ' a > ( ccx : & CrateContext < ' a , ' tcx > ,
59
+ cv : ConstVal ,
60
+ ty : Ty < ' tcx > )
61
+ -> Const < ' tcx > {
62
62
let llty = type_of:: type_of ( ccx, ty) ;
63
63
let val = match cv {
64
64
ConstVal :: Float ( v) => C_floating_f64 ( v, llty) ,
@@ -110,7 +110,7 @@ impl<'tcx> Const<'tcx> {
110
110
}
111
111
}
112
112
113
- fn to_operand < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> OperandRef < ' tcx > {
113
+ pub fn to_operand < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> OperandRef < ' tcx > {
114
114
let llty = type_of:: immediate_type_of ( ccx, self . ty ) ;
115
115
let llvalty = val_ty ( self . llval ) ;
116
116
@@ -799,7 +799,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
799
799
pub fn trans_constant ( & mut self ,
800
800
bcx : & BlockAndBuilder < ' bcx , ' tcx > ,
801
801
constant : & mir:: Constant < ' tcx > )
802
- -> OperandRef < ' tcx >
802
+ -> Const < ' tcx >
803
803
{
804
804
let ty = bcx. monomorphize ( & constant. ty ) ;
805
805
let result = match constant. literal . clone ( ) {
@@ -808,10 +808,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
808
808
// types, which would not work with MirConstContext.
809
809
if common:: type_is_zero_size ( bcx. ccx ( ) , ty) {
810
810
let llty = type_of:: type_of ( bcx. ccx ( ) , ty) ;
811
- return OperandRef {
812
- val : OperandValue :: Immediate ( C_null ( llty) ) ,
813
- ty : ty
814
- } ;
811
+ return Const :: new ( C_null ( llty) , ty) ;
815
812
}
816
813
817
814
let substs = bcx. tcx ( ) . mk_substs ( bcx. monomorphize ( substs) ) ;
@@ -827,7 +824,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
827
824
}
828
825
} ;
829
826
830
- let val = match result {
827
+ match result {
831
828
Ok ( v) => v,
832
829
Err ( ConstEvalFailure :: Compiletime ( _) ) => {
833
830
// We've errored, so we don't have to produce working code.
@@ -839,14 +836,6 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
839
836
"MIR constant {:?} results in runtime panic: {}" ,
840
837
constant, err. description( ) )
841
838
}
842
- } ;
843
-
844
- let operand = val. to_operand ( bcx. ccx ( ) ) ;
845
- if let OperandValue :: Ref ( ptr) = operand. val {
846
- // If this is a OperandValue::Ref to an immediate constant, load it.
847
- self . trans_load ( bcx, ptr, operand. ty )
848
- } else {
849
- operand
850
839
}
851
840
}
852
841
}
0 commit comments