| 690 | } |
| 691 | |
| 692 | fn encode_quote_wat(module: QuoteWat) -> (Option<String>, Vec<u8>) { |
| 693 | match module { |
| 694 | QuoteWat::QuoteModule(_, quoted_wat) => { |
| 695 | let wat = quoted_wat |
| 696 | .iter() |
| 697 | .map(|(_, s)| std::str::from_utf8(s).expect("failed to convert wast to utf8")) |
| 698 | .collect::<Vec<_>>() |
| 699 | .join("\n"); |
| 700 | let lexer = wast::lexer::Lexer::new(&wat); |
| 701 | let buf = wast::parser::ParseBuffer::new_with_lexer(lexer).expect("failed to create parse buffer"); |
| 702 | let mut wat_data = wast::parser::parse::<wast::Wat>(&buf).expect("failed to parse wat"); |
| 703 | (None, wat_data.encode().expect("failed to encode module")) |
| 704 | } |
| 705 | QuoteWat::Wat(mut wat) => { |
| 706 | let wast::Wat::Module(ref module) = wat else { unimplemented!("Not supported") }; |
| 707 | (module.id.map(|id| id.name().to_string()), wat.encode().expect("failed to encode module")) |
| 708 | } |
| 709 | QuoteWat::QuoteComponent(..) => unimplemented!("components are not supported"), |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | fn parse_module_bytes(bytes: &[u8]) -> Result<Module> { |
| 714 | Ok(tinywasm::parse_bytes(bytes)?) |