native.backend + native.frontend
This commit is contained in:
@@ -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,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>
|
||||||
+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,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,81 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minamoto on 14/09/16.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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)
|
||||||
+13
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
+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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user