cranelift_interpreter/
instruction.rs1use cranelift_codegen::ir::{DataFlowGraph, Inst, InstructionData, Type, Value};
4
5pub trait InstructionContext {
10 fn data(&self) -> InstructionData;
11 fn args(&self) -> &[Value];
12 fn type_of(&self, v: Value) -> Option<Type>;
13 fn controlling_type(&self) -> Option<Type>;
14}
15
16pub struct DfgInstructionContext<'a>(Inst, &'a DataFlowGraph);
19
20impl<'a> DfgInstructionContext<'a> {
21 pub fn new(inst: Inst, dfg: &'a DataFlowGraph) -> Self {
22 Self(inst, dfg)
23 }
24}
25
26impl InstructionContext for DfgInstructionContext<'_> {
27 fn data(&self) -> InstructionData {
28 self.1.insts[self.0]
29 }
30
31 fn args(&self) -> &[Value] {
32 self.1.inst_args(self.0)
33 }
34
35 fn type_of(&self, v: Value) -> Option<Type> {
36 Some(self.1.value_type(v))
37 }
38
39 fn controlling_type(&self) -> Option<Type> {
40 Some(self.1.ctrl_typevar(self.0))
41 }
42}