HEAD UPS! Global move: experiments -> kotlin-native
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# Kotlin-native backend #
|
||||
|
||||
## Build
|
||||
|
||||
To build just use:
|
||||
|
||||
gradle dist ; may fail in JS
|
||||
gradle :backend.native:cli.bc:run
|
||||
|
||||
And it will run simple example (currently prints out IR of test file).
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/compiler/ir/backend.native/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
<orderEntry type="module" module-name="backend" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,34 @@
|
||||
diff --git a/compiler/backend/backend.iml b/compiler/backend/backend.iml
|
||||
index 35bbf20..cfbb3dc 100644
|
||||
--- a/compiler/backend/backend.iml
|
||||
+++ b/compiler/backend/backend.iml
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="backend.jvm" />
|
||||
<orderEntry type="module" module-name="ir.tree" />
|
||||
+ <orderEntry type="module" module-name="backend.native" />
|
||||
</component>
|
||||
</module>
|
||||
\ No newline at end of file
|
||||
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt
|
||||
index 39077d2..f0cbb87 100644
|
||||
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt
|
||||
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
||||
+import org.jetbrains.kotlin.backend.native.NativeIrCodegenFactory
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||
import org.jetbrains.kotlin.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.`when`.MappingsClassesForWhenByEnum
|
||||
@@ -69,7 +70,8 @@ class GenerationState @JvmOverloads constructor(
|
||||
// TODO: get rid of it with the proper module infrastructure
|
||||
val outDirectory: File? = null,
|
||||
private val onIndependentPartCompilationEnd: GenerationStateEventCallback = GenerationStateEventCallback.DO_NOTHING,
|
||||
- val codegenFactory: CodegenFactory = if (configuration.getBoolean(JVMConfigurationKeys.IR)) JvmIrCodegenFactory else DefaultCodegenFactory
|
||||
+ //val codegenFactory: CodegenFactory = if (configuration.getBoolean(JVMConfigurationKeys.IR)) NativeIrCodegenFactory else DefaultCodegenFactory
|
||||
+ val codegenFactory: CodegenFactory = NativeIrCodegenFactory
|
||||
) {
|
||||
abstract class GenerateClassFilter {
|
||||
abstract fun shouldAnnotateClass(processingClassOrObject: KtClassOrObject): Boolean
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime (3)" level="project" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,11 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.0.3'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.3"
|
||||
}
|
||||
}
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package org.jetbrains.kotlin.bc.analyze
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.context.ModuleContext
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import kotlin.reflect.jvm.internal.impl.descriptors.PackagePartProvider
|
||||
|
||||
|
||||
fun analyze(moduleContext: ModuleContext,
|
||||
files:Collection<KtFile>,
|
||||
trace:BindingTrace,
|
||||
configuration: CompilerConfiguration,
|
||||
packagePartProvider: PackagePartProvider) : AnalysisResult {
|
||||
val bindingContext = trace.bindingContext
|
||||
val module = moduleContext.module
|
||||
return AnalysisResult.success(bindingContext, module)
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.0.3'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
|
||||
dependencies {
|
||||
compile files('../kotlin-ir/dist//kotlin-build-common-sources.jar',
|
||||
'../kotlin-ir/dist//kotlin-compiler-before-shrink.jar',
|
||||
'../kotlin-ir/dist//kotlin-compiler-for-maven.jar',
|
||||
'../kotlin-ir/dist//kotlin-compiler-javadoc.jar',
|
||||
'../kotlin-ir/dist//kotlin-compiler-sources.jar',
|
||||
'../kotlin-ir/dist//kotlin-mock-runtime-for-test.jar',
|
||||
'../kotlin-ir/dist//kotlin-reflect-before-jarjar.jar',
|
||||
'../kotlin-ir/dist//kotlin-reflect-jarjar.jar',
|
||||
'../kotlin-ir/dist//kotlin-reflect-sources-for-maven.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/android-extensions-compiler.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-annotation-processing.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-ant.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-build-common-test.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-build-common.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-compiler.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-daemon-client.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-jslib-sources.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-jslib.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-preloader.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-reflect-internal-bootstrap.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-reflect.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-runner.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-runtime-internal-bootstrap.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-runtime-sources.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-runtime.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-test-internal-bootstrap.jar',
|
||||
'../kotlin-ir/dist//kotlinc/lib/kotlin-test.jar')
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'compiler/ir/backend.native/src/'
|
||||
main.kotlin.srcDirs += 'compiler/ir/backend.native/src/'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'cli.bc/src'
|
||||
main.kotlin.srcDirs += 'cli.bc/src'
|
||||
}
|
||||
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'bc.frontend/src'
|
||||
main.kotlin.srcDirs += 'bc.frontend/src'
|
||||
}
|
||||
|
||||
task run(type: JavaExec) {
|
||||
main 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
||||
classpath = sourceSets.main.runtimeClasspath.add(files(['build/classes/main']))
|
||||
args '../translator/src/test/kotlin/tests/classfields_1/classfields_1.kt'
|
||||
}
|
||||
|
||||
task jars {
|
||||
project.buildscript.configurations.classpath.each {
|
||||
String jarName = it.getName();
|
||||
print jarName + ":"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="Kotlin" />
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="ir.psi2ir" />
|
||||
<orderEntry type="module" module-name="ir.tree" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.config.addKotlinSourceRoots
|
||||
import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
|
||||
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
|
||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
||||
import java.lang.System.out
|
||||
import java.util.Collections.emptyList
|
||||
import kotlin.reflect.jvm.internal.impl.load.java.JvmAbi
|
||||
|
||||
class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
override fun doExecute(arguments: K2NativeCompilerArguments, configuration: CompilerConfiguration, rootDisposable: Disposable): ExitCode {
|
||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
|
||||
|
||||
configuration.addKotlinSourceRoots(arguments.freeArgs)
|
||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, emptyList())
|
||||
val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(collector)
|
||||
|
||||
analyzerWithCompilerReport.analyzeAndReport(
|
||||
environment.getSourceFiles(), object : AnalyzerWithCompilerReport.Analyzer {
|
||||
override fun analyze(): AnalysisResult {
|
||||
val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
|
||||
|
||||
/* replace this with native specific */
|
||||
val moduleContext =
|
||||
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.configuration)
|
||||
|
||||
|
||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
moduleContext,
|
||||
environment.getSourceFiles(),
|
||||
sharedTrace,
|
||||
environment.configuration,
|
||||
JvmPackagePartProvider(environment)
|
||||
)
|
||||
}
|
||||
override fun reportEnvironmentErrors() {
|
||||
TODO("implement me")
|
||||
}
|
||||
})
|
||||
|
||||
val translator = Psi2IrTranslator(Psi2IrConfiguration(false))
|
||||
val module = translator.generateModule(analyzerWithCompilerReport.analysisResult.moduleDescriptor,
|
||||
environment.getSourceFiles(),
|
||||
analyzerWithCompilerReport.analysisResult.bindingContext)
|
||||
|
||||
module.accept(DumpIrTreeVisitor(out), "")
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
override fun setupPlatformSpecificArgumentsAndServices(configuration: CompilerConfiguration, arguments: K2NativeCompilerArguments, services: Services) {}
|
||||
|
||||
override fun createArguments(): K2NativeCompilerArguments {
|
||||
return K2NativeCompilerArguments()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic fun main(args: Array<String>) {
|
||||
CLICompiler.doMain(K2Native(), args)
|
||||
}
|
||||
}
|
||||
}
|
||||
fun main(args: Array<String>) = K2Native.main(args)
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains.kotlin.cli.bc;
|
||||
|
||||
import com.sampullara.cli.Argument;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.ValueDescription;
|
||||
|
||||
|
||||
public class K2NativeCompilerArguments extends CommonCompilerArguments {
|
||||
@Argument(value = "output", description = "Output file path")
|
||||
@ValueDescription("<path>")
|
||||
public String outputFile;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.0.3'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package org.jetbrains.kotlin.backend.native
|
||||
|
||||
import org.jetbrains.kotlin.codegen.CompilationErrorHandler
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
object NativeBackendFacade {
|
||||
fun doGenerateFiles(files: Collection<KtFile>, state: GenerationState, errorHandler: CompilationErrorHandler) {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.jetbrains.kotlin.backend.native
|
||||
|
||||
import org.jetbrains.kotlin.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.context.PackageContext
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
|
||||
|
||||
object NativeIrCodegenFactory: CodegenFactory {
|
||||
override fun createPackageCodegen(state: GenerationState, files: Collection<org.jetbrains.kotlin.psi.KtFile>, fqName: org.jetbrains.kotlin.name.FqName, registry: PackagePartRegistry): PackageCodegen {
|
||||
val impl = PackageCodegenImpl(state, files, fqName, registry)
|
||||
|
||||
|
||||
return object : PackageCodegen {
|
||||
override fun generate(errorHandler: CompilationErrorHandler) {
|
||||
NativeBackendFacade.doGenerateFiles(files, state, errorHandler)
|
||||
}
|
||||
|
||||
override fun generateClassOrObject(classOrObject: KtClassOrObject, packagePartContext: PackageContext) {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun getPackageFragment(): PackageFragmentDescriptor {
|
||||
return impl.packageFragment
|
||||
}
|
||||
}
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
override fun createMultifileClassCodegen(state: GenerationState, files: Collection<org.jetbrains.kotlin.psi.KtFile>, fqName: org.jetbrains.kotlin.name.FqName, registry: PackagePartRegistry): MultifileClassCodegen {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
diff --git a/core/builtins/src/kotlin/Progressions.kt b/core/builtins/src/kotlin/Progressions.kt
|
||||
index 704d49f..509baaa 100644
|
||||
--- a/core/builtins/src/kotlin/Progressions.kt
|
||||
+++ b/core/builtins/src/kotlin/Progressions.kt
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package kotlin.ranges
|
||||
|
||||
+import java.lang.IllegalArgumentException
|
||||
import kotlin.internal.getProgressionLastElement
|
||||
|
||||
/**
|
||||
diff --git a/core/builtins/src/kotlin/internal/progressionUtil.kt b/core/builtins/src/kotlin/internal/progressionUtil.kt
|
||||
index 026c99f..f7a222e 100644
|
||||
--- a/core/builtins/src/kotlin/internal/progressionUtil.kt
|
||||
+++ b/core/builtins/src/kotlin/internal/progressionUtil.kt
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package kotlin.internal
|
||||
|
||||
+import java.lang.IllegalArgumentException
|
||||
+
|
||||
// a mod b (in arithmetical sense)
|
||||
private fun mod(a: Int, b: Int): Int {
|
||||
val mod = a % b
|
||||
@@ -0,0 +1,12 @@
|
||||
diff --git a/compiler/frontend/frontend.iml b/compiler/frontend/frontend.iml
|
||||
index 15545cc..00b8bed 100644
|
||||
--- a/compiler/frontend/frontend.iml
|
||||
+++ b/compiler/frontend/frontend.iml
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="container" exported="" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
||||
<orderEntry type="module" module-name="resolution" exported="" />
|
||||
+ <orderEntry type="module" module-name="runtime.jvm" />
|
||||
</component>
|
||||
</module>
|
||||
\ No newline at end of file
|
||||
Submodule
+1
Submodule backend.native/kotlin-ir added at 2be402ced7
@@ -0,0 +1,13 @@
|
||||
diff --git a/update_dependencies.xml b/update_dependencies.xml
|
||||
index cbfcb42..b5c029f 100644
|
||||
--- a/update_dependencies.xml
|
||||
+++ b/update_dependencies.xml
|
||||
@@ -74,7 +74,7 @@
|
||||
|
||||
<target name="jb_update" depends="fetch-third-party,fetch-annotations" description="Update dependencies for JB local network">
|
||||
<execute_update_with_idea_maven_artifacts
|
||||
- base.url="http://jetbrains-com-mirror.labs.intellij.net/intellij-repository/releases/com/jetbrains/intellij/idea"
|
||||
+ base.url="http://www.jetbrains.com/intellij-repository/releases/com/jetbrains/intellij/idea"
|
||||
idea.maven.version="${ideaVersion}"/>
|
||||
</target>
|
||||
|
||||
Reference in New Issue
Block a user