Skip to content

Commit

Permalink
cmd/internal/obj: add As type for assembly opcodes
Browse files Browse the repository at this point in the history
Passes toolstash/buildall.

Fixes #14692.

Change-Id: I4352678d8251309f2b8b7793674c550fac948006
Reviewed-on: https://go-review.googlesource.com/20350
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
mdempsky committed Mar 8, 2016
1 parent b1785a5 commit 0d9258a
Show file tree
Hide file tree
Showing 51 changed files with 461 additions and 459 deletions.
44 changes: 22 additions & 22 deletions src/cmd/asm/internal/arch/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
type Arch struct {
*obj.LinkArch
// Map of instruction names to enumeration.
Instructions map[string]int
Instructions map[string]obj.As
// Map of register names to enumeration.
Register map[string]int16
// Table of register prefix names. These are things like R for R(0) and SPR for SPR(268).
Expand All @@ -44,7 +44,7 @@ func nilRegisterNumber(name string, n int16) (int16, bool) {
return 0, false
}

var Pseudos = map[string]int{
var Pseudos = map[string]obj.As{
"DATA": obj.ADATA,
"FUNCDATA": obj.AFUNCDATA,
"GLOBL": obj.AGLOBL,
Expand Down Expand Up @@ -102,13 +102,13 @@ func archX86(linkArch *obj.LinkArch) *Arch {
register["PC"] = RPC
// Register prefix not used on this architecture.

instructions := make(map[string]int)
instructions := make(map[string]obj.As)
for i, s := range obj.Anames {
instructions[s] = i
instructions[s] = obj.As(i)
}
for i, s := range x86.Anames {
if i >= obj.A_ARCHSPECIFIC {
instructions[s] = i + obj.ABaseAMD64
if obj.As(i) >= obj.A_ARCHSPECIFIC {
instructions[s] = obj.As(i) + obj.ABaseAMD64
}
}
// Annoying aliases.
Expand Down Expand Up @@ -200,13 +200,13 @@ func archArm() *Arch {
"R": true,
}

instructions := make(map[string]int)
instructions := make(map[string]obj.As)
for i, s := range obj.Anames {
instructions[s] = i
instructions[s] = obj.As(i)
}
for i, s := range arm.Anames {
if i >= obj.A_ARCHSPECIFIC {
instructions[s] = i + obj.ABaseARM
if obj.As(i) >= obj.A_ARCHSPECIFIC {
instructions[s] = obj.As(i) + obj.ABaseARM
}
}
// Annoying aliases.
Expand Down Expand Up @@ -288,13 +288,13 @@ func archArm64() *Arch {
"V": true,
}

instructions := make(map[string]int)
instructions := make(map[string]obj.As)
for i, s := range obj.Anames {
instructions[s] = i
instructions[s] = obj.As(i)
}
for i, s := range arm64.Anames {
if i >= obj.A_ARCHSPECIFIC {
instructions[s] = i + obj.ABaseARM64
if obj.As(i) >= obj.A_ARCHSPECIFIC {
instructions[s] = obj.As(i) + obj.ABaseARM64
}
}
// Annoying aliases.
Expand Down Expand Up @@ -348,13 +348,13 @@ func archPPC64() *Arch {
"SPR": true,
}

instructions := make(map[string]int)
instructions := make(map[string]obj.As)
for i, s := range obj.Anames {
instructions[s] = i
instructions[s] = obj.As(i)
}
for i, s := range ppc64.Anames {
if i >= obj.A_ARCHSPECIFIC {
instructions[s] = i + obj.ABasePPC64
if obj.As(i) >= obj.A_ARCHSPECIFIC {
instructions[s] = obj.As(i) + obj.ABasePPC64
}
}
// Annoying aliases.
Expand Down Expand Up @@ -403,13 +403,13 @@ func archMips64() *Arch {
"R": true,
}

instructions := make(map[string]int)
instructions := make(map[string]obj.As)
for i, s := range obj.Anames {
instructions[s] = i
instructions[s] = obj.As(i)
}
for i, s := range mips.Anames {
if i >= obj.A_ARCHSPECIFIC {
instructions[s] = i + obj.ABaseMIPS64
if obj.As(i) >= obj.A_ARCHSPECIFIC {
instructions[s] = obj.As(i) + obj.ABaseMIPS64
}
}
// Annoying alias.
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/asm/internal/arch/arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func jumpArm(word string) bool {

// IsARMCMP reports whether the op (as defined by an arm.A* constant) is
// one of the comparison instructions that require special handling.
func IsARMCMP(op int) bool {
func IsARMCMP(op obj.As) bool {
switch op {
case arm.ACMN, arm.ACMP, arm.ATEQ, arm.ATST:
return true
Expand All @@ -99,7 +99,7 @@ func IsARMCMP(op int) bool {

// IsARMSTREX reports whether the op (as defined by an arm.A* constant) is
// one of the STREX-like instructions that require special handling.
func IsARMSTREX(op int) bool {
func IsARMSTREX(op obj.As) bool {
switch op {
case arm.ASTREX, arm.ASTREXD, arm.ASWPW, arm.ASWPBU:
return true
Expand All @@ -114,7 +114,7 @@ const aMCR = arm.ALAST + 1

// IsARMMRC reports whether the op (as defined by an arm.A* constant) is
// MRC or MCR
func IsARMMRC(op int) bool {
func IsARMMRC(op obj.As) bool {
switch op {
case arm.AMRC, aMCR: // Note: aMCR is defined in this package.
return true
Expand All @@ -123,7 +123,7 @@ func IsARMMRC(op int) bool {
}

// IsARMFloatCmp reports whether the op is a floating comparison instruction.
func IsARMFloatCmp(op int) bool {
func IsARMFloatCmp(op obj.As) bool {
switch op {
case arm.ACMPF, arm.ACMPD:
return true
Expand All @@ -135,7 +135,7 @@ func IsARMFloatCmp(op int) bool {
// The difference between MRC and MCR is represented by a bit high in the word, not
// in the usual way by the opcode itself. Asm must use AMRC for both instructions, so
// we return the opcode for MRC so that asm doesn't need to import obj/arm.
func ARMMRCOffset(op int, cond string, x0, x1, x2, x3, x4, x5 int64) (offset int64, op0 int16, ok bool) {
func ARMMRCOffset(op obj.As, cond string, x0, x1, x2, x3, x4, x5 int64) (offset int64, op0 obj.As, ok bool) {
op1 := int64(0)
if op == arm.AMRC {
op1 = 1
Expand All @@ -159,15 +159,15 @@ func ARMMRCOffset(op int, cond string, x0, x1, x2, x3, x4, x5 int64) (offset int

// IsARMMULA reports whether the op (as defined by an arm.A* constant) is
// MULA, MULAWT or MULAWB, the 4-operand instructions.
func IsARMMULA(op int) bool {
func IsARMMULA(op obj.As) bool {
switch op {
case arm.AMULA, arm.AMULAWB, arm.AMULAWT:
return true
}
return false
}

var bcode = []int{
var bcode = []obj.As{
arm.ABEQ,
arm.ABNE,
arm.ABCS,
Expand Down Expand Up @@ -198,7 +198,7 @@ func ARMConditionCodes(prog *obj.Prog, cond string) bool {
}
/* hack to make B.NE etc. work: turn it into the corresponding conditional */
if prog.As == arm.AB {
prog.As = int16(bcode[(bits^arm.C_SCOND_XOR)&0xf])
prog.As = bcode[(bits^arm.C_SCOND_XOR)&0xf]
bits = (bits &^ 0xf) | arm.C_SCOND_NONE
}
prog.Scond = bits
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/asm/internal/arch/arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func jumpArm64(word string) bool {

// IsARM64CMP reports whether the op (as defined by an arm.A* constant) is
// one of the comparison instructions that require special handling.
func IsARM64CMP(op int) bool {
func IsARM64CMP(op obj.As) bool {
switch op {
case arm64.ACMN, arm64.ACMP, arm64.ATST,
arm64.ACMNW, arm64.ACMPW, arm64.ATSTW:
Expand All @@ -63,7 +63,7 @@ func IsARM64CMP(op int) bool {
// IsARM64STLXR reports whether the op (as defined by an arm64.A*
// constant) is one of the STLXR-like instructions that require special
// handling.
func IsARM64STLXR(op int) bool {
func IsARM64STLXR(op obj.As) bool {
switch op {
case arm64.ASTLXRB, arm64.ASTLXRH, arm64.ASTLXRW, arm64.ASTLXR:
return true
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/asm/internal/arch/mips64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

package arch

import "cmd/internal/obj/mips"
import (
"cmd/internal/obj"
"cmd/internal/obj/mips"
)

func jumpMIPS64(word string) bool {
switch word {
Expand All @@ -20,7 +23,7 @@ func jumpMIPS64(word string) bool {

// IsMIPS64CMP reports whether the op (as defined by an mips.A* constant) is
// one of the CMP instructions that require special handling.
func IsMIPS64CMP(op int) bool {
func IsMIPS64CMP(op obj.As) bool {
switch op {
case mips.ACMPEQF, mips.ACMPEQD, mips.ACMPGEF, mips.ACMPGED,
mips.ACMPGTF, mips.ACMPGTD:
Expand All @@ -31,7 +34,7 @@ func IsMIPS64CMP(op int) bool {

// IsMIPS64MUL reports whether the op (as defined by an mips.A* constant) is
// one of the MUL/DIV/REM instructions that require special handling.
func IsMIPS64MUL(op int) bool {
func IsMIPS64MUL(op obj.As) bool {
switch op {
case mips.AMUL, mips.AMULU, mips.AMULV, mips.AMULVU,
mips.ADIV, mips.ADIVU, mips.ADIVV, mips.ADIVVU,
Expand Down
11 changes: 7 additions & 4 deletions src/cmd/asm/internal/arch/ppc64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

package arch

import "cmd/internal/obj/ppc64"
import (
"cmd/internal/obj"
"cmd/internal/obj/ppc64"
)

func jumpPPC64(word string) bool {
switch word {
Expand All @@ -21,7 +24,7 @@ func jumpPPC64(word string) bool {
// IsPPC64RLD reports whether the op (as defined by an ppc64.A* constant) is
// one of the RLD-like instructions that require special handling.
// The FMADD-like instructions behave similarly.
func IsPPC64RLD(op int) bool {
func IsPPC64RLD(op obj.As) bool {
switch op {
case ppc64.ARLDC, ppc64.ARLDCCC, ppc64.ARLDCL, ppc64.ARLDCLCC,
ppc64.ARLDCR, ppc64.ARLDCRCC, ppc64.ARLDMI, ppc64.ARLDMICC,
Expand All @@ -38,7 +41,7 @@ func IsPPC64RLD(op int) bool {

// IsPPC64CMP reports whether the op (as defined by an ppc64.A* constant) is
// one of the CMP instructions that require special handling.
func IsPPC64CMP(op int) bool {
func IsPPC64CMP(op obj.As) bool {
switch op {
case ppc64.ACMP, ppc64.ACMPU, ppc64.ACMPW, ppc64.ACMPWU:
return true
Expand All @@ -48,7 +51,7 @@ func IsPPC64CMP(op int) bool {

// IsPPC64NEG reports whether the op (as defined by an ppc64.A* constant) is
// one of the NEG-like instructions that require special handling.
func IsPPC64NEG(op int) bool {
func IsPPC64NEG(op obj.As) bool {
switch op {
case ppc64.AADDMECC, ppc64.AADDMEVCC, ppc64.AADDMEV, ppc64.AADDME,
ppc64.AADDZECC, ppc64.AADDZEVCC, ppc64.AADDZEV, ppc64.AADDZE,
Expand Down
14 changes: 7 additions & 7 deletions src/cmd/asm/internal/asm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ func (p *Parser) asmFuncData(word string, operands [][]lex.Token) {
// JMP R1
// JMP exit
// JMP 3(PC)
func (p *Parser) asmJump(op int, cond string, a []obj.Addr) {
func (p *Parser) asmJump(op obj.As, cond string, a []obj.Addr) {
var target *obj.Addr
prog := &obj.Prog{
Ctxt: p.ctxt,
Lineno: p.histLineNum,
As: int16(op),
As: op,
}
switch len(a) {
case 1:
Expand Down Expand Up @@ -455,12 +455,12 @@ func (p *Parser) branch(jmp, target *obj.Prog) {

// asmInstruction assembles an instruction.
// MOVW R9, (R10)
func (p *Parser) asmInstruction(op int, cond string, a []obj.Addr) {
func (p *Parser) asmInstruction(op obj.As, cond string, a []obj.Addr) {
// fmt.Printf("%s %+v\n", obj.Aconv(op), a)
prog := &obj.Prog{
Ctxt: p.ctxt,
Lineno: p.histLineNum,
As: int16(op),
As: op,
}
switch len(a) {
case 0:
Expand Down Expand Up @@ -707,23 +707,23 @@ func (p *Parser) getConstantPseudo(pseudo string, addr *obj.Addr) int64 {
}

// getConstant checks that addr represents a plain constant and returns its value.
func (p *Parser) getConstant(prog *obj.Prog, op int, addr *obj.Addr) int64 {
func (p *Parser) getConstant(prog *obj.Prog, op obj.As, addr *obj.Addr) int64 {
if addr.Type != obj.TYPE_MEM || addr.Name != 0 || addr.Reg != 0 || addr.Index != 0 {
p.errorf("%s: expected integer constant; found %s", obj.Aconv(op), obj.Dconv(prog, addr))
}
return addr.Offset
}

// getImmediate checks that addr represents an immediate constant and returns its value.
func (p *Parser) getImmediate(prog *obj.Prog, op int, addr *obj.Addr) int64 {
func (p *Parser) getImmediate(prog *obj.Prog, op obj.As, addr *obj.Addr) int64 {
if addr.Type != obj.TYPE_CONST || addr.Name != 0 || addr.Reg != 0 || addr.Index != 0 {
p.errorf("%s: expected immediate constant; found %s", obj.Aconv(op), obj.Dconv(prog, addr))
}
return addr.Offset
}

// getRegister checks that addr represents a register and returns its value.
func (p *Parser) getRegister(prog *obj.Prog, op int, addr *obj.Addr) int16 {
func (p *Parser) getRegister(prog *obj.Prog, op obj.As, addr *obj.Addr) int16 {
if addr.Type != obj.TYPE_REG || addr.Offset != 0 || addr.Name != 0 || addr.Index != 0 {
p.errorf("%s: expected register; found %s", obj.Aconv(op), obj.Dconv(prog, addr))
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/asm/internal/asm/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (p *Parser) line() bool {
return true
}

func (p *Parser) instruction(op int, word, cond string, operands [][]lex.Token) {
func (p *Parser) instruction(op obj.As, word, cond string, operands [][]lex.Token) {
p.addr = p.addr[0:0]
p.isJump = p.arch.IsJump(word)
for _, op := range operands {
Expand All @@ -214,7 +214,7 @@ func (p *Parser) instruction(op int, word, cond string, operands [][]lex.Token)
p.asmInstruction(op, cond, p.addr)
}

func (p *Parser) pseudo(op int, word string, operands [][]lex.Token) {
func (p *Parser) pseudo(op obj.As, word string, operands [][]lex.Token) {
switch op {
case obj.ATEXT:
p.asmText(word, operands)
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/compile/internal/amd64/galign.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func linkarchinit() {
var MAXWIDTH int64 = 1 << 50

var (
addptr int = x86.AADDQ
movptr int = x86.AMOVQ
leaptr int = x86.ALEAQ
cmpptr int = x86.ACMPQ
addptr = x86.AADDQ
movptr = x86.AMOVQ
leaptr = x86.ALEAQ
cmpptr = x86.ACMPQ
)

func betypeinit() {
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/amd64/ggen.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, ax *uint32, x0 *uin
return p
}

func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
func appendpp(p *obj.Prog, as obj.As, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
q := gc.Ctxt.NewProg()
gc.Clearp(q)
q.As = int16(as)
q.As = as
q.Lineno = p.Lineno
q.From.Type = ftype
q.From.Reg = int16(freg)
Expand Down Expand Up @@ -747,7 +747,7 @@ func expandchecks(firstp *obj.Prog) {
p2.Lineno = p.Lineno
p1.Pc = 9999
p2.Pc = 9999
p.As = int16(cmpptr)
p.As = cmpptr
p.To.Type = obj.TYPE_CONST
p.To.Offset = 0
p1.As = x86.AJNE
Expand Down
Loading

0 comments on commit 0d9258a

Please sign in to comment.