CODEGEN: emprovements:
- fixed stop on non body functions - IMPLICIT_CAST implemented - naive extension function implementation (cherry picked from commit 3d3b51b0fca3980012e77f47feded5030f0d7901)
This commit is contained in:
committed by
vvlevchenko
parent
1b1360c77e
commit
7a0d0ec5a7
+7
-7
@@ -15,16 +15,16 @@ internal class CodeGenerator(override val context:Context) : ContextUtils {
|
||||
var currentFunction:FunctionDescriptor? = null
|
||||
|
||||
fun function(declaration: IrFunction) {
|
||||
if (declaration.body == null) {
|
||||
// Abstract and external methods.
|
||||
return
|
||||
}
|
||||
assert(declaration.body != null)
|
||||
|
||||
if (currentFunction == declaration.descriptor) return
|
||||
val descriptor = declaration.descriptor
|
||||
if (currentFunction == descriptor) return
|
||||
val fn = prolog(declaration)
|
||||
|
||||
var indexOffset = 0
|
||||
if (declaration.descriptor is ClassConstructorDescriptor || declaration.descriptor.dispatchReceiverParameter != null) {
|
||||
if (descriptor is ClassConstructorDescriptor
|
||||
|| descriptor.dispatchReceiverParameter != null
|
||||
|| descriptor.extensionReceiverParameter != null) {
|
||||
val name = "this"
|
||||
val type = pointerType(LLVMInt8Type());
|
||||
val v = alloca(type, name)
|
||||
@@ -33,7 +33,7 @@ internal class CodeGenerator(override val context:Context) : ContextUtils {
|
||||
indexOffset = 1;
|
||||
}
|
||||
|
||||
declaration.descriptor.valueParameters.forEachIndexed { i, descriptor ->
|
||||
descriptor.valueParameters.forEachIndexed { i, descriptor ->
|
||||
val name = descriptor.name.asString()
|
||||
val type = descriptor.type
|
||||
val v = alloca(type, name)
|
||||
|
||||
+4
-3
@@ -233,7 +233,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
logger.log("visitFunction : ${ir2string(declaration)}")
|
||||
if (declaration.descriptor.modality == Modality.ABSTRACT)
|
||||
if (declaration.descriptor.modality == Modality.ABSTRACT || declaration.body == null)
|
||||
return
|
||||
codegen.function(declaration)
|
||||
metadator.function(declaration)
|
||||
@@ -414,7 +414,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
val variable = codegen.variable(value.descriptor.name.asString())
|
||||
return codegen.load(variable!!, tmpVariableName)
|
||||
}
|
||||
is LazyClassReceiverParameterDescriptor -> {
|
||||
is LazyClassReceiverParameterDescriptor,
|
||||
is ReceiverParameterDescriptor -> {
|
||||
if (value.descriptor.name.asString() == "<this>") {
|
||||
return codegen.load(codegen.thisVariable(), tmpVariableName)
|
||||
}
|
||||
@@ -450,7 +451,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
private fun evaluateTypeOperator(tmpVariableName: String, value: IrTypeOperatorCall): LLVMValueRef? {
|
||||
when (value.operator) {
|
||||
IrTypeOperator.CAST -> return evaluateCast(tmpVariableName, value)
|
||||
IrTypeOperator.IMPLICIT_CAST -> TODO("${ir2string(value)}")
|
||||
IrTypeOperator.IMPLICIT_CAST -> return evaluateExpression(tmpVariableName, value.argument)
|
||||
IrTypeOperator.IMPLICIT_NOTNULL -> TODO("${ir2string(value)}")
|
||||
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> return evaluateExpression(tmpVariableName, value.argument)
|
||||
IrTypeOperator.SAFE_CAST -> TODO("${ir2string(value)}")
|
||||
|
||||
Reference in New Issue
Block a user