mirror of
https://github.com/irmen/prog8.git
synced 2024-12-01 15:52:54 +00:00
remove empty when choices, fixes ir compilation error on those
This commit is contained in:
parent
334d382bfa
commit
d2154f5f2e
@ -99,16 +99,18 @@ class IRCodeGen(
|
|||||||
// make sure that first chunks in Blocks and Subroutines share the name of the block/sub as label.
|
// make sure that first chunks in Blocks and Subroutines share the name of the block/sub as label.
|
||||||
|
|
||||||
irProg.blocks.forEach { block ->
|
irProg.blocks.forEach { block ->
|
||||||
block.children.firstOrNull { it is IRInlineAsmChunk }?.let { first->
|
if(block.isNotEmpty()) {
|
||||||
first as IRInlineAsmChunk
|
val firstAsm = block.children[0] as? IRInlineAsmChunk
|
||||||
if(first.label==null) {
|
if(firstAsm!=null) {
|
||||||
val replacement = IRInlineAsmChunk(block.label, first.assembly, first.isIR, first.next)
|
if(firstAsm.label==null) {
|
||||||
|
val replacement = IRInlineAsmChunk(block.label, firstAsm.assembly, firstAsm.isIR, firstAsm.next)
|
||||||
block.children.removeAt(0)
|
block.children.removeAt(0)
|
||||||
block.children.add(0, replacement)
|
block.children.add(0, replacement)
|
||||||
} else if(first.label != block.label) {
|
} else if(firstAsm.label != block.label) {
|
||||||
throw AssemblyError("first chunk in block has label that differs from block name")
|
throw AssemblyError("first chunk in block has label that differs from block name")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
block.children.filterIsInstance<IRSubroutine>().forEach { sub ->
|
block.children.filterIsInstance<IRSubroutine>().forEach { sub ->
|
||||||
if(sub.chunks.isNotEmpty()) {
|
if(sub.chunks.isNotEmpty()) {
|
||||||
|
@ -262,5 +262,15 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
|
|||||||
}
|
}
|
||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun after(whenStmt: When, parent: Node): Iterable<IAstModification> {
|
||||||
|
val removals = mutableListOf<Int>()
|
||||||
|
whenStmt.choices.withIndex().forEach { (index, choice) ->
|
||||||
|
if(choice.statements.isEmpty())
|
||||||
|
removals.add(index)
|
||||||
|
}
|
||||||
|
removals.reversed().forEach { whenStmt.choices.removeAt(it) }
|
||||||
|
return noModifications
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,4 +451,26 @@ main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("asm chunk labels in IR code") {
|
||||||
|
val src="""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
instructions.match()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
instructions {
|
||||||
|
asmsub match() {
|
||||||
|
%asm {{
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
%asm {{
|
||||||
|
nop
|
||||||
|
}}
|
||||||
|
}"""
|
||||||
|
compileText(VMTarget(), false, src, writeAssembly = true) shouldNotBe null
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
@ -1,8 +1,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- Fix expericodegen errors (assem, rockrunners)
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,41 +1,18 @@
|
|||||||
%import textio
|
%import textio
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
; uword[] routines = [ 0, &command, $4444 ]
|
cx16.r0 = 2
|
||||||
; cx16.r0 = routines[1]
|
when cx16.r0 {
|
||||||
|
1-> {
|
||||||
&ubyte[5] cells = $4000
|
;nothing
|
||||||
cells = [1,2,3,4,5]
|
}
|
||||||
str name = "irmen"
|
2 -> {
|
||||||
|
txt.print("two")
|
||||||
ubyte[5] othercells = [11,22,33,44,55]
|
}
|
||||||
|
0-> {
|
||||||
txt.print_ub(1 in cells)
|
;nothing
|
||||||
txt.print_ub(44 in othercells)
|
}
|
||||||
txt.print_ub('a' in name)
|
|
||||||
txt.print_ub('e' in name)
|
|
||||||
txt.nl()
|
|
||||||
txt.print_ub(all(othercells))
|
|
||||||
txt.print_ub(any(othercells))
|
|
||||||
othercells[3] = 0
|
|
||||||
txt.print_ub(all(othercells))
|
|
||||||
txt.print_ub(any(othercells))
|
|
||||||
reverse(othercells)
|
|
||||||
sort(othercells)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
txt.print_ub(all(cells))
|
|
||||||
txt.print_ub(any(cells))
|
|
||||||
cells[3] = 0
|
|
||||||
txt.print_ub(all(cells))
|
|
||||||
txt.print_ub(any(cells))
|
|
||||||
reverse(cells)
|
|
||||||
sort(cells)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub command() {
|
|
||||||
cx16.r0++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user