Enabled arm64 encoding
This commit is contained in:
@ -1,23 +1,54 @@
|
||||
package asmc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.urbach.dev/cli/q/src/arm"
|
||||
"git.urbach.dev/cli/q/src/asm"
|
||||
)
|
||||
|
||||
func (c *compiler) compileARM(x asm.Instruction) {
|
||||
switch x.Mnemonic {
|
||||
// case asm.MOVE:
|
||||
// switch operands := x.Data.(type) {
|
||||
// case *asm.RegisterNumber:
|
||||
// c.code = arm.MoveRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
// }
|
||||
case asm.CALL:
|
||||
switch data := x.Data.(type) {
|
||||
case *asm.Label:
|
||||
position := len(c.code)
|
||||
c.code = arm.Call(c.code, 0)
|
||||
|
||||
// case asm.RETURN:
|
||||
// c.code = arm.Return(c.code)
|
||||
pointer := &pointer{
|
||||
Position: Address(position),
|
||||
OpSize: 0,
|
||||
Size: 4,
|
||||
}
|
||||
|
||||
// case asm.SYSCALL:
|
||||
// c.code = arm.Syscall(c.code)
|
||||
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) / 4
|
||||
return arm.EncodeCall(distance)
|
||||
}
|
||||
|
||||
c.codePointers = append(c.codePointers, pointer)
|
||||
}
|
||||
|
||||
case asm.LABEL:
|
||||
c.codeLabels[x.Data.(*asm.Label).Name] = Address(len(c.code))
|
||||
|
||||
case asm.MOVE:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterNumber:
|
||||
c.code = arm.MoveRegisterNumber(c.code, operands.Register, operands.Number)
|
||||
}
|
||||
|
||||
case asm.RETURN:
|
||||
c.code = arm.Return(c.code)
|
||||
|
||||
case asm.SYSCALL:
|
||||
c.code = arm.Syscall(c.code)
|
||||
|
||||
default:
|
||||
c.code = arm.Nop(c.code)
|
||||
|
Reference in New Issue
Block a user