Improved assembler performance
This commit is contained in:
@ -13,8 +13,9 @@ import (
|
||||
func (c *compiler) compileARM(x asm.Instruction) {
|
||||
switch x.Mnemonic {
|
||||
case asm.CALL:
|
||||
switch data := x.Data.(type) {
|
||||
case *asm.Label:
|
||||
switch x.Type {
|
||||
case asm.TypeLabel:
|
||||
label := c.assembler.Param.Label[x.Index]
|
||||
position := Address(len(c.code))
|
||||
c.append(arm.Call(0))
|
||||
|
||||
@ -25,10 +26,10 @@ func (c *compiler) compileARM(x asm.Instruction) {
|
||||
}
|
||||
|
||||
pointer.Resolve = func() Address {
|
||||
destination, exists := c.codeLabels[data.Name]
|
||||
destination, exists := c.codeLabels[label.Name]
|
||||
|
||||
if !exists {
|
||||
panic(fmt.Sprintf("unknown jump label %s", data.Name))
|
||||
panic(fmt.Sprintf("unknown jump label %s", label.Name))
|
||||
}
|
||||
|
||||
distance := (destination - position) / 4
|
||||
@ -39,13 +40,16 @@ func (c *compiler) compileARM(x asm.Instruction) {
|
||||
}
|
||||
|
||||
case asm.LABEL:
|
||||
c.codeLabels[x.Data.(*asm.Label).Name] = Address(len(c.code))
|
||||
label := c.assembler.Param.Label[x.Index]
|
||||
c.codeLabels[label.Name] = Address(len(c.code))
|
||||
c.append(0xa9be7bfd)
|
||||
c.append(0x910003fd)
|
||||
|
||||
case asm.LOAD:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.MemoryRegister:
|
||||
switch x.Type {
|
||||
case asm.TypeMemoryRegister:
|
||||
operands := c.assembler.Param.MemoryRegister[x.Index]
|
||||
|
||||
if operands.Address.OffsetRegister == math.MaxUint8 {
|
||||
c.append(arm.LoadRegister(operands.Register, operands.Address.Base, int16(operands.Address.Offset), operands.Address.Length))
|
||||
} else {
|
||||
@ -55,14 +59,17 @@ func (c *compiler) compileARM(x asm.Instruction) {
|
||||
}
|
||||
|
||||
case asm.MOVE:
|
||||
switch operands := x.Data.(type) {
|
||||
case *asm.RegisterRegister:
|
||||
switch x.Type {
|
||||
case asm.TypeRegisterRegister:
|
||||
operands := c.assembler.Param.RegisterRegister[x.Index]
|
||||
c.append(arm.MoveRegisterRegister(operands.Destination, operands.Source))
|
||||
|
||||
case *asm.RegisterNumber:
|
||||
case asm.TypeRegisterNumber:
|
||||
operands := c.assembler.Param.RegisterNumber[x.Index]
|
||||
c.append(arm.MoveRegisterNumber(operands.Register, operands.Number))
|
||||
|
||||
case *asm.RegisterLabel:
|
||||
case asm.TypeRegisterLabel:
|
||||
operands := c.assembler.Param.RegisterLabel[x.Index]
|
||||
position := Address(len(c.code))
|
||||
c.append(arm.LoadAddress(operands.Register, 0))
|
||||
|
||||
|
Reference in New Issue
Block a user