MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / insert_opcode

Function insert_opcode

cranelift/fuzzgen/src/function_generator.rs:31–73  ·  view source on GitHub ↗
(
    fgen: &mut FunctionGenerator,
    builder: &mut FunctionBuilder,
    opcode: Opcode,
    args: &[Type],
    rets: &[Type],
)

Source from the content-addressed store, hash-verified

29type BlockSignature = Vec<Type>;
30
31fn 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
75fn insert_call_to_function(
76 fgen: &mut FunctionGenerator,

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
get_variable_of_typeMethod · 0.80
copiedMethod · 0.80
constraintsMethod · 0.80
lenMethod · 0.45
into_iterMethod · 0.45
use_varMethod · 0.45
pushMethod · 0.45
firstMethod · 0.45
formatMethod · 0.45
insMethod · 0.45

Tested by

no test coverage detected