mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: switch to one global Aconv
Aconv is the pretty-printer for instruction opcodes like AMOVQ. There was one for each architecture. Make the space of A names have a different region for each architecture, much as we did for the registers, so a single global Aconv function can do the work. Each architecture registers its region as a slice of names at a given offset. The global names like CALL and JMP are now defined only once. The A values are used for indexing tables, so make it easy to do the indexing by making the offset maskable. Remove a bunch of now-duplicated architecture-specific code. Change-Id: Ib15647b7145a1c089e21e36543691a19e146b60e Reviewed-on: https://go-review.googlesource.com/6620 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
91e7ca588d
commit
74e88dfdee
24 changed files with 560 additions and 625 deletions
|
|
@ -491,3 +491,68 @@ func regListConv(list int) string {
|
|||
str += "]"
|
||||
return str
|
||||
}
|
||||
|
||||
/*
|
||||
Each architecture defines an instruction (A*) space as a unique
|
||||
integer range.
|
||||
Global opcodes like CALL start at 0; the architecture-specific ones
|
||||
start at a distinct, big-maskable offsets.
|
||||
Here is the list of architectures and the base of their opcode spaces.
|
||||
*/
|
||||
|
||||
const (
|
||||
ABase386 = (1 + iota) << 12
|
||||
ABaseARM
|
||||
ABaseAMD64
|
||||
ABasePPC64
|
||||
AMask = 1<<12 - 1 // AND with this to use the opcode as an array index.
|
||||
)
|
||||
|
||||
type opSet struct {
|
||||
lo int
|
||||
names []string
|
||||
}
|
||||
|
||||
// Not even worth sorting
|
||||
var aSpace []opSet
|
||||
|
||||
// RegisterOpcode binds a list of instruction names
|
||||
// to a given instruction number range.
|
||||
func RegisterOpcode(lo int, Anames []string) {
|
||||
aSpace = append(aSpace, opSet{lo, Anames})
|
||||
}
|
||||
|
||||
func Aconv(a int) string {
|
||||
if a < A_ARCHSPECIFIC {
|
||||
return Anames[a]
|
||||
}
|
||||
for i := range aSpace {
|
||||
as := &aSpace[i]
|
||||
if as.lo <= a && a < as.lo+len(as.names) {
|
||||
return as.names[a-as.lo]
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("A???%d", a)
|
||||
}
|
||||
|
||||
var Anames = []string{
|
||||
"XXX",
|
||||
"CALL",
|
||||
"CHECKNIL",
|
||||
"DATA",
|
||||
"DUFFCOPY",
|
||||
"DUFFZERO",
|
||||
"END",
|
||||
"FUNCDATA",
|
||||
"GLOBL",
|
||||
"JMP",
|
||||
"NOP",
|
||||
"PCDATA",
|
||||
"RET",
|
||||
"TEXT",
|
||||
"TYPE",
|
||||
"UNDEF",
|
||||
"USEFIELD",
|
||||
"VARDEF",
|
||||
"VARKILL",
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue