1 //! This module contains everything needed to instantiate an interpreter.
2 //! This separation exists to ensure that no fancy miri features like
3 //! interpreting common C functions leak into CTFE.
13 use syntax::codemap::Span;
15 /// Methods of this trait signifies a point where CTFE evaluation would fail
16 /// and some use case dependent behaviour can instead be applied
17 pub trait Machine<'tcx>: Sized {
18 /// Additional data that can be accessed via the EvalContext
21 /// Additional data that can be accessed via the Memory
24 /// Additional memory kinds a machine wishes to distinguish from the builtin ones
25 type MemoryKinds: ::std::fmt::Debug + PartialEq + Copy + Clone;
27 /// Entry point to all function calls.
29 /// Returns Ok(true) when the function was handled completely
30 /// e.g. due to missing mir
32 /// Returns Ok(false) if a new stack frame was pushed
34 ecx: &mut EvalContext<'a, 'tcx, Self>,
35 instance: ty::Instance<'tcx>,
36 destination: Option<(Lvalue<'tcx>, mir::BasicBlock)>,
37 arg_operands: &[mir::Operand<'tcx>],
40 ) -> EvalResult<'tcx, bool>;
42 /// directly process an intrinsic without pushing a stack frame.
43 fn call_intrinsic<'a>(
44 ecx: &mut EvalContext<'a, 'tcx, Self>,
45 instance: ty::Instance<'tcx>,
46 args: &[mir::Operand<'tcx>],
48 dest_ty: ty::Ty<'tcx>,
49 dest_layout: &'tcx ty::layout::Layout,
50 target: mir::BasicBlock,
51 ) -> EvalResult<'tcx>;
53 /// Called when operating on the value of pointers.
55 /// Returns `None` if the operation should be handled by the integer
58 /// Returns a (value, overflowed) pair otherwise
60 ecx: &EvalContext<'a, 'tcx, Self>,
63 left_ty: ty::Ty<'tcx>,
65 right_ty: ty::Ty<'tcx>,
66 ) -> EvalResult<'tcx, Option<(PrimVal, bool)>>;
68 /// Called when trying to mark machine defined `MemoryKinds` as static
69 fn mark_static_initialized(m: Self::MemoryKinds) -> EvalResult<'tcx>;
71 /// Heap allocations via the `box` keyword
73 /// Returns a pointer to the allocated memory
75 ecx: &mut EvalContext<'a, 'tcx, Self>,
77 ) -> EvalResult<'tcx, PrimVal>;