Move createPhaseConfig to module cli
To use things like MessageCollector to report errors/warnings related to incorrect phase configuration flags
This commit is contained in:
committed by
Georgy Bronnikov
parent
2995be8bd2
commit
0fb444a5d1
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.phaser.AnyNamedPhase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
|
||||
fun createPhaseConfig(compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration): PhaseConfig {
|
||||
val phases = compoundPhase.toPhaseMap()
|
||||
val enabled = computeEnabled(phases, config).toMutableSet()
|
||||
val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES)
|
||||
|
||||
val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE)
|
||||
val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER)
|
||||
val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE)
|
||||
val toDumpStateBefore = beforeDumpSet + bothDumpSet
|
||||
val toDumpStateAfter = afterDumpSet + bothDumpSet
|
||||
val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE)
|
||||
val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER)
|
||||
val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE)
|
||||
val toValidateStateBefore = beforeValidateSet + bothValidateSet
|
||||
val toValidateStateAfter = afterValidateSet + bothValidateSet
|
||||
|
||||
val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES)
|
||||
val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS)
|
||||
val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS)
|
||||
|
||||
return PhaseConfig(
|
||||
compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter,
|
||||
needProfiling, checkConditions, checkStickyConditions
|
||||
)
|
||||
}
|
||||
|
||||
private fun computeEnabled(
|
||||
phases: MutableMap<String, AnyNamedPhase>,
|
||||
config: CompilerConfiguration
|
||||
): Set<AnyNamedPhase> {
|
||||
val disabledPhases = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.DISABLED_PHASES)
|
||||
return phases.values.toSet() - disabledPhases
|
||||
}
|
||||
|
||||
private fun phaseSetFromConfiguration(
|
||||
phases: MutableMap<String, AnyNamedPhase>,
|
||||
config: CompilerConfiguration,
|
||||
key: CompilerConfigurationKey<Set<String>>
|
||||
): Set<AnyNamedPhase> {
|
||||
val phaseNames = config.get(key) ?: emptySet()
|
||||
if ("ALL" in phaseNames) return phases.values.toSet()
|
||||
return phaseNames.map { phases[it]!! }.toSet()
|
||||
}
|
||||
+1
-5
@@ -16,28 +16,25 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.jvm.compiler
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.psi.PsiJavaModule
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.impl.PsiModificationTrackerImpl
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
|
||||
import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection
|
||||
import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.jvmPhases
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
|
||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.createPhaseConfig
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING
|
||||
@@ -67,7 +64,6 @@ import org.jetbrains.kotlin.utils.newLinkedHashMapWithExpectedSize
|
||||
import java.io.File
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.net.URLClassLoader
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
object KotlinToJVMBytecodeCompiler {
|
||||
private fun writeOutput(
|
||||
|
||||
+1
-46
@@ -5,33 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.phaser
|
||||
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||
|
||||
fun createPhaseConfig(compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration): PhaseConfig {
|
||||
val phases = compoundPhase.toPhaseMap()
|
||||
val enabled = computeEnabled(phases, config).toMutableSet()
|
||||
val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES)
|
||||
|
||||
val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE)
|
||||
val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER)
|
||||
val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE)
|
||||
val toDumpStateBefore = beforeDumpSet + bothDumpSet
|
||||
val toDumpStateAfter = afterDumpSet + bothDumpSet
|
||||
val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE)
|
||||
val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER)
|
||||
val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE)
|
||||
val toValidateStateBefore = beforeValidateSet + bothValidateSet
|
||||
val toValidateStateAfter = afterValidateSet + bothValidateSet
|
||||
|
||||
val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES)
|
||||
val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS)
|
||||
val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS)
|
||||
|
||||
return PhaseConfig(compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter, needProfiling, checkConditions, checkStickyConditions)
|
||||
}
|
||||
|
||||
fun createDefaultPhaseConfig(compoundPhase: CompilerPhase<*, *, *>): PhaseConfig {
|
||||
val phases = compoundPhase.toPhaseMap()
|
||||
val enabled = phases.values.toMutableSet()
|
||||
@@ -44,31 +17,13 @@ fun createDefaultPhaseConfig(compoundPhase: CompilerPhase<*, *, *>): PhaseConfig
|
||||
)
|
||||
}
|
||||
|
||||
private fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> =
|
||||
fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> =
|
||||
getNamedSubphases().fold(mutableMapOf()) { acc, (_, phase) ->
|
||||
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"}
|
||||
acc[phase.name] = phase
|
||||
acc
|
||||
}
|
||||
|
||||
private fun computeEnabled(
|
||||
phases: MutableMap<String, AnyNamedPhase>,
|
||||
config: CompilerConfiguration
|
||||
): Set<AnyNamedPhase> {
|
||||
val disabledPhases = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.DISABLED_PHASES)
|
||||
return phases.values.toSet() - disabledPhases
|
||||
}
|
||||
|
||||
private fun phaseSetFromConfiguration(
|
||||
phases: MutableMap<String, AnyNamedPhase>,
|
||||
config: CompilerConfiguration,
|
||||
key: CompilerConfigurationKey<Set<String>>
|
||||
): Set<AnyNamedPhase> {
|
||||
val phaseNames = config.get(key) ?: emptySet()
|
||||
if ("ALL" in phaseNames) return phases.values.toSet()
|
||||
return phaseNames.map { phases[it]!! }.toSet()
|
||||
}
|
||||
|
||||
class PhaseConfig(
|
||||
private val compoundPhase: CompilerPhase<*, *, *>,
|
||||
private val phases: MutableMap<String, AnyNamedPhase>,
|
||||
|
||||
@@ -18,9 +18,9 @@ package org.jetbrains.kotlin.codegen
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.TestsCompiletimeError
|
||||
import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.jvmPhases
|
||||
import org.jetbrains.kotlin.cli.common.createPhaseConfig
|
||||
import org.jetbrains.kotlin.cli.common.output.writeAllTo
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig
|
||||
import org.jetbrains.kotlin.cli.common.createPhaseConfig
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.test
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig
|
||||
import org.jetbrains.kotlin.cli.common.createPhaseConfig
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.ir.backend.js.*
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
|
||||
Reference in New Issue
Block a user