[JS IR] support new Ir2Js in tests and in K2JsTranslator
This commit is contained in:
committed by
TeamCityServer
parent
3c859138d1
commit
d565cc4262
+3
@@ -176,6 +176,9 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xir-per-file", description = "Splits generated .js per-file")
|
||||
var irPerFile: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xir-new-ir2js", description = "New fragment-based ir2js")
|
||||
var irNewIr2Js: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xinclude",
|
||||
valueDescription = "<path>",
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.ir.backend.js.ic.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.ir.backend.js.codegen.JsGenerationGranularity
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformerTmp
|
||||
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
|
||||
import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult
|
||||
import org.jetbrains.kotlin.js.config.*
|
||||
@@ -381,16 +382,29 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
granularity = granularity
|
||||
)
|
||||
|
||||
val transformer = IrModuleToJsTransformer(
|
||||
ir.context,
|
||||
mainCallArguments,
|
||||
fullJs = true,
|
||||
dceJs = arguments.irDce,
|
||||
multiModule = arguments.irPerModule,
|
||||
relativeRequirePath = false,
|
||||
generateGlobalThisPolyfill = configuration.languageVersionSettings.supportsFeature(LanguageFeature.JsAllowInvalidCharsIdentifiersEscaping)
|
||||
)
|
||||
val compiledModule: CompilerResult = transformer.generateModule(ir.allModules)
|
||||
val compiledModule: CompilerResult = if (arguments.irNewIr2Js) {
|
||||
val transformer = IrModuleToJsTransformerTmp(
|
||||
ir.context,
|
||||
mainCallArguments,
|
||||
fullJs = true,
|
||||
dceJs = arguments.irDce,
|
||||
multiModule = arguments.irPerModule,
|
||||
relativeRequirePath = false,
|
||||
)
|
||||
|
||||
transformer.generateModule(ir.allModules)
|
||||
} else {
|
||||
val transformer = IrModuleToJsTransformer(
|
||||
ir.context,
|
||||
mainCallArguments,
|
||||
fullJs = true,
|
||||
dceJs = arguments.irDce,
|
||||
multiModule = arguments.irPerModule,
|
||||
relativeRequirePath = false
|
||||
)
|
||||
|
||||
transformer.generateModule(ir.allModules)
|
||||
}
|
||||
|
||||
messageCollector.report(INFO, "Executable production duration: ${System.currentTimeMillis() - start}ms")
|
||||
|
||||
|
||||
+1
@@ -19,6 +19,7 @@ where advanced options include:
|
||||
-Xir-dce-runtime-diagnostic={log|exception}
|
||||
Enable runtime diagnostics when performing DCE instead of removing declarations
|
||||
-Xir-module-name=<name> Specify a compilation module name for IR backend
|
||||
-Xir-new-ir2js New fragment-based ir2js
|
||||
-Xir-only Disables pre-IR backend
|
||||
-Xir-per-file Splits generated .js per-file
|
||||
-Xir-per-module Splits generated .js per-module
|
||||
|
||||
+5
@@ -234,4 +234,9 @@ object JsEnvironmentConfigurationDirectives : SimpleDirectivesContainer() {
|
||||
description = "",
|
||||
applicability = DirectiveApplicability.Global
|
||||
)
|
||||
|
||||
val RUN_NEW_IR_2_JS by directive(
|
||||
description = "",
|
||||
applicability = DirectiveApplicability.Global
|
||||
)
|
||||
}
|
||||
|
||||
@@ -133,19 +133,34 @@ class JsIrBackendFacade(
|
||||
.run { if (shouldBeGenerated()) arguments() else null }
|
||||
val runIrDce = JsEnvironmentConfigurationDirectives.RUN_IR_DCE in module.directives
|
||||
val esModules = JsEnvironmentConfigurationDirectives.ES_MODULES in module.directives
|
||||
val runNewIr2Js = JsEnvironmentConfigurationDirectives.RUN_NEW_IR_2_JS in module.directives
|
||||
|
||||
val outputFile = File(JsEnvironmentConfigurator.getJsModuleArtifactPath(testServices, module.name) + ".js")
|
||||
val dceOutputFile = File(JsEnvironmentConfigurator.getDceJsArtifactPath(testServices, module.name) + ".js")
|
||||
if (!esModules) {
|
||||
val transformer = IrModuleToJsTransformerTmp(
|
||||
loweredIr.context,
|
||||
mainArguments,
|
||||
fullJs = true,
|
||||
dceJs = runIrDce,
|
||||
multiModule = granularity == JsGenerationGranularity.PER_MODULE,
|
||||
relativeRequirePath = false
|
||||
)
|
||||
return BinaryArtifacts.Js.JsIrArtifact(outputFile, transformer.generateModule(loweredIr.allModules)).dump(module)
|
||||
if (runNewIr2Js) {
|
||||
val transformer = IrModuleToJsTransformerTmp(
|
||||
loweredIr.context,
|
||||
mainArguments,
|
||||
fullJs = true,
|
||||
dceJs = runIrDce,
|
||||
multiModule = granularity == JsGenerationGranularity.PER_MODULE,
|
||||
relativeRequirePath = false
|
||||
)
|
||||
|
||||
return BinaryArtifacts.Js.JsIrArtifact(outputFile, transformer.generateModule(loweredIr.allModules)).dump(module)
|
||||
} else {
|
||||
val transformer = IrModuleToJsTransformer(
|
||||
loweredIr.context,
|
||||
mainArguments,
|
||||
fullJs = true,
|
||||
dceJs = runIrDce,
|
||||
multiModule = granularity == JsGenerationGranularity.PER_MODULE,
|
||||
relativeRequirePath = false
|
||||
)
|
||||
|
||||
return BinaryArtifacts.Js.JsIrArtifact(outputFile, transformer.generateModule(loweredIr.allModules)).dump(module)
|
||||
}
|
||||
}
|
||||
|
||||
val options = JsGenerationOptions(generatePackageJson = true, generateTypeScriptDefinitions = generateDts)
|
||||
|
||||
@@ -57,6 +57,7 @@ abstract class AbstractJsIrTest(
|
||||
if (getBoolean("kotlin.js.ir.klibMainModule")) +JsEnvironmentConfigurationDirectives.KLIB_MAIN_MODULE
|
||||
if (getBoolean("kotlin.js.ir.perModule")) +JsEnvironmentConfigurationDirectives.PER_MODULE
|
||||
if (getBoolean("kotlin.js.ir.dce", true)) +JsEnvironmentConfigurationDirectives.RUN_IR_DCE
|
||||
if (getBoolean("kotlin.js.ir.newIr2Js", false)) +JsEnvironmentConfigurationDirectives.RUN_NEW_IR_2_JS
|
||||
}
|
||||
|
||||
configureJsArtifactsHandlersStep {
|
||||
|
||||
Reference in New Issue
Block a user