]> git.lizzy.rs Git - rust.git/commitdiff
trans: split trans_consume off from trans_operand.
authorEduard Burtescu <edy.burt@gmail.com>
Thu, 9 Jun 2016 15:13:16 +0000 (18:13 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Mon, 20 Jun 2016 20:18:21 +0000 (23:18 +0300)
src/librustc_trans/mir/operand.rs

index 80ff0a92d8d4630e517ced286bf62f27c1def5cb..980db76d632c12da936f2df4d4f217c109dc5fc2 100644 (file)
@@ -164,56 +164,66 @@ pub fn trans_load(&mut self,
         OperandRef { val: val, ty: ty }
     }
 
-    pub fn trans_operand(&mut self,
+    pub fn trans_consume(&mut self,
                          bcx: &BlockAndBuilder<'bcx, 'tcx>,
-                         operand: &mir::Operand<'tcx>)
+                         lvalue: &mir::Lvalue<'tcx>)
                          -> OperandRef<'tcx>
     {
-        debug!("trans_operand(operand={:?})", operand);
+        debug!("trans_consume(lvalue={:?})", lvalue);
 
-        match *operand {
-            mir::Operand::Consume(ref lvalue) => {
-                // watch out for temporaries that do not have an
-                // alloca; they are handled somewhat differently
-                if let &mir::Lvalue::Temp(index) = lvalue {
-                    match self.temps[index] {
-                        TempRef::Operand(Some(o)) => {
-                            return o;
-                        }
-                        TempRef::Operand(None) => {
-                            bug!("use of {:?} before def", lvalue);
-                        }
-                        TempRef::Lvalue(..) => {
-                            // use path below
-                        }
-                    }
+        // watch out for temporaries that do not have an
+        // alloca; they are handled somewhat differently
+        if let &mir::Lvalue::Temp(index) = lvalue {
+            match self.temps[index] {
+                TempRef::Operand(Some(o)) => {
+                    return o;
+                }
+                TempRef::Operand(None) => {
+                    bug!("use of {:?} before def", lvalue);
                 }
+                TempRef::Lvalue(..) => {
+                    // use path below
+                }
+            }
+        }
 
-                // Moves out of pair fields are trivial.
-                if let &mir::Lvalue::Projection(ref proj) = lvalue {
-                    if let mir::Lvalue::Temp(index) = proj.base {
-                        let temp_ref = &self.temps[index];
-                        if let &TempRef::Operand(Some(o)) = temp_ref {
-                            match (o.val, &proj.elem) {
-                                (OperandValue::Pair(a, b),
-                                 &mir::ProjectionElem::Field(ref f, ty)) => {
-                                    let llval = [a, b][f.index()];
-                                    return OperandRef {
-                                        val: OperandValue::Immediate(llval),
-                                        ty: bcx.monomorphize(&ty)
-                                    };
-                                }
-                                _ => {}
-                            }
+        // Moves out of pair fields are trivial.
+        if let &mir::Lvalue::Projection(ref proj) = lvalue {
+            if let mir::Lvalue::Temp(index) = proj.base {
+                let temp_ref = &self.temps[index];
+                if let &TempRef::Operand(Some(o)) = temp_ref {
+                    match (o.val, &proj.elem) {
+                        (OperandValue::Pair(a, b),
+                         &mir::ProjectionElem::Field(ref f, ty)) => {
+                            let llval = [a, b][f.index()];
+                            return OperandRef {
+                                val: OperandValue::Immediate(llval),
+                                ty: bcx.monomorphize(&ty)
+                            };
                         }
+                        _ => {}
                     }
                 }
+            }
+        }
+
+        // for most lvalues, to consume them we just load them
+        // out from their home
+        let tr_lvalue = self.trans_lvalue(bcx, lvalue);
+        let ty = tr_lvalue.ty.to_ty(bcx.tcx());
+        self.trans_load(bcx, tr_lvalue.llval, ty)
+    }
 
-                // for most lvalues, to consume them we just load them
-                // out from their home
-                let tr_lvalue = self.trans_lvalue(bcx, lvalue);
-                let ty = tr_lvalue.ty.to_ty(bcx.tcx());
-                self.trans_load(bcx, tr_lvalue.llval, ty)
+    pub fn trans_operand(&mut self,
+                         bcx: &BlockAndBuilder<'bcx, 'tcx>,
+                         operand: &mir::Operand<'tcx>)
+                         -> OperandRef<'tcx>
+    {
+        debug!("trans_operand(operand={:?})", operand);
+
+        match *operand {
+            mir::Operand::Consume(ref lvalue) => {
+                self.trans_consume(bcx, lvalue)
             }
 
             mir::Operand::Constant(ref constant) => {