Skip to content

Commit

Permalink
Do not generate wat file if no debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgonmic committed Oct 7, 2024
1 parent 32d3d65 commit 3b0d1d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class KotlinToJSTranslator(
files: List<KtFile>,
debugInfo: Boolean,
projectType: ProjectType,
translate: (List<KtFile>, List<String>, List<String>, List<String>) -> CompilationResult<WasmTranslationSuccessfulOutput>
translate: (List<KtFile>, List<String>, List<String>, List<String>, Boolean) -> CompilationResult<WasmTranslationSuccessfulOutput>
): TranslationResultWithJsCode {
return try {
val (dependencies, compilerPlugins, compilerPluginOptions) = when (projectType) {
Expand All @@ -67,7 +67,8 @@ class KotlinToJSTranslator(
files,
dependencies,
compilerPlugins,
compilerPluginOptions
compilerPluginOptions,
debugInfo
)
val wasmCompilationOutput = when (compilationResult) {
is Compiled<WasmTranslationSuccessfulOutput> -> compilationResult.result
Expand Down Expand Up @@ -134,6 +135,7 @@ class KotlinToJSTranslator(
dependencies: List<String>,
compilerPlugins: List<String>,
compilerPluginOptions: List<String>,
debugInfo: Boolean,
): CompilationResult<WasmTranslationSuccessfulOutput> =
usingTempDirectory { inputDir ->
val moduleName = "moduleId"
Expand Down Expand Up @@ -161,23 +163,22 @@ class KotlinToJSTranslator(

k2JsIrCompiler.tryCompilation(inputDir, ioFiles, filePaths + additionalCompilerArgumentsForKLib)
.flatMap {
k2JsIrCompiler.tryCompilation(inputDir, ioFiles, listOf(
k2JsIrCompiler.tryCompilation(inputDir, ioFiles, mutableListOf(
"-Xwasm",
"-Xwasm-generate-wat",
"-Xir-produce-js",
"-Xir-dce",
"-Xinclude=$klibPath",
"-libraries=${dependencies.joinToString(PATH_SEPARATOR)}",
"-ir-output-dir=${(outputDir / "wasm").toFile().canonicalPath}",
"-ir-output-name=$moduleName",
))
).also { if (debugInfo) it.add("-Xwasm-generate-wat") })
}
.map {
WasmTranslationSuccessfulOutput(
jsCode = (outputDir / "wasm" / "$moduleName.uninstantiated.mjs").readText(),
jsInstantiated = (outputDir / "wasm" / "$moduleName.mjs").readText(),
wasm = (outputDir / "wasm" / "$moduleName.wasm").readBytes(),
wat = (outputDir / "wasm" / "$moduleName.wat").readText(),
wat = if (debugInfo) (outputDir / "wasm" / "$moduleName.wat").readText() else null,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class KotlinProjectExecutor(
private fun convertWasmWithConverter(
project: Project,
debugInfo: Boolean,
converter: (List<KtFile>, List<String>, List<String>, List<String>) -> CompilationResult<WasmTranslationSuccessfulOutput>
converter: (List<KtFile>, List<String>, List<String>, List<String>, Boolean) -> CompilationResult<WasmTranslationSuccessfulOutput>
): TranslationResultWithJsCode {
return kotlinEnvironment.environment { environment ->
val files = getFilesFrom(project, environment).map { it.kotlinFile }
Expand Down

0 comments on commit 3b0d1d1

Please sign in to comment.