pointer types should just be uwords in IR

This commit is contained in:
Irmen de Jong
2025-07-30 00:59:05 +02:00
parent c4c5636a81
commit 88b074c208
3 changed files with 6 additions and 15 deletions

View File

@@ -1,7 +1,6 @@
TODO
====
don't write pointer types into P8IR files, just write uword as the type? (actually breaks the VARIABLESWITHINIT now that zp vars get initialized to 0 again; all the pointer examples won't compile anymore)
fix ^^Node nodes / cx16.r0L = nodes[2].weight (TODO("IR datatype for struct instances")
fix bool bb2 = bptr[2]^^ ... peekbool(bptr[2]) gives a arg 1 type error... just omit peekbool() here?
fix countries[2]^^ = 0 compiler crash
@@ -122,6 +121,7 @@ Future Things and Ideas
IR/VM
-----
- possible to use LOADFIELD/STOREFIELD instructions more?
- pointer dt's are all reduced to just an uword (in the irTypeString method) - is this okay or could it be beneficial to reintroduce the actual pointer type information? See commit fcda2dd92d0ec64d24dad05018a3cd6aef2fed84
- change the instruction format so an indirect register (a pointer) can be used more often, at least for the inplace assignment operators that operate on pointer
- getting it in shape for code generation...: the IR file should be able to encode every detail about a prog8 program (the VM doesn't have to actually be able to run all of it though!)
- fix call() return value handling (... what's wrong with it again?)

View File

@@ -73,8 +73,8 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
is IRAsmSubroutine -> {
val clobbers = child.clobbers.joinToString(",")
val returns = child.returns.joinToString(",") { ret ->
if (ret.reg.registerOrPair != null) "${ret.reg.registerOrPair}:${ret.dt.toString().lowercase()}"
else "${ret.reg.statusflag}:${ret.dt.toString().lowercase()}"
if (ret.reg.registerOrPair != null) "${ret.reg.registerOrPair}:${ret.dt.irTypeString(null)}"
else "${ret.reg.statusflag}:${ret.dt.irTypeString(null)}"
}
xml.writeStartElement("ASMSUB")
xml.writeAttribute("NAME", child.label)

View File

@@ -8,6 +8,7 @@ import prog8.right
fun DataType.irTypeString(length: UInt?): String {
val lengthStr = if(length==0u) "" else length.toString()
// note: pointer types are all reduced to just an uword (untyped pointer / address)
return when (this.base) {
BaseDataType.BOOL -> "bool"
BaseDataType.UBYTE -> "ubyte"
@@ -17,24 +18,14 @@ fun DataType.irTypeString(length: UInt?): String {
BaseDataType.LONG -> "long"
BaseDataType.FLOAT -> "float"
BaseDataType.STR -> "ubyte[$lengthStr]" // here string doesn't exist as a seperate datatype anymore
BaseDataType.POINTER -> {
if(sub!=null)
"^${sub!!.name.lowercase()}"
else
"^${subType!!.scopedNameString}"
}
BaseDataType.POINTER -> "uword"
BaseDataType.ARRAY_POINTER -> "uword"
BaseDataType.STRUCT_INSTANCE -> {
if(sub!=null)
sub!!.name.lowercase()
else
subType!!.scopedNameString
}
BaseDataType.ARRAY_POINTER -> {
if(sub!=null)
"^${sub!!.name.lowercase()}[$lengthStr]"
else
"^${subType!!.scopedNameString}[$lengthStr]"
}
BaseDataType.ARRAY -> {
when(this.sub) {
BaseDataType.UBYTE -> "ubyte[$lengthStr]"