1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:34:49 -07:00

[dev.cc] cmd/asm: fix build: handle g in register lists on ARM

Handle the special name of R10 on the ARM - it's g - when it appears
in a register list [R0, g, R3]. Also simplify the pseudo-register parsing
a little.

Should fix the ARM build.

Change-Id: Ifcafc8195dcd3622653b43663ced6e4a144a3e51
Reviewed-on: https://go-review.googlesource.com/4965
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Rob Pike 2015-02-17 08:24:08 -08:00
parent 201b12499c
commit 09ce5d38d0

View File

@ -494,39 +494,32 @@ func (p *Parser) symbolReference(a *obj.Addr, name string, prefix rune) {
p.get('(') p.get('(')
reg := p.get(scanner.Ident).String() reg := p.get(scanner.Ident).String()
p.get(')') p.get(')')
// On some machines, SP is a real register, on some it's pseudo. Make sure p.setPseudoRegister(a, reg, isStatic != 0, prefix)
// setPseudoRegister sees the pseudo always.
// TODO: Set up a pseudo-register map analogous to the register map in arch?
r := p.arch.Registers[reg]
if reg == "SP" {
r = arch.RSP
}
p.setPseudoRegister(a, reg, r, isStatic != 0, prefix)
} }
// setPseudoRegister sets the NAME field of addr for a pseudo-register reference such as (SB). // setPseudoRegister sets the NAME field of addr for a pseudo-register reference such as (SB).
func (p *Parser) setPseudoRegister(addr *obj.Addr, name string, reg int16, isStatic bool, prefix rune) { func (p *Parser) setPseudoRegister(addr *obj.Addr, reg string, isStatic bool, prefix rune) {
if addr.Reg != 0 { if addr.Reg != 0 {
p.errorf("internal error: reg %s already set in pseudo", name) p.errorf("internal error: reg %s already set in pseudo", reg)
} }
switch reg { switch reg {
case arch.RFP: case "FP":
addr.Name = obj.NAME_PARAM addr.Name = obj.NAME_PARAM
case arch.RPC: case "PC":
// Fine as is. // Fine as is.
if prefix != 0 { if prefix != 0 {
p.errorf("illegal addressing mode for PC") p.errorf("illegal addressing mode for PC")
} }
addr.Reg = arch.RPC // Tells asmJump how to interpret this address. addr.Reg = arch.RPC // Tells asmJump how to interpret this address.
case arch.RSB: case "SB":
addr.Name = obj.NAME_EXTERN addr.Name = obj.NAME_EXTERN
if isStatic { if isStatic {
addr.Name = obj.NAME_STATIC addr.Name = obj.NAME_STATIC
} }
case arch.RSP: case "SP":
addr.Name = obj.NAME_AUTO // The pseudo-stack. addr.Name = obj.NAME_AUTO // The pseudo-stack.
default: default:
p.errorf("expected pseudo-register; found %s", name) p.errorf("expected pseudo-register; found %s", reg)
} }
if prefix == '$' { if prefix == '$' {
addr.Type = obj.TYPE_ADDR addr.Type = obj.TYPE_ADDR
@ -554,7 +547,7 @@ func (p *Parser) registerIndirect(a *obj.Addr, prefix rune) {
p.errorf("cannot use pseudo-register in pair") p.errorf("cannot use pseudo-register in pair")
return return
} }
p.setPseudoRegister(a, name, r1, false, prefix) p.setPseudoRegister(a, name, false, prefix)
return return
} }
a.Reg = r1 a.Reg = r1
@ -641,7 +634,11 @@ func (p *Parser) registerNumber(name string) uint16 {
p.errorf("expected register; found %s", name) p.errorf("expected register; found %s", name)
} }
// Register must be of the form R0 through R15. // Register must be of the form R0 through R15.
if name[0] != 'R' && name != "g" { // On ARM, g is register 10.
if p.arch.Thechar == '5' && name == "g" {
return 10
}
if name[0] != 'R' {
p.errorf("expected g or R0 through R15; found %s", name) p.errorf("expected g or R0 through R15; found %s", name)
} }
num, err := strconv.ParseUint(name[1:], 10, 8) num, err := strconv.ParseUint(name[1:], 10, 8)