Skip to content

Commit 887f897

Browse files
abrownyurydelendik
authored andcommitted
Update wasmparser to 0.45.0 (bytecodealliance#1295)
Adds many new operators and a few API changes.
1 parent 8db7349 commit 887f897

File tree

3 files changed

+117
-91
lines changed

3 files changed

+117
-91
lines changed

cranelift/wasm/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ keywords = ["webassembly", "wasm"]
1111
edition = "2018"
1212

1313
[dependencies]
14-
wasmparser = { version = "0.39.2", default-features = false }
14+
wasmparser = { version = "0.45.0", default-features = false }
1515
cranelift-codegen = { path = "../cranelift-codegen", version = "0.51.0", default-features = false }
1616
cranelift-entity = { path = "../cranelift-entity", version = "0.51.0" }
1717
cranelift-frontend = { path = "../cranelift-frontend", version = "0.51.0", default-features = false }
@@ -26,8 +26,8 @@ target-lexicon = "0.9"
2626

2727
[features]
2828
default = ["std", "basic-blocks"]
29-
std = ["cranelift-codegen/std", "cranelift-frontend/std", "wasmparser/std"]
30-
core = ["hashbrown", "cranelift-codegen/core", "cranelift-frontend/core", "wasmparser/core"]
29+
std = ["cranelift-codegen/std", "cranelift-frontend/std"]
30+
core = ["hashbrown", "cranelift-codegen/core", "cranelift-frontend/core"]
3131
enable-serde = ["serde"]
3232

3333
# Temporary feature that enforces basic block semantics.

cranelift/wasm/src/code_translator.rs

Lines changed: 108 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
6565
* `get_local` and `set_local` are treated as non-SSA variables and will completely
6666
* disappear in the Cranelift Code
6767
***********************************************************************************/
68-
Operator::GetLocal { local_index } => {
68+
Operator::LocalGet { local_index } => {
6969
let val = builder.use_var(Variable::with_u32(*local_index));
7070
state.push1(val);
7171
let label = ValueLabel::from_u32(*local_index);
7272
builder.set_val_label(val, label);
7373
}
74-
Operator::SetLocal { local_index } => {
74+
Operator::LocalSet { local_index } => {
7575
let val = state.pop1();
7676
builder.def_var(Variable::with_u32(*local_index), val);
7777
let label = ValueLabel::from_u32(*local_index);
7878
builder.set_val_label(val, label);
7979
}
80-
Operator::TeeLocal { local_index } => {
80+
Operator::LocalTee { local_index } => {
8181
let val = state.peek1();
8282
builder.def_var(Variable::with_u32(*local_index), val);
8383
let label = ValueLabel::from_u32(*local_index);
@@ -86,7 +86,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
8686
/********************************** Globals ****************************************
8787
* `get_global` and `set_global` are handled by the environment.
8888
***********************************************************************************/
89-
Operator::GetGlobal { global_index } => {
89+
Operator::GlobalGet { global_index } => {
9090
let val = match state.get_global(builder.func, *global_index, environ)? {
9191
GlobalVariable::Const(val) => val,
9292
GlobalVariable::Memory { gv, offset, ty } => {
@@ -97,7 +97,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
9797
};
9898
state.push1(val);
9999
}
100-
Operator::SetGlobal { global_index } => {
100+
Operator::GlobalSet { global_index } => {
101101
match state.get_global(builder.func, *global_index, environ)? {
102102
GlobalVariable::Const(_) => panic!("global #{} is a constant", *global_index),
103103
GlobalVariable::Memory { gv, offset, ty } => {
@@ -639,11 +639,11 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
639639
let arg = state.pop1();
640640
state.push1(builder.ins().popcnt(arg));
641641
}
642-
Operator::I64ExtendSI32 => {
642+
Operator::I64ExtendI32S => {
643643
let val = state.pop1();
644644
state.push1(builder.ins().sextend(I64, val));
645645
}
646-
Operator::I64ExtendUI32 => {
646+
Operator::I64ExtendI32U => {
647647
let val = state.pop1();
648648
state.push1(builder.ins().uextend(I64, val));
649649
}
@@ -679,19 +679,19 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
679679
let arg = state.pop1();
680680
state.push1(builder.ins().fneg(arg));
681681
}
682-
Operator::F64ConvertUI64 | Operator::F64ConvertUI32 => {
682+
Operator::F64ConvertI64U | Operator::F64ConvertI32U => {
683683
let val = state.pop1();
684684
state.push1(builder.ins().fcvt_from_uint(F64, val));
685685
}
686-
Operator::F64ConvertSI64 | Operator::F64ConvertSI32 => {
686+
Operator::F64ConvertI64S | Operator::F64ConvertI32S => {
687687
let val = state.pop1();
688688
state.push1(builder.ins().fcvt_from_sint(F64, val));
689689
}
690-
Operator::F32ConvertSI64 | Operator::F32ConvertSI32 => {
690+
Operator::F32ConvertI64S | Operator::F32ConvertI32S => {
691691
let val = state.pop1();
692692
state.push1(builder.ins().fcvt_from_sint(F32, val));
693693
}
694-
Operator::F32ConvertUI64 | Operator::F32ConvertUI32 => {
694+
Operator::F32ConvertI64U | Operator::F32ConvertI32U => {
695695
let val = state.pop1();
696696
state.push1(builder.ins().fcvt_from_uint(F32, val));
697697
}
@@ -703,35 +703,35 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
703703
let val = state.pop1();
704704
state.push1(builder.ins().fdemote(F32, val));
705705
}
706-
Operator::I64TruncSF64 | Operator::I64TruncSF32 => {
706+
Operator::I64TruncF64S | Operator::I64TruncF32S => {
707707
let val = state.pop1();
708708
state.push1(builder.ins().fcvt_to_sint(I64, val));
709709
}
710-
Operator::I32TruncSF64 | Operator::I32TruncSF32 => {
710+
Operator::I32TruncF64S | Operator::I32TruncF32S => {
711711
let val = state.pop1();
712712
state.push1(builder.ins().fcvt_to_sint(I32, val));
713713
}
714-
Operator::I64TruncUF64 | Operator::I64TruncUF32 => {
714+
Operator::I64TruncF64U | Operator::I64TruncF32U => {
715715
let val = state.pop1();
716716
state.push1(builder.ins().fcvt_to_uint(I64, val));
717717
}
718-
Operator::I32TruncUF64 | Operator::I32TruncUF32 => {
718+
Operator::I32TruncF64U | Operator::I32TruncF32U => {
719719
let val = state.pop1();
720720
state.push1(builder.ins().fcvt_to_uint(I32, val));
721721
}
722-
Operator::I64TruncSSatF64 | Operator::I64TruncSSatF32 => {
722+
Operator::I64TruncSatF64S | Operator::I64TruncSatF32S => {
723723
let val = state.pop1();
724724
state.push1(builder.ins().fcvt_to_sint_sat(I64, val));
725725
}
726-
Operator::I32TruncSSatF64 | Operator::I32TruncSSatF32 => {
726+
Operator::I32TruncSatF64S | Operator::I32TruncSatF32S => {
727727
let val = state.pop1();
728728
state.push1(builder.ins().fcvt_to_sint_sat(I32, val));
729729
}
730-
Operator::I64TruncUSatF64 | Operator::I64TruncUSatF32 => {
730+
Operator::I64TruncSatF64U | Operator::I64TruncSatF32U => {
731731
let val = state.pop1();
732732
state.push1(builder.ins().fcvt_to_uint_sat(I64, val));
733733
}
734-
Operator::I32TruncUSatF64 | Operator::I32TruncUSatF32 => {
734+
Operator::I32TruncSatF64U | Operator::I32TruncSatF32U => {
735735
let val = state.pop1();
736736
state.push1(builder.ins().fcvt_to_uint_sat(I32, val));
737737
}
@@ -918,9 +918,12 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
918918
let val = builder.ins().is_null(arg);
919919
state.push1(val);
920920
}
921-
Operator::Wake { .. }
922-
| Operator::I32Wait { .. }
923-
| Operator::I64Wait { .. }
921+
Operator::RefFunc { .. } => {
922+
return Err(wasm_unsupported!("proposed ref operator {:?}", op))
923+
}
924+
Operator::AtomicNotify { .. }
925+
| Operator::I32AtomicWait { .. }
926+
| Operator::I64AtomicWait { .. }
924927
| Operator::I32AtomicLoad { .. }
925928
| Operator::I64AtomicLoad { .. }
926929
| Operator::I32AtomicLoad8U { .. }
@@ -937,54 +940,54 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
937940
| Operator::I64AtomicStore32 { .. }
938941
| Operator::I32AtomicRmwAdd { .. }
939942
| Operator::I64AtomicRmwAdd { .. }
940-
| Operator::I32AtomicRmw8UAdd { .. }
941-
| Operator::I32AtomicRmw16UAdd { .. }
942-
| Operator::I64AtomicRmw8UAdd { .. }
943-
| Operator::I64AtomicRmw16UAdd { .. }
944-
| Operator::I64AtomicRmw32UAdd { .. }
943+
| Operator::I32AtomicRmw8AddU { .. }
944+
| Operator::I32AtomicRmw16AddU { .. }
945+
| Operator::I64AtomicRmw8AddU { .. }
946+
| Operator::I64AtomicRmw16AddU { .. }
947+
| Operator::I64AtomicRmw32AddU { .. }
945948
| Operator::I32AtomicRmwSub { .. }
946949
| Operator::I64AtomicRmwSub { .. }
947-
| Operator::I32AtomicRmw8USub { .. }
948-
| Operator::I32AtomicRmw16USub { .. }
949-
| Operator::I64AtomicRmw8USub { .. }
950-
| Operator::I64AtomicRmw16USub { .. }
951-
| Operator::I64AtomicRmw32USub { .. }
950+
| Operator::I32AtomicRmw8SubU { .. }
951+
| Operator::I32AtomicRmw16SubU { .. }
952+
| Operator::I64AtomicRmw8SubU { .. }
953+
| Operator::I64AtomicRmw16SubU { .. }
954+
| Operator::I64AtomicRmw32SubU { .. }
952955
| Operator::I32AtomicRmwAnd { .. }
953956
| Operator::I64AtomicRmwAnd { .. }
954-
| Operator::I32AtomicRmw8UAnd { .. }
955-
| Operator::I32AtomicRmw16UAnd { .. }
956-
| Operator::I64AtomicRmw8UAnd { .. }
957-
| Operator::I64AtomicRmw16UAnd { .. }
958-
| Operator::I64AtomicRmw32UAnd { .. }
957+
| Operator::I32AtomicRmw8AndU { .. }
958+
| Operator::I32AtomicRmw16AndU { .. }
959+
| Operator::I64AtomicRmw8AndU { .. }
960+
| Operator::I64AtomicRmw16AndU { .. }
961+
| Operator::I64AtomicRmw32AndU { .. }
959962
| Operator::I32AtomicRmwOr { .. }
960963
| Operator::I64AtomicRmwOr { .. }
961-
| Operator::I32AtomicRmw8UOr { .. }
962-
| Operator::I32AtomicRmw16UOr { .. }
963-
| Operator::I64AtomicRmw8UOr { .. }
964-
| Operator::I64AtomicRmw16UOr { .. }
965-
| Operator::I64AtomicRmw32UOr { .. }
964+
| Operator::I32AtomicRmw8OrU { .. }
965+
| Operator::I32AtomicRmw16OrU { .. }
966+
| Operator::I64AtomicRmw8OrU { .. }
967+
| Operator::I64AtomicRmw16OrU { .. }
968+
| Operator::I64AtomicRmw32OrU { .. }
966969
| Operator::I32AtomicRmwXor { .. }
967970
| Operator::I64AtomicRmwXor { .. }
968-
| Operator::I32AtomicRmw8UXor { .. }
969-
| Operator::I32AtomicRmw16UXor { .. }
970-
| Operator::I64AtomicRmw8UXor { .. }
971-
| Operator::I64AtomicRmw16UXor { .. }
972-
| Operator::I64AtomicRmw32UXor { .. }
971+
| Operator::I32AtomicRmw8XorU { .. }
972+
| Operator::I32AtomicRmw16XorU { .. }
973+
| Operator::I64AtomicRmw8XorU { .. }
974+
| Operator::I64AtomicRmw16XorU { .. }
975+
| Operator::I64AtomicRmw32XorU { .. }
973976
| Operator::I32AtomicRmwXchg { .. }
974977
| Operator::I64AtomicRmwXchg { .. }
975-
| Operator::I32AtomicRmw8UXchg { .. }
976-
| Operator::I32AtomicRmw16UXchg { .. }
977-
| Operator::I64AtomicRmw8UXchg { .. }
978-
| Operator::I64AtomicRmw16UXchg { .. }
979-
| Operator::I64AtomicRmw32UXchg { .. }
978+
| Operator::I32AtomicRmw8XchgU { .. }
979+
| Operator::I32AtomicRmw16XchgU { .. }
980+
| Operator::I64AtomicRmw8XchgU { .. }
981+
| Operator::I64AtomicRmw16XchgU { .. }
982+
| Operator::I64AtomicRmw32XchgU { .. }
980983
| Operator::I32AtomicRmwCmpxchg { .. }
981984
| Operator::I64AtomicRmwCmpxchg { .. }
982-
| Operator::I32AtomicRmw8UCmpxchg { .. }
983-
| Operator::I32AtomicRmw16UCmpxchg { .. }
984-
| Operator::I64AtomicRmw8UCmpxchg { .. }
985-
| Operator::I64AtomicRmw16UCmpxchg { .. }
986-
| Operator::I64AtomicRmw32UCmpxchg { .. }
987-
| Operator::Fence { .. } => {
985+
| Operator::I32AtomicRmw8CmpxchgU { .. }
986+
| Operator::I32AtomicRmw16CmpxchgU { .. }
987+
| Operator::I64AtomicRmw8CmpxchgU { .. }
988+
| Operator::I64AtomicRmw16CmpxchgU { .. }
989+
| Operator::I64AtomicRmw32CmpxchgU { .. }
990+
| Operator::AtomicFence { .. } => {
988991
return Err(wasm_unsupported!("proposed thread operator {:?}", op));
989992
}
990993
Operator::MemoryCopy => {
@@ -1039,7 +1042,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
10391042
table,
10401043
)?);
10411044
}
1042-
Operator::TableCopy => {
1045+
Operator::TableCopy { .. } => {
10431046
// The WebAssembly MVP only supports one table and wasmparser will
10441047
// ensure that the table index specified is zero.
10451048
let dst_table_index = 0;
@@ -1060,7 +1063,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
10601063
len,
10611064
)?;
10621065
}
1063-
Operator::TableInit { segment } => {
1066+
Operator::TableInit { segment, table: _ } => {
10641067
// The WebAssembly MVP only supports one table and we assume it here.
10651068
let table_index = 0;
10661069
let table = state.get_table(builder.func, table_index, environ)?;
@@ -1077,6 +1080,9 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
10771080
len,
10781081
)?;
10791082
}
1083+
Operator::TableFill { .. } => {
1084+
return Err(wasm_unsupported!("proposed table operator {:?}", op));
1085+
}
10801086
Operator::ElemDrop { segment } => {
10811087
environ.translate_elem_drop(builder.cursor(), *segment)?;
10821088
}
@@ -1330,20 +1336,42 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
13301336
| Operator::I8x16ShrS
13311337
| Operator::I8x16ShrU
13321338
| Operator::I8x16Mul
1339+
| Operator::I64x2Mul
13331340
| Operator::I64x2ShrS
1334-
| Operator::I32x4TruncSF32x4Sat
1335-
| Operator::I32x4TruncUF32x4Sat
1336-
| Operator::I64x2TruncSF64x2Sat
1337-
| Operator::I64x2TruncUF64x2Sat
1338-
| Operator::F32x4ConvertSI32x4
1339-
| Operator::F32x4ConvertUI32x4
1340-
| Operator::F64x2ConvertSI64x2
1341-
| Operator::F64x2ConvertUI64x2 { .. }
1341+
| Operator::I32x4TruncSatF32x4S
1342+
| Operator::I32x4TruncSatF32x4U
1343+
| Operator::I64x2TruncSatF64x2S
1344+
| Operator::I64x2TruncSatF64x2U
1345+
| Operator::F32x4ConvertI32x4S
1346+
| Operator::F32x4ConvertI32x4U
1347+
| Operator::F64x2ConvertI64x2S
1348+
| Operator::F64x2ConvertI64x2U { .. }
1349+
| Operator::I8x16NarrowI16x8S { .. }
1350+
| Operator::I8x16NarrowI16x8U { .. }
1351+
| Operator::I16x8NarrowI32x4S { .. }
1352+
| Operator::I16x8NarrowI32x4U { .. }
1353+
| Operator::I16x8WidenLowI8x16S { .. }
1354+
| Operator::I16x8WidenHighI8x16S { .. }
1355+
| Operator::I16x8WidenLowI8x16U { .. }
1356+
| Operator::I16x8WidenHighI8x16U { .. }
1357+
| Operator::I32x4WidenLowI16x8S { .. }
1358+
| Operator::I32x4WidenHighI16x8S { .. }
1359+
| Operator::I32x4WidenLowI16x8U { .. }
1360+
| Operator::I32x4WidenHighI16x8U { .. }
13421361
| Operator::V8x16Swizzle
1343-
| Operator::I8x16LoadSplat { .. }
1344-
| Operator::I16x8LoadSplat { .. }
1345-
| Operator::I32x4LoadSplat { .. }
1346-
| Operator::I64x2LoadSplat { .. } => {
1362+
| Operator::V8x16LoadSplat { .. }
1363+
| Operator::V16x8LoadSplat { .. }
1364+
| Operator::V32x4LoadSplat { .. }
1365+
| Operator::V64x2LoadSplat { .. }
1366+
| Operator::I16x8Load8x8S { .. }
1367+
| Operator::I16x8Load8x8U { .. }
1368+
| Operator::I32x4Load16x4S { .. }
1369+
| Operator::I32x4Load16x4U { .. }
1370+
| Operator::I64x2Load32x2S { .. }
1371+
| Operator::I64x2Load32x2U { .. }
1372+
| Operator::I8x16RoundingAverageU { .. }
1373+
| Operator::I16x8RoundingAverageU { .. }
1374+
| Operator::V128AndNot { .. } => {
13471375
return Err(wasm_unsupported!("proposed SIMD operator {:?}", op));
13481376
}
13491377
};
@@ -1727,8 +1755,8 @@ fn type_of(operator: &Operator) -> Type {
17271755
| Operator::I32x4Add
17281756
| Operator::I32x4Sub
17291757
| Operator::I32x4Mul
1730-
| Operator::F32x4ConvertSI32x4
1731-
| Operator::F32x4ConvertUI32x4 => I32X4,
1758+
| Operator::F32x4ConvertI32x4S
1759+
| Operator::F32x4ConvertI32x4U => I32X4,
17321760

17331761
Operator::I64x2Splat
17341762
| Operator::I64x2ExtractLane { .. }
@@ -1741,8 +1769,8 @@ fn type_of(operator: &Operator) -> Type {
17411769
| Operator::I64x2ShrU
17421770
| Operator::I64x2Add
17431771
| Operator::I64x2Sub
1744-
| Operator::F64x2ConvertSI64x2
1745-
| Operator::F64x2ConvertUI64x2 => I64X2,
1772+
| Operator::F64x2ConvertI64x2S
1773+
| Operator::F64x2ConvertI64x2U => I64X2,
17461774

17471775
Operator::F32x4Splat
17481776
| Operator::F32x4ExtractLane { .. }
@@ -1762,8 +1790,8 @@ fn type_of(operator: &Operator) -> Type {
17621790
| Operator::F32x4Div
17631791
| Operator::F32x4Min
17641792
| Operator::F32x4Max
1765-
| Operator::I32x4TruncSF32x4Sat
1766-
| Operator::I32x4TruncUF32x4Sat => F32X4,
1793+
| Operator::I32x4TruncSatF32x4S
1794+
| Operator::I32x4TruncSatF32x4U => F32X4,
17671795

17681796
Operator::F64x2Splat
17691797
| Operator::F64x2ExtractLane { .. }
@@ -1783,8 +1811,8 @@ fn type_of(operator: &Operator) -> Type {
17831811
| Operator::F64x2Div
17841812
| Operator::F64x2Min
17851813
| Operator::F64x2Max
1786-
| Operator::I64x2TruncSF64x2Sat
1787-
| Operator::I64x2TruncUF64x2Sat => F64X2,
1814+
| Operator::I64x2TruncSatF64x2S
1815+
| Operator::I64x2TruncSatF64x2U => F64X2,
17881816

17891817
_ => unimplemented!(
17901818
"Currently only the SIMD instructions are translated to their return type: {:?}",

0 commit comments

Comments
 (0)