translator: code fix, add double type and llvm return operator
This commit is contained in:
@@ -49,7 +49,7 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
|
|||||||
else -> UnsupportedOperationException()
|
else -> UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
|
||||||
expressionWalker(expr?.getNextSiblingIgnoringWhitespaceAndComments())
|
expressionWalker(expr.getNextSiblingIgnoringWhitespaceAndComments())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun evaluateExpression(expr: PsiElement?): LLVMNode? {
|
private fun evaluateExpression(expr: PsiElement?): LLVMNode? {
|
||||||
@@ -81,10 +81,10 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
|
|||||||
var currentArg = argumentList?.getNextSiblingIgnoringWhitespaceAndComments()
|
var currentArg = argumentList?.getNextSiblingIgnoringWhitespaceAndComments()
|
||||||
|
|
||||||
while (currentArg?.text != ")" && currentArg != null) {
|
while (currentArg?.text != ")" && currentArg != null) {
|
||||||
args.add(currentArg?.text)
|
args.add(currentArg.text)
|
||||||
|
|
||||||
currentArg = currentArg
|
currentArg = currentArg
|
||||||
?.getNextSiblingIgnoringWhitespaceAndComments()
|
.getNextSiblingIgnoringWhitespaceAndComments()
|
||||||
?.getNextSiblingIgnoringWhitespaceAndComments()
|
?.getNextSiblingIgnoringWhitespaceAndComments()
|
||||||
}
|
}
|
||||||
return args
|
return args
|
||||||
@@ -125,7 +125,7 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
|
|||||||
val identifier = element.getNextSiblingIgnoringWhitespaceAndComments()
|
val identifier = element.getNextSiblingIgnoringWhitespaceAndComments()
|
||||||
val eq = identifier?.getNextSiblingIgnoringWhitespaceAndComments() ?: return null
|
val eq = identifier?.getNextSiblingIgnoringWhitespaceAndComments() ?: return null
|
||||||
|
|
||||||
val assignExpression = evaluateExpression(eq?.getNextSiblingIgnoringWhitespaceAndComments()) ?: return null
|
val assignExpression = evaluateExpression(eq.getNextSiblingIgnoringWhitespaceAndComments()) ?: return null
|
||||||
codeBuilder.addAssignment(LLVMVariable("%${identifier!!.text}"), assignExpression)
|
codeBuilder.addAssignment(LLVMVariable("%${identifier!!.text}"), assignExpression)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ class FunctionCodegen(val state: TranslationState, val function: KtNamedFunction
|
|||||||
var next = element.getNextSiblingIgnoringWhitespaceAndComments()
|
var next = element.getNextSiblingIgnoringWhitespaceAndComments()
|
||||||
val retVar = evaluateExpression(next) as LLVMVariable
|
val retVar = evaluateExpression(next) as LLVMVariable
|
||||||
|
|
||||||
codeBuilder.addLLVMCode("ret i32 ${retVar?.label}")
|
codeBuilder.addReturnOperator(retVar)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,10 @@ class LLVMBuilder {
|
|||||||
llvmCode.appendln("$llvmVariable = $rhs")
|
llvmCode.appendln("$llvmVariable = $rhs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addReturnOperator(llvmVariable: LLVMVariable) {
|
||||||
|
llvmCode.appendln("ret i32 $llvmVariable")
|
||||||
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return llvmCode.toString()
|
return llvmCode.toString()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,8 @@ class LLVMDoubleType() : LLVMType() {
|
|||||||
return LLVMExpression(LLVMDoubleType(), "fadd double $firstOp, $secondOp")
|
return LLVMExpression(LLVMDoubleType(), "fadd double $firstOp, $secondOp")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return "double"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user