Added more tests

This commit is contained in:
2024-07-31 15:24:21 +02:00
parent 76c916018a
commit 3d245a15f9
6 changed files with 52 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package register
import (
"git.akyoto.dev/cli/q/src/build/asm"
"git.akyoto.dev/cli/q/src/build/cpu"
"git.akyoto.dev/cli/q/src/build/sizeof"
)
func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
@ -10,11 +11,20 @@ func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
f.SaveRegister(a)
}
f.Assembler.RegisterNumber(mnemonic, a, b)
if sizeof.Signed(int64(b)) == 8 {
tmp := f.NewRegister()
f.Assembler.RegisterNumber(asm.MOVE, tmp, b)
f.UseRegister(tmp)
f.postInstruction()
f.Assembler.RegisterRegister(mnemonic, a, tmp)
f.postInstruction()
f.FreeRegister(tmp)
} else {
f.Assembler.RegisterNumber(mnemonic, a, b)
f.postInstruction()
}
if mnemonic == asm.MOVE {
f.UseRegister(a)
}
f.postInstruction()
}