@@ -5,10 +5,33 @@ use rustc::ty::{self, Ty};
55use rustc:: ty:: layout:: { self , HasTyCtxt } ;
66use syntax:: source_map:: Span ;
77use crate :: traits:: * ;
8+ use crate :: mir:: operand:: OperandRef ;
89
910use super :: FunctionCx ;
1011
1112impl < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > FunctionCx < ' a , ' tcx , Bx > {
13+ pub fn eval_mir_constant_to_operand (
14+ & mut self ,
15+ bx : & mut Bx ,
16+ constant : & mir:: Constant < ' tcx > ,
17+ ) -> Result < OperandRef < ' tcx , Bx :: Value > , ErrorHandled > {
18+ match constant. literal . val {
19+ mir:: interpret:: ConstValue :: Unevaluated ( def_id, substs)
20+ if self . cx . tcx ( ) . is_static ( def_id) => {
21+ assert ! ( substs. is_empty( ) , "we don't support generic statics yet" ) ;
22+ let static_ = bx. get_static ( def_id) ;
23+ // we treat operands referring to statics as if they were `&STATIC` instead
24+ let ptr_ty = self . cx . tcx ( ) . mk_mut_ptr ( self . monomorphize ( & constant. literal . ty ) ) ;
25+ let layout = bx. layout_of ( ptr_ty) ;
26+ Ok ( OperandRef :: from_immediate_or_packed_pair ( bx, static_, layout) )
27+ }
28+ _ => {
29+ let val = self . eval_mir_constant ( constant) ?;
30+ Ok ( OperandRef :: from_const ( bx, val) )
31+ }
32+ }
33+ }
34+
1235 pub fn eval_mir_constant (
1336 & mut self ,
1437 constant : & mir:: Constant < ' tcx > ,
0 commit comments