translator: fix assignment argument variables
This commit is contained in:
@@ -297,11 +297,11 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
|
||||
val assignExpression = evaluateExpression(eq.getNextSiblingIgnoringWhitespaceAndComments(), scopeDepth) ?: return null
|
||||
|
||||
when (assignExpression) {
|
||||
//TODO resolving
|
||||
is LLVMVariable -> {
|
||||
assignExpression.kotlinName = identifier!!.text
|
||||
assignExpression.pointer = false
|
||||
variableManager.addVariable(identifier.text, assignExpression, scopeDepth)
|
||||
val allocVar = variableManager.getVariable(identifier!!.text, LLVMIntType(), pointer = true)
|
||||
codeBuilder.allocVar(allocVar)
|
||||
variableManager.addVariable(identifier.text, allocVar, scopeDepth)
|
||||
codeBuilder.copyVariableValue(assignExpression, allocVar)
|
||||
}
|
||||
is LLVMConstant -> {
|
||||
val newVar = variableManager.getVariable(identifier!!.text, LLVMIntType(), pointer = true)
|
||||
|
||||
@@ -117,6 +117,13 @@ class LLVMBuilder(val arm: Boolean) {
|
||||
llvmCode.appendln(code)
|
||||
}
|
||||
|
||||
fun copyVariableValue(from: LLVMVariable, to: LLVMVariable) {
|
||||
val tmp = getNewVariable(from.type, from.pointer)
|
||||
llvmCode.appendln("$tmp = load ${tmp.type}, ${from.getType()} $from, align ${tmp.type.align}")
|
||||
llvmCode.appendln("store ${to.type} $tmp, ${to.getType()} $to, align ${tmp.type.align}")
|
||||
|
||||
}
|
||||
|
||||
fun loadArgument(llvmVariable: LLVMVariable, store: Boolean = true): LLVMVariable {
|
||||
val allocVar = LLVMVariable("${llvmVariable.label}.addr", llvmVariable.type, llvmVariable.kotlinName, true)
|
||||
addVariableByRef(allocVar, llvmVariable, store)
|
||||
|
||||
Reference in New Issue
Block a user