Eliminated Logger class.
Context now provides the log(message: String) method. This method knows if the current phase is verbose or not.
This commit is contained in:
committed by
alexander-gorshenev
parent
e48c5a7215
commit
82143d6c8a
+6
@@ -121,5 +121,11 @@ internal final class Context(val config: KonanConfig,
|
|||||||
fun shouldPrintBitCode(): Boolean {
|
fun shouldPrintBitCode(): Boolean {
|
||||||
return config.configuration.getBoolean(KonanConfigKeys.PRINT_BITCODE)
|
return config.configuration.getBoolean(KonanConfigKeys.PRINT_BITCODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun log(message: String) {
|
||||||
|
if (phase?.verbose) {
|
||||||
|
println(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
@@ -1,7 +1,11 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.ir.*
|
||||||
|
import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
|
import java.io.StringWriter
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,3 +64,13 @@ internal fun IrMemberAccessExpression.addArguments(args: Map<ParameterDescriptor
|
|||||||
|
|
||||||
internal fun IrMemberAccessExpression.addArguments(args: List<Pair<ParameterDescriptor, IrExpression>>) =
|
internal fun IrMemberAccessExpression.addArguments(args: List<Pair<ParameterDescriptor, IrExpression>>) =
|
||||||
this.addArguments(args.toMap())
|
this.addArguments(args.toMap())
|
||||||
|
|
||||||
|
fun ir2string(ir: IrElement?): String = ir2stringWhole(ir).takeWhile { it != '\n' }
|
||||||
|
|
||||||
|
fun ir2stringWhole(ir: IrElement?): String {
|
||||||
|
val strWriter = StringWriter()
|
||||||
|
|
||||||
|
ir?.accept(DumpIrTreeVisitor(strWriter), "")
|
||||||
|
return strWriter.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+31
-36
@@ -121,11 +121,6 @@ internal class MetadatorVisitor(val context: Context) : IrElementVisitorVoid {
|
|||||||
internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid {
|
internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid {
|
||||||
|
|
||||||
val codegen = CodeGenerator(context)
|
val codegen = CodeGenerator(context)
|
||||||
val logger = if (context.phase!!.verbose) {
|
|
||||||
Logger(codegen, context)
|
|
||||||
} else {
|
|
||||||
DummyLogger(codegen, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
@@ -234,7 +229,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
override fun visitModuleFragment(module: IrModuleFragment) {
|
override fun visitModuleFragment(module: IrModuleFragment) {
|
||||||
logger.log("visitModule : ${ir2string(module)}")
|
context.log("visitModule : ${ir2string(module)}")
|
||||||
|
|
||||||
module.acceptChildrenVoid(this)
|
module.acceptChildrenVoid(this)
|
||||||
appendLlvmUsed(context.llvm.usedFunctions)
|
appendLlvmUsed(context.llvm.usedFunctions)
|
||||||
@@ -314,7 +309,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitWhen(expression: IrWhen) {
|
override fun visitWhen(expression: IrWhen) {
|
||||||
logger.log("visitWhen : ${ir2string(expression)}")
|
context.log("visitWhen : ${ir2string(expression)}")
|
||||||
evaluateWhen(expression)
|
evaluateWhen(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,13 +434,13 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
}
|
}
|
||||||
|
|
||||||
codegen.epilogue(constructorDeclaration)
|
codegen.epilogue(constructorDeclaration)
|
||||||
logger.log("visitConstructor : ${ir2string(constructorDeclaration)}")
|
context.log("visitConstructor : ${ir2string(constructorDeclaration)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) {
|
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) {
|
||||||
logger.log("visitAnonymousInitializer : ${ir2string(declaration)}")
|
context.log("visitAnonymousInitializer : ${ir2string(declaration)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
@@ -462,7 +457,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.log("visitBlockBody : ${ir2string(body)}")
|
context.log("visitBlockBody : ${ir2string(body)}")
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
@@ -474,7 +469,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall) {
|
override fun visitCall(expression: IrCall) {
|
||||||
logger.log("visitCall : ${ir2string(expression)}")
|
context.log("visitCall : ${ir2string(expression)}")
|
||||||
val isUnit = KotlinBuiltIns.isUnit(expression.descriptor.returnType!!)
|
val isUnit = KotlinBuiltIns.isUnit(expression.descriptor.returnType!!)
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
}
|
}
|
||||||
@@ -482,14 +477,14 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitThrow(expression: IrThrow) {
|
override fun visitThrow(expression: IrThrow) {
|
||||||
logger.log("visitThrow : ${ir2string(expression)}")
|
context.log("visitThrow : ${ir2string(expression)}")
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitTry(expression: IrTry) {
|
override fun visitTry(expression: IrTry) {
|
||||||
logger.log("visitTry : ${ir2string(expression)}")
|
context.log("visitTry : ${ir2string(expression)}")
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,7 +602,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunction(declaration: IrFunction) {
|
override fun visitFunction(declaration: IrFunction) {
|
||||||
logger.log("visitFunction : ${ir2string(declaration)}")
|
context.log("visitFunction : ${ir2string(declaration)}")
|
||||||
if (declaration.descriptor.modality == Modality.ABSTRACT || declaration.body == null)
|
if (declaration.descriptor.modality == Modality.ABSTRACT || declaration.body == null)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -625,7 +620,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass) {
|
override fun visitClass(declaration: IrClass) {
|
||||||
logger.log("visitClass : ${ir2string(declaration)}")
|
context.log("visitClass : ${ir2string(declaration)}")
|
||||||
if (declaration.descriptor.kind == ClassKind.ANNOTATION_CLASS) {
|
if (declaration.descriptor.kind == ClassKind.ANNOTATION_CLASS) {
|
||||||
// do not generate any code for annotation classes as a workaround for NotImplementedError
|
// do not generate any code for annotation classes as a workaround for NotImplementedError
|
||||||
return
|
return
|
||||||
@@ -644,28 +639,28 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
// Create new variable in LLVM ir
|
// Create new variable in LLVM ir
|
||||||
|
|
||||||
override fun visitVariable(declaration: IrVariable) {
|
override fun visitVariable(declaration: IrVariable) {
|
||||||
logger.log("visitVariable : ${ir2string(declaration)}")
|
context.log("visitVariable : ${ir2string(declaration)}")
|
||||||
evaluateVariable(declaration)
|
evaluateVariable(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitReturn(expression: IrReturn) {
|
override fun visitReturn(expression: IrReturn) {
|
||||||
logger.log("visitReturn : ${ir2string(expression)}")
|
context.log("visitReturn : ${ir2string(expression)}")
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitSetVariable(expression: IrSetVariable) {
|
override fun visitSetVariable(expression: IrSetVariable) {
|
||||||
logger.log("visitSetVariable : ${ir2string(expression)}")
|
context.log("visitSetVariable : ${ir2string(expression)}")
|
||||||
evaluateSetVariable(expression)
|
evaluateSetVariable(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
// top level setter for field
|
// top level setter for field
|
||||||
override fun visitSetField(expression: IrSetField) {
|
override fun visitSetField(expression: IrSetField) {
|
||||||
logger.log("visitSetField : ${ir2string(expression)}")
|
context.log("visitSetField : ${ir2string(expression)}")
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,14 +689,14 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
// in this situation our visitGetField will be charged, that why no
|
// in this situation our visitGetField will be charged, that why no
|
||||||
// temporal variable is required.
|
// temporal variable is required.
|
||||||
override fun visitGetField(expression: IrGetField) {
|
override fun visitGetField(expression: IrGetField) {
|
||||||
logger.log("visitGetField : ${ir2string(expression)}")
|
context.log("visitGetField : ${ir2string(expression)}")
|
||||||
evaluateExpression(expression)
|
evaluateExpression(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
override fun visitField(expression: IrField) {
|
override fun visitField(expression: IrField) {
|
||||||
logger.log("visitField : ${ir2string(expression)}")
|
context.log("visitField : ${ir2string(expression)}")
|
||||||
val descriptor = expression.descriptor
|
val descriptor = expression.descriptor
|
||||||
if (descriptor.containingDeclaration is PackageFragmentDescriptor) {
|
if (descriptor.containingDeclaration is PackageFragmentDescriptor) {
|
||||||
val globalProperty = LLVMAddGlobal(context.llvmModule, codegen.getLLVMType(descriptor.type), descriptor.symbolName)
|
val globalProperty = LLVMAddGlobal(context.llvmModule, codegen.getLLVMType(descriptor.type), descriptor.symbolName)
|
||||||
@@ -1246,7 +1241,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateWhen(expression: IrWhen): LLVMValueRef? {
|
private fun evaluateWhen(expression: IrWhen): LLVMValueRef? {
|
||||||
logger.log("evaluateWhen : ${ir2string(expression)}")
|
context.log("evaluateWhen : ${ir2string(expression)}")
|
||||||
var bbExit: LLVMBasicBlockRef? = null // By default "when" does not have "exit".
|
var bbExit: LLVMBasicBlockRef? = null // By default "when" does not have "exit".
|
||||||
if (!KotlinBuiltIns.isNothing(expression.type)) // If "when" has "exit".
|
if (!KotlinBuiltIns.isNothing(expression.type)) // If "when" has "exit".
|
||||||
bbExit = codegen.basicBlock() // Create basic block to process "exit".
|
bbExit = codegen.basicBlock() // Create basic block to process "exit".
|
||||||
@@ -1314,14 +1309,14 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateGetValue(value: IrGetValue): LLVMValueRef {
|
private fun evaluateGetValue(value: IrGetValue): LLVMValueRef {
|
||||||
logger.log("evaluateGetValue : ${ir2string(value)}")
|
context.log("evaluateGetValue : ${ir2string(value)}")
|
||||||
return currentCodeContext.genGetValue(value.descriptor)
|
return currentCodeContext.genGetValue(value.descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateSetVariable(value: IrSetVariable): LLVMValueRef? {
|
private fun evaluateSetVariable(value: IrSetVariable): LLVMValueRef? {
|
||||||
logger.log("evaluateSetVariable : ${ir2string(value)}")
|
context.log("evaluateSetVariable : ${ir2string(value)}")
|
||||||
val ret = evaluateExpression(value.value)!!
|
val ret = evaluateExpression(value.value)!!
|
||||||
val variable = currentCodeContext.getDeclaredVariable(value.descriptor)!!
|
val variable = currentCodeContext.getDeclaredVariable(value.descriptor)!!
|
||||||
codegen.store(ret, variable)
|
codegen.store(ret, variable)
|
||||||
@@ -1331,7 +1326,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateVariable(value: IrVariable): LLVMValueRef? {
|
private fun evaluateVariable(value: IrVariable): LLVMValueRef? {
|
||||||
logger.log("evaluateVariable : ${ir2string(value)}")
|
context.log("evaluateVariable : ${ir2string(value)}")
|
||||||
val ret = value.initializer?.let { evaluateExpression(it)!! }
|
val ret = value.initializer?.let { evaluateExpression(it)!! }
|
||||||
createVariable(value.descriptor, ret)
|
createVariable(value.descriptor, ret)
|
||||||
return null
|
return null
|
||||||
@@ -1403,7 +1398,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
// double | fptosi fptosi fptosi fptosi fptrunc x
|
// double | fptosi fptosi fptosi fptosi fptrunc x
|
||||||
|
|
||||||
private fun evaluateCast(value: IrTypeOperatorCall): LLVMValueRef {
|
private fun evaluateCast(value: IrTypeOperatorCall): LLVMValueRef {
|
||||||
logger.log("evaluateCast : ${ir2string(value)}")
|
context.log("evaluateCast : ${ir2string(value)}")
|
||||||
val type = value.typeOperand
|
val type = value.typeOperand
|
||||||
assert(!KotlinBuiltIns.isPrimitiveType(type) && !KotlinBuiltIns.isPrimitiveType(value.argument.type))
|
assert(!KotlinBuiltIns.isPrimitiveType(type) && !KotlinBuiltIns.isPrimitiveType(value.argument.type))
|
||||||
|
|
||||||
@@ -1419,7 +1414,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateInstanceOf(value: IrTypeOperatorCall): LLVMValueRef {
|
private fun evaluateInstanceOf(value: IrTypeOperatorCall): LLVMValueRef {
|
||||||
logger.log("evaluateInstanceOf : ${ir2string(value)}")
|
context.log("evaluateInstanceOf : ${ir2string(value)}")
|
||||||
|
|
||||||
val type = value.typeOperand
|
val type = value.typeOperand
|
||||||
val srcArg = evaluateExpression(value.argument)!! // Evaluate src expression.
|
val srcArg = evaluateExpression(value.argument)!! // Evaluate src expression.
|
||||||
@@ -1469,7 +1464,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateGetField(value: IrGetField): LLVMValueRef {
|
private fun evaluateGetField(value: IrGetField): LLVMValueRef {
|
||||||
logger.log("evaluateGetField : ${ir2string(value)}")
|
context.log("evaluateGetField : ${ir2string(value)}")
|
||||||
if (value.descriptor.dispatchReceiverParameter != null) {
|
if (value.descriptor.dispatchReceiverParameter != null) {
|
||||||
val thisPtr = instanceFieldAccessReceiver(value)
|
val thisPtr = instanceFieldAccessReceiver(value)
|
||||||
return codegen.load(fieldPtrOfClass(thisPtr, value.descriptor))
|
return codegen.load(fieldPtrOfClass(thisPtr, value.descriptor))
|
||||||
@@ -1507,7 +1502,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateSetField(value: IrSetField): LLVMValueRef? {
|
private fun evaluateSetField(value: IrSetField): LLVMValueRef? {
|
||||||
logger.log("evaluateSetField : ${ir2string(value)}")
|
context.log("evaluateSetField : ${ir2string(value)}")
|
||||||
val valueToAssign = evaluateExpression(value.value)!!
|
val valueToAssign = evaluateExpression(value.value)!!
|
||||||
if (value.descriptor.dispatchReceiverParameter != null) {
|
if (value.descriptor.dispatchReceiverParameter != null) {
|
||||||
val thisPtr = instanceFieldAccessReceiver(value)
|
val thisPtr = instanceFieldAccessReceiver(value)
|
||||||
@@ -1570,7 +1565,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateConst(value: IrConst<*>): LLVMValueRef? {
|
private fun evaluateConst(value: IrConst<*>): LLVMValueRef? {
|
||||||
logger.log("evaluateConst : ${ir2string(value)}")
|
context.log("evaluateConst : ${ir2string(value)}")
|
||||||
when (value.kind) {
|
when (value.kind) {
|
||||||
IrConstKind.Null -> return codegen.kNullObjHeaderPtr
|
IrConstKind.Null -> return codegen.kNullObjHeaderPtr
|
||||||
IrConstKind.Boolean -> when (value.value) {
|
IrConstKind.Boolean -> when (value.value) {
|
||||||
@@ -1593,7 +1588,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateReturn(expression: IrReturn): LLVMValueRef? {
|
private fun evaluateReturn(expression: IrReturn): LLVMValueRef? {
|
||||||
logger.log("evaluateReturn : ${ir2string(expression)}")
|
context.log("evaluateReturn : ${ir2string(expression)}")
|
||||||
val value = expression.value
|
val value = expression.value
|
||||||
|
|
||||||
val evaluated = if (value is IrGetObjectValue && value.type.isUnit()) {
|
val evaluated = if (value is IrGetObjectValue && value.type.isUnit()) {
|
||||||
@@ -1616,7 +1611,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateBlock(value: IrStatementContainer): LLVMValueRef? {
|
private fun evaluateBlock(value: IrStatementContainer): LLVMValueRef? {
|
||||||
logger.log("evaluateBlock : ${value.statements.forEach { ir2string(it) }}")
|
context.log("evaluateBlock : ${value.statements.forEach { ir2string(it) }}")
|
||||||
|
|
||||||
val scope = if (value is IrContainerExpression && value.isTransparentScope) {
|
val scope = if (value is IrContainerExpression && value.isTransparentScope) {
|
||||||
null
|
null
|
||||||
@@ -1676,7 +1671,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun evaluateCall(value: IrMemberAccessExpression): LLVMValueRef {
|
private fun evaluateCall(value: IrMemberAccessExpression): LLVMValueRef {
|
||||||
logger.log("evaluateCall : ${ir2string(value)}")
|
context.log("evaluateCall : ${ir2string(value)}")
|
||||||
|
|
||||||
val args = evaluateExplicitArgs(value)
|
val args = evaluateExplicitArgs(value)
|
||||||
|
|
||||||
@@ -1772,7 +1767,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateSimpleFunctionCall(descriptor: FunctionDescriptor, args: List<LLVMValueRef>): LLVMValueRef {
|
private fun evaluateSimpleFunctionCall(descriptor: FunctionDescriptor, args: List<LLVMValueRef>): LLVMValueRef {
|
||||||
//logger.log("evaluateSimpleFunctionCall : $tmpVariableName = ${ir2string(value)}")
|
//context.log("evaluateSimpleFunctionCall : $tmpVariableName = ${ir2string(value)}")
|
||||||
if (descriptor.isOverridable)
|
if (descriptor.isOverridable)
|
||||||
return callVirtual(descriptor, args)
|
return callVirtual(descriptor, args)
|
||||||
else
|
else
|
||||||
@@ -1793,7 +1788,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun evaluateConstructorCall(callee: IrCall, args: List<LLVMValueRef>): LLVMValueRef {
|
private fun evaluateConstructorCall(callee: IrCall, args: List<LLVMValueRef>): LLVMValueRef {
|
||||||
logger.log("evaluateConstructorCall : ${ir2string(callee)}")
|
context.log("evaluateConstructorCall : ${ir2string(callee)}")
|
||||||
memScoped {
|
memScoped {
|
||||||
val containingClass = (callee.descriptor as ClassConstructorDescriptor).containingDeclaration
|
val containingClass = (callee.descriptor as ClassConstructorDescriptor).containingDeclaration
|
||||||
val typeInfo = codegen.typeInfoValue(containingClass)
|
val typeInfo = codegen.typeInfoValue(containingClass)
|
||||||
@@ -1828,7 +1823,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
|||||||
|
|
||||||
|
|
||||||
private fun evaluateOperatorCall(callee: IrCall, args: List<LLVMValueRef?>): LLVMValueRef {
|
private fun evaluateOperatorCall(callee: IrCall, args: List<LLVMValueRef?>): LLVMValueRef {
|
||||||
logger.log("evaluateCall : origin:${ir2string(callee)}")
|
context.log("evaluateCall : origin:${ir2string(callee)}")
|
||||||
val descriptor = callee.descriptor
|
val descriptor = callee.descriptor
|
||||||
when (descriptor.name) {
|
when (descriptor.name) {
|
||||||
kEqeq -> return evaluateOperatorEqeq (callee as IrBinaryPrimitiveImpl, args[0]!!, args[1]!!)
|
kEqeq -> return evaluateOperatorEqeq (callee as IrBinaryPrimitiveImpl, args[0]!!, args[1]!!)
|
||||||
|
|||||||
+6
@@ -191,3 +191,9 @@ internal fun functionType(returnType: LLVMTypeRef, isVarArg: Boolean = false, va
|
|||||||
val paramTypesPtr = allocArrayOf(*paramTypes)[0].ptr
|
val paramTypesPtr = allocArrayOf(*paramTypes)[0].ptr
|
||||||
LLVMFunctionType(returnType, paramTypesPtr, paramTypes.size, if (isVarArg) 1 else 0)!!
|
LLVMFunctionType(returnType, paramTypesPtr, paramTypes.size, if (isVarArg) 1 else 0)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun llvm2string(value: LLVMValueRef?): String {
|
||||||
|
if (value == null) return "<null>"
|
||||||
|
return LLVMPrintValueToString(value)!!.asCString().toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
-57
@@ -1,57 +0,0 @@
|
|||||||
package org.jetbrains.kotlin.backend.konan.llvm
|
|
||||||
|
|
||||||
import kotlinx.cinterop.*
|
|
||||||
import llvm.*
|
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
|
||||||
import org.jetbrains.kotlin.ir.util.DumpIrTreeVisitor
|
|
||||||
import java.io.StringWriter
|
|
||||||
|
|
||||||
internal open class Logger(val generator: CodeGenerator, override val context: Context) : ContextUtils {
|
|
||||||
private var logcounter: Int = LLVMPrintModuleToString(context.llvmModule)!!.asCString().toString().lines().size
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
open fun log(msg: String) {
|
|
||||||
println(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
open fun logIr() {
|
|
||||||
val function = generator.currentFunction ?: return
|
|
||||||
|
|
||||||
val irFunctionDeclaration = LLVMPrintValueToString(function.llvmFunction)!!.asCString().toString()
|
|
||||||
irFunctionDeclaration.lines().forEach { println(" $it") }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
fun ir2string(ir: IrElement?): String = ir2stringWhole(ir).takeWhile { it != '\n' }
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
fun ir2stringWhole(ir: IrElement?): String {
|
|
||||||
val strWriter = StringWriter()
|
|
||||||
|
|
||||||
ir?.accept(DumpIrTreeVisitor(strWriter), "")
|
|
||||||
return strWriter.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
fun llvm2string(value: LLVMValueRef?): String {
|
|
||||||
if (value == null) return "<null>"
|
|
||||||
return LLVMPrintValueToString(value)!!.asCString().toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
internal class DummyLogger(generator: CodeGenerator, context: Context) : Logger(generator, context) {
|
|
||||||
override fun log(msg: String) = Unit
|
|
||||||
override fun logIr() = Unit
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user