translator: fix function result store
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
|
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)
|
||||||
declare i8* @malloc(i32)
|
declare i8* @malloc_static(i32)
|
||||||
|
attributes #0 = { nounwind "stack-protector-buffer-size"="8" "target-cpu"="cortex-m3" "target-features"="+hwdiv,+strict-align" }
|
||||||
%class.ComplexRef = type { i32, %class.Simple* }
|
%class.ComplexRef = type { i32, %class.Simple* }
|
||||||
define void @ComplexRef(%class.ComplexRef* %classvariable.this, i32 %i, %class.Simple* %s)
|
define void @ComplexRef(%class.ComplexRef* %classvariable.this, i32 %i, %class.Simple* %s) #0
|
||||||
{
|
{
|
||||||
%classvariable.this.addr = alloca %class.ComplexRef, align 4
|
%classvariable.this.addr = alloca %class.ComplexRef, align 4
|
||||||
%i.addr = alloca i32, align 4
|
%i.addr = alloca i32, align 4
|
||||||
@@ -17,7 +18,7 @@ call void @llvm.memcpy.p0i8.p0i8.i64(i8* %var4, i8* %var5, i64 8, i32 4, i1 fals
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
%class.Simple = type { i32 }
|
%class.Simple = type { i32 }
|
||||||
define void @Simple(%class.Simple* %classvariable.this, i32 %i)
|
define void @Simple(%class.Simple* %classvariable.this, i32 %i) #0
|
||||||
{
|
{
|
||||||
%classvariable.this.addr = alloca %class.Simple, align 4
|
%classvariable.this.addr = alloca %class.Simple, align 4
|
||||||
%i.addr = alloca i32, align 4
|
%i.addr = alloca i32, align 4
|
||||||
@@ -30,20 +31,30 @@ store i32 %var6, i32* %var7, align 4
|
|||||||
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %var8, i8* %var9, i64 4, i32 4, i1 false)
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %var8, i8* %var9, i64 4, i32 4, i1 false)
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
define void @main()
|
define void @myFunction(%class.ComplexRef* %ref) #0
|
||||||
{
|
{
|
||||||
%var11 = call i8* @malloc(i32 4)
|
%var10 = getelementptr inbounds %class.ComplexRef* %ref, i32 0, i32 0
|
||||||
%var10 = bitcast i8* %var11 to %class.Simple*
|
%var11 = load i32* %var10, align 4
|
||||||
call void @Simple(%class.Simple* %var10, i32 5)
|
store i32 1, i32* %var10, align 4
|
||||||
%managed.s.1 = alloca %class.Simple, align 4
|
ret void
|
||||||
%var12 = load %class.Simple* %var10, align 4
|
}
|
||||||
store %class.Simple %var12, %class.Simple* %managed.s.1, align 4
|
define i32 @const(i32 %i) #0
|
||||||
%var14 = call i8* @malloc(i32 4)
|
{
|
||||||
%var13 = bitcast i8* %var14 to %class.ComplexRef*
|
%i.addr = alloca i32, align 4
|
||||||
call void @ComplexRef(%class.ComplexRef* %var13, i32 1, %class.Simple* %managed.s.1)
|
store i32 %i, i32* %i.addr, align 4
|
||||||
%managed.i.1 = alloca %class.ComplexRef, align 4
|
%var12 = load i32* %i.addr, align 4
|
||||||
%var15 = load %class.ComplexRef* %var13, align 4
|
ret i32 %var12
|
||||||
store %class.ComplexRef %var15, %class.ComplexRef* %managed.i.1, align 4
|
}
|
||||||
|
define void @kotlin_main() #0
|
||||||
|
{
|
||||||
|
%var13 = add nsw i32 3, 4
|
||||||
|
%var14 = call i32 @const(i32 %var13)
|
||||||
|
%var15 = alloca i32, align 4
|
||||||
|
store i32 %var14, i32* %var15, align 4
|
||||||
|
%var16 = load i32* %var15, align 4
|
||||||
|
%var17 = call i32 @const(i32 %var16)
|
||||||
|
%var18 = alloca i32, align 4
|
||||||
|
store i32 %var17, i32* %var18, align 4
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,9 +85,3 @@ define i8* @malloc_dynamic(i32 %size) #0 {
|
|||||||
|
|
||||||
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||||
|
|
||||||
!llvm.module.flags = !{!0, !1}
|
|
||||||
!llvm.ident = !{!2}
|
|
||||||
|
|
||||||
!0 = !{i32 1, !"wchar_size", i32 4}
|
|
||||||
!1 = !{i32 1, !"min_enum_size", i32 4}
|
|
||||||
!2 = !{!"Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)"}
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val disposer = Disposer.newDisposable()
|
val disposer = Disposer.newDisposable()
|
||||||
val state = parseAndAnalyze(args.asList(), disposer, arm = false)
|
val state = parseAndAnalyze(args.asList(), disposer, arm = true)
|
||||||
|
|
||||||
val files = state.environment.getSourceFiles()
|
val files = state.environment.getSourceFiles()
|
||||||
if (files.isEmpty()) {
|
if (files.isEmpty()) {
|
||||||
|
|||||||
@@ -311,8 +311,7 @@ class FunctionCodegen(val state: TranslationState, val variableManager: Variable
|
|||||||
|
|
||||||
for (arg in args) {
|
for (arg in args) {
|
||||||
val currentExpression = evaluateExpression(arg.getArgumentExpression(), scopeDepth) as LLVMSingleValue
|
val currentExpression = evaluateExpression(arg.getArgumentExpression(), scopeDepth) as LLVMSingleValue
|
||||||
val nativeExpression = codeBuilder.receiveNativeValue(currentExpression)
|
result.add(currentExpression)
|
||||||
result.add(nativeExpression)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -448,6 +447,7 @@ class FunctionCodegen(val state: TranslationState, val variableManager: Variable
|
|||||||
|
|
||||||
private fun copyVariable(from: LLVMVariable, to: LLVMVariable) = when (from.type) {
|
private fun copyVariable(from: LLVMVariable, to: LLVMVariable) = when (from.type) {
|
||||||
is LLVMStringType -> codeBuilder.storeString(to, from, 0)
|
is LLVMStringType -> codeBuilder.storeString(to, from, 0)
|
||||||
|
is LLVMReferenceType -> codeBuilder.copyVariableRef(to, from)
|
||||||
else -> codeBuilder.copyVariableValue(to, from)
|
else -> codeBuilder.copyVariableValue(to, from)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,10 +459,7 @@ class FunctionCodegen(val state: TranslationState, val variableManager: Variable
|
|||||||
|
|
||||||
when (assignExpression) {
|
when (assignExpression) {
|
||||||
is LLVMVariable -> {
|
is LLVMVariable -> {
|
||||||
val allocVar = variableManager.receiveVariable(identifier!!.text, assignExpression.type, LLVMRegisterScope(), pointer = 1)
|
variableManager.addVariable(identifier!!.text, assignExpression, scopeDepth)
|
||||||
codeBuilder.allocStackVar(allocVar)
|
|
||||||
variableManager.addVariable(identifier.text, allocVar, scopeDepth)
|
|
||||||
copyVariable(assignExpression, allocVar)
|
|
||||||
}
|
}
|
||||||
is LLVMConstant -> {
|
is LLVMConstant -> {
|
||||||
val newVar = variableManager.receiveVariable(identifier!!.text, assignExpression.type!!, LLVMRegisterScope(), pointer = 1)
|
val newVar = variableManager.receiveVariable(identifier!!.text, assignExpression.type!!, LLVMRegisterScope(), pointer = 1)
|
||||||
|
|||||||
@@ -162,6 +162,10 @@ class LLVMBuilder(val arm: Boolean) {
|
|||||||
localCode.appendln("store ${target.type} $from, ${target.getType()} $target, align ${from.type.align}")
|
localCode.appendln("store ${target.type} $from, ${target.getType()} $target, align ${from.type.align}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun copyVariableRef(to: LLVMVariable, from: LLVMVariable) {
|
||||||
|
var i = 1
|
||||||
|
}
|
||||||
|
|
||||||
fun loadArgument(llvmVariable: LLVMVariable, store: Boolean = true): LLVMVariable {
|
fun loadArgument(llvmVariable: LLVMVariable, store: Boolean = true): LLVMVariable {
|
||||||
val allocVar = LLVMVariable("${llvmVariable.label}.addr", llvmVariable.type, llvmVariable.kotlinName, LLVMRegisterScope(), pointer = llvmVariable.pointer + 1)
|
val allocVar = LLVMVariable("${llvmVariable.label}.addr", llvmVariable.type, llvmVariable.kotlinName, LLVMRegisterScope(), pointer = llvmVariable.pointer + 1)
|
||||||
addVariableByRef(allocVar, llvmVariable, store)
|
addVariableByRef(allocVar, llvmVariable, store)
|
||||||
@@ -174,7 +178,7 @@ class LLVMBuilder(val arm: Boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun allocStackVar(target: LLVMVariable) {
|
fun allocStackVar(target: LLVMVariable) {
|
||||||
localCode.appendln("$target = alloca ${target.type}, align ${target.type.align}")
|
localCode.appendln("$target = alloca ${target.getType()}, align ${target.type.align}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allocStaticVar(target: LLVMVariable) {
|
fun allocStaticVar(target: LLVMVariable) {
|
||||||
@@ -239,4 +243,5 @@ class LLVMBuilder(val arm: Boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString() = globalCode.toString() + localCode.toString()
|
override fun toString() = globalCode.toString() + localCode.toString()
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,7 +2,7 @@ package org.kotlinnative.translator.llvm.types
|
|||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class LLVMReferenceType(val type: String, var prefix: String = "", override val align: Int = 4, var byRef: Boolean = false) : LLVMType() {
|
class LLVMReferenceType(val type: String, var prefix: String = "", override val align: Int = 4, var byRef: Boolean = true) : LLVMType() {
|
||||||
|
|
||||||
override val defaultValue: String = ""
|
override val defaultValue: String = ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user