Move const val handling to constant.rs
This commit is contained in:
parent
a95a6729b1
commit
4694fa4f3d
34
src/base.rs
34
src/base.rs
@ -497,8 +497,6 @@ fn trans_place<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, place: &Place<'tcx>)
|
||||
}
|
||||
|
||||
fn trans_operand<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx>, operand: &Operand<'tcx>) -> CValue<'tcx> {
|
||||
use rustc::mir::interpret::{Scalar, ConstValue, GlobalId};
|
||||
|
||||
match operand {
|
||||
Operand::Move(place) |
|
||||
Operand::Copy(place) => {
|
||||
@ -506,37 +504,7 @@ fn trans_operand<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx>, operand: &Operand<'tcx
|
||||
cplace.to_cvalue(fx)
|
||||
},
|
||||
Operand::Constant(const_) => {
|
||||
let value = match const_.literal {
|
||||
Literal::Value { value } => value,
|
||||
Literal::Promoted { index } => fx
|
||||
.tcx
|
||||
.const_eval(ParamEnv::reveal_all().and(GlobalId {
|
||||
instance: fx.instance,
|
||||
promoted: Some(index),
|
||||
}))
|
||||
.unwrap(),
|
||||
};
|
||||
|
||||
let layout = fx.layout_of(const_.ty);
|
||||
match const_.ty.sty {
|
||||
TypeVariants::TyBool => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as u64 as i64)
|
||||
}
|
||||
TypeVariants::TyUint(_) => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as u64 as i64)
|
||||
}
|
||||
TypeVariants::TyInt(_) => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as i128 as i64)
|
||||
}
|
||||
TypeVariants::TyFnDef(def_id, substs) => {
|
||||
let func_ref = fx.get_function_ref(Instance::new(def_id, substs));
|
||||
CValue::Func(func_ref, fx.layout_of(const_.ty))
|
||||
}
|
||||
_ => unimplemented!("value {:?} ty {:?}", value, const_.ty),
|
||||
}
|
||||
::constant::trans_constant(fx, const_)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
src/constant.rs
Normal file
37
src/constant.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use prelude::*;
|
||||
|
||||
pub fn trans_constant<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, const_: &Constant<'tcx>) -> CValue<'tcx> {
|
||||
use rustc::mir::interpret::{Scalar, ConstValue, GlobalId};
|
||||
|
||||
let value = match const_.literal {
|
||||
Literal::Value { value } => value,
|
||||
Literal::Promoted { index } => fx
|
||||
.tcx
|
||||
.const_eval(ParamEnv::reveal_all().and(GlobalId {
|
||||
instance: fx.instance,
|
||||
promoted: Some(index),
|
||||
}))
|
||||
.unwrap(),
|
||||
};
|
||||
|
||||
let layout = fx.layout_of(const_.ty);
|
||||
match const_.ty.sty {
|
||||
TypeVariants::TyBool => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as u64 as i64)
|
||||
}
|
||||
TypeVariants::TyUint(_) => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as u64 as i64)
|
||||
}
|
||||
TypeVariants::TyInt(_) => {
|
||||
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
|
||||
CValue::const_val(fx, const_.ty, bits as i128 as i64)
|
||||
}
|
||||
TypeVariants::TyFnDef(def_id, substs) => {
|
||||
let func_ref = fx.get_function_ref(Instance::new(def_id, substs));
|
||||
CValue::Func(func_ref, fx.layout_of(const_.ty))
|
||||
}
|
||||
_ => unimplemented!("value {:?} ty {:?}", value, const_.ty),
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
mod base;
|
||||
mod constant;
|
||||
mod common;
|
||||
mod pretty_clif;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user