Improved code generation

This commit is contained in:
2024-07-09 17:00:04 +02:00
parent 1204591cdc
commit 4386392844
23 changed files with 201 additions and 95 deletions

View File

@ -7,34 +7,34 @@ type CPU struct {
Syscall []Register
Input []Register
Output []Register
reserved uint64
used uint64
Reserved uint64
Used uint64
}
// Free will reset the reserved and used status which means the register can be allocated again.
func (c *CPU) Free(reg Register) {
c.used &= ^(1 << reg)
c.reserved &= ^(1 << reg)
c.Used &= ^(1 << reg)
c.Reserved &= ^(1 << reg)
}
// IsReserved returns true if the register was marked for future use.
func (c *CPU) IsReserved(reg Register) bool {
return c.reserved&(1<<reg) != 0
return c.Reserved&(1<<reg) != 0
}
// IsUsed returns true if the register is currently in use and holds a value.
func (c *CPU) IsUsed(reg Register) bool {
return c.used&(1<<reg) != 0
return c.Used&(1<<reg) != 0
}
// Reserve reserves a register for future use.
func (c *CPU) Reserve(reg Register) {
c.reserved |= (1 << reg)
c.Reserved |= (1 << reg)
}
// Use marks a register to be currently in use which means it must be preserved across function calls.
func (c *CPU) Use(reg Register) {
c.used |= (1 << reg)
c.Used |= (1 << reg)
}
// FindFree tries to find a free register in the given slice of registers.