]> git.lizzy.rs Git - rust.git/commitdiff
[MIR trans] Translate statics
authorSimonas Kazlauskas <git@kazlauskas.me>
Tue, 10 Nov 2015 21:22:57 +0000 (23:22 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Tue, 10 Nov 2015 22:15:16 +0000 (00:15 +0200)
Fixes #29578

src/librustc_trans/trans/common.rs
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/mir/lvalue.rs

index 8d6ba53dd222d9b52c220887d5cb444524368137..7dda864d1ed9c5b656ccabb0d7e97756c1273e7d 100644 (file)
@@ -1214,3 +1214,13 @@ pub fn shift_mask_val<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
     }
 }
 
+pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
+                            did: DefId,
+                            ty: Ty<'tcx>)
+                            -> ValueRef {
+    if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
+        base::get_item_val(ccx, node_id)
+    } else {
+        base::trans_external_path(ccx, did, ty)
+    }
+}
index 90faef51c2c6c6a3444d2afd3ae3dbf173ef4cb8..b849888cf7cfbbe7488ef77c0fa58284c78a85aa 100644 (file)
@@ -29,8 +29,8 @@
 use middle::def_id::DefId;
 use trans::{adt, closure, debuginfo, expr, inline, machine};
 use trans::base::{self, push_ctxt};
+use trans::common::{self, type_is_sized, ExprOrMethodCall, node_id_substs, C_nil, const_get_elt};
 use trans::common::{CrateContext, C_integral, C_floating, C_bool, C_str_slice, C_bytes, val_ty};
-use trans::common::{type_is_sized, ExprOrMethodCall, node_id_substs, C_nil, const_get_elt};
 use trans::common::{C_struct, C_undef, const_to_opt_int, const_to_opt_uint, VariantInfo, C_uint};
 use trans::common::{type_is_fat_ptr, Field, C_vector, C_array, C_null, ExprId, MethodCallKey};
 use trans::declare;
@@ -795,7 +795,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             }
             let opt_def = cx.tcx().def_map.borrow().get(&cur.id).map(|d| d.full_def());
             if let Some(def::DefStatic(def_id, _)) = opt_def {
-                get_static_val(cx, def_id, ety)
+                common::get_static_val(cx, def_id, ety)
             } else {
                 // If this isn't the address of a static, then keep going through
                 // normal constant evaluation.
@@ -1075,15 +1075,3 @@ pub fn trans_static(ccx: &CrateContext,
         Ok(g)
     }
 }
-
-
-fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
-                            did: DefId,
-                            ty: Ty<'tcx>)
-                            -> ValueRef {
-    if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
-        base::get_item_val(ccx, node_id)
-    } else {
-        base::trans_external_path(ccx, did, ty)
-    }
-}
index 1ce7b55a9c686400d077d7eb44ecd88091212427..98c1566997616e34a36f8f06f7ae50cea352314d 100644 (file)
@@ -65,7 +65,10 @@ pub fn trans_lvalue(&mut self,
                     tcx.sess.bug(&format!("using operand temp {:?} as lvalue", lvalue)),
             },
             mir::Lvalue::Arg(index) => self.args[index as usize],
-            mir::Lvalue::Static(_def_id) => unimplemented!(),
+            mir::Lvalue::Static(def_id) => {
+                let const_ty = self.mir.lvalue_ty(tcx, lvalue);
+                LvalueRef::new(common::get_static_val(ccx, def_id, const_ty.to_ty(tcx)), const_ty)
+            },
             mir::Lvalue::ReturnPointer => {
                 let return_ty = bcx.monomorphize(&self.mir.return_ty);
                 let llval = fcx.get_ret_slot(bcx, return_ty, "return");