Browse Source

fuzzgen: Generate const's (#4500)

We already have const support, but currently only use it when building
the pool of variables but never in the main instruction selection.
pull/4503/head
Afonso Bordado 2 years ago
committed by GitHub
parent
commit
ca36ce57c2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      cranelift/fuzzgen/src/function_generator.rs

24
cranelift/fuzzgen/src/function_generator.rs

@ -80,6 +80,20 @@ fn insert_stack_store(
Ok(())
}
fn insert_const(
fgen: &mut FunctionGenerator,
builder: &mut FunctionBuilder,
_opcode: Opcode,
_args: &'static [Type],
rets: &'static [Type],
) -> Result<()> {
let typevar = rets[0];
let var = fgen.get_variable_of_type(typevar)?;
let val = fgen.generate_const(builder, typevar)?;
builder.def_var(var, val);
Ok(())
}
type OpcodeInserter = fn(
fgen: &mut FunctionGenerator,
builder: &mut FunctionBuilder,
@ -182,6 +196,16 @@ const OPCODE_SIGNATURES: &'static [(
(Opcode::StackLoad, &[], &[I16], insert_stack_load),
(Opcode::StackLoad, &[], &[I32], insert_stack_load),
(Opcode::StackLoad, &[], &[I64], insert_stack_load),
// Integer Consts
(Opcode::Iconst, &[], &[I8], insert_const),
(Opcode::Iconst, &[], &[I16], insert_const),
(Opcode::Iconst, &[], &[I32], insert_const),
(Opcode::Iconst, &[], &[I64], insert_const),
// Float Consts
(Opcode::F32const, &[], &[F32], insert_const),
(Opcode::F64const, &[], &[F64], insert_const),
// Bool Consts
(Opcode::Bconst, &[], &[B1], insert_const),
];
pub struct FunctionGenerator<'r, 'data>

Loading…
Cancel
Save