@@ -56,6 +56,8 @@ pub struct TranspileOpts {
5656    /// Disable verification of component Wasm data structures when 
5757/// lifting as a production optimization 
5858pub  valid_lifting_optimization :  bool , 
59+     /// Whether or not to emit `tracing` calls on function entry/exit. 
60+ pub  tracing :  bool , 
5961} 
6062
6163struct  JsBindgen < ' a >  { 
@@ -736,6 +738,11 @@ impl<'a> Instantiator<'a, '_> {
736738        self . bindgen ( 
737739            nparams, 
738740            false , 
741+             if  import_name. is_empty ( )  { 
742+                 None 
743+             }  else  { 
744+                 Some ( import_name) 
745+             } , 
739746            & callee_name, 
740747            options, 
741748            func, 
@@ -850,6 +857,7 @@ impl<'a> Instantiator<'a, '_> {
850857        & mut  self , 
851858        nparams :  usize , 
852859        this_ref :  bool , 
860+         module_name :  Option < & str > , 
853861        callee :  & str , 
854862        opts :  & CanonicalOptions , 
855863        func :  & Function , 
@@ -888,6 +896,26 @@ impl<'a> Instantiator<'a, '_> {
888896        } 
889897        uwriteln ! ( self . src. js,  ") {{" ) ; 
890898
899+         let  tracing_prefix = format ! ( 
900+             "[module=\" {}\" , function=\" {}\" ]" , 
901+             module_name. unwrap_or( "<no module>" ) , 
902+             func. name
903+         ) ; 
904+ 
905+         if  self . gen . opts . tracing  { 
906+             let  event_fields = func
907+                 . params 
908+                 . iter ( ) 
909+                 . enumerate ( ) 
910+                 . map ( |( i,  ( name,  _ty) ) | format ! ( "{name}=${{arguments[{i}]}}" ) ) 
911+                 . collect :: < Vec < String > > ( ) ; 
912+             uwriteln ! ( 
913+                 self . src. js, 
914+                 "console.trace(`{tracing_prefix} call {}`);" , 
915+                 event_fields. join( ", " ) 
916+             ) ; 
917+         } 
918+ 
891919        if  self . gen . opts . tla_compat  && matches ! ( abi,  AbiVariant :: GuestExport )  { 
892920            let  throw_uninitialized = self . gen . intrinsic ( Intrinsic :: ThrowUninitialized ) ; 
893921            uwrite ! ( 
@@ -920,6 +948,11 @@ impl<'a> Instantiator<'a, '_> {
920948            tmp :  0 , 
921949            params, 
922950            post_return :  post_return. as_ref ( ) , 
951+             tracing_prefix :  if  self . gen . opts . tracing  { 
952+                 Some ( & tracing_prefix) 
953+             }  else  { 
954+                 None 
955+             } , 
923956            encoding :  match  opts. string_encoding  { 
924957                component:: StringEncoding :: Utf8  => StringEncoding :: UTF8 , 
925958                component:: StringEncoding :: Utf16  => StringEncoding :: UTF16 , 
@@ -1100,6 +1133,7 @@ impl<'a> Instantiator<'a, '_> {
11001133                        func, 
11011134                        existing_resource_def, 
11021135                        * ty, 
1136+                         export_name, 
11031137                    ) ; 
11041138                    if  let  FunctionKind :: Constructor ( ty) 
11051139                    | FunctionKind :: Method ( ty) 
@@ -1156,6 +1190,7 @@ impl<'a> Instantiator<'a, '_> {
11561190                            func, 
11571191                            existing_resource_def, 
11581192                            * ty, 
1193+                             export_name, 
11591194                        ) ; 
11601195
11611196                        if  let  FunctionKind :: Constructor ( ty) 
@@ -1198,6 +1233,7 @@ impl<'a> Instantiator<'a, '_> {
11981233        func :  & Function , 
11991234        existing_resource_def :  bool , 
12001235        ty_func_idx :  TypeFuncIndex , 
1236+         export_name :  & String , 
12011237    )  { 
12021238        let  resource_map = self . create_resource_map ( func,  ty_func_idx) ; 
12031239        match  func. kind  { 
@@ -1247,6 +1283,11 @@ impl<'a> Instantiator<'a, '_> {
12471283        self . bindgen ( 
12481284            func. params . len ( ) , 
12491285            matches ! ( func. kind,  FunctionKind :: Method ( _) ) , 
1286+             if  export_name. is_empty ( )  { 
1287+                 None 
1288+             }  else  { 
1289+                 Some ( export_name) 
1290+             } , 
12501291            & callee, 
12511292            options, 
12521293            func, 
0 commit comments