Create separate source set for interpreter map generator
A separate source set is needed so that the generator no longer depends on the generated code
This commit is contained in:
@@ -23,6 +23,7 @@ fun extraSourceSet(name: String, extendMain: Boolean = true): Pair<SourceSet, Co
|
||||
|
||||
val (builtinsSourceSet, builtinsApi) = extraSourceSet("builtins", extendMain = false)
|
||||
val (evaluateSourceSet, evaluateApi) = extraSourceSet("evaluate")
|
||||
val (interpreterSourceSet, interpreterApi) = extraSourceSet("interpreter")
|
||||
|
||||
dependencies {
|
||||
// for GeneratorsFileUtil
|
||||
@@ -31,11 +32,11 @@ dependencies {
|
||||
|
||||
builtinsApi("org.jetbrains.kotlin:kotlin-stdlib:$bootstrapKotlinVersion") { isTransitive = false }
|
||||
evaluateApi(project(":core:deserialization"))
|
||||
evaluateApi(project(":compiler:ir.tree"))
|
||||
evaluateApi(project(":compiler:ir.backend.common"))
|
||||
interpreterApi(project(":compiler:ir.tree"))
|
||||
|
||||
testCompile(builtinsSourceSet.output)
|
||||
testCompile(evaluateSourceSet.output)
|
||||
testCompile(interpreterSourceSet.output)
|
||||
|
||||
testCompile(projectTests(":compiler:cli"))
|
||||
testCompile(projectTests(":idea:idea-maven"))
|
||||
@@ -90,5 +91,6 @@ val generateKeywordStrings by generator("org.jetbrains.kotlin.generators.fronten
|
||||
|
||||
val generateBuiltins by generator("org.jetbrains.kotlin.generators.builtins.generateBuiltIns.GenerateBuiltInsKt", builtinsSourceSet)
|
||||
val generateOperationsMap by generator("org.jetbrains.kotlin.generators.evaluate.GenerateOperationsMapKt", evaluateSourceSet)
|
||||
val generateInterpreterMap by generator("org.jetbrains.kotlin.generators.interpreter.GenerateInterpreterMapKt", interpreterSourceSet)
|
||||
|
||||
testsJar()
|
||||
|
||||
+35
-6
@@ -3,24 +3,33 @@
|
||||
* 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.generators.evaluate
|
||||
package org.jetbrains.kotlin.generators.interpreter
|
||||
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import java.io.File
|
||||
|
||||
val DESTINATION = File("compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/builtins/IrBuiltInsMapGenerated.kt")
|
||||
|
||||
fun generateMap(irBuiltIns: IrBuiltIns): String {
|
||||
fun main() {
|
||||
GeneratorsFileUtil.writeFileIfContentChanged(DESTINATION, generateMap())
|
||||
}
|
||||
|
||||
fun generateMap(): String {
|
||||
val sb = StringBuilder()
|
||||
val p = Printer(sb)
|
||||
p.println(File("license/COPYRIGHT.txt").readText())
|
||||
@@ -32,6 +41,7 @@ fun generateMap(irBuiltIns: IrBuiltIns): String {
|
||||
p.println("/** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */")
|
||||
p.println()
|
||||
|
||||
val irBuiltIns = getIrBuiltIns()
|
||||
val unaryOperationsMap = getOperationMap(1)
|
||||
val binaryOperationsMap = getOperationMap(2)
|
||||
val ternaryOperationsMap = getOperationMap(3)
|
||||
@@ -180,3 +190,22 @@ private fun getIrMethodSymbolByName(methodName: String): String {
|
||||
else -> throw UnsupportedOperationException("Unknown ir operation \"$methodName\"")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getIrBuiltIns(): IrBuiltIns {
|
||||
val builtIns = DefaultBuiltIns.Instance
|
||||
val languageSettings = LanguageVersionSettingsImpl(LanguageVersion.KOTLIN_1_3, ApiVersion.KOTLIN_1_3)
|
||||
|
||||
val moduleDescriptor = ModuleDescriptorImpl(Name.special("<test-module>"), LockBasedStorageManager(""), builtIns)
|
||||
val signaturer = object : IdSignatureComposer {
|
||||
override fun composeSignature(descriptor: DeclarationDescriptor): IdSignature? = null
|
||||
|
||||
override fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? = null
|
||||
}
|
||||
val symbolTable = SymbolTable(signaturer)
|
||||
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
val typeTranslator = TypeTranslator(symbolTable, languageSettings, builtIns)
|
||||
constantValueGenerator.typeTranslator = typeTranslator
|
||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||
|
||||
return IrBuiltIns(builtIns, typeTranslator, symbolTable)
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.generators.test.evaluate
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.generators.evaluate.DESTINATION
|
||||
import org.jetbrains.kotlin.generators.evaluate.generateMap
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmManglerDesc
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.util.ConstantValueGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
|
||||
class GenerateBuiltInsMapTest : TestCase() {
|
||||
fun testGeneratedDataIsUpToDate() {
|
||||
val text = generateMap(getIrBuiltIns())
|
||||
KotlinTestUtils.assertEqualsToFile(DESTINATION, text)
|
||||
}
|
||||
|
||||
private fun getIrBuiltIns(): IrBuiltIns {
|
||||
val builtIns = DefaultBuiltIns.Instance
|
||||
val languageSettings = LanguageVersionSettingsImpl(LanguageVersion.KOTLIN_1_3, ApiVersion.KOTLIN_1_3)
|
||||
|
||||
val moduleDescriptor = ModuleDescriptorImpl(Name.special("<test-module>"), LockBasedStorageManager(""), builtIns)
|
||||
val mangler = JvmManglerDesc()
|
||||
val signaturer = JvmIdSignatureDescriptor(mangler)
|
||||
val symbolTable = SymbolTable(signaturer)
|
||||
val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
|
||||
val typeTranslator = TypeTranslator(symbolTable, languageSettings, builtIns)
|
||||
constantValueGenerator.typeTranslator = typeTranslator
|
||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||
|
||||
return IrBuiltIns(builtIns, typeTranslator, symbolTable)
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.generators.test.interpreter
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.generators.interpreter.DESTINATION
|
||||
import org.jetbrains.kotlin.generators.interpreter.generateMap
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
|
||||
class GenerateBuiltInsMapTest : TestCase() {
|
||||
fun testGeneratedDataIsUpToDate() {
|
||||
val text = generateMap()
|
||||
KotlinTestUtils.assertEqualsToFile(DESTINATION, text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user