Same as `store_flat`, except loads the flat values from `ptr+offset`. Results are placed directly on the wasm stack.
(
&'a self,
s: &mut String,
ptr: &str,
offset: u32,
helpers: &mut IndexSet<Helper<'a>>,
)
| 429 | /// |
| 430 | /// Results are placed directly on the wasm stack. |
| 431 | fn load_flat<'a>( |
| 432 | &'a self, |
| 433 | s: &mut String, |
| 434 | ptr: &str, |
| 435 | offset: u32, |
| 436 | helpers: &mut IndexSet<Helper<'a>>, |
| 437 | ) { |
| 438 | enum Kind { |
| 439 | Primitive(&'static str), |
| 440 | PointerPair, |
| 441 | Helper, |
| 442 | } |
| 443 | let kind = match self { |
| 444 | Type::Bool | Type::U8 => Kind::Primitive("i32.load8_u"), |
| 445 | Type::S8 => Kind::Primitive("i32.load8_s"), |
| 446 | Type::U16 => Kind::Primitive("i32.load16_u"), |
| 447 | Type::S16 => Kind::Primitive("i32.load16_s"), |
| 448 | Type::U32 | Type::S32 | Type::Char => Kind::Primitive("i32.load"), |
| 449 | Type::U64 | Type::S64 => Kind::Primitive("i64.load"), |
| 450 | Type::Float32 => Kind::Primitive("f32.load"), |
| 451 | Type::Float64 => Kind::Primitive("f64.load"), |
| 452 | Type::String | Type::List(_) | Type::Map(_, _) => Kind::PointerPair, |
| 453 | Type::Enum(n) if *n <= (1 << 8) => Kind::Primitive("i32.load8_u"), |
| 454 | Type::Enum(n) if *n <= (1 << 16) => Kind::Primitive("i32.load16_u"), |
| 455 | Type::Enum(_) => Kind::Primitive("i32.load"), |
| 456 | Type::Flags(n) if *n <= 8 => Kind::Primitive("i32.load8_u"), |
| 457 | Type::Flags(n) if *n <= 16 => Kind::Primitive("i32.load16_u"), |
| 458 | Type::Flags(n) if *n <= 32 => Kind::Primitive("i32.load"), |
| 459 | Type::Flags(_) => unreachable!(), |
| 460 | |
| 461 | Type::Record(_) |
| 462 | | Type::Tuple(_) |
| 463 | | Type::Variant(_) |
| 464 | | Type::Option(_) |
| 465 | | Type::Result { .. } => Kind::Helper, |
| 466 | }; |
| 467 | match kind { |
| 468 | Kind::Primitive(op) => uwriteln!(s, "({op} offset={offset} (local.get {ptr}))"), |
| 469 | Kind::PointerPair => { |
| 470 | uwriteln!(s, "(i32.load offset={offset} (local.get {ptr}))",); |
| 471 | let offset = offset + 4; |
| 472 | uwriteln!(s, "(i32.load offset={offset} (local.get {ptr}))",); |
| 473 | } |
| 474 | Kind::Helper => { |
| 475 | let (index, _) = helpers.insert_full(Helper(self)); |
| 476 | uwriteln!(s, "(i32.add (local.get {ptr}) (i32.const {offset}))"); |
| 477 | uwriteln!(s, "call $load_helper_{index}"); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /// Same as `store_flat_helper` but for loading the flat representation. |
| 483 | fn load_flat_helper<'a>( |
no test coverage detected