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.CALL: switch data := x.Data.(type) { case *asm.Label: position := len(c.code) c.code = arm.Call(c.code, 0) pointer := &pointer{ Position: Address(position), OpSize: 0, Size: 4, } 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) } }