2018-11-07 06:29:38 -06:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
|
|
use rustc::mir::interpret::{
|
2018-12-14 06:42:26 -06:00
|
|
|
read_target_uint, AllocId, AllocKind, Allocation, ConstValue, EvalResult, GlobalId, Scalar,
|
2018-08-30 13:14:56 -05:00
|
|
|
};
|
2019-03-21 14:24:46 -05:00
|
|
|
use rustc::ty::Const;
|
2018-11-07 06:32:02 -06:00
|
|
|
use rustc_mir::interpret::{
|
2019-02-21 08:06:09 -06:00
|
|
|
EvalContext, ImmTy, MPlaceTy, Machine, Memory, MemoryKind, OpTy, PlaceTy, Pointer,
|
|
|
|
StackPopCleanup,
|
2018-11-07 06:32:02 -06:00
|
|
|
};
|
2018-11-07 06:29:38 -06:00
|
|
|
|
|
|
|
use cranelift_module::*;
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
2018-08-13 05:13:43 -05:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct ConstantCx {
|
2018-08-13 11:31:26 -05:00
|
|
|
todo: HashSet<TodoItem>,
|
2018-08-13 05:13:43 -05:00
|
|
|
done: HashSet<DataId>,
|
|
|
|
}
|
|
|
|
|
2018-08-13 11:31:26 -05:00
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
|
|
enum TodoItem {
|
|
|
|
Alloc(AllocId),
|
|
|
|
Static(DefId),
|
|
|
|
}
|
|
|
|
|
2018-08-13 05:13:43 -05:00
|
|
|
impl ConstantCx {
|
2018-08-13 11:04:39 -05:00
|
|
|
pub fn finalize<'a, 'tcx: 'a, B: Backend>(
|
|
|
|
mut self,
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
module: &mut Module<B>,
|
|
|
|
) {
|
2018-08-15 08:28:08 -05:00
|
|
|
//println!("todo {:?}", self.todo);
|
2018-08-13 09:58:07 -05:00
|
|
|
define_all_allocs(tcx, module, &mut self);
|
2018-08-15 08:28:08 -05:00
|
|
|
//println!("done {:?}", self.done);
|
2018-09-09 07:45:23 -05:00
|
|
|
self.done.clear();
|
2018-08-13 05:13:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:52:43 -05:00
|
|
|
pub fn codegen_static<'a, 'tcx: 'a>(ccx: &mut ConstantCx, def_id: DefId) {
|
|
|
|
ccx.todo.insert(TodoItem::Static(def_id));
|
2018-08-13 05:13:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn codegen_static_ref<'a, 'tcx: 'a>(
|
2018-08-14 13:31:16 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
2018-08-13 05:13:43 -05:00
|
|
|
static_: &Static<'tcx>,
|
|
|
|
) -> CPlace<'tcx> {
|
2019-03-11 14:36:29 -05:00
|
|
|
let linkage = crate::linkage::get_static_ref_linkage(fx.tcx, static_.def_id);
|
|
|
|
let data_id = data_id_for_static(fx.tcx, fx.module, static_.def_id, linkage);
|
2018-08-13 11:31:26 -05:00
|
|
|
cplace_for_dataid(fx, static_.ty, data_id)
|
2018-08-13 05:13:43 -05:00
|
|
|
}
|
2018-07-14 09:45:20 -05:00
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
pub fn trans_promoted<'a, 'tcx: 'a>(
|
2018-08-14 13:31:16 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
2018-07-31 05:25:16 -05:00
|
|
|
promoted: Promoted,
|
2019-02-24 11:07:20 -06:00
|
|
|
dest_ty: Ty<'tcx>,
|
2018-07-31 05:25:16 -05:00
|
|
|
) -> CPlace<'tcx> {
|
2019-02-24 11:07:20 -06:00
|
|
|
match fx
|
2018-07-30 09:57:40 -05:00
|
|
|
.tcx
|
|
|
|
.const_eval(ParamEnv::reveal_all().and(GlobalId {
|
|
|
|
instance: fx.instance,
|
|
|
|
promoted: Some(promoted),
|
2018-10-10 12:07:13 -05:00
|
|
|
}))
|
2019-02-24 11:07:20 -06:00
|
|
|
{
|
|
|
|
Ok(const_) => {
|
|
|
|
let cplace = trans_const_place(fx, const_);
|
|
|
|
debug_assert_eq!(cplace.layout(), fx.layout_of(dest_ty));
|
|
|
|
cplace
|
|
|
|
}
|
|
|
|
Err(_) => crate::trap::trap_unreachable_ret_place(fx, fx.layout_of(dest_ty)),
|
|
|
|
}
|
2018-07-30 09:57:40 -05:00
|
|
|
}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
pub fn trans_constant<'a, 'tcx: 'a>(
|
2018-08-14 13:31:16 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
2018-07-31 05:25:16 -05:00
|
|
|
constant: &Constant<'tcx>,
|
|
|
|
) -> CValue<'tcx> {
|
2019-03-21 14:24:46 -05:00
|
|
|
let const_ = force_eval_const(fx, &constant.literal);
|
2018-07-30 09:57:40 -05:00
|
|
|
trans_const_value(fx, const_)
|
|
|
|
}
|
|
|
|
|
2018-10-06 06:50:31 -05:00
|
|
|
pub fn force_eval_const<'a, 'tcx: 'a>(
|
2019-03-21 14:24:46 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
|
|
|
const_: &'tcx Const,
|
2019-01-06 08:27:20 -06:00
|
|
|
) -> Const<'tcx> {
|
2019-03-21 14:24:46 -05:00
|
|
|
match const_.val {
|
|
|
|
ConstValue::Unevaluated(def_id, ref substs) => {
|
2018-07-21 11:44:34 -05:00
|
|
|
let param_env = ParamEnv::reveal_all();
|
2019-03-21 14:24:46 -05:00
|
|
|
let substs = fx.monomorphize(substs);
|
2018-07-21 11:44:34 -05:00
|
|
|
let instance = Instance::resolve(fx.tcx, param_env, def_id, substs).unwrap();
|
|
|
|
let cid = GlobalId {
|
|
|
|
instance,
|
|
|
|
promoted: None,
|
|
|
|
};
|
|
|
|
fx.tcx.const_eval(param_env.and(cid)).unwrap()
|
2018-07-31 05:25:16 -05:00
|
|
|
}
|
2019-03-21 14:24:46 -05:00
|
|
|
_ => *fx.monomorphize(&const_),
|
2018-07-30 09:57:40 -05:00
|
|
|
}
|
|
|
|
}
|
2018-07-14 09:45:20 -05:00
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
fn trans_const_value<'a, 'tcx: 'a>(
|
2018-08-14 13:31:16 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
2019-01-06 08:27:20 -06:00
|
|
|
const_: Const<'tcx>,
|
2018-07-31 05:25:16 -05:00
|
|
|
) -> CValue<'tcx> {
|
2018-07-18 06:46:56 -05:00
|
|
|
let ty = fx.monomorphize(&const_.ty);
|
|
|
|
let layout = fx.layout_of(ty);
|
|
|
|
match ty.sty {
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::Bool => {
|
|
|
|
let bits = const_.val.try_to_bits(layout.size).unwrap();
|
2018-07-18 06:46:56 -05:00
|
|
|
CValue::const_val(fx, ty, bits as u64 as i64)
|
2018-07-14 09:45:20 -05:00
|
|
|
}
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::Uint(_) => {
|
|
|
|
let bits = const_.val.try_to_bits(layout.size).unwrap();
|
2018-07-18 06:46:56 -05:00
|
|
|
CValue::const_val(fx, ty, bits as u64 as i64)
|
2018-07-14 09:45:20 -05:00
|
|
|
}
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::Int(_) => {
|
|
|
|
let bits = const_.val.try_to_bits(layout.size).unwrap();
|
2019-03-11 14:44:05 -05:00
|
|
|
CValue::const_val(fx, ty, rustc::mir::interpret::sign_extend(bits, layout.size) as i128 as i64)
|
2018-07-14 09:45:20 -05:00
|
|
|
}
|
2019-02-21 08:06:09 -06:00
|
|
|
ty::FnDef(_def_id, _substs) => CValue::ByRef(
|
|
|
|
fx.bcx
|
|
|
|
.ins()
|
|
|
|
.iconst(fx.pointer_type, fx.pointer_type.bytes() as i64),
|
|
|
|
layout,
|
|
|
|
),
|
2018-07-31 05:25:16 -05:00
|
|
|
_ => trans_const_place(fx, const_).to_cvalue(fx),
|
2018-07-16 08:13:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 05:25:16 -05:00
|
|
|
fn trans_const_place<'a, 'tcx: 'a>(
|
2018-08-14 13:31:16 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
2019-01-06 08:27:20 -06:00
|
|
|
const_: Const<'tcx>,
|
2018-07-31 05:25:16 -05:00
|
|
|
) -> CPlace<'tcx> {
|
2018-08-30 13:14:56 -05:00
|
|
|
// Adapted from https://github.com/rust-lang/rust/pull/53671/files#diff-e0b58bb6712edaa8595ad7237542c958L551
|
|
|
|
let result = || -> EvalResult<'tcx, &'tcx Allocation> {
|
|
|
|
let mut ecx = EvalContext::new(
|
|
|
|
fx.tcx.at(DUMMY_SP),
|
|
|
|
ty::ParamEnv::reveal_all(),
|
2018-09-24 12:31:46 -05:00
|
|
|
TransPlaceInterpreter,
|
2018-08-30 13:14:56 -05:00
|
|
|
);
|
2018-11-24 05:47:53 -06:00
|
|
|
ecx.push_stack_frame(
|
|
|
|
fx.instance,
|
|
|
|
DUMMY_SP,
|
|
|
|
fx.mir,
|
|
|
|
None,
|
|
|
|
StackPopCleanup::None { cleanup: false },
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
let op = ecx.eval_operand(
|
|
|
|
&Operand::Constant(Box::new(Constant {
|
|
|
|
span: DUMMY_SP,
|
|
|
|
ty: const_.ty,
|
|
|
|
user_ty: None,
|
2019-03-21 14:24:46 -05:00
|
|
|
literal: fx.tcx.mk_const(const_),
|
2018-11-24 05:47:53 -06:00
|
|
|
})),
|
|
|
|
None,
|
|
|
|
)?;
|
2018-12-24 07:50:18 -06:00
|
|
|
let ptr = ecx.allocate(op.layout, MemoryKind::Stack);
|
2018-08-30 13:14:56 -05:00
|
|
|
ecx.copy_op(op, ptr.into())?;
|
2018-10-30 11:58:42 -05:00
|
|
|
let alloc = ecx.memory().get(ptr.to_ptr()?.alloc_id)?;
|
2018-08-30 13:14:56 -05:00
|
|
|
Ok(fx.tcx.intern_const_alloc(alloc.clone()))
|
|
|
|
};
|
|
|
|
let alloc = result().expect("unable to convert ConstValue to Allocation");
|
|
|
|
|
2018-07-30 09:57:40 -05:00
|
|
|
//println!("const value: {:?} allocation: {:?}", value, alloc);
|
2018-08-13 05:13:43 -05:00
|
|
|
let alloc_id = fx.tcx.alloc_map.lock().allocate(alloc);
|
2018-08-13 11:31:26 -05:00
|
|
|
fx.constants.todo.insert(TodoItem::Alloc(alloc_id));
|
|
|
|
let data_id = data_id_for_alloc_id(fx.module, alloc_id);
|
|
|
|
cplace_for_dataid(fx, const_.ty, data_id)
|
2018-07-30 09:57:40 -05:00
|
|
|
}
|
|
|
|
|
2018-08-13 11:31:26 -05:00
|
|
|
fn data_id_for_alloc_id<B: Backend>(module: &mut Module<B>, alloc_id: AllocId) -> DataId {
|
2018-08-13 09:58:07 -05:00
|
|
|
module
|
2019-01-12 05:37:12 -06:00
|
|
|
.declare_data(&format!("__alloc_{}", alloc_id.0), Linkage::Local, false)
|
2018-08-13 09:58:07 -05:00
|
|
|
.unwrap()
|
2018-07-16 08:13:37 -05:00
|
|
|
}
|
|
|
|
|
2018-08-22 05:31:45 -05:00
|
|
|
fn data_id_for_static<'a, 'tcx: 'a, B: Backend>(
|
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
module: &mut Module<B>,
|
|
|
|
def_id: DefId,
|
2018-11-16 13:37:45 -06:00
|
|
|
linkage: Linkage,
|
2018-08-22 05:31:45 -05:00
|
|
|
) -> DataId {
|
2018-08-13 11:31:26 -05:00
|
|
|
let symbol_name = tcx.symbol_name(Instance::mono(tcx, def_id)).as_str();
|
2018-11-09 10:54:28 -06:00
|
|
|
let is_mutable = if let ::rustc::hir::Mutability::MutMutable = tcx.is_static(def_id).unwrap() {
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
!tcx.type_of(def_id)
|
|
|
|
.is_freeze(tcx, ParamEnv::reveal_all(), DUMMY_SP)
|
|
|
|
};
|
2019-03-11 14:36:29 -05:00
|
|
|
|
|
|
|
let data_id = module
|
2018-11-16 13:37:45 -06:00
|
|
|
.declare_data(&*symbol_name, linkage, is_mutable)
|
2019-03-11 14:36:29 -05:00
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
if linkage == Linkage::Preemptible {
|
|
|
|
if let ty::RawPtr(_) = tcx.type_of(def_id).sty {
|
|
|
|
} else {
|
|
|
|
tcx.sess.span_fatal(tcx.def_span(def_id), "must have type `*const T` or `*mut T`")
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut data_ctx = DataContext::new();
|
|
|
|
let zero_bytes = std::iter::repeat(0)
|
|
|
|
.take(pointer_ty(tcx).bytes() as usize)
|
|
|
|
.collect::<Vec<u8>>()
|
|
|
|
.into_boxed_slice();
|
|
|
|
data_ctx.define(zero_bytes);
|
|
|
|
match module.define_data(data_id, &data_ctx) {
|
|
|
|
// Everytime a weak static is referenced, there will be a zero pointer definition,
|
|
|
|
// so duplicate definitions are expected and allowed.
|
|
|
|
Err(ModuleError::DuplicateDefinition(_)) => {}
|
|
|
|
res => res.unwrap(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data_id
|
2018-08-13 11:31:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn cplace_for_dataid<'a, 'tcx: 'a>(
|
2018-08-14 13:31:16 -05:00
|
|
|
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
|
2018-08-13 11:31:26 -05:00
|
|
|
ty: Ty<'tcx>,
|
|
|
|
data_id: DataId,
|
|
|
|
) -> CPlace<'tcx> {
|
|
|
|
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
2018-11-07 06:32:02 -06:00
|
|
|
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
|
2018-08-13 11:31:26 -05:00
|
|
|
let layout = fx.layout_of(fx.monomorphize(&ty));
|
2018-08-22 08:38:10 -05:00
|
|
|
assert!(!layout.is_unsized(), "unsized statics aren't supported");
|
|
|
|
CPlace::Addr(global_ptr, None, layout)
|
2018-08-13 09:58:07 -05:00
|
|
|
}
|
2018-07-16 08:13:37 -05:00
|
|
|
|
2018-08-13 11:04:39 -05:00
|
|
|
fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>(
|
2018-08-13 09:58:07 -05:00
|
|
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
module: &mut Module<B>,
|
|
|
|
cx: &mut ConstantCx,
|
|
|
|
) {
|
2018-10-22 04:06:09 -05:00
|
|
|
let memory = Memory::<TransPlaceInterpreter>::new(tcx.at(DUMMY_SP));
|
2018-08-13 05:13:43 -05:00
|
|
|
|
2018-08-13 11:31:26 -05:00
|
|
|
while let Some(todo_item) = pop_set(&mut cx.todo) {
|
|
|
|
let (data_id, alloc) = match todo_item {
|
|
|
|
TodoItem::Alloc(alloc_id) => {
|
2018-08-15 08:28:08 -05:00
|
|
|
//println!("alloc_id {}", alloc_id);
|
2018-08-13 11:31:26 -05:00
|
|
|
let data_id = data_id_for_alloc_id(module, alloc_id);
|
|
|
|
let alloc = memory.get(alloc_id).unwrap();
|
|
|
|
(data_id, alloc)
|
|
|
|
}
|
|
|
|
TodoItem::Static(def_id) => {
|
2018-08-15 08:28:08 -05:00
|
|
|
//println!("static {:?}", def_id);
|
2019-03-11 14:36:29 -05:00
|
|
|
|
|
|
|
if tcx.is_foreign_item(def_id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-08-13 11:31:26 -05:00
|
|
|
let instance = ty::Instance::mono(tcx, def_id);
|
|
|
|
let cid = GlobalId {
|
|
|
|
instance,
|
|
|
|
promoted: None,
|
|
|
|
};
|
|
|
|
let const_ = tcx.const_eval(ParamEnv::reveal_all().and(cid)).unwrap();
|
|
|
|
|
|
|
|
let alloc = match const_.val {
|
2019-02-26 04:34:38 -06:00
|
|
|
ConstValue::ByRef(ptr, alloc) if ptr.offset.bytes() == 0 => alloc,
|
2018-08-13 11:31:26 -05:00
|
|
|
_ => bug!("static const eval returned {:#?}", const_),
|
|
|
|
};
|
|
|
|
|
2019-03-11 14:36:29 -05:00
|
|
|
// FIXME set correct linkage
|
2018-11-16 13:37:45 -06:00
|
|
|
let data_id = data_id_for_static(tcx, module, def_id, Linkage::Export);
|
2018-08-13 11:31:26 -05:00
|
|
|
(data_id, alloc)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-15 08:28:08 -05:00
|
|
|
//("data_id {}", data_id);
|
2018-08-13 09:26:30 -05:00
|
|
|
if cx.done.contains(&data_id) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-16 08:13:37 -05:00
|
|
|
|
|
|
|
let mut data_ctx = DataContext::new();
|
|
|
|
|
2018-09-05 12:43:42 -05:00
|
|
|
data_ctx.define(alloc.bytes.to_vec().into_boxed_slice());
|
2018-07-16 08:13:37 -05:00
|
|
|
|
2018-10-12 12:23:24 -05:00
|
|
|
for &(offset, (_tag, reloc)) in alloc.relocations.iter() {
|
2019-01-06 10:51:21 -06:00
|
|
|
let addend = {
|
2018-09-16 09:21:07 -05:00
|
|
|
let endianness = tcx.data_layout.endian;
|
|
|
|
let offset = offset.bytes() as usize;
|
|
|
|
let ptr_size = tcx.data_layout.pointer_size;
|
|
|
|
let bytes = &alloc.bytes[offset..offset + ptr_size.bytes() as usize];
|
|
|
|
read_target_uint(endianness, bytes).unwrap()
|
|
|
|
};
|
|
|
|
|
2018-08-13 12:02:42 -05:00
|
|
|
let data_id = match tcx.alloc_map.lock().get(reloc).unwrap() {
|
2018-12-14 06:42:26 -06:00
|
|
|
AllocKind::Function(instance) => {
|
2019-01-06 10:51:21 -06:00
|
|
|
assert_eq!(addend, 0);
|
2019-01-02 05:20:32 -06:00
|
|
|
let func_id = crate::abi::import_function(tcx, module, instance);
|
2018-09-16 09:21:07 -05:00
|
|
|
let local_func_id = module.declare_func_in_data(func_id, &mut data_ctx);
|
2019-01-06 10:51:21 -06:00
|
|
|
data_ctx.write_function_addr(offset.bytes() as u32, local_func_id);
|
2018-09-16 09:21:07 -05:00
|
|
|
continue;
|
2018-09-26 08:40:11 -05:00
|
|
|
}
|
2018-12-14 06:42:26 -06:00
|
|
|
AllocKind::Memory(_) => {
|
2018-08-13 12:02:42 -05:00
|
|
|
cx.todo.insert(TodoItem::Alloc(reloc));
|
|
|
|
data_id_for_alloc_id(module, reloc)
|
|
|
|
}
|
2018-12-14 06:42:26 -06:00
|
|
|
AllocKind::Static(def_id) => {
|
2018-08-13 12:02:42 -05:00
|
|
|
cx.todo.insert(TodoItem::Static(def_id));
|
2019-03-11 14:36:29 -05:00
|
|
|
let linkage = crate::linkage::get_static_ref_linkage(tcx, def_id);
|
|
|
|
data_id_for_static(tcx, module, def_id, linkage)
|
2018-08-13 12:02:42 -05:00
|
|
|
}
|
|
|
|
};
|
2018-07-16 08:13:37 -05:00
|
|
|
|
2018-08-13 05:13:43 -05:00
|
|
|
let global_value = module.declare_data_in_data(data_id, &mut data_ctx);
|
2019-01-06 10:51:21 -06:00
|
|
|
data_ctx.write_data_addr(offset.bytes() as u32, global_value, addend as i64);
|
2018-07-16 08:13:37 -05:00
|
|
|
}
|
|
|
|
|
2018-08-13 05:13:43 -05:00
|
|
|
module.define_data(data_id, &data_ctx).unwrap();
|
|
|
|
cx.done.insert(data_id);
|
2018-07-14 09:45:20 -05:00
|
|
|
}
|
2018-08-13 09:58:07 -05:00
|
|
|
|
2018-08-13 11:31:26 -05:00
|
|
|
assert!(cx.todo.is_empty(), "{:?}", cx.todo);
|
2018-07-16 08:13:37 -05:00
|
|
|
}
|
2018-08-13 10:22:24 -05:00
|
|
|
|
|
|
|
fn pop_set<T: Copy + Eq + ::std::hash::Hash>(set: &mut HashSet<T>) -> Option<T> {
|
|
|
|
if let Some(elem) = set.iter().next().map(|elem| *elem) {
|
|
|
|
set.remove(&elem);
|
|
|
|
Some(elem)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2018-08-13 11:04:39 -05:00
|
|
|
}
|
2018-09-24 12:31:46 -05:00
|
|
|
|
|
|
|
struct TransPlaceInterpreter;
|
|
|
|
|
|
|
|
impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for TransPlaceInterpreter {
|
2018-10-22 04:06:09 -05:00
|
|
|
type MemoryKinds = !;
|
2018-10-12 12:23:24 -05:00
|
|
|
type PointerTag = ();
|
2018-10-22 04:06:09 -05:00
|
|
|
type AllocExtra = ();
|
2018-11-30 11:08:08 -06:00
|
|
|
type MemoryExtra = ();
|
|
|
|
type FrameExtra = ();
|
2018-10-22 04:06:09 -05:00
|
|
|
type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation<()>)>;
|
|
|
|
const STATIC_KIND: Option<!> = None;
|
2018-10-16 07:16:37 -05:00
|
|
|
|
|
|
|
fn enforce_validity(_: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2018-09-24 12:31:46 -05:00
|
|
|
|
|
|
|
fn before_terminator(_: &mut EvalContext<'a, 'mir, 'tcx, Self>) -> EvalResult<'tcx> {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_fn(
|
|
|
|
_: &mut EvalContext<'a, 'mir, 'tcx, Self>,
|
|
|
|
_: Instance<'tcx>,
|
|
|
|
_: &[OpTy<'tcx>],
|
|
|
|
_: Option<PlaceTy<'tcx>>,
|
|
|
|
_: Option<BasicBlock>,
|
|
|
|
) -> EvalResult<'tcx, Option<&'mir Mir<'tcx>>> {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call_intrinsic(
|
|
|
|
_: &mut EvalContext<'a, 'mir, 'tcx, Self>,
|
|
|
|
_: Instance<'tcx>,
|
|
|
|
_: &[OpTy<'tcx>],
|
|
|
|
_: PlaceTy<'tcx>,
|
|
|
|
) -> EvalResult<'tcx> {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_foreign_static(
|
|
|
|
_: DefId,
|
2018-11-30 11:08:08 -06:00
|
|
|
_: ::rustc::ty::query::TyCtxtAt<'a, 'tcx, 'tcx>,
|
|
|
|
_: &(),
|
2018-10-12 12:23:24 -05:00
|
|
|
) -> EvalResult<'tcx, Cow<'tcx, Allocation>> {
|
2018-09-24 12:31:46 -05:00
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ptr_op(
|
|
|
|
_: &EvalContext<'a, 'mir, 'tcx, Self>,
|
|
|
|
_: mir::BinOp,
|
2019-02-16 05:35:45 -06:00
|
|
|
_: ImmTy<'tcx>,
|
|
|
|
_: ImmTy<'tcx>,
|
2018-09-24 12:31:46 -05:00
|
|
|
) -> EvalResult<'tcx, (Scalar, bool)> {
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn box_alloc(_: &mut EvalContext<'a, 'mir, 'tcx, Self>, _: PlaceTy<'tcx>) -> EvalResult<'tcx> {
|
|
|
|
panic!();
|
|
|
|
}
|
2018-10-22 04:06:09 -05:00
|
|
|
|
2018-11-07 06:32:02 -06:00
|
|
|
fn tag_dereference(
|
|
|
|
_: &EvalContext<'a, 'mir, 'tcx, Self>,
|
2018-11-09 10:54:28 -06:00
|
|
|
_: MPlaceTy<'tcx>,
|
|
|
|
_: Option<::rustc::hir::Mutability>,
|
|
|
|
) -> EvalResult<'tcx, Scalar> {
|
2018-10-22 04:06:09 -05:00
|
|
|
panic!();
|
|
|
|
}
|
2018-10-30 11:58:42 -05:00
|
|
|
|
2018-11-30 11:08:08 -06:00
|
|
|
fn adjust_static_allocation<'alloc>(
|
|
|
|
alloc: &'alloc Allocation,
|
|
|
|
_: &(),
|
|
|
|
) -> Cow<'alloc, Allocation> {
|
2018-10-30 11:58:42 -05:00
|
|
|
Cow::Borrowed(alloc)
|
|
|
|
}
|
|
|
|
|
2018-11-07 06:32:02 -06:00
|
|
|
fn tag_new_allocation(
|
|
|
|
_: &mut EvalContext<'a, 'mir, 'tcx, Self>,
|
|
|
|
ptr: Pointer,
|
|
|
|
_: MemoryKind<!>,
|
2018-12-24 07:50:18 -06:00
|
|
|
) -> Pointer {
|
|
|
|
ptr
|
2018-10-30 11:58:42 -05:00
|
|
|
}
|
2018-11-30 11:08:08 -06:00
|
|
|
|
2019-02-21 08:06:09 -06:00
|
|
|
fn stack_push(_: &mut EvalContext<'a, 'mir, 'tcx, Self>) -> EvalResult<'tcx> {
|
2018-11-30 11:08:08 -06:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn stack_pop(_: &mut EvalContext<'a, 'mir, 'tcx, Self>, _: ()) -> EvalResult<'tcx> {
|
|
|
|
Ok(())
|
|
|
|
}
|
2018-09-24 12:31:46 -05:00
|
|
|
}
|