CODEGEN: naive implementation of string_concatination (not tested)
(cherry picked from commit 8e0e9480d7cbec6e640f1b5a8a15af0d2f1bc278)
This commit is contained in:
committed by
vvlevchenko
parent
7a0d0ec5a7
commit
8496a0f2a9
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanPlatform
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanPlatform
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.context.ContextForNewModule
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanPlatform
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.container.get
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
|
||||
+40
-16
@@ -4,6 +4,7 @@ import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanPlatform
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LazyClassReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
@@ -345,27 +346,42 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
|
||||
private fun evaluateExpression(tmpVariableName: String, value: IrElement?): LLVMValueRef? {
|
||||
when (value) {
|
||||
is IrSetterCallImpl -> return evaluateSetterCall (tmpVariableName, value)
|
||||
is IrTypeOperatorCall-> return evaluateTypeOperator(tmpVariableName, value)
|
||||
is IrCall -> return evaluateCall (tmpVariableName, value)
|
||||
is IrGetValue -> return evaluateGetValue (tmpVariableName, value)
|
||||
is IrSetVariable -> return evaluateSetVariable ( value)
|
||||
is IrVariable -> return evaluateVariable ( value)
|
||||
is IrGetField -> return evaluateGetField ( value)
|
||||
is IrSetField -> return evaluateSetField ( value)
|
||||
is IrConst<*> -> return evaluateConst ( value)
|
||||
is IrReturn -> return evaluateReturn ( value)
|
||||
is IrBlock -> return evaluateBlock ( value)
|
||||
is IrExpressionBody -> return evaluateExpression (tmpVariableName, value.expression)
|
||||
is IrWhen -> return evaluateWhen (tmpVariableName, value)
|
||||
is IrThrow -> return evaluateThrow (tmpVariableName, value)
|
||||
null -> return null
|
||||
else -> {
|
||||
is IrSetterCallImpl -> return evaluateSetterCall (tmpVariableName, value)
|
||||
is IrTypeOperatorCall -> return evaluateTypeOperator (tmpVariableName, value)
|
||||
is IrCall -> return evaluateCall (tmpVariableName, value)
|
||||
is IrGetValue -> return evaluateGetValue (tmpVariableName, value)
|
||||
is IrSetVariable -> return evaluateSetVariable ( value)
|
||||
is IrVariable -> return evaluateVariable ( value)
|
||||
is IrGetField -> return evaluateGetField ( value)
|
||||
is IrSetField -> return evaluateSetField ( value)
|
||||
is IrConst<*> -> return evaluateConst ( value)
|
||||
is IrReturn -> return evaluateReturn ( value)
|
||||
is IrBlock -> return evaluateBlock ( value)
|
||||
is IrExpressionBody -> return evaluateExpression (tmpVariableName, value.expression)
|
||||
is IrWhen -> return evaluateWhen (tmpVariableName, value)
|
||||
is IrThrow -> return evaluateThrow (tmpVariableName, value)
|
||||
is IrStringConcatenation -> return evaluateStringConcatenation(tmpVariableName, value)
|
||||
null -> return null
|
||||
else -> {
|
||||
TODO("${ir2string(value)}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun evaluateStringConcatenation(tmpVariableName: String, value: IrStringConcatenation): LLVMValueRef? {
|
||||
val stringPlus = KonanPlatform.builtIns.stringType.memberScope.getContributedFunctions(Name.identifier("plus"), NoLookupLocation.FROM_BACKEND).first()
|
||||
var res:LLVMValueRef? = null
|
||||
val strings:List<LLVMValueRef?> = value.arguments.map {
|
||||
val descriptor = getToString(it.type)
|
||||
|
||||
val args = listOf(evaluateExpression(codegen.newVar(), it))
|
||||
return@map evaluateSimpleFunctionCall(codegen.newVar(), descriptor, args)!!
|
||||
}
|
||||
val concatResult = strings.take(1).fold(strings.first()) {res, it -> evaluateSimpleFunctionCall(codegen.newVar(), stringPlus, listOf(res, it))}
|
||||
return concatResult
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun evaluateThrow(tmpVariableName: String, expression: IrThrow): LLVMValueRef? {
|
||||
@@ -747,6 +763,14 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun getToString(type: KotlinType): SimpleFunctionDescriptor {
|
||||
val name = Name.identifier("toString")
|
||||
val descriptor = type.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND).first()
|
||||
return descriptor
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
private fun evaluateOperatorEqeq(callee: IrBinaryPrimitiveImpl, arg0: LLVMValueRef, arg1: LLVMValueRef, tmpVariableName: String): LLVMValueRef {
|
||||
|
||||
val arg0Type = callee.argument0.type
|
||||
|
||||
+2
-1
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.KonanPlatformConfigurator
|
||||
import org.jetbrains.kotlin.resolve.ImportPath
|
||||
import org.jetbrains.kotlin.resolve.PlatformConfigurator
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
+2
-2
@@ -16,7 +16,7 @@
|
||||
|
||||
// Adapted from JS compiler, but everyhing has been switched off for now.
|
||||
|
||||
package org.jetbrains.kotlin.cli.bc
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
@@ -42,7 +42,7 @@ object KonanPlatformConfigurator : PlatformConfigurator(
|
||||
overloadFilter = OverloadFilter.DEFAULT,
|
||||
platformToKotlinClassMap = PlatformToKotlinClassMap.EMPTY
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useInstance(SyntheticScopes.Empty)
|
||||
container.useInstance(SyntheticConstructorsProvider.Empty)
|
||||
container.useInstance(TypeSpecificityComparator.NONE)
|
||||
Reference in New Issue
Block a user