Simplify immutableBinaryBlobOf support in codegen
This commit is contained in:
committed by
SvyatoslavScherbina
parent
07f26dc1df
commit
aece25344f
+5
-23
@@ -1387,12 +1387,8 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
private fun evaluateStringConst(value: IrConst<String>) =
|
private fun evaluateStringConst(value: IrConst<String>) =
|
||||||
if (this.produceImmutableBinaryBlob) {
|
|
||||||
context.llvm.staticData.createImmutableBinaryBlob(value)
|
|
||||||
} else {
|
|
||||||
context.llvm.staticData.kotlinStringLiteral(
|
context.llvm.staticData.kotlinStringLiteral(
|
||||||
context.builtIns.stringType, value).llvm
|
context.builtIns.stringType, value).llvm
|
||||||
}
|
|
||||||
|
|
||||||
private fun evaluateConst(value: IrConst<*>): LLVMValueRef {
|
private fun evaluateConst(value: IrConst<*>): LLVMValueRef {
|
||||||
context.log{"evaluateConst : ${ir2string(value)}"}
|
context.log{"evaluateConst : ${ir2string(value)}"}
|
||||||
@@ -1619,6 +1615,11 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
callDirect(constructorDescriptor, args, Lifetime.IRRELEVANT)
|
callDirect(constructorDescriptor, args, Lifetime.IRRELEVANT)
|
||||||
return receiver
|
return receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.builtIns.immutableBinaryBlobOf -> {
|
||||||
|
val arg = expression.getValueArgument(0) as IrConst<String>
|
||||||
|
return context.llvm.staticData.createImmutableBinaryBlob(arg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1793,30 +1794,16 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
|
|
||||||
private fun CallableDescriptor.returnsUnit() = returnType == context.builtIns.unitType && !isSuspend
|
private fun CallableDescriptor.returnsUnit() = returnType == context.builtIns.unitType && !isSuspend
|
||||||
|
|
||||||
|
|
||||||
private var produceImmutableBinaryBlob: Boolean = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluates all arguments of [expression] that are explicitly represented in the IR.
|
* Evaluates all arguments of [expression] that are explicitly represented in the IR.
|
||||||
* Returns results in the same order as LLVM function expects, assuming that all explicit arguments
|
* Returns results in the same order as LLVM function expects, assuming that all explicit arguments
|
||||||
* exactly correspond to a tail of LLVM parameters.
|
* exactly correspond to a tail of LLVM parameters.
|
||||||
*/
|
*/
|
||||||
private fun evaluateExplicitArgs(expression: IrMemberAccessExpression): List<LLVMValueRef> {
|
private fun evaluateExplicitArgs(expression: IrMemberAccessExpression): List<LLVMValueRef> {
|
||||||
// TODO: remove this hack by properly implementing blobs in the frontend.
|
|
||||||
if (expression.descriptor.original == context.builtIns.immutableBinaryBlobOf) {
|
|
||||||
// As calls to immutableBinaryBlobOf() cannot be composed, it's OK to
|
|
||||||
// have simple flag for that purpose.
|
|
||||||
assert(!produceImmutableBinaryBlob)
|
|
||||||
produceImmutableBinaryBlob = true
|
|
||||||
}
|
|
||||||
|
|
||||||
val evaluatedArgs = expression.getArguments().map { (param, argExpr) ->
|
val evaluatedArgs = expression.getArguments().map { (param, argExpr) ->
|
||||||
param to evaluateExpression(argExpr)
|
param to evaluateExpression(argExpr)
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
if (produceImmutableBinaryBlob)
|
|
||||||
produceImmutableBinaryBlob = false
|
|
||||||
|
|
||||||
val allValueParameters = expression.descriptor.allParameters
|
val allValueParameters = expression.descriptor.allParameters
|
||||||
|
|
||||||
return allValueParameters.dropWhile { it !in evaluatedArgs }.map {
|
return allValueParameters.dropWhile { it !in evaluatedArgs }.map {
|
||||||
@@ -2022,11 +2009,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context.builtIns.immutableBinaryBlobOf -> {
|
|
||||||
// LLVM value is already computed when evaluating argument, just use it.
|
|
||||||
args.single()
|
|
||||||
}
|
|
||||||
|
|
||||||
interop.objCObjectInitFromPtr -> {
|
interop.objCObjectInitFromPtr -> {
|
||||||
genObjCObjectInitFromPtr(args)
|
genObjCObjectInitFromPtr(args)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user