q/src/asmc/call.go

45 lines
962 B
Go

package asmc
import (
"fmt"
"git.urbach.dev/cli/q/src/asm"
"git.urbach.dev/cli/q/src/x86"
)
func (c *compiler) call(x asm.Instruction) {
switch x.Type {
case asm.TypeLabel:
data := c.assembler.Param.Label[x.Index]
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[data.Name]
if !exists {
panic(fmt.Sprintf("unknown jump label %s", data.Name))
}
distance := destination - (pointer.Position + Address(pointer.Size))
return distance
}
c.codePointers = append(c.codePointers, pointer)
case asm.TypeRegister:
data := c.assembler.Param.Register[x.Index]
c.code = x86.CallRegister(c.code, data.Register)
case asm.TypeMemory:
data := c.assembler.Param.Memory[x.Index]
c.code = x86.CallAtMemory(c.code, data.Base, data.Offset)
}
}