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.
This commit is contained in:
@@ -80,6 +80,20 @@ fn insert_stack_store(
|
|||||||
Ok(())
|
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(
|
type OpcodeInserter = fn(
|
||||||
fgen: &mut FunctionGenerator,
|
fgen: &mut FunctionGenerator,
|
||||||
builder: &mut FunctionBuilder,
|
builder: &mut FunctionBuilder,
|
||||||
@@ -182,6 +196,16 @@ const OPCODE_SIGNATURES: &'static [(
|
|||||||
(Opcode::StackLoad, &[], &[I16], insert_stack_load),
|
(Opcode::StackLoad, &[], &[I16], insert_stack_load),
|
||||||
(Opcode::StackLoad, &[], &[I32], insert_stack_load),
|
(Opcode::StackLoad, &[], &[I32], insert_stack_load),
|
||||||
(Opcode::StackLoad, &[], &[I64], 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>
|
pub struct FunctionGenerator<'r, 'data>
|
||||||
|
|||||||
Reference in New Issue
Block a user