diff --git a/w2c2/c.c b/w2c2/c.c index 2429404..6382781 100644 --- a/w2c2/c.c +++ b/w2c2/c.c @@ -5078,23 +5078,43 @@ wasmCWriteModuleImplementation( /* Write implementations */ - MUST (wasmCWriteModuleImplementationFiles( - module, - moduleName, - headerName, - staticFunctionIDs, - 's', - options - )) + if (options.functionsPerFile >= module->functions.count + && dynamicFunctionIDs.length == 0) + { + WasmDebugLines debugLines = module->debugLines; - MUST (wasmCWriteModuleImplementationFiles( - module, - moduleName, - headerName, - dynamicFunctionIDs, - 'd', - options - )) + MUST (wasmCWriteFunctionImplementations( + file, + module, + moduleName, + &debugLines, + 0, + (U32)staticFunctionIDs.length, + staticFunctionIDs, + options.pretty, + options.debug, + options.multipleModules + )) + } else { + + MUST (wasmCWriteModuleImplementationFiles( + module, + moduleName, + headerName, + staticFunctionIDs, + 's', + options + )) + + MUST (wasmCWriteModuleImplementationFiles( + module, + moduleName, + headerName, + dynamicFunctionIDs, + 'd', + options + )) + } /* Write initializations code */ diff --git a/w2c2/main.c b/w2c2/main.c index 7af1de6..e80e795 100644 --- a/w2c2/main.c +++ b/w2c2/main.c @@ -410,10 +410,10 @@ main( referenceFunctionIDs = wasmSortedFunctionIDs(referenceReader.module->functions); wasmSplitStaticAndDynamicFunctions( - functionIDs, - referenceFunctionIDs, - &staticFunctionIDs, - &dynamicFunctionIDs + functionIDs, + referenceFunctionIDs, + &staticFunctionIDs, + &dynamicFunctionIDs ); total = dynamicFunctionIDs.length + staticFunctionIDs.length;