Add reference types R32 and R64
-Add resumable_trap, safepoint, isnull, and null instructions -Add Stackmap struct and StackmapSink trait Co-authored-by: Mir Ahmed <mirahmed753@gmail.com> Co-authored-by: Dan Gohman <sunfish@mozilla.com>
This commit is contained in:
@@ -834,6 +834,12 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
Operator::F32Le | Operator::F64Le => {
|
||||
translate_fcmp(FloatCC::LessThanOrEqual, builder, state)
|
||||
}
|
||||
Operator::RefNull => state.push1(builder.ins().null(environ.reference_type())),
|
||||
Operator::RefIsNull => {
|
||||
let arg = state.pop1();
|
||||
let val = builder.ins().is_null(arg);
|
||||
state.push1(val);
|
||||
}
|
||||
Operator::Wake { .. }
|
||||
| Operator::I32Wait { .. }
|
||||
| Operator::I64Wait { .. }
|
||||
@@ -902,9 +908,6 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
| Operator::I64AtomicRmw32UCmpxchg { .. } => {
|
||||
wasm_unsupported!("proposed thread operator {:?}", op);
|
||||
}
|
||||
Operator::RefNull | Operator::RefIsNull { .. } => {
|
||||
wasm_unsupported!("proposed reference-type operator {:?}", op);
|
||||
}
|
||||
Operator::MemoryInit { .. }
|
||||
| Operator::DataDrop { .. }
|
||||
| Operator::MemoryCopy
|
||||
|
||||
@@ -131,6 +131,17 @@ pub trait FuncEnvironment {
|
||||
ReturnMode::NormalReturns
|
||||
}
|
||||
|
||||
/// Get the Cranelift reference type to use for native references.
|
||||
///
|
||||
/// This returns `R64` for 64-bit architectures and `R32` for 32-bit architectures.
|
||||
fn reference_type(&self) -> ir::Type {
|
||||
match self.pointer_type() {
|
||||
ir::types::I32 => ir::types::R32,
|
||||
ir::types::I64 => ir::types::R64,
|
||||
_ => panic!("unsupported pointer type"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set up the necessary preamble definitions in `func` to access the global variable
|
||||
/// identified by `index`.
|
||||
///
|
||||
|
||||
@@ -104,7 +104,7 @@ impl FuncTranslator {
|
||||
builder.append_ebb_params_for_function_returns(exit_block);
|
||||
self.state.initialize(&builder.func.signature, exit_block);
|
||||
|
||||
parse_local_decls(&mut reader, &mut builder, num_params)?;
|
||||
parse_local_decls(&mut reader, &mut builder, num_params, environ)?;
|
||||
parse_function_body(reader, &mut builder, &mut self.state, environ)?;
|
||||
|
||||
builder.finalize();
|
||||
@@ -143,10 +143,11 @@ fn declare_wasm_parameters(builder: &mut FunctionBuilder, entry_block: Ebb) -> u
|
||||
/// Parse the local variable declarations that precede the function body.
|
||||
///
|
||||
/// Declare local variables, starting from `num_params`.
|
||||
fn parse_local_decls(
|
||||
fn parse_local_decls<FE: FuncEnvironment + ?Sized>(
|
||||
reader: &mut BinaryReader,
|
||||
builder: &mut FunctionBuilder,
|
||||
num_params: usize,
|
||||
environ: &mut FE,
|
||||
) -> WasmResult<()> {
|
||||
let mut next_local = num_params;
|
||||
let local_count = reader.read_local_count()?;
|
||||
@@ -155,7 +156,7 @@ fn parse_local_decls(
|
||||
for _ in 0..local_count {
|
||||
builder.set_srcloc(cur_srcloc(reader));
|
||||
let (count, ty) = reader.read_local_decl(&mut locals_total)?;
|
||||
declare_locals(builder, count, ty, &mut next_local)?;
|
||||
declare_locals(builder, count, ty, &mut next_local, environ)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -164,11 +165,12 @@ fn parse_local_decls(
|
||||
/// Declare `count` local variables of the same type, starting from `next_local`.
|
||||
///
|
||||
/// Fail of too many locals are declared in the function, or if the type is not valid for a local.
|
||||
fn declare_locals(
|
||||
fn declare_locals<FE: FuncEnvironment + ?Sized>(
|
||||
builder: &mut FunctionBuilder,
|
||||
count: u32,
|
||||
wasm_type: wasmparser::Type,
|
||||
next_local: &mut usize,
|
||||
environ: &mut FE,
|
||||
) -> WasmResult<()> {
|
||||
// All locals are initialized to 0.
|
||||
use wasmparser::Type::*;
|
||||
@@ -177,6 +179,7 @@ fn declare_locals(
|
||||
I64 => builder.ins().iconst(ir::types::I64, 0),
|
||||
F32 => builder.ins().f32const(ir::immediates::Ieee32::with_bits(0)),
|
||||
F64 => builder.ins().f64const(ir::immediates::Ieee64::with_bits(0)),
|
||||
AnyRef => builder.ins().null(environ.reference_type()),
|
||||
ty => wasm_unsupported!("unsupported local type {:?}", ty),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user