elide double returns and get rid of function end emits

This commit is contained in:
Alex Zenla 2025-07-26 16:24:02 -07:00
parent 1d664e807b
commit b451f74239
No known key found for this signature in database
GPG Key ID: 067B238899B51269
2 changed files with 5 additions and 2 deletions

View File

@ -40,6 +40,8 @@ class CodeBuilder(val symbol: CompilableSymbol) {
ops.add(PatchSymOp(Op(code, arguments), patches))
}
fun lastOp(): StubOp? = ops.lastOrNull()
fun annotate(text: String) {
annotations.add(StubOpAnnotation(symbol, nextOpInst(), text))
}

View File

@ -17,8 +17,9 @@ class IrStubOpEmitter(val irDefinition: IrDefinition, val code: CodeBuilder) : I
}
fun final() {
code.emit(Opcode.Return)
code.emit(Opcode.End)
if (code.lastOp()?.op?.code != Opcode.Return) {
code.emit(Opcode.Return)
}
}
private fun resolve(symbol: IrSymbol): Loadable = code.localState.resolve(symbol)