@@ -5,10 +5,33 @@ use rustc::ty::{self, Ty};
5
5
use rustc:: ty:: layout:: { self , HasTyCtxt } ;
6
6
use syntax:: source_map:: Span ;
7
7
use crate :: traits:: * ;
8
+ use crate :: mir:: operand:: OperandRef ;
8
9
9
10
use super :: FunctionCx ;
10
11
11
12
impl < ' 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
+
12
35
pub fn eval_mir_constant (
13
36
& mut self ,
14
37
constant : & mir:: Constant < ' tcx > ,
0 commit comments