minor refactoring in native to frontend interface
This commit is contained in:
-19
@@ -1,19 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
@@ -20,53 +20,64 @@ import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
|
|||||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
||||||
import java.lang.System.out
|
import java.lang.System.out
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.Collections.emptyList
|
|
||||||
import kotlin.reflect.jvm.internal.impl.load.java.JvmAbi
|
import kotlin.reflect.jvm.internal.impl.load.java.JvmAbi
|
||||||
|
|
||||||
|
class NativeAnalyzer(val environment: KotlinCoreEnvironment) :
|
||||||
|
AnalyzerWithCompilerReport.Analyzer {
|
||||||
|
override fun analyze(): AnalysisResult {
|
||||||
|
val sharedTrace =
|
||||||
|
CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
|
||||||
|
|
||||||
|
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(
|
||||||
|
environment.project, environment.configuration)
|
||||||
|
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
|
environment.project,
|
||||||
|
environment.getSourceFiles(),
|
||||||
|
sharedTrace,
|
||||||
|
environment.configuration,
|
||||||
|
{ scope -> JvmPackagePartProvider(environment, scope) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reportEnvironmentErrors() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||||
override fun doExecute(arguments: K2NativeCompilerArguments, configuration: CompilerConfiguration, rootDisposable: Disposable): ExitCode {
|
override fun doExecute(arguments : K2NativeCompilerArguments,
|
||||||
configuration.put(CommonConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
|
configuration : CompilerConfiguration,
|
||||||
|
rootDisposable: Disposable): ExitCode {
|
||||||
|
configuration.put(CommonConfigurationKeys.MODULE_NAME,
|
||||||
|
JvmAbi.DEFAULT_MODULE_NAME)
|
||||||
|
configuration.addKotlinSourceRoots(arguments.freeArgs)
|
||||||
|
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
|
||||||
|
configuration, Arrays.asList<String>("extensions/common.xml"))
|
||||||
|
|
||||||
configuration.addKotlinSourceRoots(arguments.freeArgs)
|
val collector = configuration.getNotNull(
|
||||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, Arrays.asList<String>("extensions/common.xml"))
|
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||||
val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(collector)
|
||||||
val analyzerWithCompilerReport = AnalyzerWithCompilerReport(collector)
|
|
||||||
|
|
||||||
analyzerWithCompilerReport.analyzeAndReport(
|
// Build AST and binding info.
|
||||||
environment.getSourceFiles(), object : AnalyzerWithCompilerReport.Analyzer {
|
analyzerWithCompilerReport.analyzeAndReport(environment.getSourceFiles(),
|
||||||
override fun analyze(): AnalysisResult {
|
NativeAnalyzer(environment))
|
||||||
val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
|
|
||||||
|
|
||||||
/* replace this with native specific */
|
// Translate AST to high level IR.
|
||||||
val moduleContext =
|
val translator = Psi2IrTranslator(Psi2IrConfiguration(false))
|
||||||
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.configuration)
|
val module = translator.generateModule(
|
||||||
|
analyzerWithCompilerReport.analysisResult.moduleDescriptor,
|
||||||
|
environment.getSourceFiles(),
|
||||||
|
analyzerWithCompilerReport.analysisResult.bindingContext)
|
||||||
|
|
||||||
|
// Emit LLVM code.
|
||||||
|
module.accept(DumpIrTreeVisitor(out), "")
|
||||||
|
emitLLVM(module, arguments.runtimeFile, arguments.outputFile)
|
||||||
|
return ExitCode.OK
|
||||||
|
}
|
||||||
|
|
||||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
override fun setupPlatformSpecificArgumentsAndServices(
|
||||||
environment.project,
|
configuration: CompilerConfiguration,
|
||||||
environment.getSourceFiles(),
|
arguments : K2NativeCompilerArguments,
|
||||||
sharedTrace,
|
services : Services) {}
|
||||||
environment.configuration,
|
|
||||||
{ scope -> JvmPackagePartProvider(environment, scope) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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), "")
|
|
||||||
emitLLVM(module, arguments.runtimeFile, arguments.outputFile)
|
|
||||||
return ExitCode.OK
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setupPlatformSpecificArgumentsAndServices(configuration: CompilerConfiguration, arguments: K2NativeCompilerArguments, services: Services) {}
|
|
||||||
|
|
||||||
override fun createArguments(): K2NativeCompilerArguments {
|
override fun createArguments(): K2NativeCompilerArguments {
|
||||||
return K2NativeCompilerArguments()
|
return K2NativeCompilerArguments()
|
||||||
|
|||||||
Reference in New Issue
Block a user