q/src/asmc/dllCall.go

37 lines
708 B
Go

package asmc
import (
"strings"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/x86"
)
func (c *compiler) dllCall(x asm.Instruction) {
size := 4
c.code = x86.CallAtAddress(c.code, 0x00_00_00_00)
position := len(c.code) - size
label := x.Data.(*asm.Label)
pointer := &pointer{
Position: Address(position),
OpSize: 2,
Size: uint8(size),
}
pointer.Resolve = func() Address {
dot := strings.Index(label.Name, ".")
library := label.Name[:dot]
funcName := label.Name[dot+1:]
index := c.dlls.Index(library, funcName)
if index == -1 {
panic("unknown DLL function " + label.Name)
}
return Address(index * 8)
}
c.dllPointers = append(c.dllPointers, pointer)
}