Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
154 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/github/youta1119/kotlin/compiler/CompilerPhases.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.youta1119.kotlin.compiler | ||
|
||
import org.jetbrains.kotlin.backend.common.phaser.* | ||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport | ||
import org.jetbrains.kotlin.config.languageVersionSettings | ||
|
||
|
||
internal fun createUnitPhase( | ||
name: String, | ||
description: String, | ||
prerequisite: Set<AnyNamedPhase> = emptySet(), | ||
op: DotNetBackendContext.() -> Unit | ||
) = namedOpUnitPhase(name, description, prerequisite, op) | ||
|
||
internal val noOpPhase = createUnitPhase( | ||
op = { | ||
println("no op") | ||
}, | ||
name = "NoOp", | ||
description = "no-op" | ||
) | ||
|
||
val toplevelPhase: CompilerPhase<DotNetBackendContext, Unit, Unit> = namedUnitPhase( | ||
name = "Compiler", | ||
description = "The whole compilation process", | ||
lower = noOpPhase | ||
) |
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/com/github/youta1119/kotlin/compiler/DotNetBackendContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.github.youta1119.kotlin.compiler | ||
|
||
|
||
import com.github.youta1119.kotlin.config.DotNetConfigurationKeys | ||
import org.jetbrains.kotlin.backend.common.CommonBackendContext | ||
import org.jetbrains.kotlin.backend.common.ir.DeclarationFactory | ||
import org.jetbrains.kotlin.backend.common.ir.Ir | ||
import org.jetbrains.kotlin.backend.common.ir.SharedVariablesManager | ||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys | ||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity | ||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector | ||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor | ||
import org.jetbrains.kotlin.ir.IrElement | ||
import org.jetbrains.kotlin.ir.declarations.IrFile | ||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns | ||
import org.jetbrains.kotlin.name.FqName | ||
import org.jetbrains.kotlin.resolve.BindingContext | ||
|
||
class DotNetBackendContext(val environment: KotlinCoreEnvironment, override val configuration: CompilerConfiguration) : | ||
CommonBackendContext { | ||
lateinit var moduleDescriptor: ModuleDescriptor | ||
lateinit var bindingContext: BindingContext | ||
|
||
val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)!! | ||
|
||
val outputName = configuration.get(DotNetConfigurationKeys.OUTPUT_NAME) ?: DEFAULT_OUTPUT_NAME | ||
|
||
override val builtIns: DotNetBuiltIns by lazy { | ||
moduleDescriptor.builtIns as DotNetBuiltIns | ||
} | ||
|
||
override val irBuiltIns: IrBuiltIns | ||
get() = TODO("not implemented") | ||
|
||
override val sharedVariablesManager: SharedVariablesManager | ||
get() = TODO("not implemented") | ||
|
||
override val declarationFactory: DeclarationFactory | ||
get() = TODO("not implemented") | ||
override var inVerbosePhase: Boolean = false | ||
|
||
override val internalPackageFqn: FqName | ||
get() = TODO("not implemented") | ||
|
||
override val ir: Ir<CommonBackendContext> | ||
get() = TODO("not implemented") | ||
|
||
override fun log(message: () -> String) { | ||
if (inVerbosePhase) { | ||
println(message()) | ||
} | ||
} | ||
|
||
override fun report(element: IrElement?, irFile: IrFile?, message: String, isError: Boolean) { | ||
this.messageCollector.report( | ||
if (isError) CompilerMessageSeverity.ERROR else CompilerMessageSeverity.WARNING, | ||
message, null | ||
) | ||
} | ||
|
||
private val messageCollector: MessageCollector | ||
get() = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) | ||
|
||
companion object { | ||
private const val DEFAULT_OUTPUT_NAME = "program" | ||
} | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/github/youta1119/kotlin/compiler/DotNetPlatform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.github.youta1119.kotlin.compiler | ||
|
||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns | ||
import org.jetbrains.kotlin.storage.StorageManager | ||
|
||
|
||
class DotNetBuiltIns(storageManager: StorageManager) : KotlinBuiltIns(storageManager) |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/github/youta1119/kotlin/compiler/compiler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.github.youta1119.kotlin.compiler | ||
|
||
import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel | ||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
|
||
|
||
fun compileToDotNetByteCode(environment: KotlinCoreEnvironment, configuration: CompilerConfiguration) { | ||
val context = DotNetBackendContext(environment, configuration) | ||
toplevelPhase.invokeToplevel(context.phaseConfig, context, Unit) | ||
} |
2 changes: 1 addition & 1 deletion
2
...otlin/compiler/DotNetConfigurationKeys.kt → .../kotlin/config/DotNetConfigurationKeys.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters