Improved branch code generation

This commit is contained in:
2024-07-07 14:07:34 +02:00
parent 91e300e49a
commit 403e78f655
3 changed files with 11 additions and 9 deletions

View File

@ -10,13 +10,14 @@ import (
// CompileIf compiles a branch instruction.
func (f *Function) CompileIf(branch *ast.If) error {
condition := branch.Condition
tmpRight := f.cpu.Input[1]
tmpRight := f.cpu.MustFindFree(f.cpu.General)
err := f.ExpressionToRegister(condition.Children[1], tmpRight)
if err != nil {
return err
}
f.cpu.Use(tmpRight)
tmpLeft := f.cpu.Input[0]
err = f.ExpressionToRegister(condition.Children[0], tmpLeft)
@ -25,6 +26,7 @@ func (f *Function) CompileIf(branch *ast.If) error {
}
f.assembler.RegisterRegister(asm.COMPARE, tmpLeft, tmpRight)
f.cpu.Free(tmpRight)
elseLabel := fmt.Sprintf("%s_if_%d_else", f.Name, f.count.branch)
switch condition.Token.Text() {