fix parse cpureg in IR regspec

This commit is contained in:
Irmen de Jong 2023-05-14 21:02:40 +02:00
parent 0e3d75cfeb
commit 88ce9300bc
2 changed files with 20 additions and 17 deletions

View File

@ -504,17 +504,6 @@ class IRFileReader {
}
}
private fun parseRegisterOrStatusflag(regs: String): RegisterOrStatusflag {
var reg: RegisterOrPair? = null
var sf: Statusflag? = null
try {
reg = RegisterOrPair.valueOf(regs)
} catch (x: IllegalArgumentException) {
sf = Statusflag.valueOf(regs)
}
return RegisterOrStatusflag(reg, sf)
}
private val posPattern = Regex("\\[(.+): line (.+) col (.+)-(.+)\\]")
private fun parsePosition(strpos: String): Position {

View File

@ -1,10 +1,7 @@
package prog8.intermediate
import prog8.code.*
import prog8.code.core.AssemblyError
import prog8.code.core.DataType
import prog8.code.core.InternalCompilerException
import prog8.code.core.PassByReferenceDatatypes
import prog8.code.core.*
fun getTypeString(dt : DataType): String = when(dt) {
@ -225,7 +222,7 @@ private class ParsedCall(
private fun parseCall(rest: String): ParsedCall {
fun parseRegspec(reg: String): FunctionCallArgs.RegSpec {
val pattern = Regex("f?r([0-9]+)\\.(.)")
val pattern = Regex("f?r([0-9]+)\\.(.)(@.{1,2})?$")
val match = pattern.matchEntire(reg) ?: throw IRParseException("invalid regspec $reg")
val num = match.groups[1]!!.value.toInt()
val type = when(match.groups[2]!!.value) {
@ -234,7 +231,12 @@ private fun parseCall(rest: String): ParsedCall {
"f" -> IRDataType.FLOAT
else -> throw IRParseException("invalid type spec in $reg")
}
return FunctionCallArgs.RegSpec(type, num, null) // TODO parse cpu register
val cpuRegister: RegisterOrStatusflag? =
if(match.groups[3]!=null) {
val cpuRegStr = match.groups[3]!!.value.drop(1)
parseRegisterOrStatusflag(cpuRegStr)
} else null
return FunctionCallArgs.RegSpec(type, num, cpuRegister)
}
fun parseArgs(args: String): List<FunctionCallArgs.ArgumentSpec> {
@ -264,6 +266,18 @@ private fun parseCall(rest: String): ParsedCall {
}
internal fun parseRegisterOrStatusflag(regs: String): RegisterOrStatusflag {
var reg: RegisterOrPair? = null
var sf: Statusflag? = null
try {
reg = RegisterOrPair.valueOf(regs)
} catch (x: IllegalArgumentException) {
sf = Statusflag.valueOf(regs)
}
return RegisterOrStatusflag(reg, sf)
}
fun irType(type: DataType): IRDataType {
return when(type) {
DataType.BOOL,