@@ -104,15 +104,17 @@ public static InstanceCreator<TExports> FromBinary<TExports>(Stream input, Compi
104104 {
105105 CheckPreamble ( reader ) ;
106106
107- constructor = FromBinary (
108- AssemblyBuilder . DefineDynamicAssembly (
107+ var assembly = AssemblyBuilder . DefineDynamicAssembly (
109108 new AssemblyName ( "CompiledWebAssembly" ) ,
110- AssemblyBuilderAccess . RunAndCollect
111- ) ,
112- reader ,
109+ AssemblyBuilderAccess . RunAndCollect ) ;
110+
111+ constructor = FromBinary (
112+ assembly ,
113+ reader ,
113114 configuration ,
114115 typeof ( Instance < TExports > ) ,
115- typeof ( TExports )
116+ typeof ( TExports ) ,
117+ assembly . DefineDynamicModule ( "CompiledWebAssembly" )
116118 ) ;
117119 }
118120 catch ( OverflowException x )
@@ -203,11 +205,19 @@ private static void CheckPreamble(Reader reader)
203205
204206#if NET9_0_OR_GREATER
205207 /// <summary>
206- /// Creates an <see cref="AssemblyBuilder"/> from a binary WASM source.
208+ /// Creates a <see cref="PersistedAssemblyBuilder"/> from a binary WASM source.
209+ /// </summary>
210+ /// <param name="input">The source of data. The stream is left open after reading is complete.</param>
211+ /// <returns>An assembly builder that can be used to further modify or save the assembly.</returns>
212+ public static PersistedAssemblyBuilder CreatePersistedAssembly( Stream input )
213+ => CreatePersistedAssembly ( input , new ( ) ) ;
214+
215+ /// <summary>
216+ /// Creates a <see cref="PersistedAssemblyBuilder"/> from a binary WASM source.
207217 /// </summary>
208218 /// <param name="input">The source of data. The stream is left open after reading is complete.</param>
209219 /// <param name="configuration">Configures the compiler.</param>
210- /// <returns>The created assembly.</returns>
220+ /// <returns>An assembly builder that can be used to further modify or save the assembly.</returns>
211221 public static PersistedAssemblyBuilder CreatePersistedAssembly (
212222 Stream input ,
213223 CompilerConfiguration configuration
@@ -272,7 +282,7 @@ private static ConstructorInfo FromBinary(
272282 CompilerConfiguration configuration ,
273283 Type instanceContainer ,
274284 Type exportContainer ,
275- ModuleBuilder ? module = null ,
285+ ModuleBuilder module ,
276286 TypeBuilder ? importBuilder = null
277287 )
278288 {
@@ -299,8 +309,6 @@ private static ConstructorInfo FromBinary(
299309 KeyValuePair < string , uint > [ ] ? exportedFunctions = null ;
300310 var previousSection = Section. None;
301311
302- module ??= assembly. DefineDynamicModule( "CompiledWebAssembly" ) ;
303-
304312 var context = new CompilationContext ( configuration ) ;
305313 var exportsBuilder = context. CheckedExportsBuilder = module. DefineType( "CompiledExports" , ClassAttributes , exportContainer ) ;
306314 MethodBuilder ? importedMemoryProvider = null ;
0 commit comments