rust/src/librustc_trans/trans/mir/constant.rs

61 lines
1.9 KiB
Rust
Raw Normal View History

// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use middle::ty::{Ty, HasTypeFlags};
use rustc::middle::const_eval::ConstVal;
use rustc::mir::repr as mir;
use trans::consts;
use trans::common::{self, Block};
2015-11-12 16:12:50 -06:00
use super::operand::OperandRef;
use super::MirContext;
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
2015-11-08 12:11:11 -06:00
pub fn trans_constval(&mut self,
bcx: Block<'bcx, 'tcx>,
cv: &ConstVal,
ty: Ty<'tcx>)
-> OperandRef<'tcx>
2015-11-08 12:11:11 -06:00
{
2015-11-12 16:12:50 -06:00
use super::operand::OperandValue::{Ref, Immediate};
2015-11-08 12:11:11 -06:00
let ccx = bcx.ccx();
let val = consts::trans_constval(ccx, cv, ty, bcx.fcx.param_substs);
let val = if common::type_is_immediate(ccx, ty) {
Immediate(val)
} else {
Ref(val)
};
assert!(!ty.has_erasable_regions());
OperandRef {
ty: ty,
val: val
2015-11-08 12:11:11 -06:00
}
}
pub fn trans_constant(&mut self,
bcx: Block<'bcx, 'tcx>,
constant: &mir::Constant<'tcx>)
-> OperandRef<'tcx>
{
let constant_ty = bcx.monomorphize(&constant.ty);
match constant.literal {
mir::Literal::Item { .. } => {
unimplemented!()
}
mir::Literal::Value { ref value } => {
2015-11-08 12:11:11 -06:00
self.trans_constval(bcx, value, constant_ty)
}
}
}
}