Implemented register calls

This commit is contained in:
2025-03-02 17:53:18 +01:00
parent d7f30d8319
commit c3054369e3
16 changed files with 133 additions and 43 deletions

View File

@ -6,26 +6,31 @@ import (
)
func (c *compiler) call(x asm.Instruction) {
c.code = x86.Call(c.code, 0x00_00_00_00)
size := 4
label := x.Data.(*asm.Label)
switch data := x.Data.(type) {
case *asm.Label:
c.code = x86.Call(c.code, 0x00_00_00_00)
size := 4
pointer := &pointer{
Position: Address(len(c.code) - size),
OpSize: 1,
Size: uint8(size),
}
pointer.Resolve = func() Address {
destination, exists := c.codeLabels[label.Name]
if !exists {
panic("unknown jump label")
pointer := &pointer{
Position: Address(len(c.code) - size),
OpSize: 1,
Size: uint8(size),
}
distance := destination - (pointer.Position + Address(pointer.Size))
return distance
}
pointer.Resolve = func() Address {
destination, exists := c.codeLabels[data.Name]
c.codePointers = append(c.codePointers, pointer)
if !exists {
panic("unknown jump label")
}
distance := destination - (pointer.Position + Address(pointer.Size))
return distance
}
c.codePointers = append(c.codePointers, pointer)
case *asm.Register:
c.code = x86.CallRegister(c.code, data.Register)
}
}