diff options
| author | Rob Pike <r@golang.org> | 2015-03-02 20:17:20 -0800 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2015-03-03 17:06:27 +0000 |
| commit | 74e88dfdeebef392d52d3f792e2071b058c1e231 (patch) | |
| tree | e066ac4bde456ffd50b2ecaf402020056f97653c /src/cmd/internal/obj/util.go | |
| parent | 91e7ca588d07b8e04e9608c4436d2d701f6c59d0 (diff) | |
| download | go-74e88dfdeebef392d52d3f792e2071b058c1e231.tar.xz | |
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>
Diffstat (limited to 'src/cmd/internal/obj/util.go')
| -rw-r--r-- | src/cmd/internal/obj/util.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go index a3c88a2b8a..d626793475 100644 --- a/src/cmd/internal/obj/util.go +++ b/src/cmd/internal/obj/util.go @@ -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", +} |
