ir: fix overwriting chunk label

This commit is contained in:
Irmen de Jong 2022-10-30 19:03:02 +01:00
parent 0eda7ac498
commit 5b6569d0f9
3 changed files with 9 additions and 8 deletions

View File

@ -346,8 +346,14 @@ class IRCodeGen(
private fun labelFirstChunk(chunks: IRCodeChunks, label: String): IRCodeChunks {
require(chunks.isNotEmpty() && label.isNotBlank())
val newChunks = chunks.drop(1).toMutableList()
val labeledFirstChunk = when(val first=chunks[0]) {
val first = chunks[0]
if(first.label!=null) {
if(first.label==label)
return chunks
val newFirst = IRCodeChunk(label, first.position, first)
return listOf(newFirst) + chunks
}
val labeledFirstChunk = when(first) {
is IRCodeChunk -> {
val newChunk = IRCodeChunk(label, first.position, first.next)
newChunk.instructions += first.instructions
@ -363,8 +369,7 @@ class IRCodeGen(
throw AssemblyError("invalid chunk")
}
}
newChunks.add(0, labeledFirstChunk)
return newChunks
return listOf(labeledFirstChunk) + chunks.drop(1)
}
private fun translate(whenStmt: PtWhen): IRCodeChunks {

View File

@ -99,19 +99,16 @@ mylabel2:
goto mylabel2
} until cx16.r0
; TODO fix this for vm codegen:
repeat cx16.r0 {
mylabel3:
goto mylabel3
}
; TODO fix this for vm codegen:
for cx16.r0L in 0 to 2 {
mylabel4:
goto mylabel4
}
; TODO fix this for vm codegen:
for cx16.r0L in cx16.r1L to cx16.r2L {
mylabel5:
goto mylabel5

View File

@ -3,7 +3,6 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- ir: fix unit tests
- ir: join more codechunks, before ir is written to file
- ir: fix removeWeirdBranches in IR optimizer
- update diagram in technical.rst?