(
fgen: &mut FunctionGenerator,
builder: &mut FunctionBuilder,
opcode: Opcode,
args: &[Type],
rets: &[Type],
)
| 29 | type BlockSignature = Vec<Type>; |
| 30 | |
| 31 | fn insert_opcode( |
| 32 | fgen: &mut FunctionGenerator, |
| 33 | builder: &mut FunctionBuilder, |
| 34 | opcode: Opcode, |
| 35 | args: &[Type], |
| 36 | rets: &[Type], |
| 37 | ) -> Result<()> { |
| 38 | let mut vals = Vec::with_capacity(args.len()); |
| 39 | for &arg in args.into_iter() { |
| 40 | let var = fgen.get_variable_of_type(arg)?; |
| 41 | let val = builder.use_var(var); |
| 42 | vals.push(val); |
| 43 | } |
| 44 | |
| 45 | // Some opcodes require us to look at their input arguments to determine the |
| 46 | // controlling type. This is not the general case, but we can neatly check this |
| 47 | // using `requires_typevar_operand`. |
| 48 | let ctrl_type = if opcode.constraints().requires_typevar_operand() { |
| 49 | args.first() |
| 50 | } else { |
| 51 | rets.first() |
| 52 | } |
| 53 | .copied() |
| 54 | .unwrap_or(INVALID); |
| 55 | |
| 56 | // Choose the appropriate instruction format for this opcode |
| 57 | let (inst, dfg) = match opcode.format() { |
| 58 | InstructionFormat::NullAry => builder.ins().NullAry(opcode, ctrl_type), |
| 59 | InstructionFormat::Unary => builder.ins().Unary(opcode, ctrl_type, vals[0]), |
| 60 | InstructionFormat::Binary => builder.ins().Binary(opcode, ctrl_type, vals[0], vals[1]), |
| 61 | InstructionFormat::Ternary => builder |
| 62 | .ins() |
| 63 | .Ternary(opcode, ctrl_type, vals[0], vals[1], vals[2]), |
| 64 | _ => unimplemented!(), |
| 65 | }; |
| 66 | let results = dfg.inst_results(inst).to_vec(); |
| 67 | |
| 68 | for (val, &ty) in results.into_iter().zip(rets) { |
| 69 | let var = fgen.get_variable_of_type(ty)?; |
| 70 | builder.def_var(var, val); |
| 71 | } |
| 72 | Ok(()) |
| 73 | } |
| 74 | |
| 75 | fn insert_call_to_function( |
| 76 | fgen: &mut FunctionGenerator, |
nothing calls this directly
no test coverage detected