| 1 |
//! Nodes for intermediate representation of Wasm operators |
| 2 |
//! |
| 3 |
use egg::Id; |
| 4 |
use std::fmt::{self, Display}; |
| 5 |
use std::str::FromStr; |
| 6 |
use wasm_encoder::{AbstractHeapType, HeapType}; |
| 7 |
|
| 8 |
/// This is a macro used to define the `Lang` enum. |
| 9 |
/// |
| 10 |
/// The goal of this macro is to synthesize an implementation of the |
| 11 |
/// `egg::Language` trait which involves parsing strings, displaying operands, |
| 12 |
/// determining whether operands are equal, and getting the child nodes of |
| 13 |
/// operands. The macro here attempts to synthesize all these operations purely |
| 14 |
/// from the structure of each variant. Some more details are below on the |
| 15 |
/// definition of `enum Lang`. |
| 16 |
/// |
| 17 |
/// It's recommended to probably gloss over this macro. Ideally you can follow |
| 18 |
/// the pattern of all other existing variants and ignore this. If you can't |
| 19 |
/// ignore this macro I can apologize in advance because it's a pretty gnarly |
| 20 |
/// macro. While it seems to work it's "macro soup" incarnate. |
| 21 |
macro_rules! lang { |
| 22 |
( |
| 23 |
$(#[$attr:meta])* |
| 24 |
pub enum $lang:ident { |
| 25 |
$( |
| 26 |
$(#[$docs:meta])* |
| 27 |
$case:ident $(($($inner:tt)*))? = $name:tt, |
| 28 |
)* |
| 29 |
} |
| 30 |
) => { |
| 31 |
$(#[$attr])* |
| 32 |
pub enum $lang { |
| 33 |
$( |
| 34 |
$(#[$docs])* |
| 35 |
$case $(($($inner)*))?, |
| 36 |
)* |
| 37 |
} |
| 38 |
|
| 39 |
impl Display for $lang { |
| 40 |
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 41 |
match self { |
| 42 |
$( |
| 43 |
lang!(@first _x $lang::$case $(($($inner)*))?) => { |
| 44 |
lang!(@fmt f _x $name $($($inner)*)?) |
| 45 |
} |
| 46 |
)* |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
impl egg::Language for Lang { |
| 52 |
fn matches(&self, other: &Self) -> bool { |
| 53 |
match (self, other) { |
| 54 |
$( |
| 55 |
( |
| 56 |
lang!(@first _x $lang::$case $(($($inner)*))?), |
| 57 |
lang!(@first _y $lang::$case $(($($inner)*))?), |
| 58 |
) => lang!(@matches _x _y $($($inner)*)?), |
| 59 |
)* |
| 60 |
|
| 61 |
_ => false, |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
fn children(&self) -> &[Id] { |
| 66 |
match self { |
| 67 |
$( |
| 68 |
lang!(@last _x $lang::$case $(($($inner)*))?) => { |
| 69 |
lang!(@children _x $($($inner)*)?) |
| 70 |
} |
| 71 |
)* |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
fn children_mut(&mut self) -> &mut [Id] { |
| 76 |
match self { |
| 77 |
$( |
| 78 |
lang!(@last _x $lang::$case $(($($inner)*))?) => { |
| 79 |
lang!(@children_mut _x $($($inner)*)?) |
| 80 |
} |
| 81 |
)* |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
fn display_op(&self) -> &dyn std::fmt::Display { |
| 86 |
self |
| 87 |
} |
| 88 |
|
| 89 |
fn from_op_str(op_str: &str, children: Vec<Id>) -> Result<Self, String> { |
| 90 |
$( |
| 91 |
lang!(@from_op_str op_str children $name $lang::$case $(($($inner)*))?); |
| 92 |
)* |
| 93 |
Err(format!("invalid token {:?}", op_str)) |
| 94 |
} |
| 95 |
} |
| 96 |
}; |
| 97 |
|
| 98 |
// Helper to generate a match-pattern that extracts the first variant as |
| 99 |
// $x, and with no types it matches nothing. |
| 100 |
(@first $x:ident $lang:ident :: $case:ident) => ($lang::$case); |
| 101 |
(@first $x:ident $lang:ident :: $case:ident ($($t:tt)* )) => ($lang::$case($x, ..)); |
| 102 |
|
| 103 |
// Same as above, but matches the last variant. Note that for variants |
| 104 |
// with one type this will return that binding. |
| 105 |
(@last $x:ident $lang:ident :: $case:ident) => ($lang::$case); |
| 106 |
(@last $x:ident $lang:ident :: $case:ident ($($t:tt)* )) => ($lang::$case(.., $x)); |
| 107 |
|
| 108 |
// Implementation of `children` and `children_mut` |
| 109 |
// |
| 110 |
// These largely delegate the `Children` trait to perform the actual |
| 111 |
// slicing, but only if the last argument of the binding (which is input |
| 112 |
// via `$x` here) looks like a child. |
| 113 |
(@children $x:ident $($t:tt)*) => ( |
| 114 |
lang!(@if_last_is_child ($($t)*) { Children::as_slice($x) } else { &[] }) |
| 115 |
); |
| 116 |
(@children_mut $x:ident $($t:tt)*) => ( |
| 117 |
lang!(@if_last_is_child ($($t)*) { Children::as_slice_mut($x) } else { &mut [] }) |
| 118 |
); |
| 119 |
|
| 120 |
// Implementation of `display_op` |
| 121 |
|
| 122 |
(@fmt $fmt:ident $payload:ident $opname:tt) => ($fmt.write_str($opname)); |
| 123 |
(@fmt $fmt:ident $payload:ident $opname:tt $($t:tt)*) => ( |
| 124 |
lang!(@if_first_is_child ($($t)*) { |
| 125 |
// If the first type argument is a child then this variant has no |
| 126 |
// payload so our string representation is simply the operation. |
| 127 |
$fmt.write_str($opname) |
| 128 |
} else { |
| 129 |
// ... otherwise if the first type, `$payload`, isn't a child then |
| 130 |
// it's part of the static payload and is included after the |
| 131 |
// operand with a `.` |
| 132 |
write!($fmt, "{}.{}", $opname, $payload) |
| 133 |
}) |
| 134 |
); |
| 135 |
|
| 136 |
// Implementation of `matches` |
| 137 |
|
| 138 |
// special case for empty variants |
| 139 |
(@matches $x:ident $y:ident) => (true); |
| 140 |
// If the first element, which is bound by x/y, is a child then no equality |
| 141 |
// check is necessary, otherwise equality is performed. |
| 142 |
(@matches $x:ident $y:ident $($t:tt)*) => ( |
| 143 |
lang!(@if_first_is_child ($($t)*) { true } else { $x == $y }) |
| 144 |
); |
| 145 |
|
| 146 |
// Macro selection to condition on whether the last element of the tuple is |
| 147 |
// a list of children or not. |
| 148 |
|
| 149 |
// 2 types? Conventionally the last is always a list of children |
| 150 |
(@if_last_is_child ($t1:ty, $t2:ty) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 151 |
// 1 type? Well if the first looks like a list of children then it's a child |
| 152 |
(@if_last_is_child ([Id; $n:tt]) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 153 |
(@if_last_is_child (Vec<Id>) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 154 |
(@if_last_is_child (Id) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 155 |
// ... otherwise all other types and 0 types the last type isn't a child |
| 156 |
(@if_last_is_child ($($ty:tt)*) { $($t:tt)* } else { $($f:tt)* }) => ($($f)*); |
| 157 |
|
| 158 |
// Macro selection to condition on whether the first element of the tuple is |
| 159 |
// a list of children or not. |
| 160 |
|
| 161 |
// 2 types? Conventionally the first is never a child |
| 162 |
(@if_first_is_child ($t1:ty, $t2:ty) { $($t:tt)* } else { $($f:tt)* }) => ($($f)*); |
| 163 |
// 1 type? Check to see if the first looks like a child or not |
| 164 |
(@if_first_is_child ([Id; $n:tt]) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 165 |
(@if_first_is_child (Vec<Id>) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 166 |
(@if_first_is_child (Id) { $($t:tt)* } else { $($f:tt)* }) => ($($t)*); |
| 167 |
// ... otherwise all other types or 0 types don't have a child as tthe first type |
| 168 |
(@if_first_is_child ($($ty:tt)*) { $($t:tt)* } else { $($f:tt)* }) => ($($f)*); |
| 169 |
|
| 170 |
// Implementation of `from_op_str`. |
| 171 |
|
| 172 |
// Special case for no payload. The `$op` must match exactly and |
| 173 |
// `$children` must be empty. |
| 174 |
(@from_op_str $op:ident $children:ident $name:tt $lang:ident :: $case:ident) => ({ |
| 175 |
if $op == $name { |
| 176 |
if $children.len() != 0 { |
| 177 |
return Err(format!("expected zero children")) |
| 178 |
} |
| 179 |
return Ok($lang::$case); |
| 180 |
} |
| 181 |
}); |
| 182 |
|
| 183 |
(@from_op_str $op:ident $children:ident $name:tt $lang:ident::$case:ident($($t:tt)*)) => ( |
| 184 |
lang!(@if_first_is_child ($($t)*) { |
| 185 |
// If the first type is a child, then there's no payload and we |
| 186 |
// simply match `$op` to `$name` and fallibly convert the list of |
| 187 |
// children to the correct type. |
| 188 |
if $op == $name { |
| 189 |
return Ok($lang::$case(Children::from($children)?)) |
| 190 |
} |
| 191 |
} else { |
| 192 |
// Otherwise if the first type isn't a child, and this isn't an |
| 193 |
// empty variant handled above, our operator has a payload. Look |
| 194 |
// to see whether this is the correct operator by stripping the |
| 195 |
// prefix. |
| 196 |
if let Some(suffix) = $op.strip_prefix(concat!($name, ".")) { |
| 197 |
lang!(@if_last_is_child ($($t)*) {{ |
| 198 |
// If the last part of this type is a child list then the |
| 199 |
// first part parses `suffix` and children goes into the |
| 200 |
// list of children. |
| 201 |
return Ok($lang::$case( |
| 202 |
match suffix.parse() { |
| 203 |
Ok(e) => e, |
| 204 |
Err(e) => return Err(e.to_string()), |
| 205 |
}, |
| 206 |
Children::from($children)?, |
| 207 |
)); |
| 208 |
}} else {{ |
| 209 |
// If the last type isn't a child list then it means this |
| 210 |
// node has no children. Verify as such and then parse the |
| 211 |
// suffix for the static information. |
| 212 |
if $children.len() != 0 { |
| 213 |
return Err(format!("expected zero children")) |
| 214 |
} |
| 215 |
return Ok($lang::$case( |
| 216 |
match suffix.parse() { |
| 217 |
Ok(e) => e, |
| 218 |
Err(e) => return Err(e.to_string()), |
| 219 |
}, |
| 220 |
)); |
| 221 |
}}) |
| 222 |
} |
| 223 |
}) |
| 224 |
); |
| 225 |
} |
| 226 |
|
| 227 |
lang! { |
| 228 |
/// Each "mutable" operator of Wasm is defined here plus articial operators |
| 229 |
/// with a a custom behavior. |
| 230 |
/// |
| 231 |
/// As a note this enum is actually defined by the `lang!` macro above. The |
| 232 |
/// definition here is intended to look similar to the generated |
| 233 |
/// definition, but some conventions must be upheld for now: |
| 234 |
/// |
| 235 |
/// * Variants must either be `A`, `A(B)`, or `A(B, C)`. |
| 236 |
/// * For `A(B)` then `B` can either be a "list" of children or static |
| 237 |
/// information. |
| 238 |
/// * For `A(B, C)`, if specified `C` must be a "list" of children. |
| 239 |
/// |
| 240 |
/// The "list" of children can be either `Id`, `[Id; N]`, or `Vec<Id>`. When |
| 241 |
/// `B` is not a list of children it must implement both `Display` and |
| 242 |
/// `FromStr`. |
| 243 |
/// |
| 244 |
/// You can define custom operators by adding a variant to this enum. |
| 245 |
/// Notice that custom operator nodes can only be created from rewriting |
| 246 |
/// rules and not form the direct translation of the Wasm binary. Let's |
| 247 |
/// assume for example that we want to implement a custom node that insert |
| 248 |
/// three `nop` operators when it is written back to Wasm. |
| 249 |
/// |
| 250 |
/// * We firsts need to define the custom node ```ThreeNops``` as a variant of |
| 251 |
/// the [Lang] enum. |
| 252 |
/// ```ignore |
| 253 |
/// ThreeNops = "three.nops", |
| 254 |
/// ``` |
| 255 |
/// * The custom node needs to translated to Wasm. To do so, you need to modify |
| 256 |
/// the `expr2wasm` function somehow as follow |
| 257 |
/// ```ignore |
| 258 |
/// Lang::ThreeNops => { |
| 259 |
/// newfunc.instructions() |
| 260 |
/// .nop() |
| 261 |
/// .nop() |
| 262 |
/// .nop(); |
| 263 |
/// } |
| 264 |
/// ``` |
| 265 |
/// * The final step is to use this node in a rewriting rule. Inside the |
| 266 |
/// [`rules.rs`]() file |
| 267 |
/// ```ignore |
| 268 |
/// rewrite!("three-nops"; "?x" => "(container ?x three_nops)"), |
| 269 |
/// ``` |
| 270 |
/// |
| 271 |
/// Most other details about the `Lang` should be generated from the enum |
| 272 |
/// variant definition and you can otherwise be guided by various compiler |
| 273 |
/// errors. |
| 274 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 275 |
pub enum Lang { |
| 276 |
// binops integers |
| 277 |
/// i32.add operator |
| 278 |
I32Add([Id; 2]) = "i32.add", |
| 279 |
/// i64.add operator |
| 280 |
I64Add([Id; 2]) = "i64.add", |
| 281 |
/// i32.sub operator |
| 282 |
I32Sub([Id; 2]) = "i32.sub", |
| 283 |
/// i64.sub operator |
| 284 |
I64Sub([Id; 2]) = "i64.sub", |
| 285 |
/// i32.mul operator |
| 286 |
I32Mul([Id; 2]) = "i32.mul", |
| 287 |
/// i64.mul operator |
| 288 |
I64Mul([Id; 2]) = "i64.mul", |
| 289 |
/// i32.and operator |
| 290 |
I32And([Id; 2]) = "i32.and", |
| 291 |
/// i64.and operator |
| 292 |
I64And([Id; 2]) = "i64.and", |
| 293 |
/// i32.or operator |
| 294 |
I32Or([Id; 2]) = "i32.or", |
| 295 |
/// i64.or operator |
| 296 |
I64Or([Id; 2]) = "i64.or", |
| 297 |
/// i32.xor operator |
| 298 |
I32Xor([Id; 2]) = "i32.xor", |
| 299 |
/// i64.xor operator |
| 300 |
I64Xor([Id; 2]) = "i64.xor", |
| 301 |
/// i32.shl operator |
| 302 |
I32Shl([Id; 2]) = "i32.shl", |
| 303 |
/// i64.shl operator |
| 304 |
I64Shl([Id; 2]) = "i64.shl", |
| 305 |
/// i32.shru operator |
| 306 |
I32ShrU([Id; 2]) = "i32.shr_u", |
| 307 |
/// i64.shru operator |
| 308 |
I64ShrU([Id; 2]) = "i64.shr_u", |
| 309 |
/// i32.divu operator |
| 310 |
I32DivU([Id; 2]) = "i32.div_u", |
| 311 |
/// i64.divu operator |
| 312 |
I64DivU([Id; 2]) = "i64.div_u", |
| 313 |
/// i32.divs operator |
| 314 |
I32DivS([Id; 2]) = "i32.div_s", |
| 315 |
/// i64.divs operator |
| 316 |
I64DivS([Id; 2]) = "i64.div_s", |
| 317 |
/// i32.shrs operator |
| 318 |
I32ShrS([Id; 2]) = "i32.shr_s", |
| 319 |
/// i64.shrs operator |
| 320 |
I64ShrS([Id; 2]) = "i64.shr_s", |
| 321 |
/// i32.rotr operator |
| 322 |
I32RotR([Id; 2]) = "i32.rotr", |
| 323 |
/// i64.rotr operator |
| 324 |
I64RotR([Id; 2]) = "i64.rotr", |
| 325 |
/// i32.rotl operator |
| 326 |
I32RotL([Id; 2]) = "i32.rotl", |
| 327 |
/// i64.rotl operator |
| 328 |
I64RotL([Id; 2]) = "i64.rotl", |
| 329 |
/// i32.rems operator |
| 330 |
I32RemS([Id; 2]) = "i32.rem_s", |
| 331 |
/// i64.rems operator |
| 332 |
I64RemS([Id; 2]) = "i64.rem_s", |
| 333 |
/// i32.remu operator |
| 334 |
I32RemU([Id; 2]) = "i32.rem_u", |
| 335 |
/// i64.remu operator |
| 336 |
I64RemU([Id; 2]) = "i64.rem_u", |
| 337 |
/// i32.eq operator |
| 338 |
I32Eq([Id; 2]) = "i32.eq", |
| 339 |
/// i64.eq operator |
| 340 |
I64Eq([Id; 2]) = "i64.eq", |
| 341 |
/// i32.ne operator |
| 342 |
I32Ne([Id; 2]) = "i32.ne", |
| 343 |
/// i64.ne operator |
| 344 |
I64Ne([Id; 2]) = "i64.ne", |
| 345 |
/// i32.lts operator |
| 346 |
I32LtS([Id; 2]) = "i32.lt_s", |
| 347 |
/// i64.lts operator |
| 348 |
I64LtS([Id; 2]) = "i64.lt_s", |
| 349 |
/// i32.ltu operator |
| 350 |
I32LtU([Id; 2]) = "i32.lt_u", |
| 351 |
/// i64.ltu operator |
| 352 |
I64LtU([Id; 2]) = "i64.lt_u", |
| 353 |
/// i32.gts operator |
| 354 |
I32GtS([Id; 2]) = "i32.gt_s", |
| 355 |
/// i64.gts operator |
| 356 |
I64GtS([Id; 2]) = "i64.gt_s", |
| 357 |
/// i32.gtu operator |
| 358 |
I32GtU([Id; 2]) = "i32.gt_u", |
| 359 |
/// i64.gtu operator |
| 360 |
I64GtU([Id; 2]) = "i64.gt_u", |
| 361 |
/// i32.les operator |
| 362 |
I32LeS([Id; 2]) = "i32.le_s", |
| 363 |
/// i64.les operator |
| 364 |
I64LeS([Id; 2]) = "i64.le_s", |
| 365 |
/// i32.leu operator |
| 366 |
I32LeU([Id; 2]) = "i32.le_u", |
| 367 |
/// i64.leu operator |
| 368 |
I64LeU([Id; 2]) = "i64.le_u", |
| 369 |
/// i32.ges operator |
| 370 |
I32GeS([Id; 2]) = "i32.ge_s", |
| 371 |
/// i64.ges operator |
| 372 |
I64GeS([Id; 2]) = "i64.ge_s", |
| 373 |
/// i32.geu operator |
| 374 |
I32GeU([Id; 2]) = "i32.ge_u", |
| 375 |
/// i64.geu operator |
| 376 |
I64GeU([Id; 2]) = "i64.ge_u", |
| 377 |
// binops floats |
| 378 |
/// f32.add operator |
| 379 |
F32Add([Id; 2]) = "f32.add", |
| 380 |
/// f64.add operator |
| 381 |
F64Add([Id; 2]) = "f64.add", |
| 382 |
/// f32.sub operator |
| 383 |
F32Sub([Id; 2]) = "f32.sub", |
| 384 |
/// f64.sub operator |
| 385 |
F64Sub([Id; 2]) = "f64.sub", |
| 386 |
/// f32.mul operator |
| 387 |
F32Mul([Id; 2]) = "f32.mul", |
| 388 |
/// f64.mul operator |
| 389 |
F64Mul([Id; 2]) = "f64.mul", |
| 390 |
/// f32.div operator |
| 391 |
F32Div([Id; 2]) = "f32.div", |
| 392 |
/// f64.div operator |
| 393 |
F64Div([Id; 2]) = "f64.div", |
| 394 |
/// f32.min operator |
| 395 |
F32Min([Id; 2]) = "f32.min", |
| 396 |
/// f64.min operator |
| 397 |
F64Min([Id; 2]) = "f64.min", |
| 398 |
/// f32.max operator |
| 399 |
F32Max([Id; 2]) = "f32.max", |
| 400 |
/// f64.max operator |
| 401 |
F64Max([Id; 2]) = "f64.max", |
| 402 |
/// f32.copysign operator |
| 403 |
F32Copysign([Id; 2]) = "f32.copysign", |
| 404 |
/// f64.copysign operator |
| 405 |
F64Copysign([Id; 2]) = "f64.copysign", |
| 406 |
|
| 407 |
// unops v128 |
| 408 |
/// v128.not operator |
| 409 |
V128Not([Id; 1]) = "v128.not", |
| 410 |
/// v128.any_true operator |
| 411 |
V128AnyTrue([Id; 1]) = "v128.any_true", |
| 412 |
|
| 413 |
// binops v128 |
| 414 |
/// v128.bitselect operator |
| 415 |
V128And([Id; 2]) = "v128.and", |
| 416 |
/// v128.and_not operator |
| 417 |
V128AndNot([Id; 2]) = "v128.and_not", |
| 418 |
/// v128.or operator |
| 419 |
V128Or([Id; 2]) = "v128.or", |
| 420 |
/// v128.xor operator |
| 421 |
V128Xor([Id; 2]) = "v128.xor", |
| 422 |
|
| 423 |
// ternary ops v128 |
| 424 |
/// v128.bitselect operator |
| 425 |
V128Bitselect([Id; 3]) = "v128.bitselect", |
| 426 |
|
| 427 |
// frelops |
| 428 |
/// f32.eq operator |
| 429 |
F32Eq([Id; 2]) = "f32.eq", |
| 430 |
/// f64.eq operator |
| 431 |
F64Eq([Id; 2]) = "f64.eq", |
| 432 |
/// f32.ne operator |
| 433 |
F32Ne([Id; 2]) = "f32.ne", |
| 434 |
/// f64.ne operator |
| 435 |
F64Ne([Id; 2]) = "f64.ne", |
| 436 |
/// f32.lt operator |
| 437 |
F32Lt([Id; 2]) = "f32.lt", |
| 438 |
/// f64.lt operator |
| 439 |
F64Lt([Id; 2]) = "f64.lt", |
| 440 |
/// f32.gt operator |
| 441 |
F32Gt([Id; 2]) = "f32.gt", |
| 442 |
/// f64.gt operator |
| 443 |
F64Gt([Id; 2]) = "f64.gt", |
| 444 |
/// f32.le operator |
| 445 |
F32Le([Id; 2]) = "f32.le", |
| 446 |
/// f64.le operator |
| 447 |
F64Le([Id; 2]) = "f64.le", |
| 448 |
/// f32.ge operator |
| 449 |
F32Ge([Id; 2]) = "f32.ge", |
| 450 |
/// f64.ge operator |
| 451 |
F64Ge([Id; 2]) = "f64.ge", |
| 452 |
|
| 453 |
// unops integers |
| 454 |
/// i32.eqz operator |
| 455 |
I32Eqz([Id; 1]) = "i32.eqz", |
| 456 |
/// i64.eqz operator |
| 457 |
I64Eqz([Id; 1]) = "i64.eqz", |
| 458 |
|
| 459 |
/// i32.popcnt operator |
| 460 |
I32Popcnt([Id; 1]) = "i32.popcnt", |
| 461 |
/// i64.popcnt operator |
| 462 |
I64Popcnt([Id; 1]) = "i64.popcnt", |
| 463 |
/// i32.clz operator |
| 464 |
I32Clz([Id; 1]) = "i32.clz", |
| 465 |
/// i32.ctz operator |
| 466 |
I32Ctz([Id; 1]) = "i32.ctz", |
| 467 |
/// i64.ctz operator |
| 468 |
I64Ctz([Id; 1]) = "i64.ctz", |
| 469 |
/// i64.clz operator |
| 470 |
I64Clz([Id; 1]) = "i64.clz", |
| 471 |
|
| 472 |
// unops floats |
| 473 |
/// f32.abs operator |
| 474 |
F32Abs([Id; 1]) = "f32.abs", |
| 475 |
/// f64.abs operator |
| 476 |
F64Abs([Id; 1]) = "f64.abs", |
| 477 |
/// f32.neg operator |
| 478 |
F32Neg([Id; 1]) = "f32.neg", |
| 479 |
/// f64.neg operator |
| 480 |
F64Neg([Id; 1]) = "f64.neg", |
| 481 |
/// f32.sqrt operator |
| 482 |
F32Sqrt([Id; 1]) = "f32.sqrt", |
| 483 |
/// f64.sqrt operator |
| 484 |
F64Sqrt([Id; 1]) = "f64.sqrt", |
| 485 |
/// f32.ceil operator |
| 486 |
F32Ceil([Id; 1]) = "f32.ceil", |
| 487 |
/// f64.ceil operator |
| 488 |
F64Ceil([Id; 1]) = "f64.ceil", |
| 489 |
/// f32.floor operator |
| 490 |
F32Floor([Id; 1]) = "f32.floor", |
| 491 |
/// f64.floor operator |
| 492 |
F64Floor([Id; 1]) = "f64.floor", |
| 493 |
/// f32.trunc operator |
| 494 |
F32Trunc([Id; 1]) = "f32.trunc", |
| 495 |
/// f64.trunc operator |
| 496 |
F64Trunc([Id; 1]) = "f64.trunc", |
| 497 |
/// f32.nearest operator |
| 498 |
F32Nearest([Id; 1]) = "f32.nearest", |
| 499 |
/// f64.nearest operator |
| 500 |
F64Nearest([Id; 1]) = "f64.nearest", |
| 501 |
|
| 502 |
// Locals |
| 503 |
// Idx and value |
| 504 |
/// local.tee operator |
| 505 |
LocalTee(u32, Id) = "local.tee", |
| 506 |
// Idx and value |
| 507 |
/// local.set operator |
| 508 |
LocalSet(u32, Id) = "local.set", |
| 509 |
/// local.get operator |
| 510 |
LocalGet(u32) = "local.get", |
| 511 |
|
| 512 |
// Globals |
| 513 |
// Idx and value |
| 514 |
/// global.set operator |
| 515 |
GlobalSet(u32, Id) = "global.set", |
| 516 |
/// global.get operator |
| 517 |
GlobalGet(u32) = "global.get", |
| 518 |
|
| 519 |
// conversion operators |
| 520 |
/// i32.wrap_i64 operator |
| 521 |
Wrap([Id; 1]) = "wrap", |
| 522 |
|
| 523 |
// conversion |
| 524 |
/// i32.extend.8s operator |
| 525 |
I32Extend8S([Id; 1]) = "i32.extend8_s", |
| 526 |
/// i64.extend.8s operator |
| 527 |
I64Extend8S([Id; 1]) = "i64.extend8_s", |
| 528 |
/// i32.extend.16s operator |
| 529 |
I32Extend16S([Id; 1]) = "i32.extend16_s", |
| 530 |
/// i64.extend.16s operator |
| 531 |
I64Extend16S([Id; 1]) = "i64.extend16_s", |
| 532 |
/// i64.extend.32s operator |
| 533 |
I64Extend32S([Id; 1]) = "i64.extend32_s", |
| 534 |
/// i64.extendi.32s operator |
| 535 |
I64ExtendI32S([Id; 1]) = "i64.extend_i32_s", |
| 536 |
/// i64.extendi.32u operator |
| 537 |
I64ExtendI32U([Id; 1]) = "i64.extend_i32_u", |
| 538 |
/// i32.truncf.32s operator |
| 539 |
I32TruncF32S([Id; 1]) = "i32.trunc_f32_s", |
| 540 |
/// i32.truncf.32u operator |
| 541 |
I32TruncF32U([Id; 1]) = "i32.trunc_f32_u", |
| 542 |
/// i32.truncf.64s operator |
| 543 |
I32TruncF64S([Id; 1]) = "i32.trunc_f64_s", |
| 544 |
/// i32.truncf.64u operator |
| 545 |
I32TruncF64U([Id; 1]) = "i32.trunc_f64_u", |
| 546 |
/// i64.truncf.32s operator |
| 547 |
I64TruncF32S([Id; 1]) = "i64.trunc_f32_s", |
| 548 |
/// i64.truncf.32u operator |
| 549 |
I64TruncF32U([Id; 1]) = "i64.trunc_f32_u", |
| 550 |
/// i64.truncf.64s operator |
| 551 |
I64TruncF64S([Id; 1]) = "i64.trunc_f64_s", |
| 552 |
/// i64.truncf.64u operator |
| 553 |
I64TruncF64U([Id; 1]) = "i64.trunc_f64_u", |
| 554 |
/// f32.converti.32s operator |
| 555 |
F32ConvertI32S([Id; 1]) = "f32.convert_i32_s", |
| 556 |
/// f32.converti.32u operator |
| 557 |
F32ConvertI32U([Id; 1]) = "f32.convert_i32_u", |
| 558 |
/// f32.converti.64s operator |
| 559 |
F32ConvertI64S([Id; 1]) = "f32.convert_i64_s", |
| 560 |
/// f32.converti.64u operator |
| 561 |
F32ConvertI64U([Id; 1]) = "f32.convert_i64_u", |
| 562 |
/// f32.demote.f64 operator |
| 563 |
F32DemoteF64([Id; 1]) = "f32.demote_f64", |
| 564 |
/// f64.converti.32s operator |
| 565 |
F64ConvertI32S([Id; 1]) = "f64.convert_i32_s", |
| 566 |
/// f64.converti.32u operator |
| 567 |
F64ConvertI32U([Id; 1]) = "f64.convert_i32_u", |
| 568 |
/// f64.converti.64s operator |
| 569 |
F64ConvertI64S([Id; 1]) = "f64.convert_i64_s", |
| 570 |
/// f64.converti.64u operator |
| 571 |
F64ConvertI64U([Id; 1]) = "f64.convert_i64_u", |
| 572 |
/// f64.promote.f32 operator |
| 573 |
F64PromoteF32([Id; 1]) = "f64.promote_f32", |
| 574 |
/// i32.reinterpret.f32 operator |
| 575 |
I32ReinterpretF32([Id; 1]) = "i32.reinterpret_f32", |
| 576 |
/// i64.reinterpret.f64 operator |
| 577 |
I64ReinterpretF64([Id; 1]) = "i64.reinterpret_f64", |
| 578 |
/// f32.reinterpret.i32 operator |
| 579 |
F32ReinterpretI32([Id; 1]) = "f32.reinterpret_i32", |
| 580 |
/// f64.reinterpret.i64 operator |
| 581 |
F64ReinterpretI64([Id; 1]) = "f64.reinterpret_i64", |
| 582 |
/// i32.truncsatf.32s operator |
| 583 |
I32TruncSatF32S([Id; 1]) = "i32.trunc_sat_f32_s", |
| 584 |
/// i32.truncsatf.32u operator |
| 585 |
I32TruncSatF32U([Id; 1]) = "i32.trunc_sat_f32_u", |
| 586 |
/// i32.truncsatf.64s operator |
| 587 |
I32TruncSatF64S([Id; 1]) = "i32.trunc_sat_f64_s", |
| 588 |
/// i32.truncsatf.64u operator |
| 589 |
I32TruncSatF64U([Id; 1]) = "i32.trunc_sat_f64_u", |
| 590 |
/// i64.truncsatf.32s operator |
| 591 |
I64TruncSatF32S([Id; 1]) = "i64.trunc_sat_f32_s", |
| 592 |
/// i64.truncsatf.32u operator |
| 593 |
I64TruncSatF32U([Id; 1]) = "i64.trunc_sat_f32_u", |
| 594 |
/// i64.truncsatf.64s operator |
| 595 |
I64TruncSatF64S([Id; 1]) = "i64.trunc_sat_f64_s", |
| 596 |
/// i64.truncsatf.64u operator |
| 597 |
I64TruncSatF64U([Id; 1]) = "i64.trunc_sat_f64_u", |
| 598 |
|
| 599 |
// The u32 argument should be the function index |
| 600 |
/// call operator node |
| 601 |
Call(u32, Vec<Id>) = "call", |
| 602 |
/// drop operator |
| 603 |
Drop([Id; 1]) = "drop", |
| 604 |
/// nop operator |
| 605 |
Nop = "nop", |
| 606 |
|
| 607 |
// Memory operations |
| 608 |
// loads |
| 609 |
/// i32.load operator |
| 610 |
I32Load(MemArg, Id) = "i32.load", |
| 611 |
/// i64.load operator |
| 612 |
I64Load(MemArg, Id) = "i64.load", |
| 613 |
/// f32.load operator |
| 614 |
F32Load(MemArg, Id) = "f32.load", |
| 615 |
/// f64.load operator |
| 616 |
F64Load(MemArg, Id) = "f64.load", |
| 617 |
/// i32.load8_s operator |
| 618 |
I32Load8S(MemArg, Id) = "i32.load8_s", |
| 619 |
/// i32.load8_u operator |
| 620 |
I32Load8U(MemArg, Id) = "i32.load8_u", |
| 621 |
/// i32.load16_s operator |
| 622 |
I32Load16S(MemArg, Id) = "i32.load16_s", |
| 623 |
/// i32.load16_u operator |
| 624 |
I32Load16U(MemArg, Id) = "i32.load16_u", |
| 625 |
/// i64.load8_s operator |
| 626 |
I64Load8S(MemArg, Id) = "i64.load8_s", |
| 627 |
/// i64.load8_u operator |
| 628 |
I64Load8U(MemArg, Id) = "i64.load8_u", |
| 629 |
/// i64.load16_s operator |
| 630 |
I64Load16S(MemArg, Id) = "i64.load16_s", |
| 631 |
/// i64.load16_u operator |
| 632 |
I64Load16U(MemArg, Id) = "i64.load16_u", |
| 633 |
/// i64.load32_s operator |
| 634 |
I64Load32S(MemArg, Id) = "i64.load32_s", |
| 635 |
/// i64.load32_u operator |
| 636 |
I64Load32U(MemArg, Id) = "i64.load32_u", |
| 637 |
|
| 638 |
/// i32.store operator |
| 639 |
I32Store(MemArg, [Id; 2]) = "i32.store", |
| 640 |
/// i64.store operator |
| 641 |
I64Store(MemArg, [Id; 2]) = "i64.store", |
| 642 |
/// f32.store operator |
| 643 |
F32Store(MemArg, [Id; 2]) = "f32.store", |
| 644 |
/// f64.store operator |
| 645 |
F64Store(MemArg, [Id; 2]) = "f64.store", |
| 646 |
/// i32.store8 operator |
| 647 |
I32Store8(MemArg, [Id; 2]) = "i32.store8", |
| 648 |
/// i32.store16 operator |
| 649 |
I32Store16(MemArg, [Id; 2]) = "i32.store16", |
| 650 |
/// i64.store8 operator |
| 651 |
I64Store8(MemArg, [Id; 2]) = "i64.store8", |
| 652 |
/// i64.store16 operator |
| 653 |
I64Store16(MemArg, [Id; 2]) = "i64.store16", |
| 654 |
/// i64.store32 operator |
| 655 |
I64Store32(MemArg, [Id; 2]) = "i64.store32", |
| 656 |
|
| 657 |
/// Select operator |
| 658 |
Select([Id; 3]) = "select", |
| 659 |
/// Memory grow operator |
| 660 |
MemoryGrow(u32, Id) = "memory.grow", |
| 661 |
/// Memory size operator |
| 662 |
MemorySize(u32) = "memory.size", |
| 663 |
|
| 664 |
MemoryInit(MemoryInit, [Id; 3]) = "memory.init", |
| 665 |
DataDrop(u32) = "data.drop", |
| 666 |
MemoryCopy(MemoryCopy, [Id; 3]) = "memory.copy", |
| 667 |
MemoryFill(u32, [Id; 3]) = "memory.fill", |
| 668 |
|
| 669 |
TableInit(TableInit, [Id; 3]) = "table.init", |
| 670 |
ElemDrop(u32) = "elem.drop", |
| 671 |
TableCopy(TableCopy, [Id; 3]) = "table.copy", |
| 672 |
TableFill(u32, [Id; 3]) = "table.fill", |
| 673 |
TableGet(u32, Id) = "table.get", |
| 674 |
TableSet(u32, [Id; 2]) = "table.set", |
| 675 |
TableGrow(u32, [Id; 2]) = "table.grow", |
| 676 |
TableSize(u32) = "table.size", |
| 677 |
RefIsNull(Id) = "ref.is_null", |
| 678 |
|
| 679 |
V128Load(MemArg, Id) = "v128.load", |
| 680 |
V128Load8x8S(MemArg, Id) = "v128.load8x8_s", |
| 681 |
V128Load8x8U(MemArg, Id) = "v128.load8x8_u", |
| 682 |
V128Load16x4S(MemArg, Id) = "v128.load16x4_s", |
| 683 |
V128Load16x4U(MemArg, Id) = "v128.load16x4_u", |
| 684 |
V128Load32x2S(MemArg, Id) = "v128.load32x2_s", |
| 685 |
V128Load32x2U(MemArg, Id) = "v128.load32x2_u", |
| 686 |
V128Load8Splat(MemArg, Id) = "v128.load8_splat", |
| 687 |
V128Load16Splat(MemArg, Id) = "v128.load16_splat", |
| 688 |
V128Load32Splat(MemArg, Id) = "v128.load32_splat", |
| 689 |
V128Load64Splat(MemArg, Id) = "v128.load64_splat", |
| 690 |
V128Load32Zero(MemArg, Id) = "v128.load32_zero", |
| 691 |
V128Load64Zero(MemArg, Id) = "v128.load64_zero", |
| 692 |
V128Store(MemArg, [Id; 2]) = "v128.store", |
| 693 |
V128Load8Lane(MemArgLane, [Id; 2]) = "v128.load8_lane", |
| 694 |
V128Load16Lane(MemArgLane, [Id; 2]) = "v128.load16_lane", |
| 695 |
V128Load32Lane(MemArgLane, [Id; 2]) = "v128.load32_lane", |
| 696 |
V128Load64Lane(MemArgLane, [Id; 2]) = "v128.load64_lane", |
| 697 |
V128Store8Lane(MemArgLane, [Id; 2]) = "v128.store8_lane", |
| 698 |
V128Store16Lane(MemArgLane, [Id; 2]) = "v128.store16_lane", |
| 699 |
V128Store32Lane(MemArgLane, [Id; 2]) = "v128.store32_lane", |
| 700 |
V128Store64Lane(MemArgLane, [Id; 2]) = "v128.store64_lane", |
| 701 |
|
| 702 |
I8x16ExtractLaneS(u8, Id) = "i8x16.extract_lane_s", |
| 703 |
I8x16ExtractLaneU(u8, Id) = "i8x16.extract_lane_u", |
| 704 |
I8x16ReplaceLane(u8, [Id; 2]) = "i8x16.replace_lane", |
| 705 |
I16x8ExtractLaneS(u8, Id) = "i16x8.extract_lane_s", |
| 706 |
I16x8ExtractLaneU(u8, Id) = "i16x8.extract_lane_u", |
| 707 |
I16x8ReplaceLane(u8, [Id; 2]) = "i16x8.replace_lane", |
| 708 |
I32x4ExtractLane(u8, Id) = "i32x4.extract_lane", |
| 709 |
I32x4ReplaceLane(u8, [Id; 2]) = "i32x4.replace_lane", |
| 710 |
I64x2ExtractLane(u8, Id) = "i64x2.extract_lane", |
| 711 |
I64x2ReplaceLane(u8, [Id; 2]) = "i64x2.replace_lane", |
| 712 |
F32x4ExtractLane(u8, Id) = "f32x4.extract_lane", |
| 713 |
F32x4ReplaceLane(u8, [Id; 2]) = "f32x4.replace_lane", |
| 714 |
F64x2ExtractLane(u8, Id) = "f64x2.extract_lane", |
| 715 |
F64x2ReplaceLane(u8, [Id; 2]) = "f64x2.replace_lane", |
| 716 |
|
| 717 |
I8x16Swizzle([Id; 2]) = "i8x16.swizzle", |
| 718 |
I8x16Shuffle(Shuffle, [Id; 2]) = "i8x16.shuffle", |
| 719 |
I8x16Splat([Id; 1]) = "i8x16.splat", |
| 720 |
I16x8Splat([Id; 1]) = "i16x8.splat", |
| 721 |
I32x4Splat([Id; 1]) = "i32x4.splat", |
| 722 |
I64x2Splat([Id; 1]) = "i64x2.splat", |
| 723 |
F32x4Splat([Id; 1]) = "f32x4.splat", |
| 724 |
F64x2Splat([Id; 1]) = "f64x2.splat", |
| 725 |
|
| 726 |
I8x16Eq([Id; 2]) = "i8x16.eq", |
| 727 |
I8x16Ne([Id; 2]) = "i8x16.ne", |
| 728 |
I8x16LtS([Id; 2]) = "i8x16.lt_s", |
| 729 |
I8x16LtU([Id; 2]) = "i8x16.lt_u", |
| 730 |
I8x16GtS([Id; 2]) = "i8x16.gt_s", |
| 731 |
I8x16GtU([Id; 2]) = "i8x16.gt_u", |
| 732 |
I8x16LeS([Id; 2]) = "i8x16.le_s", |
| 733 |
I8x16LeU([Id; 2]) = "i8x16.le_u", |
| 734 |
I8x16GeS([Id; 2]) = "i8x16.ge_s", |
| 735 |
I8x16GeU([Id; 2]) = "i8x16.ge_u", |
| 736 |
|
| 737 |
I16x8Eq([Id; 2]) = "i16x8.eq", |
| 738 |
I16x8Ne([Id; 2]) = "i16x8.ne", |
| 739 |
I16x8LtS([Id; 2]) = "i16x8.lt_s", |
| 740 |
I16x8LtU([Id; 2]) = "i16x8.lt_u", |
| 741 |
I16x8GtS([Id; 2]) = "i16x8.gt_s", |
| 742 |
I16x8GtU([Id; 2]) = "i16x8.gt_u", |
| 743 |
I16x8LeS([Id; 2]) = "i16x8.le_s", |
| 744 |
I16x8LeU([Id; 2]) = "i16x8.le_u", |
| 745 |
I16x8GeS([Id; 2]) = "i16x8.ge_s", |
| 746 |
I16x8GeU([Id; 2]) = "i16x8.ge_u", |
| 747 |
|
| 748 |
I32x4Eq([Id; 2]) = "i32x4.eq", |
| 749 |
I32x4Ne([Id; 2]) = "i32x4.ne", |
| 750 |
I32x4LtS([Id; 2]) = "i32x4.lt_s", |
| 751 |
I32x4LtU([Id; 2]) = "i32x4.lt_u", |
| 752 |
I32x4GtS([Id; 2]) = "i32x4.gt_s", |
| 753 |
I32x4GtU([Id; 2]) = "i32x4.gt_u", |
| 754 |
I32x4LeS([Id; 2]) = "i32x4.le_s", |
| 755 |
I32x4LeU([Id; 2]) = "i32x4.le_u", |
| 756 |
I32x4GeS([Id; 2]) = "i32x4.ge_s", |
| 757 |
I32x4GeU([Id; 2]) = "i32x4.ge_u", |
| 758 |
|
| 759 |
I64x2Eq([Id; 2]) = "i64x2.eq", |
| 760 |
I64x2Ne([Id; 2]) = "i64x2.ne", |
| 761 |
I64x2LtS([Id; 2]) = "i64x2.lt_s", |
| 762 |
I64x2GtS([Id; 2]) = "i64x2.gt_s", |
| 763 |
I64x2LeS([Id; 2]) = "i64x2.le_s", |
| 764 |
I64x2GeS([Id; 2]) = "i64x2.ge_s", |
| 765 |
|
| 766 |
F32x4Eq([Id; 2]) = "f32x4.eq", |
| 767 |
F32x4Ne([Id; 2]) = "f32x4.ne", |
| 768 |
F32x4Lt([Id; 2]) = "f32x4.lt", |
| 769 |
F32x4Gt([Id; 2]) = "f32x4.gt", |
| 770 |
F32x4Le([Id; 2]) = "f32x4.le", |
| 771 |
F32x4Ge([Id; 2]) = "f32x4.ge", |
| 772 |
|
| 773 |
I8x16Abs([Id; 1]) = "i8x16.abs", |
| 774 |
I8x16Neg([Id; 1]) = "i8x16.neg", |
| 775 |
I8x16Popcnt([Id; 1]) = "i8x16.popcnt", |
| 776 |
I8x16AllTrue([Id; 1]) = "i8x16.all_true", |
| 777 |
I8x16Bitmask([Id; 1]) = "i8x16.bitmask", |
| 778 |
I8x16NarrowI16x8S([Id; 2]) = "i8x16.narrow_i16x8_s", |
| 779 |
I8x16NarrowI16x8U([Id; 2]) = "i8x16.narrow_i16x8_u", |
| 780 |
I8x16Shl([Id; 2]) = "i8x16.shl", |
| 781 |
I8x16ShrS([Id; 2]) = "i8x16.shr_s", |
| 782 |
I8x16ShrU([Id; 2]) = "i8x16.shr_u", |
| 783 |
I8x16Add([Id; 2]) = "i8x16.add", |
| 784 |
I8x16AddSatS([Id; 2]) = "i8x16.add_sat_s", |
| 785 |
I8x16AddSatU([Id; 2]) = "i8x16.add_sat_u", |
| 786 |
I8x16Sub([Id; 2]) = "i8x16.sub", |
| 787 |
I8x16SubSatS([Id; 2]) = "i8x16.sub_sat_s", |
| 788 |
I8x16SubSatU([Id; 2]) = "i8x16.sub_sat_u", |
| 789 |
I8x16MinS([Id; 2]) = "i8x16.min_s", |
| 790 |
I8x16MinU([Id; 2]) = "i8x16.min_u", |
| 791 |
I8x16MaxS([Id; 2]) = "i8x16.max_s", |
| 792 |
I8x16MaxU([Id; 2]) = "i8x16.max_u", |
| 793 |
I8x16AvgrU([Id; 2]) = "i8x16.avgr_u", |
| 794 |
|
| 795 |
I16x8ExtAddPairwiseI8x16S([Id; 1]) = "i16x8.extadd_pairwise_i8x16_s", |
| 796 |
I16x8ExtAddPairwiseI8x16U([Id; 1]) = "i16x8.extadd_pairwise_i8x16_u", |
| 797 |
I16x8Abs([Id; 1]) = "i16x8.abs", |
| 798 |
I16x8Neg([Id; 1]) = "i16x8.neg", |
| 799 |
I16x8Q15MulrSatS([Id; 2]) = "i16x8.q15mulr_sat_s", |
| 800 |
I16x8AllTrue([Id; 1]) = "i16x8.all_true", |
| 801 |
I16x8Bitmask([Id; 1]) = "i16x8.bitmask", |
| 802 |
I16x8NarrowI32x4S([Id; 2]) = "i16x8.narrow_i32x4_s", |
| 803 |
I16x8NarrowI32x4U([Id; 2]) = "i16x8.narrow_i32x4_u", |
| 804 |
I16x8ExtendLowI8x16S([Id; 1]) = "i16x8.extend_low_i8x16_s", |
| 805 |
I16x8ExtendHighI8x16S([Id; 1]) = "i16x8.extend_high_i8x16_s", |
| 806 |
I16x8ExtendLowI8x16U([Id; 1]) = "i16x8.extend_low_i8x16_u", |
| 807 |
I16x8ExtendHighI8x16U([Id; 1]) = "i16x8.extend_high_i8x16_u", |
| 808 |
I16x8Shl([Id; 2]) = "i16x8.shl", |
| 809 |
I16x8ShrS([Id; 2]) = "i16x8.shr_s", |
| 810 |
I16x8ShrU([Id; 2]) = "i16x8.shr_u", |
| 811 |
I16x8Add([Id; 2]) = "i16x8.add", |
| 812 |
I16x8AddSatS([Id; 2]) = "i16x8.add_sat_s", |
| 813 |
I16x8AddSatU([Id; 2]) = "i16x8.add_sat_u", |
| 814 |
I16x8Sub([Id; 2]) = "i16x8.sub", |
| 815 |
I16x8SubSatS([Id; 2]) = "i16x8.sub_sat_s", |
| 816 |
I16x8SubSatU([Id; 2]) = "i16x8.sub_sat_u", |
| 817 |
I16x8Mul([Id; 2]) = "i16x8.mul", |
| 818 |
I16x8MinS([Id; 2]) = "i16x8.min_s", |
| 819 |
I16x8MinU([Id; 2]) = "i16x8.min_u", |
| 820 |
I16x8MaxS([Id; 2]) = "i16x8.max_s", |
| 821 |
I16x8MaxU([Id; 2]) = "i16x8.max_u", |
| 822 |
I16x8AvgrU([Id; 2]) = "i16x8.avgr_u", |
| 823 |
I16x8ExtMulLowI8x16S([Id; 2]) = "i16x8.extmul_low_i8x16_s", |
| 824 |
I16x8ExtMulHighI8x16S([Id; 2]) = "i16x8.extmul_low_i8x16_s", |
| 825 |
I16x8ExtMulLowI8x16U([Id; 2]) = "i16x8.extmul_low_i8x16_u", |
| 826 |
I16x8ExtMulHighI8x16U([Id; 2]) = "i16x8.extmul_low_i8x16_u", |
| 827 |
|
| 828 |
I32x4ExtAddPairwiseI16x8S([Id; 1]) = "i32x4.extadd_pairwise_i16x8_s", |
| 829 |
I32x4ExtAddPairwiseI16x8U([Id; 1]) = "i32x4.extadd_pairwise_i16x8_u", |
| 830 |
I32x4Abs([Id; 1]) = "i32x4.abs", |
| 831 |
I32x4Neg([Id; 1]) = "i32x4.neg", |
| 832 |
I32x4AllTrue([Id; 1]) = "i32x4.all_true", |
| 833 |
I32x4Bitmask([Id; 1]) = "i32x4.bitmask", |
| 834 |
I32x4ExtendLowI16x8S([Id; 1]) = "i32x4.extend_low_i16x8_s", |
| 835 |
I32x4ExtendHighI16x8S([Id; 1]) = "i32x4.extend_high_i16x8_s", |
| 836 |
I32x4ExtendLowI16x8U([Id; 1]) = "i32x4.extend_low_i16x8_u", |
| 837 |
I32x4ExtendHighI16x8U([Id; 1]) = "i32x4.extend_high_i16x8_u", |
| 838 |
I32x4Shl([Id; 2]) = "i32x4.shl", |
| 839 |
I32x4ShrS([Id; 2]) = "i32x4.shr_s", |
| 840 |
I32x4ShrU([Id; 2]) = "i32x4.shr_u", |
| 841 |
I32x4Add([Id; 2]) = "i32x4.add", |
| 842 |
I32x4Sub([Id; 2]) = "i32x4.sub", |
| 843 |
I32x4Mul([Id; 2]) = "i32x4.mul", |
| 844 |
I32x4MinS([Id; 2]) = "i32x4.min_s", |
| 845 |
I32x4MinU([Id; 2]) = "i32x4.min_u", |
| 846 |
I32x4MaxS([Id; 2]) = "i32x4.max_s", |
| 847 |
I32x4MaxU([Id; 2]) = "i32x4.max_u", |
| 848 |
I32x4DotI16x8S([Id; 2]) = "i32x4.dot_i16x8_s", |
| 849 |
I32x4ExtMulLowI16x8S([Id; 2]) = "i32x4.extmul_low_i16x8_s", |
| 850 |
I32x4ExtMulHighI16x8S([Id; 2]) = "i32x4.extmul_low_i16x8_s", |
| 851 |
I32x4ExtMulLowI16x8U([Id; 2]) = "i32x4.extmul_low_i16x8_u", |
| 852 |
I32x4ExtMulHighI16x8U([Id; 2]) = "i32x4.extmul_low_i16x8_u", |
| 853 |
|
| 854 |
I64x2Abs([Id; 1]) = "i64x2.abs", |
| 855 |
I64x2Neg([Id; 1]) = "i64x2.neg", |
| 856 |
I64x2AllTrue([Id; 1]) = "i64x2.all_true", |
| 857 |
I64x2Bitmask([Id; 1]) = "i64x2.bitmask", |
| 858 |
I64x2ExtendLowI32x4S([Id; 1]) = "i64x2.extend_low_i32x4_s", |
| 859 |
I64x2ExtendHighI32x4S([Id; 1]) = "i64x2.extend_high_i32x4_s", |
| 860 |
I64x2ExtendLowI32x4U([Id; 1]) = "i64x2.extend_low_i32x4_u", |
| 861 |
I64x2ExtendHighI32x4U([Id; 1]) = "i64x2.extend_high_i32x4_u", |
| 862 |
I64x2Shl([Id; 2]) = "i64x2.shl", |
| 863 |
I64x2ShrS([Id; 2]) = "i64x2.shr_s", |
| 864 |
I64x2ShrU([Id; 2]) = "i64x2.shr_u", |
| 865 |
I64x2Add([Id; 2]) = "i64x2.add", |
| 866 |
I64x2Sub([Id; 2]) = "i64x2.sub", |
| 867 |
I64x2Mul([Id; 2]) = "i64x2.mul", |
| 868 |
I64x2ExtMulLowI32x4S([Id; 2]) = "i64x2.extmul_low_i32x4_s", |
| 869 |
I64x2ExtMulHighI32x4S([Id; 2]) = "i64x2.extmul_low_i32x4_s", |
| 870 |
I64x2ExtMulLowI32x4U([Id; 2]) = "i64x2.extmul_low_i32x4_u", |
| 871 |
I64x2ExtMulHighI32x4U([Id; 2]) = "i64x2.extmul_low_i32x4_u", |
| 872 |
|
| 873 |
F64x2Eq([Id; 2]) = "f64x2.eq", |
| 874 |
F64x2Ne([Id; 2]) = "f64x2.ne", |
| 875 |
F64x2Lt([Id; 2]) = "f64x2.lt", |
| 876 |
F64x2Gt([Id; 2]) = "f64x2.gt", |
| 877 |
F64x2Le([Id; 2]) = "f64x2.le", |
| 878 |
F64x2Ge([Id; 2]) = "f64x2.ge", |
| 879 |
|
| 880 |
F32x4Ceil([Id; 1]) = "f32x4.ceil", |
| 881 |
F32x4Floor([Id; 1]) = "f32x4.floor", |
| 882 |
F32x4Trunc([Id; 1]) = "f32x4.trunc", |
| 883 |
F32x4Nearest([Id; 1]) = "f32x4.nearest", |
| 884 |
F32x4Abs([Id; 1]) = "f32x4.abs", |
| 885 |
F32x4Neg([Id; 1]) = "f32x4.neg", |
| 886 |
F32x4Sqrt([Id; 1]) = "f32x4.sqrt", |
| 887 |
F32x4Add([Id; 2]) = "f32x4.add", |
| 888 |
F32x4Sub([Id; 2]) = "f32x4.sub", |
| 889 |
F32x4Mul([Id; 2]) = "f32x4.mul", |
| 890 |
F32x4Div([Id; 2]) = "f32x4.div", |
| 891 |
F32x4Min([Id; 2]) = "f32x4.min", |
| 892 |
F32x4Max([Id; 2]) = "f32x4.max", |
| 893 |
F32x4PMin([Id; 2]) = "f32x4.pmin", |
| 894 |
F32x4PMax([Id; 2]) = "f32x4.pmax", |
| 895 |
|
| 896 |
F64x2Ceil([Id; 1]) = "f64x2.ceil", |
| 897 |
F64x2Floor([Id; 1]) = "f64x2.floor", |
| 898 |
F64x2Trunc([Id; 1]) = "f64x2.trunc", |
| 899 |
F64x2Nearest([Id; 1]) = "f64x2.nearest", |
| 900 |
F64x2Abs([Id; 1]) = "f64x2.abs", |
| 901 |
F64x2Neg([Id; 1]) = "f64x2.neg", |
| 902 |
F64x2Sqrt([Id; 1]) = "f64x2.sqrt", |
| 903 |
F64x2Add([Id; 2]) = "f64x2.add", |
| 904 |
F64x2Sub([Id; 2]) = "f64x2.sub", |
| 905 |
F64x2Mul([Id; 2]) = "f64x2.mul", |
| 906 |
F64x2Div([Id; 2]) = "f64x2.div", |
| 907 |
F64x2Min([Id; 2]) = "f64x2.min", |
| 908 |
F64x2Max([Id; 2]) = "f64x2.max", |
| 909 |
F64x2PMin([Id; 2]) = "f64x2.pmin", |
| 910 |
F64x2PMax([Id; 2]) = "f64x2.pmax", |
| 911 |
|
| 912 |
I32x4TruncSatF32x4S([Id; 1]) = "i32x4.trunc_sat_f32x4_s", |
| 913 |
I32x4TruncSatF32x4U([Id; 1]) = "i32x4.trunc_sat_f32x4_u", |
| 914 |
F32x4ConvertI32x4S([Id; 1]) = "f32x4.convert_i32x4_s", |
| 915 |
F32x4ConvertI32x4U([Id; 1]) = "f32x4.convert_i32x4_u", |
| 916 |
I32x4TruncSatF64x2SZero([Id; 1]) = "i32x4.trunc_sat_f64x2_s_zero", |
| 917 |
I32x4TruncSatF64x2UZero([Id; 1]) = "i32x4.trunc_sat_f64x2_u_zero", |
| 918 |
F64x2ConvertLowI32x4S([Id; 1]) = "f64x2.convert_low_i32x4_s", |
| 919 |
F64x2ConvertLowI32x4U([Id; 1]) = "f64x2.convert_low_i32x4_u", |
| 920 |
F32x4DemoteF64x2Zero([Id; 1]) = "f32x4.demote_f64x2_zero", |
| 921 |
F64x2PromoteLowF32x4([Id; 1]) = "f64x2.promote_low_f32x4", |
| 922 |
|
| 923 |
// relaxed-simd instructions |
| 924 |
|
| 925 |
I8x16RelaxedSwizzle([Id; 2]) = "i8x16.relaxed_swizzle", |
| 926 |
I32x4RelaxedTruncF32x4S([Id; 1]) = "i32x4.relaxed_trunc_f32x4_s", |
| 927 |
I32x4RelaxedTruncF32x4U([Id; 1]) = "i32x4.relaxed_trunc_f32x4_u", |
| 928 |
I32x4RelaxedTruncF64x2SZero([Id; 1]) = "i32x4.relaxed_trunc_f64x2_s_zero", |
| 929 |
I32x4RelaxedTruncF64x2UZero([Id; 1]) = "i32x4.relaxed_trunc_f64x2_u_zero", |
| 930 |
F32x4RelaxedMadd([Id; 3]) = "f32x4.relaxed_madd", |
| 931 |
F32x4RelaxedNmadd([Id; 3]) = "f32x4.relaxed_nmadd", |
| 932 |
F64x2RelaxedMadd([Id; 3]) = "f64x2.relaxed_madd", |
| 933 |
F64x2RelaxedNmadd([Id; 3]) = "f64x2.relaxed_nmadd", |
| 934 |
I8x16RelaxedLaneselect([Id; 3]) = "i8x16.relaxed_laneselect", |
| 935 |
I16x8RelaxedLaneselect([Id; 3]) = "i16x8.relaxed_laneselect", |
| 936 |
I32x4RelaxedLaneselect([Id; 3]) = "i32x4.relaxed_laneselect", |
| 937 |
I64x2RelaxedLaneselect([Id; 3]) = "i64x2.relaxed_laneselect", |
| 938 |
F32x4RelaxedMin([Id; 2]) = "f32x4.relaxed_min", |
| 939 |
F32x4RelaxedMax([Id; 2]) = "f32x4.relaxed_max", |
| 940 |
F64x2RelaxedMin([Id; 2]) = "f64x2.relaxed_min", |
| 941 |
F64x2RelaxedMax([Id; 2]) = "f64x2.relaxed_max", |
| 942 |
I16x8RelaxedQ15mulrS([Id; 2]) = "i16x8.relaxed_q15_mulr_s", |
| 943 |
I16x8RelaxedDotI8x16I7x16S([Id; 2]) = "i16x8.relaxed_dot_i8x16_i7x16_s", |
| 944 |
I32x4RelaxedDotI8x16I7x16AddS([Id; 3]) = "i32x4.relaxed_dot_i8x16_i7x16_add_s", |
| 945 |
|
| 946 |
/// Add custom or others operator nodes below |
| 947 |
|
| 948 |
/// Custom mutation operations and instructions |
| 949 |
/// |
| 950 |
/// This operation represents a random i32 integer |
| 951 |
RandI32 = "i32.rand", |
| 952 |
/// This operation represents a random i64 integer |
| 953 |
RandI64 = "i64.rand", |
| 954 |
/// This operation represents a random f32 |
| 955 |
RandF32 = "f32.rand", |
| 956 |
/// This operation represents a random f64 |
| 957 |
RandF64 = "f64.rand", |
| 958 |
|
| 959 |
/// This instructions is used to define unknown operands, for example |
| 960 |
/// when the value can come from the join of several basic blocks in a |
| 961 |
/// dfg |
| 962 |
Undef = "undef", |
| 963 |
|
| 964 |
/// Takes one i32 constant operand and turn it into a sum of two random |
| 965 |
/// numbers whihch sum is the operand `i32.const x = i32.const r + |
| 966 |
/// i32.const (x - r) ` |
| 967 |
UnfoldI32(Id) = "i32.unfold", |
| 968 |
/// Takes one i64 constant operand and turn it into a sum of two random |
| 969 |
/// numbers whihch sum is the operand `i64.const x = i64.const r + |
| 970 |
/// i64.const (x - r) ` |
| 971 |
UnfoldI64(Id) = "i64.unfold", |
| 972 |
|
| 973 |
/// Propsoed custom mutator from issue #391, use-of-global |
| 974 |
I32UseGlobal(Id) = "i32.use_of_global", |
| 975 |
/// Propsoed custom mutator from issue #391, use-of-global |
| 976 |
I64UseGlobal(Id) = "i64.use_of_global", |
| 977 |
/// Propsoed custom mutator from issue #391, use-of-global |
| 978 |
F32UseGlobal(Id) = "f32.use_of_global", |
| 979 |
/// Propsoed custom mutator from issue #391, use-of-global |
| 980 |
F64UseGlobal(Id) = "f64.use_of_global", |
| 981 |
|
| 982 |
/// Just a wrapper of multiple nodes, when encoding to Wasm it is written as |
| 983 |
/// nothing. Its only responsibility is to express stack-neutral operations. |
| 984 |
/// |
| 985 |
/// For example, let's assume we want to insert a nop operation after or |
| 986 |
/// before another node (or both). `container` allows us to do this with the |
| 987 |
/// following rewrites: |
| 988 |
/// |
| 989 |
/// * Before: `?x => (container nop ?x)` |
| 990 |
/// * After: `?x => (container ?x nop)` |
| 991 |
/// * Before and after: `?x => (container nop ?x nop)` |
| 992 |
/// * Stack-nuetral insertion: `?x => (container (drop i32.rand) ?x) ` |
| 993 |
Container(Vec<Id>) = "container", |
| 994 |
|
| 995 |
// End of custom mutation operations and instructions |
| 996 |
/// I32 constant node |
| 997 |
I32(i32) = "i32.const", |
| 998 |
/// I64 constant node |
| 999 |
I64(i64) = "i64.const", |
| 1000 |
|
| 1001 |
// Save bits |
| 1002 |
/// F32 constant node |
| 1003 |
F32(F32) = "f32.const", |
| 1004 |
/// F64 constant node |
| 1005 |
F64(F64) = "f64.const", |
| 1006 |
/// V128 constant node |
| 1007 |
V128(i128) = "v128.const", |
| 1008 |
/// constant ref.null node |
| 1009 |
RefNull(RefType) = "ref.null", |
| 1010 |
/// constant ref.func node |
| 1011 |
RefFunc(u32) = "ref.func", |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
impl Default for Lang { |
| 1016 |
fn default() -> Self { |
| 1017 |
Lang::Undef |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] |
| 1022 |
pub struct F32(u32); |
| 1023 |
|
| 1024 |
impl F32 { |
| 1025 |
pub fn to_f32(self) -> f32 { |
| 1026 |
f32::from_bits(self.0) |
| 1027 |
} |
| 1028 |
} |
| 1029 |
|
| 1030 |
impl FromStr for F32 { |
| 1031 |
type Err = <f32 as FromStr>::Err; |
| 1032 |
|
| 1033 |
fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1034 |
Ok(F32(f32::from_str(&s.replace(",", "."))?.to_bits())) |
| 1035 |
} |
| 1036 |
} |
| 1037 |
|
| 1038 |
impl From<f32> for F32 { |
| 1039 |
fn from(f: f32) -> Self { |
| 1040 |
Self(f.to_bits()) |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
impl From<wasmparser::Ieee32> for F32 { |
| 1045 |
fn from(f: wasmparser::Ieee32) -> Self { |
| 1046 |
Self(f.bits()) |
| 1047 |
} |
| 1048 |
} |
| 1049 |
|
| 1050 |
impl fmt::Display for F32 { |
| 1051 |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1052 |
fmt::Display::fmt(&self.to_f32(), f) |
| 1053 |
} |
| 1054 |
} |
| 1055 |
|
| 1056 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] |
| 1057 |
pub struct F64(u64); |
| 1058 |
|
| 1059 |
impl F64 { |
| 1060 |
pub fn to_f64(self) -> f64 { |
| 1061 |
f64::from_bits(self.0) |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
impl FromStr for F64 { |
| 1066 |
type Err = <f64 as FromStr>::Err; |
| 1067 |
|
| 1068 |
fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1069 |
Ok(F64(f64::from_str(&s.replace(",", "."))?.to_bits())) |
| 1070 |
} |
| 1071 |
} |
| 1072 |
|
| 1073 |
impl From<f64> for F64 { |
| 1074 |
fn from(f: f64) -> Self { |
| 1075 |
Self(f.to_bits()) |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
impl From<wasmparser::Ieee64> for F64 { |
| 1080 |
fn from(f: wasmparser::Ieee64) -> Self { |
| 1081 |
Self(f.bits()) |
| 1082 |
} |
| 1083 |
} |
| 1084 |
|
| 1085 |
impl fmt::Display for F64 { |
| 1086 |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1087 |
fmt::Display::fmt(&self.to_f64(), f) |
| 1088 |
} |
| 1089 |
} |
| 1090 |
|
| 1091 |
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] |
| 1092 |
pub enum RefType { |
| 1093 |
Func, |
| 1094 |
Extern, |
| 1095 |
} |
| 1096 |
|
| 1097 |
impl From<RefType> for HeapType { |
| 1098 |
fn from(rt: RefType) -> Self { |
| 1099 |
match rt { |
| 1100 |
RefType::Func => HeapType::Abstract { |
| 1101 |
shared: false, |
| 1102 |
ty: AbstractHeapType::Func, |
| 1103 |
}, |
| 1104 |
RefType::Extern => HeapType::Abstract { |
| 1105 |
shared: false, |
| 1106 |
ty: AbstractHeapType::Extern, |
| 1107 |
}, |
| 1108 |
} |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
impl FromStr for RefType { |
| 1113 |
type Err = Box<dyn std::error::Error + Send + Sync>; |
| 1114 |
fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1115 |
match s { |
| 1116 |
"func" => Ok(RefType::Func), |
| 1117 |
"extern" => Ok(RefType::Extern), |
| 1118 |
s => Err(format!("{s} is not a valid reference type").into()), |
| 1119 |
} |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
impl fmt::Display for RefType { |
| 1124 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1125 |
f.write_str(match self { |
| 1126 |
RefType::Func => "func", |
| 1127 |
RefType::Extern => "extern", |
| 1128 |
}) |
| 1129 |
} |
| 1130 |
} |
| 1131 |
|
| 1132 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1133 |
pub struct MemArg { |
| 1134 |
/// Inmediate static offset of the store operator |
| 1135 |
pub static_offset: u64, |
| 1136 |
/// Inmediate align value of the store operator |
| 1137 |
pub align: u8, |
| 1138 |
/// Inmediate mem value of the store operator |
| 1139 |
pub mem: u32, |
| 1140 |
} |
| 1141 |
|
| 1142 |
impl fmt::Display for MemArg { |
| 1143 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1144 |
write!(f, "{}.{}.{}", self.static_offset, self.align, self.mem) |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
impl FromStr for MemArg { |
| 1149 |
type Err = String; |
| 1150 |
fn from_str(s: &str) -> Result<MemArg, String> { |
| 1151 |
let mut parts = s.split('.'); |
| 1152 |
let static_offset = parts |
| 1153 |
.next() |
| 1154 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1155 |
.parse::<u64>() |
| 1156 |
.map_err(|e| e.to_string())?; |
| 1157 |
let align = parts |
| 1158 |
.next() |
| 1159 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1160 |
.parse::<u8>() |
| 1161 |
.map_err(|e| e.to_string())?; |
| 1162 |
let mem = parts |
| 1163 |
.next() |
| 1164 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1165 |
.parse::<u32>() |
| 1166 |
.map_err(|e| e.to_string())?; |
| 1167 |
|
| 1168 |
if parts.next().is_some() { |
| 1169 |
return Err(format!("too much info after instruction")); |
| 1170 |
} |
| 1171 |
|
| 1172 |
Ok(MemArg { |
| 1173 |
static_offset, |
| 1174 |
align, |
| 1175 |
mem, |
| 1176 |
}) |
| 1177 |
} |
| 1178 |
} |
| 1179 |
|
| 1180 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1181 |
pub struct MemArgLane { |
| 1182 |
/// Other memarg information |
| 1183 |
pub memarg: MemArg, |
| 1184 |
/// Immediate value for the simd vector lane this is operating on. |
| 1185 |
pub lane: u8, |
| 1186 |
} |
| 1187 |
|
| 1188 |
impl fmt::Display for MemArgLane { |
| 1189 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1190 |
write!(f, "{}.{}", self.memarg, self.lane) |
| 1191 |
} |
| 1192 |
} |
| 1193 |
|
| 1194 |
impl FromStr for MemArgLane { |
| 1195 |
type Err = String; |
| 1196 |
fn from_str(s: &str) -> Result<MemArgLane, String> { |
| 1197 |
let mut parts = s.rsplitn(2, '.'); |
| 1198 |
let lane = parts |
| 1199 |
.next() |
| 1200 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1201 |
.parse::<u8>() |
| 1202 |
.map_err(|e| e.to_string())?; |
| 1203 |
let memarg = parts |
| 1204 |
.next() |
| 1205 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1206 |
.parse::<MemArg>() |
| 1207 |
.map_err(|e| e.to_string())?; |
| 1208 |
if parts.next().is_some() { |
| 1209 |
return Err(format!("too much info after instruction")); |
| 1210 |
} |
| 1211 |
|
| 1212 |
Ok(MemArgLane { lane, memarg }) |
| 1213 |
} |
| 1214 |
} |
| 1215 |
|
| 1216 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1217 |
pub struct Shuffle { |
| 1218 |
pub indices: [u8; 16], |
| 1219 |
} |
| 1220 |
|
| 1221 |
impl fmt::Display for Shuffle { |
| 1222 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1223 |
for (i, idx) in self.indices.iter().enumerate() { |
| 1224 |
if i != 0 { |
| 1225 |
write!(f, ".")?; |
| 1226 |
} |
| 1227 |
write!(f, "{idx}")?; |
| 1228 |
} |
| 1229 |
Ok(()) |
| 1230 |
} |
| 1231 |
} |
| 1232 |
|
| 1233 |
impl FromStr for Shuffle { |
| 1234 |
type Err = String; |
| 1235 |
fn from_str(s: &str) -> Result<Shuffle, String> { |
| 1236 |
let indices = s |
| 1237 |
.split('.') |
| 1238 |
.map(|part| part.parse::<u8>()) |
| 1239 |
.collect::<Result<Vec<_>, _>>() |
| 1240 |
.map_err(|_| format!("failed to parse integer"))?; |
| 1241 |
let indices: &[u8; 16] = indices |
| 1242 |
.as_slice() |
| 1243 |
.try_into() |
| 1244 |
.map_err(|_| format!("wrong number of lanes"))?; |
| 1245 |
|
| 1246 |
Ok(Shuffle { indices: *indices }) |
| 1247 |
} |
| 1248 |
} |
| 1249 |
|
| 1250 |
trait Children: Sized { |
| 1251 |
fn from(list: Vec<Id>) -> Result<Self, String>; |
| 1252 |
fn as_slice(&self) -> &[Id]; |
| 1253 |
fn as_slice_mut(&mut self) -> &mut [Id]; |
| 1254 |
} |
| 1255 |
|
| 1256 |
impl Children for Id { |
| 1257 |
fn from(mut list: Vec<Id>) -> Result<Id, String> { |
| 1258 |
if list.len() != 1 { |
| 1259 |
Err(format!("expected one child node, got {}", list.len())) |
| 1260 |
} else { |
| 1261 |
Ok(list.remove(0)) |
| 1262 |
} |
| 1263 |
} |
| 1264 |
fn as_slice(&self) -> &[Id] { |
| 1265 |
std::slice::from_ref(self) |
| 1266 |
} |
| 1267 |
fn as_slice_mut(&mut self) -> &mut [Id] { |
| 1268 |
std::slice::from_mut(self) |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
impl<const N: usize> Children for [Id; N] { |
| 1273 |
fn from(list: Vec<Id>) -> Result<Self, String> { |
| 1274 |
if let Ok(result) = list.try_into() { |
| 1275 |
Ok(result) |
| 1276 |
} else { |
| 1277 |
Err(format!("expected {N} child nodes")) |
| 1278 |
} |
| 1279 |
} |
| 1280 |
fn as_slice(&self) -> &[Id] { |
| 1281 |
self |
| 1282 |
} |
| 1283 |
fn as_slice_mut(&mut self) -> &mut [Id] { |
| 1284 |
self |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
impl Children for Vec<Id> { |
| 1289 |
fn from(list: Vec<Id>) -> Result<Self, String> { |
| 1290 |
Ok(list) |
| 1291 |
} |
| 1292 |
fn as_slice(&self) -> &[Id] { |
| 1293 |
self |
| 1294 |
} |
| 1295 |
fn as_slice_mut(&mut self) -> &mut [Id] { |
| 1296 |
self |
| 1297 |
} |
| 1298 |
} |
| 1299 |
|
| 1300 |
fn parse_pair<T: FromStr, U: FromStr>(s: &str) -> Result<(T, U), String> |
| 1301 |
where |
| 1302 |
T::Err: fmt::Display, |
| 1303 |
U::Err: fmt::Display, |
| 1304 |
{ |
| 1305 |
let mut parts = s.split('.'); |
| 1306 |
let t = parts |
| 1307 |
.next() |
| 1308 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1309 |
.parse::<T>() |
| 1310 |
.map_err(|e| e.to_string())?; |
| 1311 |
let u = parts |
| 1312 |
.next() |
| 1313 |
.ok_or_else(|| format!("expected more static instr info"))? |
| 1314 |
.parse::<U>() |
| 1315 |
.map_err(|e| e.to_string())?; |
| 1316 |
|
| 1317 |
if parts.next().is_some() { |
| 1318 |
return Err(format!("too much info after instruction")); |
| 1319 |
} |
| 1320 |
|
| 1321 |
Ok((t, u)) |
| 1322 |
} |
| 1323 |
|
| 1324 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1325 |
pub struct TableCopy { |
| 1326 |
pub src: u32, |
| 1327 |
pub dst: u32, |
| 1328 |
} |
| 1329 |
|
| 1330 |
impl fmt::Display for TableCopy { |
| 1331 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1332 |
write!(f, "{}.{}", self.src, self.dst) |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
impl FromStr for TableCopy { |
| 1337 |
type Err = String; |
| 1338 |
|
| 1339 |
fn from_str(s: &str) -> Result<TableCopy, String> { |
| 1340 |
let (src, dst) = parse_pair(s)?; |
| 1341 |
Ok(TableCopy { src, dst }) |
| 1342 |
} |
| 1343 |
} |
| 1344 |
|
| 1345 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1346 |
pub struct MemoryCopy { |
| 1347 |
pub src: u32, |
| 1348 |
pub dst: u32, |
| 1349 |
} |
| 1350 |
|
| 1351 |
impl fmt::Display for MemoryCopy { |
| 1352 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1353 |
write!(f, "{}.{}", self.src, self.dst) |
| 1354 |
} |
| 1355 |
} |
| 1356 |
|
| 1357 |
impl FromStr for MemoryCopy { |
| 1358 |
type Err = String; |
| 1359 |
|
| 1360 |
fn from_str(s: &str) -> Result<MemoryCopy, String> { |
| 1361 |
let (src, dst) = parse_pair(s)?; |
| 1362 |
Ok(MemoryCopy { src, dst }) |
| 1363 |
} |
| 1364 |
} |
| 1365 |
|
| 1366 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1367 |
pub struct TableInit { |
| 1368 |
pub table: u32, |
| 1369 |
pub segment: u32, |
| 1370 |
} |
| 1371 |
|
| 1372 |
impl fmt::Display for TableInit { |
| 1373 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1374 |
write!(f, "{}.{}", self.table, self.segment) |
| 1375 |
} |
| 1376 |
} |
| 1377 |
|
| 1378 |
impl FromStr for TableInit { |
| 1379 |
type Err = String; |
| 1380 |
|
| 1381 |
fn from_str(s: &str) -> Result<TableInit, String> { |
| 1382 |
let (table, segment) = parse_pair(s)?; |
| 1383 |
Ok(TableInit { table, segment }) |
| 1384 |
} |
| 1385 |
} |
| 1386 |
|
| 1387 |
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)] |
| 1388 |
pub struct MemoryInit { |
| 1389 |
pub memory: u32, |
| 1390 |
pub segment: u32, |
| 1391 |
} |
| 1392 |
|
| 1393 |
impl fmt::Display for MemoryInit { |
| 1394 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1395 |
write!(f, "{}.{}", self.memory, self.segment) |
| 1396 |
} |
| 1397 |
} |
| 1398 |
|
| 1399 |
impl FromStr for MemoryInit { |
| 1400 |
type Err = String; |
| 1401 |
|
| 1402 |
fn from_str(s: &str) -> Result<MemoryInit, String> { |
| 1403 |
let (memory, segment) = parse_pair(s)?; |
| 1404 |
Ok(MemoryInit { memory, segment }) |
| 1405 |
} |
| 1406 |
} |
| 1407 |
|
| 1408 |
#[cfg(test)] |
| 1409 |
mod tests { |
| 1410 |
use super::{Lang, MemArg, RefType}; |
| 1411 |
use egg::{Id, Language}; |
| 1412 |
|
| 1413 |
#[test] |
| 1414 |
fn test_parsing2() { |
| 1415 |
let pairs = vec![ |
| 1416 |
[Lang::GlobalGet(0), Lang::GlobalGet(1)], |
| 1417 |
[ |
| 1418 |
Lang::LocalSet(0, Id::from(0)), |
| 1419 |
Lang::LocalSet(1, Id::from(1)), |
| 1420 |
], |
| 1421 |
[Lang::LocalGet(0), Lang::LocalGet(1)], |
| 1422 |
[ |
| 1423 |
Lang::GlobalSet(0, Id::from(0)), |
| 1424 |
Lang::GlobalSet(1, Id::from(1)), |
| 1425 |
], |
| 1426 |
[ |
| 1427 |
Lang::I32Load( |
| 1428 |
MemArg { |
| 1429 |
mem: 1, |
| 1430 |
align: 0, |
| 1431 |
static_offset: 120, |
| 1432 |
}, |
| 1433 |
Id::from(0), |
| 1434 |
), |
| 1435 |
Lang::I32Load( |
| 1436 |
MemArg { |
| 1437 |
mem: 1, |
| 1438 |
align: 0, |
| 1439 |
static_offset: 0, |
| 1440 |
}, |
| 1441 |
Id::from(0), |
| 1442 |
), |
| 1443 |
], |
| 1444 |
[Lang::LocalGet(0), Lang::LocalGet(1)], |
| 1445 |
[Lang::RefNull(RefType::Func), Lang::RefNull(RefType::Extern)], |
| 1446 |
]; |
| 1447 |
for [l, r] in pairs { |
| 1448 |
assert_eq!(l.matches(&r), false); |
| 1449 |
} |
| 1450 |
} |
| 1451 |
} |