translator: fix for return class and strings
This commit is contained in:
@@ -493,7 +493,11 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
args.addAll(names)
|
args.addAll(names)
|
||||||
|
|
||||||
codeBuilder.addLLVMCode(LLVMCall(LLVMVoidType(), function.toString(), args).toString())
|
codeBuilder.addLLVMCode(LLVMCall(LLVMVoidType(), function.toString(), args).toString())
|
||||||
return codeBuilder.loadAndGetVariable(returnVar)
|
if (returnVar.pointer == 2) {
|
||||||
|
return returnVar
|
||||||
|
} else {
|
||||||
|
return codeBuilder.loadAndGetVariable(returnVar)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val result = codeBuilder.getNewVariable(returnType)
|
val result = codeBuilder.getNewVariable(returnType)
|
||||||
@@ -1027,7 +1031,8 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
allocVar.kotlinName = identifier
|
allocVar.kotlinName = identifier
|
||||||
|
|
||||||
variableManager.addVariable(identifier, allocVar, scopeDepth)
|
variableManager.addVariable(identifier, allocVar, scopeDepth)
|
||||||
codeBuilder.copyVariable(assignExpression, allocVar)
|
|
||||||
|
addPrimitiveBinaryOperation(KtTokens.EQ, null, allocVar, assignExpression)
|
||||||
} else {
|
} else {
|
||||||
assignExpression.kotlinName = identifier
|
assignExpression.kotlinName = identifier
|
||||||
variableManager.addVariable(identifier, assignExpression, scopeDepth)
|
variableManager.addVariable(identifier, assignExpression, scopeDepth)
|
||||||
|
|||||||
@@ -123,8 +123,12 @@ class LLVMBuilder(val arm: Boolean = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun storeVariable(target: LLVMSingleValue, source: LLVMSingleValue) {
|
fun storeVariable(target: LLVMSingleValue, source: LLVMSingleValue) {
|
||||||
val code = "store ${source.getType()} $source, ${target.getType()} $target, align ${source.type?.align!!}"
|
if ((source.type is LLVMStringType) && (!(source.type as LLVMStringType).isLoaded)) {
|
||||||
localCode.appendln(code)
|
storeString(target as LLVMVariable, source as LLVMVariable, 0)
|
||||||
|
} else {
|
||||||
|
val code = "store ${source.getType()} $source, ${target.getType()} $target, align ${source.type?.align!!}"
|
||||||
|
localCode.appendln(code)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun storeNull(result: LLVMVariable) {
|
fun storeNull(result: LLVMVariable) {
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ class LLVMFloatType() : LLVMType() {
|
|||||||
|
|
||||||
//TODO switch by types: int + double = int
|
//TODO switch by types: int + double = int
|
||||||
override fun operatorMinus(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorMinus(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMFloatType(), "fsub float i32 $firstOp, $secondOp")
|
LLVMExpression(LLVMFloatType(), "fsub float $firstOp, $secondOp")
|
||||||
|
|
||||||
//TODO switch by types: int + double = int
|
//TODO switch by types: int + double = int
|
||||||
override fun operatorTimes(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorTimes(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMFloatType(), "fmul float i32 $firstOp, $secondOp")
|
LLVMExpression(LLVMFloatType(), "fmul float $firstOp, $secondOp")
|
||||||
|
|
||||||
//TODO switch by types: int + double = int
|
//TODO switch by types: int + double = int
|
||||||
override fun operatorPlus(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorPlus(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
|||||||
Reference in New Issue
Block a user