Update to rustfmt-preview (#348)

* Update to rustfmt-preview.

* Run "cargo fmt --all" with rustfmt 0.4.1.

rustfmt 0.4.1 is the latest release of rustfmt-preview available on the
stable channel.

* Fix a long line that rustfmt 0.4.1 can't handle.

* Remove unneeded commas left behind by rustfmt.
This commit is contained in:
Dan Gohman
2018-05-25 11:38:38 -07:00
committed by GitHub
parent 99f6055c55
commit 6b88cd44a8
137 changed files with 1914 additions and 2380 deletions

View File

@@ -194,10 +194,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let frame = state.control_stack.pop().unwrap();
if !builder.is_unreachable() || !builder.is_pristine() {
let return_count = frame.num_return_values();
builder.ins().jump(
frame.following_code(),
state.peekn(return_count),
);
builder
.ins()
.jump(frame.following_code(), state.peekn(return_count));
}
builder.switch_to_block(frame.following_code());
builder.seal_block(frame.following_code());
@@ -206,9 +205,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
builder.seal_block(header)
}
state.stack.truncate(frame.original_stack_size());
state.stack.extend_from_slice(
builder.ebb_params(frame.following_code()),
);
state
.stack
.extend_from_slice(builder.ebb_params(frame.following_code()));
}
/**************************** Branch instructions *********************************
* The branch instructions all have as arguments a target nesting level, which
@@ -244,10 +243,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
};
(return_count, frame.br_destination())
};
builder.ins().jump(
br_destination,
state.peekn(return_count),
);
builder
.ins()
.jump(br_destination, state.peekn(return_count));
state.popn(return_count);
state.reachable = false;
}
@@ -392,67 +390,86 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let heap_index = reserved as MemoryIndex;
let heap = state.get_heap(builder.func, reserved, environ);
let val = state.pop1();
state.push1(environ.translate_grow_memory(
builder.cursor(),
heap_index,
heap,
val,
)?)
state.push1(environ.translate_grow_memory(builder.cursor(), heap_index, heap, val)?)
}
Operator::CurrentMemory { reserved } => {
let heap_index = reserved as MemoryIndex;
let heap = state.get_heap(builder.func, reserved, environ);
state.push1(environ.translate_current_memory(
builder.cursor(),
heap_index,
heap,
)?);
state.push1(environ.translate_current_memory(builder.cursor(), heap_index, heap)?);
}
/******************************* Load instructions ***********************************
* Wasm specifies an integer alignment flag but we drop it in Cretonne.
* The memory base address is provided by the environment.
* TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not
************************************************************************************/
Operator::I32Load8U { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Load8U {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Uload8, I32, builder, state, environ);
}
Operator::I32Load16U { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Load16U {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Uload16, I32, builder, state, environ);
}
Operator::I32Load8S { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Load8S {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Sload8, I32, builder, state, environ);
}
Operator::I32Load16S { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Load16S {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Sload16, I32, builder, state, environ);
}
Operator::I64Load8U { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load8U {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Uload8, I64, builder, state, environ);
}
Operator::I64Load16U { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load16U {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Uload16, I64, builder, state, environ);
}
Operator::I64Load8S { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load8S {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Sload8, I64, builder, state, environ);
}
Operator::I64Load16S { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load16S {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Sload16, I64, builder, state, environ);
}
Operator::I64Load32S { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load32S {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Sload32, I64, builder, state, environ);
}
Operator::I64Load32U { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load32U {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Uload32, I64, builder, state, environ);
}
Operator::I32Load { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Load {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Load, I32, builder, state, environ);
}
Operator::F32Load { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::F32Load {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Load, F32, builder, state, environ);
}
Operator::I64Load { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Load {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Load, I64, builder, state, environ);
}
Operator::F64Load { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::F64Load {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_load(offset, ir::Opcode::Load, F64, builder, state, environ);
}
/****************************** Store instructions ***********************************
@@ -460,21 +477,39 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
* The memory base address is provided by the environment.
* TODO: differentiate between 32 bit and 64 bit architecture, to put the uextend or not
************************************************************************************/
Operator::I32Store { memarg: MemoryImmediate { flags: _, offset } } |
Operator::I64Store { memarg: MemoryImmediate { flags: _, offset } } |
Operator::F32Store { memarg: MemoryImmediate { flags: _, offset } } |
Operator::F64Store { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Store {
memarg: MemoryImmediate { flags: _, offset },
}
| Operator::I64Store {
memarg: MemoryImmediate { flags: _, offset },
}
| Operator::F32Store {
memarg: MemoryImmediate { flags: _, offset },
}
| Operator::F64Store {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_store(offset, ir::Opcode::Store, builder, state, environ);
}
Operator::I32Store8 { memarg: MemoryImmediate { flags: _, offset } } |
Operator::I64Store8 { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Store8 {
memarg: MemoryImmediate { flags: _, offset },
}
| Operator::I64Store8 {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_store(offset, ir::Opcode::Istore8, builder, state, environ);
}
Operator::I32Store16 { memarg: MemoryImmediate { flags: _, offset } } |
Operator::I64Store16 { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I32Store16 {
memarg: MemoryImmediate { flags: _, offset },
}
| Operator::I64Store16 {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_store(offset, ir::Opcode::Istore16, builder, state, environ);
}
Operator::I64Store32 { memarg: MemoryImmediate { flags: _, offset } } => {
Operator::I64Store32 {
memarg: MemoryImmediate { flags: _, offset },
} => {
translate_store(offset, ir::Opcode::Istore32, builder, state, environ);
}
/****************************** Nullary Operators ************************************/
@@ -495,8 +530,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let arg = state.pop1();
state.push1(builder.ins().ctz(arg));
}
Operator::I32Popcnt |
Operator::I64Popcnt => {
Operator::I32Popcnt | Operator::I64Popcnt => {
let arg = state.pop1();
state.push1(builder.ins().popcnt(arg));
}
@@ -512,28 +546,23 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let val = state.pop1();
state.push1(builder.ins().ireduce(I32, val));
}
Operator::F32Sqrt |
Operator::F64Sqrt => {
Operator::F32Sqrt | Operator::F64Sqrt => {
let arg = state.pop1();
state.push1(builder.ins().sqrt(arg));
}
Operator::F32Ceil |
Operator::F64Ceil => {
Operator::F32Ceil | Operator::F64Ceil => {
let arg = state.pop1();
state.push1(builder.ins().ceil(arg));
}
Operator::F32Floor |
Operator::F64Floor => {
Operator::F32Floor | Operator::F64Floor => {
let arg = state.pop1();
state.push1(builder.ins().floor(arg));
}
Operator::F32Trunc |
Operator::F64Trunc => {
Operator::F32Trunc | Operator::F64Trunc => {
let arg = state.pop1();
state.push1(builder.ins().trunc(arg));
}
Operator::F32Nearest |
Operator::F64Nearest => {
Operator::F32Nearest | Operator::F64Nearest => {
let arg = state.pop1();
state.push1(builder.ins().nearest(arg));
}
@@ -545,23 +574,19 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let arg = state.pop1();
state.push1(builder.ins().fneg(arg));
}
Operator::F64ConvertUI64 |
Operator::F64ConvertUI32 => {
Operator::F64ConvertUI64 | Operator::F64ConvertUI32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_from_uint(F64, val));
}
Operator::F64ConvertSI64 |
Operator::F64ConvertSI32 => {
Operator::F64ConvertSI64 | Operator::F64ConvertSI32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_from_sint(F64, val));
}
Operator::F32ConvertSI64 |
Operator::F32ConvertSI32 => {
Operator::F32ConvertSI64 | Operator::F32ConvertSI32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_from_sint(F32, val));
}
Operator::F32ConvertUI64 |
Operator::F32ConvertUI32 => {
Operator::F32ConvertUI64 | Operator::F32ConvertUI32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_from_uint(F32, val));
}
@@ -573,34 +598,30 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let val = state.pop1();
state.push1(builder.ins().fdemote(F32, val));
}
Operator::I64TruncSF64 |
Operator::I64TruncSF32 => {
Operator::I64TruncSF64 | Operator::I64TruncSF32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_to_sint(I64, val));
}
Operator::I32TruncSF64 |
Operator::I32TruncSF32 => {
Operator::I32TruncSF64 | Operator::I32TruncSF32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_to_sint(I32, val));
}
Operator::I64TruncUF64 |
Operator::I64TruncUF32 => {
Operator::I64TruncUF64 | Operator::I64TruncUF32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_to_uint(I64, val));
}
Operator::I32TruncUF64 |
Operator::I32TruncUF32 => {
Operator::I32TruncUF64 | Operator::I32TruncUF32 => {
let val = state.pop1();
state.push1(builder.ins().fcvt_to_uint(I32, val));
}
Operator::I64TruncSSatF64 |
Operator::I64TruncSSatF32 |
Operator::I32TruncSSatF64 |
Operator::I32TruncSSatF32 |
Operator::I64TruncUSatF64 |
Operator::I64TruncUSatF32 |
Operator::I32TruncUSatF64 |
Operator::I32TruncUSatF32 => {
Operator::I64TruncSSatF64
| Operator::I64TruncSSatF32
| Operator::I32TruncSSatF64
| Operator::I32TruncSSatF32
| Operator::I64TruncUSatF64
| Operator::I64TruncUSatF32
| Operator::I32TruncUSatF64
| Operator::I32TruncUSatF32 => {
panic!("proposed saturating conversion operators not yet supported");
}
Operator::F32ReinterpretI32 => {
@@ -670,23 +691,19 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().ishl(arg1, arg2));
}
Operator::I32ShrS |
Operator::I64ShrS => {
Operator::I32ShrS | Operator::I64ShrS => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().sshr(arg1, arg2));
}
Operator::I32ShrU |
Operator::I64ShrU => {
Operator::I32ShrU | Operator::I64ShrU => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().ushr(arg1, arg2));
}
Operator::I32Rotl |
Operator::I64Rotl => {
Operator::I32Rotl | Operator::I64Rotl => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().rotl(arg1, arg2));
}
Operator::I32Rotr |
Operator::I64Rotr => {
Operator::I32Rotr | Operator::I64Rotr => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().rotr(arg1, arg2));
}
@@ -714,23 +731,19 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().fdiv(arg1, arg2));
}
Operator::I32DivS |
Operator::I64DivS => {
Operator::I32DivS | Operator::I64DivS => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().sdiv(arg1, arg2));
}
Operator::I32DivU |
Operator::I64DivU => {
Operator::I32DivU | Operator::I64DivU => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().udiv(arg1, arg2));
}
Operator::I32RemS |
Operator::I64RemS => {
Operator::I32RemS | Operator::I64RemS => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().srem(arg1, arg2));
}
Operator::I32RemU |
Operator::I64RemU => {
Operator::I32RemU | Operator::I64RemU => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().urem(arg1, arg2));
}
@@ -742,8 +755,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().fmax(arg1, arg2));
}
Operator::F32Copysign |
Operator::F64Copysign => {
Operator::F32Copysign | Operator::F64Copysign => {
let (arg1, arg2) = state.pop2();
state.push1(builder.ins().fcopysign(arg1, arg2));
}
@@ -789,72 +801,72 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
Operator::F32Le | Operator::F64Le => {
translate_fcmp(FloatCC::LessThanOrEqual, builder, state)
}
Operator::Wake { .. } |
Operator::I32Wait { .. } |
Operator::I64Wait { .. } |
Operator::I32AtomicLoad { .. } |
Operator::I64AtomicLoad { .. } |
Operator::I32AtomicLoad8U { .. } |
Operator::I32AtomicLoad16U { .. } |
Operator::I64AtomicLoad8U { .. } |
Operator::I64AtomicLoad16U { .. } |
Operator::I64AtomicLoad32U { .. } |
Operator::I32AtomicStore { .. } |
Operator::I64AtomicStore { .. } |
Operator::I32AtomicStore8 { .. } |
Operator::I32AtomicStore16 { .. } |
Operator::I64AtomicStore8 { .. } |
Operator::I64AtomicStore16 { .. } |
Operator::I64AtomicStore32 { .. } |
Operator::I32AtomicRmwAdd { .. } |
Operator::I64AtomicRmwAdd { .. } |
Operator::I32AtomicRmw8UAdd { .. } |
Operator::I32AtomicRmw16UAdd { .. } |
Operator::I64AtomicRmw8UAdd { .. } |
Operator::I64AtomicRmw16UAdd { .. } |
Operator::I64AtomicRmw32UAdd { .. } |
Operator::I32AtomicRmwSub { .. } |
Operator::I64AtomicRmwSub { .. } |
Operator::I32AtomicRmw8USub { .. } |
Operator::I32AtomicRmw16USub { .. } |
Operator::I64AtomicRmw8USub { .. } |
Operator::I64AtomicRmw16USub { .. } |
Operator::I64AtomicRmw32USub { .. } |
Operator::I32AtomicRmwAnd { .. } |
Operator::I64AtomicRmwAnd { .. } |
Operator::I32AtomicRmw8UAnd { .. } |
Operator::I32AtomicRmw16UAnd { .. } |
Operator::I64AtomicRmw8UAnd { .. } |
Operator::I64AtomicRmw16UAnd { .. } |
Operator::I64AtomicRmw32UAnd { .. } |
Operator::I32AtomicRmwOr { .. } |
Operator::I64AtomicRmwOr { .. } |
Operator::I32AtomicRmw8UOr { .. } |
Operator::I32AtomicRmw16UOr { .. } |
Operator::I64AtomicRmw8UOr { .. } |
Operator::I64AtomicRmw16UOr { .. } |
Operator::I64AtomicRmw32UOr { .. } |
Operator::I32AtomicRmwXor { .. } |
Operator::I64AtomicRmwXor { .. } |
Operator::I32AtomicRmw8UXor { .. } |
Operator::I32AtomicRmw16UXor { .. } |
Operator::I64AtomicRmw8UXor { .. } |
Operator::I64AtomicRmw16UXor { .. } |
Operator::I64AtomicRmw32UXor { .. } |
Operator::I32AtomicRmwXchg { .. } |
Operator::I64AtomicRmwXchg { .. } |
Operator::I32AtomicRmw8UXchg { .. } |
Operator::I32AtomicRmw16UXchg { .. } |
Operator::I64AtomicRmw8UXchg { .. } |
Operator::I64AtomicRmw16UXchg { .. } |
Operator::I64AtomicRmw32UXchg { .. } |
Operator::I32AtomicRmwCmpxchg { .. } |
Operator::I64AtomicRmwCmpxchg { .. } |
Operator::I32AtomicRmw8UCmpxchg { .. } |
Operator::I32AtomicRmw16UCmpxchg { .. } |
Operator::I64AtomicRmw8UCmpxchg { .. } |
Operator::I64AtomicRmw16UCmpxchg { .. } |
Operator::I64AtomicRmw32UCmpxchg { .. } => {
Operator::Wake { .. }
| Operator::I32Wait { .. }
| Operator::I64Wait { .. }
| Operator::I32AtomicLoad { .. }
| Operator::I64AtomicLoad { .. }
| Operator::I32AtomicLoad8U { .. }
| Operator::I32AtomicLoad16U { .. }
| Operator::I64AtomicLoad8U { .. }
| Operator::I64AtomicLoad16U { .. }
| Operator::I64AtomicLoad32U { .. }
| Operator::I32AtomicStore { .. }
| Operator::I64AtomicStore { .. }
| Operator::I32AtomicStore8 { .. }
| Operator::I32AtomicStore16 { .. }
| Operator::I64AtomicStore8 { .. }
| Operator::I64AtomicStore16 { .. }
| Operator::I64AtomicStore32 { .. }
| Operator::I32AtomicRmwAdd { .. }
| Operator::I64AtomicRmwAdd { .. }
| Operator::I32AtomicRmw8UAdd { .. }
| Operator::I32AtomicRmw16UAdd { .. }
| Operator::I64AtomicRmw8UAdd { .. }
| Operator::I64AtomicRmw16UAdd { .. }
| Operator::I64AtomicRmw32UAdd { .. }
| Operator::I32AtomicRmwSub { .. }
| Operator::I64AtomicRmwSub { .. }
| Operator::I32AtomicRmw8USub { .. }
| Operator::I32AtomicRmw16USub { .. }
| Operator::I64AtomicRmw8USub { .. }
| Operator::I64AtomicRmw16USub { .. }
| Operator::I64AtomicRmw32USub { .. }
| Operator::I32AtomicRmwAnd { .. }
| Operator::I64AtomicRmwAnd { .. }
| Operator::I32AtomicRmw8UAnd { .. }
| Operator::I32AtomicRmw16UAnd { .. }
| Operator::I64AtomicRmw8UAnd { .. }
| Operator::I64AtomicRmw16UAnd { .. }
| Operator::I64AtomicRmw32UAnd { .. }
| Operator::I32AtomicRmwOr { .. }
| Operator::I64AtomicRmwOr { .. }
| Operator::I32AtomicRmw8UOr { .. }
| Operator::I32AtomicRmw16UOr { .. }
| Operator::I64AtomicRmw8UOr { .. }
| Operator::I64AtomicRmw16UOr { .. }
| Operator::I64AtomicRmw32UOr { .. }
| Operator::I32AtomicRmwXor { .. }
| Operator::I64AtomicRmwXor { .. }
| Operator::I32AtomicRmw8UXor { .. }
| Operator::I32AtomicRmw16UXor { .. }
| Operator::I64AtomicRmw8UXor { .. }
| Operator::I64AtomicRmw16UXor { .. }
| Operator::I64AtomicRmw32UXor { .. }
| Operator::I32AtomicRmwXchg { .. }
| Operator::I64AtomicRmwXchg { .. }
| Operator::I32AtomicRmw8UXchg { .. }
| Operator::I32AtomicRmw16UXchg { .. }
| Operator::I64AtomicRmw8UXchg { .. }
| Operator::I64AtomicRmw16UXchg { .. }
| Operator::I64AtomicRmw32UXchg { .. }
| Operator::I32AtomicRmwCmpxchg { .. }
| Operator::I64AtomicRmwCmpxchg { .. }
| Operator::I32AtomicRmw8UCmpxchg { .. }
| Operator::I32AtomicRmw16UCmpxchg { .. }
| Operator::I64AtomicRmw8UCmpxchg { .. }
| Operator::I64AtomicRmw16UCmpxchg { .. }
| Operator::I64AtomicRmw32UCmpxchg { .. } => {
panic!("proposed thread operators not yet supported");
}
})
@@ -876,8 +888,7 @@ fn translate_unreachable_operator(
// so we don't have any branches anywhere.
state.push_if(ir::Inst::reserved_value(), ir::Ebb::reserved_value(), 0);
}
Operator::Loop { ty: _ } |
Operator::Block { ty: _ } => {
Operator::Loop { ty: _ } | Operator::Block { ty: _ } => {
state.push_block(ir::Ebb::reserved_value(), 0);
}
Operator::Else => {
@@ -919,7 +930,9 @@ fn translate_unreachable_operator(
// And loops can't have branches to the end.
false
}
ControlStackFrame::If { reachable_from_top, .. } => {
ControlStackFrame::If {
reachable_from_top, ..
} => {
// A reachable if without an else has a branch from the top
// directly to the bottom.
reachable_from_top
@@ -998,13 +1011,9 @@ fn translate_load<FE: FuncEnvironment + ?Sized>(
// alignment immediate says it's aligned, because WebAssembly's immediate
// field is just a hint, while Cretonne's aligned flag needs a guarantee.
let flags = MemFlags::new();
let (load, dfg) = builder.ins().Load(
opcode,
result_ty,
flags,
offset.into(),
base,
);
let (load, dfg) = builder
.ins()
.Load(opcode, result_ty, flags, offset.into(), base);
state.push1(dfg.first_result(load));
}
@@ -1024,14 +1033,9 @@ fn translate_store<FE: FuncEnvironment + ?Sized>(
let (base, offset) = get_heap_addr(heap, addr32, offset, environ.native_pointer(), builder);
// See the comments in `translate_load` about the flags.
let flags = MemFlags::new();
builder.ins().Store(
opcode,
val_ty,
flags,
offset.into(),
val,
base,
);
builder
.ins()
.Store(opcode, val_ty, flags, offset.into(), val, base);
}
fn translate_icmp(

View File

@@ -165,7 +165,9 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
base: ir::HeapBase::GlobalVar(gv),
min_size: 0.into(),
guard_size: 0x8000_0000.into(),
style: ir::HeapStyle::Static { bound: 0x1_0000_0000.into() },
style: ir::HeapStyle::Static {
bound: 0x1_0000_0000.into(),
},
})
}
@@ -224,11 +226,9 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
args.extend(call_args.iter().cloned(), &mut pos.func.dfg.value_lists);
args.push(vmctx, &mut pos.func.dfg.value_lists);
Ok(
pos.ins()
.CallIndirect(ir::Opcode::CallIndirect, VOID, sig_ref, args)
.0,
)
Ok(pos.ins()
.CallIndirect(ir::Opcode::CallIndirect, VOID, sig_ref, args)
.0)
}
fn translate_call(
@@ -301,10 +301,9 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
"Imported functions must be declared first"
);
self.info.functions.push(Exportable::new(sig_index));
self.info.imported_funcs.push((
String::from(module),
String::from(field),
));
self.info
.imported_funcs
.push((String::from(module), String::from(field)));
}
fn get_num_func_imports(&self) -> usize {
@@ -353,33 +352,27 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
}
fn declare_func_export(&mut self, func_index: FunctionIndex, name: &'data str) {
self.info.functions[func_index].export_names.push(
String::from(
name,
),
);
self.info.functions[func_index]
.export_names
.push(String::from(name));
}
fn declare_table_export(&mut self, table_index: TableIndex, name: &'data str) {
self.info.tables[table_index].export_names.push(
String::from(name),
);
self.info.tables[table_index]
.export_names
.push(String::from(name));
}
fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &'data str) {
self.info.memories[memory_index].export_names.push(
String::from(
name,
),
);
self.info.memories[memory_index]
.export_names
.push(String::from(name));
}
fn declare_global_export(&mut self, global_index: GlobalIndex, name: &'data str) {
self.info.globals[global_index].export_names.push(
String::from(
name,
),
);
self.info.globals[global_index]
.export_names
.push(String::from(name));
}
fn declare_start_func(&mut self, func_index: FunctionIndex) {
@@ -395,11 +388,8 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
let sig = func_environ.vmctx_sig(self.get_func_type(function_index));
let mut func = ir::Function::with_name_signature(name, sig);
let reader = wasmparser::BinaryReader::new(body_bytes);
self.trans.translate_from_reader(
reader,
&mut func,
&mut func_environ,
)?;
self.trans
.translate_from_reader(reader, &mut func, &mut func_environ)?;
func
};
self.func_bytecode_sizes.push(body_bytes.len());

View File

@@ -135,16 +135,16 @@ fn parse_local_decls(
num_params: usize,
) -> WasmResult<()> {
let mut next_local = num_params;
let local_count = reader.read_local_count().map_err(|e| {
WasmError::from_binary_reader_error(e)
})?;
let local_count = reader
.read_local_count()
.map_err(|e| WasmError::from_binary_reader_error(e))?;
let mut locals_total = 0;
for _ in 0..local_count {
builder.set_srcloc(cur_srcloc(reader));
let (count, ty) = reader.read_local_decl(&mut locals_total).map_err(|e| {
WasmError::from_binary_reader_error(e)
})?;
let (count, ty) = reader
.read_local_decl(&mut locals_total)
.map_err(|e| WasmError::from_binary_reader_error(e))?;
declare_locals(builder, count, ty, &mut next_local);
}
@@ -195,9 +195,9 @@ fn parse_function_body<FE: FuncEnvironment + ?Sized>(
// Keep going until the final `End` operator which pops the outermost block.
while !state.control_stack.is_empty() {
builder.set_srcloc(cur_srcloc(&reader));
let op = reader.read_operator().map_err(|e| {
WasmError::from_binary_reader_error(e)
})?;
let op = reader
.read_operator()
.map_err(|e| WasmError::from_binary_reader_error(e))?;
translate_operator(op, builder, state, environ)?;
}
@@ -246,11 +246,13 @@ mod tests {
// (i32.add (get_local 0) (i32.const 1))
// )
const BODY: [u8; 7] = [
0x00, // local decl count
0x20, 0x00, // get_local 0
0x41, 0x01, // i32.const 1
0x6a, // i32.add
0x0b, // end
0x00, // local decl count
0x20,
0x00, // get_local 0
0x41,
0x01, // i32.const 1
0x6a, // i32.add
0x0b, // end
];
let mut trans = FuncTranslator::new();
@@ -276,12 +278,14 @@ mod tests {
// (return (i32.add (get_local 0) (i32.const 1)))
// )
const BODY: [u8; 8] = [
0x00, // local decl count
0x20, 0x00, // get_local 0
0x41, 0x01, // i32.const 1
0x6a, // i32.add
0x0f, // return
0x0b, // end
0x00, // local decl count
0x20,
0x00, // get_local 0
0x41,
0x01, // i32.const 1
0x6a, // i32.add
0x0f, // return
0x0b, // end
];
let mut trans = FuncTranslator::new();
@@ -312,16 +316,22 @@ mod tests {
// )
// )
const BODY: [u8; 16] = [
0x01, // 1 local decl.
0x01, 0x7f, // 1 i32 local.
0x03, 0x7f, // loop i32
0x20, 0x00, // get_local 0
0x41, 0x01, // i32.const 0
0x6a, // i32.add
0x21, 0x00, // set_local 0
0x0c, 0x00, // br 0
0x0b, // end
0x0b, // end
0x01, // 1 local decl.
0x01,
0x7f, // 1 i32 local.
0x03,
0x7f, // loop i32
0x20,
0x00, // get_local 0
0x41,
0x01, // i32.const 0
0x6a, // i32.add
0x21,
0x00, // set_local 0
0x0c,
0x00, // br 0
0x0b, // end
0x0b, // end
];
let mut trans = FuncTranslator::new();

View File

@@ -13,19 +13,10 @@
#![warn(unused_import_braces)]
#![cfg_attr(feature = "std", warn(unstable_features))]
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))]
#![cfg_attr(feature = "cargo-clippy",
allow(new_without_default, new_without_default_derive))]
#![cfg_attr(feature="cargo-clippy", warn(
float_arithmetic,
mut_mut,
nonminimal_bool,
option_map_unwrap_or,
option_map_unwrap_or_else,
print_stdout,
unicode_not_nfc,
use_self,
))]
warn(float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or,
option_map_unwrap_or_else, print_stdout, unicode_not_nfc, use_self))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
@@ -62,12 +53,12 @@ pub use translation_utils::{FunctionIndex, Global, GlobalIndex, GlobalInit, Memo
#[cfg(not(feature = "std"))]
mod std {
pub use alloc::vec;
pub use alloc::string;
pub use core::{u32, i32, str, cmp};
pub use alloc::vec;
pub use core::fmt;
pub use core::option;
pub use core::{cmp, str, i32, u32};
pub mod collections {
pub use hashmap_core::{HashMap, map as hash_map};
pub use hashmap_core::{map as hash_map, HashMap};
}
}

View File

@@ -28,42 +28,72 @@ pub fn translate_module<'data>(
let mut next_input = ParserInput::Default;
loop {
match *parser.read_with_input(next_input) {
ParserState::BeginSection { code: SectionCode::Type, .. } => {
ParserState::BeginSection {
code: SectionCode::Type,
..
} => {
parse_function_signatures(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Import, .. } => {
ParserState::BeginSection {
code: SectionCode::Import,
..
} => {
parse_import_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Function, .. } => {
ParserState::BeginSection {
code: SectionCode::Function,
..
} => {
parse_function_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Table, .. } => {
ParserState::BeginSection {
code: SectionCode::Table,
..
} => {
parse_table_section(&mut parser, environ)?;
}
ParserState::BeginSection { code: SectionCode::Memory, .. } => {
ParserState::BeginSection {
code: SectionCode::Memory,
..
} => {
parse_memory_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Global, .. } => {
ParserState::BeginSection {
code: SectionCode::Global,
..
} => {
parse_global_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Export, .. } => {
ParserState::BeginSection {
code: SectionCode::Export,
..
} => {
parse_export_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Start, .. } => {
ParserState::BeginSection {
code: SectionCode::Start,
..
} => {
parse_start_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Element, .. } => {
ParserState::BeginSection {
code: SectionCode::Element,
..
} => {
parse_elements_section(&mut parser, environ)?;
next_input = ParserInput::Default;
}
ParserState::BeginSection { code: SectionCode::Code, .. } => {
ParserState::BeginSection {
code: SectionCode::Code,
..
} => {
// The code section begins
break;
}
@@ -71,10 +101,16 @@ pub fn translate_module<'data>(
next_input = ParserInput::Default;
}
ParserState::EndWasm => return Ok(()),
ParserState::BeginSection { code: SectionCode::Data, .. } => {
ParserState::BeginSection {
code: SectionCode::Data,
..
} => {
parse_data_section(&mut parser, environ)?;
}
ParserState::BeginSection { code: SectionCode::Custom { .. }, .. } => {
ParserState::BeginSection {
code: SectionCode::Custom { .. },
..
} => {
// Ignore unknown custom sections.
next_input = ParserInput::SkipSection;
}
@@ -92,15 +128,16 @@ pub fn translate_module<'data>(
}
let mut reader = parser.create_binary_reader();
let size = reader.bytes_remaining();
environ.define_function_body(
reader.read_bytes(size).map_err(|e| {
WasmError::from_binary_reader_error(e)
})?,
)?;
environ.define_function_body(reader
.read_bytes(size)
.map_err(|e| WasmError::from_binary_reader_error(e))?)?;
}
loop {
match *parser.read() {
ParserState::BeginSection { code: SectionCode::Data, .. } => {
ParserState::BeginSection {
code: SectionCode::Data,
..
} => {
parse_data_section(&mut parser, environ)?;
}
ParserState::EndWasm => break,

View File

@@ -26,21 +26,19 @@ pub fn parse_function_signatures(
match *parser.read() {
ParserState::EndSection => break,
ParserState::TypeSectionEntry(FuncType {
form: wasmparser::Type::Func,
ref params,
ref returns,
}) => {
form: wasmparser::Type::Func,
ref params,
ref returns,
}) => {
let mut sig = Signature::new(environ.flags().call_conv());
sig.params.extend(params.iter().map(|ty| {
let cret_arg: ir::Type = type_to_type(ty).expect(
"only numeric types are supported in function signatures",
);
let cret_arg: ir::Type = type_to_type(ty)
.expect("only numeric types are supported in function signatures");
AbiParam::new(cret_arg)
}));
sig.returns.extend(returns.iter().map(|ty| {
let cret_arg: ir::Type = type_to_type(ty).expect(
"only numeric types are supported in function signatures",
);
let cret_arg: ir::Type = type_to_type(ty)
.expect("only numeric types are supported in function signatures");
AbiParam::new(cret_arg)
}));
environ.declare_signature(&sig);
@@ -72,10 +70,11 @@ pub fn parse_import_section<'data>(
environ.declare_func_import(sig as SignatureIndex, module_name, field_name);
}
ParserState::ImportSectionEntry {
ty: ImportSectionEntryType::Memory(MemoryType {
limits: ref memlimits,
shared,
}),
ty:
ImportSectionEntryType::Memory(MemoryType {
limits: ref memlimits,
shared,
}),
..
} => {
environ.declare_memory(Memory {
@@ -85,7 +84,8 @@ pub fn parse_import_section<'data>(
});
}
ParserState::ImportSectionEntry {
ty: ImportSectionEntryType::Global(ref ty), ..
ty: ImportSectionEntryType::Global(ref ty),
..
} => {
environ.declare_global(Global {
ty: type_to_type(&ty.content_type).unwrap(),
@@ -94,17 +94,16 @@ pub fn parse_import_section<'data>(
});
}
ParserState::ImportSectionEntry {
ty: ImportSectionEntryType::Table(ref tab), ..
} => {
environ.declare_table(Table {
ty: match type_to_type(&tab.element_type) {
Ok(t) => TableElementType::Val(t),
Err(()) => TableElementType::Func(),
},
size: tab.limits.initial as usize,
maximum: tab.limits.maximum.map(|x| x as usize),
})
}
ty: ImportSectionEntryType::Table(ref tab),
..
} => environ.declare_table(Table {
ty: match type_to_type(&tab.element_type) {
Ok(t) => TableElementType::Val(t),
Err(()) => TableElementType::Func(),
},
size: tab.limits.initial as usize,
maximum: tab.limits.maximum.map(|x| x as usize),
}),
ParserState::EndSection => break,
ParserState::Error(e) => return Err(WasmError::from_binary_reader_error(e)),
ref s => panic!("unexpected section content: {:?}", s),
@@ -325,16 +324,14 @@ pub fn parse_data_section<'data>(
pub fn parse_table_section(parser: &mut Parser, environ: &mut ModuleEnvironment) -> WasmResult<()> {
loop {
match *parser.read() {
ParserState::TableSectionEntry(ref table) => {
environ.declare_table(Table {
ty: match type_to_type(&table.element_type) {
Ok(t) => TableElementType::Val(t),
Err(()) => TableElementType::Func(),
},
size: table.limits.initial as usize,
maximum: table.limits.maximum.map(|x| x as usize),
})
}
ParserState::TableSectionEntry(ref table) => environ.declare_table(Table {
ty: match type_to_type(&table.element_type) {
Ok(t) => TableElementType::Val(t),
Err(()) => TableElementType::Func(),
},
size: table.limits.initial as usize,
maximum: table.limits.maximum.map(|x| x as usize),
}),
ParserState::EndSection => break,
ParserState::Error(e) => return Err(WasmError::from_binary_reader_error(e)),
ref s => panic!("unexpected section content: {:?}", s),

View File

@@ -47,54 +47,78 @@ pub enum ControlStackFrame {
impl ControlStackFrame {
pub fn num_return_values(&self) -> usize {
match *self {
ControlStackFrame::If { num_return_values, .. } |
ControlStackFrame::Block { num_return_values, .. } |
ControlStackFrame::Loop { num_return_values, .. } => num_return_values,
ControlStackFrame::If {
num_return_values, ..
}
| ControlStackFrame::Block {
num_return_values, ..
}
| ControlStackFrame::Loop {
num_return_values, ..
} => num_return_values,
}
}
pub fn following_code(&self) -> Ebb {
match *self {
ControlStackFrame::If { destination, .. } |
ControlStackFrame::Block { destination, .. } |
ControlStackFrame::Loop { destination, .. } => destination,
ControlStackFrame::If { destination, .. }
| ControlStackFrame::Block { destination, .. }
| ControlStackFrame::Loop { destination, .. } => destination,
}
}
pub fn br_destination(&self) -> Ebb {
match *self {
ControlStackFrame::If { destination, .. } |
ControlStackFrame::Block { destination, .. } => destination,
ControlStackFrame::If { destination, .. }
| ControlStackFrame::Block { destination, .. } => destination,
ControlStackFrame::Loop { header, .. } => header,
}
}
pub fn original_stack_size(&self) -> usize {
match *self {
ControlStackFrame::If { original_stack_size, .. } |
ControlStackFrame::Block { original_stack_size, .. } |
ControlStackFrame::Loop { original_stack_size, .. } => original_stack_size,
ControlStackFrame::If {
original_stack_size,
..
}
| ControlStackFrame::Block {
original_stack_size,
..
}
| ControlStackFrame::Loop {
original_stack_size,
..
} => original_stack_size,
}
}
pub fn is_loop(&self) -> bool {
match *self {
ControlStackFrame::If { .. } |
ControlStackFrame::Block { .. } => false,
ControlStackFrame::If { .. } | ControlStackFrame::Block { .. } => false,
ControlStackFrame::Loop { .. } => true,
}
}
pub fn exit_is_branched_to(&self) -> bool {
match *self {
ControlStackFrame::If { exit_is_branched_to, .. } |
ControlStackFrame::Block { exit_is_branched_to, .. } => exit_is_branched_to,
ControlStackFrame::If {
exit_is_branched_to,
..
}
| ControlStackFrame::Block {
exit_is_branched_to,
..
} => exit_is_branched_to,
ControlStackFrame::Loop { .. } => false,
}
}
pub fn set_branched_to_exit(&mut self) {
match *self {
ControlStackFrame::If { ref mut exit_is_branched_to, .. } |
ControlStackFrame::Block { ref mut exit_is_branched_to, .. } => {
*exit_is_branched_to = true
ControlStackFrame::If {
ref mut exit_is_branched_to,
..
}
| ControlStackFrame::Block {
ref mut exit_is_branched_to,
..
} => *exit_is_branched_to = true,
ControlStackFrame::Loop { .. } => {}
}
}
@@ -258,9 +282,9 @@ impl TranslationState {
environ: &mut FE,
) -> GlobalValue {
let index = index as GlobalIndex;
*self.globals.entry(index).or_insert_with(
|| environ.make_global(func, index),
)
*self.globals
.entry(index)
.or_insert_with(|| environ.make_global(func, index))
}
/// Get the `Heap` reference that should be used to access linear memory `index`.
@@ -272,9 +296,9 @@ impl TranslationState {
environ: &mut FE,
) -> ir::Heap {
let index = index as MemoryIndex;
*self.heaps.entry(index).or_insert_with(
|| environ.make_heap(func, index),
)
*self.heaps
.entry(index)
.or_insert_with(|| environ.make_heap(func, index))
}
/// Get the `SigRef` reference that should be used to make an indirect call with signature

View File

@@ -96,10 +96,10 @@ pub fn f64_translation(x: wasmparser::Ieee64) -> ir::immediates::Ieee64 {
pub fn num_return_values(ty: wasmparser::Type) -> usize {
match ty {
wasmparser::Type::EmptyBlockType => 0,
wasmparser::Type::I32 |
wasmparser::Type::F32 |
wasmparser::Type::I64 |
wasmparser::Type::F64 => 1,
wasmparser::Type::I32
| wasmparser::Type::F32
| wasmparser::Type::I64
| wasmparser::Type::F64 => 1,
_ => panic!("unsupported return value type"),
}
}