[WASM] Add text section to implement debug info

This commit is contained in:
Igor Yakovlev
2021-09-14 19:59:14 +02:00
committed by teamcityserver
parent 8286927e8c
commit b8d11f7938
7 changed files with 45 additions and 13 deletions
@@ -232,6 +232,9 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
@Argument(value = "-Xwasm", description = "Use experimental WebAssembly compiler backend")
var wasm: Boolean by FreezableVar(false)
@Argument(value = "-Xwasm-debug-info", description = "Add debug info to WebAssembly compiled module")
var wasmDebug: Boolean by FreezableVar(false)
override fun configureLanguageFeatures(collector: MessageCollector): MutableMap<LanguageFeature, LanguageFeature.State> {
return super.configureLanguageFeatures(collector).apply {
if (extensionFunctionsInExternals) {
@@ -310,7 +310,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
module,
PhaseConfig(wasmPhases),
IrFactoryImpl,
exportedDeclarations = setOf(FqName("main"))
exportedDeclarations = setOf(FqName("main")),
emitNameSection = arguments.wasmDebug,
)
val outputWasmFile = outputFile.withReplacedExtensionOrNull(outputFile.extension, "wasm")!!
outputWasmFile.writeBytes(res.wasm)
@@ -5,14 +5,10 @@
package org.jetbrains.kotlin.backend.wasm
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analyzer.AbstractAnalyzerWithCompilerReport
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel
import org.jetbrains.kotlin.backend.wasm.ir2wasm.WasmCompiledModuleFragment
import org.jetbrains.kotlin.backend.wasm.ir2wasm.WasmModuleFragmentGenerator
import org.jetbrains.kotlin.backend.wasm.ir2wasm.generateStringLiteralsSupport
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.ir.backend.js.MainModule
import org.jetbrains.kotlin.ir.backend.js.ModulesStructure
import org.jetbrains.kotlin.ir.backend.js.loadIr
@@ -21,7 +17,6 @@ import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.noUnboundLeft
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi2ir.generators.generateTypicalIrProviderList
import org.jetbrains.kotlin.wasm.ir.convertors.WasmIrToBinary
import org.jetbrains.kotlin.wasm.ir.convertors.WasmIrToText
import java.io.ByteArrayOutputStream
@@ -32,7 +27,8 @@ fun compileWasm(
depsDescriptors: ModulesStructure,
phaseConfig: PhaseConfig,
irFactory: IrFactory,
exportedDeclarations: Set<FqName> = emptySet()
exportedDeclarations: Set<FqName> = emptySet(),
emitNameSection: Boolean = false,
): WasmCompilerResult {
val mainModule = depsDescriptors.mainModule
val configuration = depsDescriptors.compilerConfiguration
@@ -76,7 +72,7 @@ fun compileWasm(
val js = compiledWasmModule.generateJs()
val os = ByteArrayOutputStream()
WasmIrToBinary(os, linkedModule).appendWasmModule()
WasmIrToBinary(os, linkedModule, moduleDescriptor.name.asString(), emitNameSection).appendWasmModule()
val byteArray = os.toByteArray()
return WasmCompilerResult(
+1
View File
@@ -36,6 +36,7 @@ where advanced options include:
-Xrepositories=<path> Paths to additional places where libraries could be found
-Xtyped-arrays Translate primitive arrays to JS typed arrays
-Xwasm Use experimental WebAssembly compiler backend
-Xwasm-debug-info Add debug info to WebAssembly compiled module
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
-Xallow-result-return-type Allow compiling code when `kotlin.Result` is used as a return type
-Xbuiltins-from-sources Compile builtIns from sources