remove logging: wiggle now provides this functionality

This commit is contained in:
Pat Hickey
2020-06-23 14:49:17 -07:00
parent bb339aaba0
commit 62237de7ce

View File

@@ -66,25 +66,21 @@ fn generate(
let mut shim_arg_decls = Vec::new(); let mut shim_arg_decls = Vec::new();
let mut params = Vec::new(); let mut params = Vec::new();
let mut formats = Vec::new();
let mut format_args = Vec::new();
let mut hostcall_args = Vec::new(); let mut hostcall_args = Vec::new();
for param in func.params.iter() { for param in func.params.iter() {
let name = names.func_param(&param.name); let name = names.func_param(&param.name);
// Registers a new parameter to the shim we're making with the // Registers a new parameter to the shim we're making with the
// given `name`, the `abi_ty` wasm type and `hex` defines // given `name`, the `abi_ty` wasm type
// whether it's debug-printed in a hex format or not.
// //
// This will register a whole bunch of things: // This will register a whole bunch of things:
// //
// * The cranelift type for the parameter // * The cranelift type for the parameter
// * Syntax to specify the actual function parameter // * Syntax to specify the actual function parameter
// * How to log the parameter value in a call to `trace!`
// * How to actually pass this argument to the host // * How to actually pass this argument to the host
// implementation, converting as necessary. // implementation, converting as necessary.
let mut add_param = |name: &Ident, abi_ty: Abi, hex: bool| { let mut add_param = |name: &Ident, abi_ty: Abi| {
match abi_ty { match abi_ty {
Abi::I32 => { Abi::I32 => {
params.push(quote! { types::I32 }); params.push(quote! { types::I32 });
@@ -103,25 +99,23 @@ fn generate(
shim_arg_decls.push(quote! { #name: f64 }); shim_arg_decls.push(quote! { #name: f64 });
} }
} }
formats.push(format!("{}={}", name, if hex { "{:#x}" } else { "{}" },));
format_args.push(name.clone());
hostcall_args.push(quote! { #name as _ }); hostcall_args.push(quote! { #name as _ });
}; };
match &*param.tref.type_() { match &*param.tref.type_() {
witx::Type::Int(e) => match e.repr { witx::Type::Int(e) => match e.repr {
witx::IntRepr::U64 => add_param(&name, Abi::I64, false), witx::IntRepr::U64 => add_param(&name, Abi::I64),
_ => add_param(&name, Abi::I32, false), _ => add_param(&name, Abi::I32),
}, },
witx::Type::Enum(e) => match e.repr { witx::Type::Enum(e) => match e.repr {
witx::IntRepr::U64 => add_param(&name, Abi::I64, false), witx::IntRepr::U64 => add_param(&name, Abi::I64),
_ => add_param(&name, Abi::I32, false), _ => add_param(&name, Abi::I32),
}, },
witx::Type::Flags(f) => match f.repr { witx::Type::Flags(f) => match f.repr {
witx::IntRepr::U64 => add_param(&name, Abi::I64, true), witx::IntRepr::U64 => add_param(&name, Abi::I64),
_ => add_param(&name, Abi::I32, true), _ => add_param(&name, Abi::I32),
}, },
witx::Type::Builtin(witx::BuiltinType::Char8) witx::Type::Builtin(witx::BuiltinType::Char8)
@@ -132,34 +126,34 @@ fn generate(
| witx::Type::Builtin(witx::BuiltinType::S32) | witx::Type::Builtin(witx::BuiltinType::S32)
| witx::Type::Builtin(witx::BuiltinType::U32) | witx::Type::Builtin(witx::BuiltinType::U32)
| witx::Type::Builtin(witx::BuiltinType::USize) => { | witx::Type::Builtin(witx::BuiltinType::USize) => {
add_param(&name, Abi::I32, false); add_param(&name, Abi::I32);
} }
witx::Type::Builtin(witx::BuiltinType::S64) witx::Type::Builtin(witx::BuiltinType::S64)
| witx::Type::Builtin(witx::BuiltinType::U64) => { | witx::Type::Builtin(witx::BuiltinType::U64) => {
add_param(&name, Abi::I64, false); add_param(&name, Abi::I64);
} }
witx::Type::Builtin(witx::BuiltinType::F32) => { witx::Type::Builtin(witx::BuiltinType::F32) => {
add_param(&name, Abi::F32, false); add_param(&name, Abi::F32);
} }
witx::Type::Builtin(witx::BuiltinType::F64) => { witx::Type::Builtin(witx::BuiltinType::F64) => {
add_param(&name, Abi::F64, false); add_param(&name, Abi::F64);
} }
// strings/arrays have an extra ABI parameter for the length // strings/arrays have an extra ABI parameter for the length
// of the array passed. // of the array passed.
witx::Type::Builtin(witx::BuiltinType::String) | witx::Type::Array(_) => { witx::Type::Builtin(witx::BuiltinType::String) | witx::Type::Array(_) => {
add_param(&name, Abi::I32, true); add_param(&name, Abi::I32);
let len = format_ident!("{}_len", name); let len = format_ident!("{}_len", name);
add_param(&len, Abi::I32, false); add_param(&len, Abi::I32);
} }
witx::Type::ConstPointer(_) witx::Type::ConstPointer(_)
| witx::Type::Handle(_) | witx::Type::Handle(_)
| witx::Type::Pointer(_) => { | witx::Type::Pointer(_) => {
add_param(&name, Abi::I32, true); add_param(&name, Abi::I32);
} }
witx::Type::Struct(_) | witx::Type::Union(_) => { witx::Type::Struct(_) | witx::Type::Union(_) => {
@@ -198,21 +192,14 @@ fn generate(
let name = format_ident!("{}", result.name.as_str()); let name = format_ident!("{}", result.name.as_str());
params.push(quote! { types::I32 }); params.push(quote! { types::I32 });
shim_arg_decls.push(quote! { #name: i32 }); shim_arg_decls.push(quote! { #name: i32 });
formats.push(format!("{}={{:#x}}", name));
format_args.push(name.clone());
hostcall_args.push(quote! { #name }); hostcall_args.push(quote! { #name });
} }
let format_str = format!("{}({})", name, formats.join(", "));
ctor_externs.push(quote! { ctor_externs.push(quote! {
let my_cx = cx.clone(); let my_cx = cx.clone();
let #name_ident = wasmtime::Func::wrap( let #name_ident = wasmtime::Func::wrap(
store, store,
move |caller: wasmtime::Caller<'_> #(,#shim_arg_decls)*| -> #ret_ty { move |caller: wasmtime::Caller<'_> #(,#shim_arg_decls)*| -> #ret_ty {
log::trace!(
#format_str,
#(#format_args),*
);
unsafe { unsafe {
let mem = match caller.get_export("memory") { let mem = match caller.get_export("memory") {
Some(wasmtime::Extern::Memory(m)) => m, Some(wasmtime::Extern::Memory(m)) => m,