Simplified file structure

This commit is contained in:
2024-08-07 19:39:10 +02:00
parent 1b13539b22
commit 66569446b1
219 changed files with 453 additions and 457 deletions

View File

@ -0,0 +1,33 @@
package register
import (
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/cpu"
"git.akyoto.dev/cli/q/src/sizeof"
)
func (f *Machine) RegisterNumber(mnemonic asm.Mnemonic, a cpu.Register, b int) {
// The `MOVE` operation is very flexible and works with any type of immediate number.
if mnemonic == asm.MOVE {
f.Assembler.RegisterNumber(mnemonic, a, b)
f.UseRegister(a)
f.postInstruction()
return
}
// If the number only needs 32 bits, we can encode the instruction.
if sizeof.Signed(int64(b)) <= 4 {
f.Assembler.RegisterNumber(mnemonic, a, b)
f.postInstruction()
return
}
// If the number needs 64 bits, we need to use a temporary register.
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)
}