From 5affb039ee4515047e85dc72a00c89624c61a4f9 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 8 Aug 2023 15:16:35 -0700 Subject: [PATCH] fixup --- .../src/transpile_bindgen.rs | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/crates/js-component-bindgen/src/transpile_bindgen.rs b/crates/js-component-bindgen/src/transpile_bindgen.rs index 787b063bd..ba7e63844 100644 --- a/crates/js-component-bindgen/src/transpile_bindgen.rs +++ b/crates/js-component-bindgen/src/transpile_bindgen.rs @@ -19,8 +19,9 @@ use wasmtime_environ::{ GlobalInitializer, InstantiateModule, LoweredIndex, RuntimeImportIndex, RuntimeInstanceIndex, StaticModuleIndex, Trampoline, TrampolineIndex, }, + fact::{FixedEncoding, Transcode}, + EntityIndex, PrimaryMap, }; -use wasmtime_environ::{EntityIndex, PrimaryMap}; use wit_component::StringEncoding; use wit_parser::abi::{AbiVariant, LiftLower}; use wit_parser::*; @@ -355,12 +356,41 @@ impl<'a> Instantiator<'a, '_> { // for now since it can't be tested and additionally JS doesn't // support multi-memory which transcoders rely on anyway. Trampoline::Transcoder { - op: _, - from: _, - from64: _, - to: _, - to64: _, - } => unimplemented!(), + op, + from, + from64, + to, + to64, + } => { + if *from64 || *to64 { + unimplemented!(); + } + let create_transcoder = match op { + Transcode::Copy(FixedEncoding::Utf8) => { + self.gen.intrinsic(Intrinsic::CreateUtf8Copier) + } + Transcode::Copy(FixedEncoding::Utf16) => unimplemented!(), + Transcode::Copy(FixedEncoding::Latin1) => unimplemented!(), + Transcode::Latin1ToUtf16 => unimplemented!(), + Transcode::Latin1ToUtf8 => unimplemented!(), + Transcode::Utf16ToCompactProbablyUtf16 => unimplemented!(), + Transcode::Utf16ToCompactUtf16 => unimplemented!(), + Transcode::Utf16ToLatin1 => unimplemented!(), + Transcode::Utf16ToUtf8 => unimplemented!(), + Transcode::Utf8ToCompactUtf16 => unimplemented!(), + Transcode::Utf8ToLatin1 => unimplemented!(), + Transcode::Utf8ToUtf16 => unimplemented!(), + }; + + // println!("{:?}", signature); + uwriteln!( + self.src.js_init, + "const transcoder{} = {create_transcoder}(memory{}, memory{});", + i.as_u32(), + from.as_u32(), + to.as_u32() + ); + } Trampoline::LowerImport { index, @@ -722,7 +752,7 @@ impl<'a> Instantiator<'a, '_> { CoreDef::Trampoline(i) => format!("trampoline{}", i.as_u32()), CoreDef::InstanceFlags(i) => { format!("instanceFlags{}", i.as_u32()) - }, + } } }