Commit 3231d4e4 authored by Daniel Martí's avatar Daniel Martí

cmd/compile: replace opnames with stringer

Now possible, since stringer just got the -trimprefix flag added.

While at it, simplify a few Op stringifications since we can now use %v,
and no longer have to worry about o<len(opnames).

Passes toolstash -cmp on std cmd.

Fixes #15462.

Change-Id: Icdcde0b0a5eb165d18488918175024da274f782b
Reviewed-on: https://go-review.googlesource.com/76790
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
Reviewed-by: 's avatarDave Cheney <dave@cheney.net>
parent 366681cc
......@@ -631,6 +631,7 @@ var knownFormats = map[string]string{
"cmd/compile/internal/gc.Nodes %.v": "",
"cmd/compile/internal/gc.Nodes %v": "",
"cmd/compile/internal/gc.Op %#v": "",
"cmd/compile/internal/gc.Op %d": "",
"cmd/compile/internal/gc.Op %v": "",
"cmd/compile/internal/gc.Val %#v": "",
"cmd/compile/internal/gc.Val %T": "",
......
......@@ -1412,7 +1412,7 @@ func (p *exporter) expr(n *Node) {
if op == OAPPEND {
p.bool(n.Isddd())
} else if n.Isddd() {
Fatalf("exporter: unexpected '...' with %s call", opnames[op])
Fatalf("exporter: unexpected '...' with %v call", op)
}
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER, OGETG:
......
......@@ -206,10 +206,6 @@ var goopnames = []string{
OXOR: "^",
}
func (o Op) String() string {
return fmt.Sprint(o)
}
func (o Op) GoString() string {
return fmt.Sprintf("%#v", o)
}
......@@ -232,12 +228,8 @@ func (o Op) oconv(s fmt.State, flag FmtFlag, mode fmtMode) {
}
}
if int(o) < len(opnames) && opnames[o] != "" {
fmt.Fprint(s, opnames[o])
return
}
fmt.Fprintf(s, "O-%d", int(o))
// 'o.String()' instead of just 'o' to avoid infinite recursion
fmt.Fprint(s, o.String())
}
var classnames = []string{
......
// Code generated by "stringer -type=Op -trimprefix=O"; DO NOT EDIT.
package gc
import "fmt"
const _Op_name = "XXXNAMENONAMETYPEPACKLITERALADDSUBORXORADDSTRADDRANDANDAPPENDARRAYBYTESTRARRAYBYTESTRTMPARRAYRUNESTRSTRARRAYBYTESTRARRAYBYTETMPSTRARRAYRUNEASAS2AS2FUNCAS2RECVAS2MAPRAS2DOTTYPEASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECMPIFACECMPSTRCOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLFIELDDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTINDINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMULDIVMODLSHRSHANDANDNOTNEWNOTCOMPLUSMINUSORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRRECOVERRECVRUNESTRSELRECVSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFBLOCKBREAKCASEXCASECONTINUEDEFEREMPTYFALLFORFORUNTILGOTOIFLABELPROCRANGERETURNSELECTSWITCHTYPESWTCHANTMAPTSTRUCTTINTERTFUNCTARRAYDDDDDDARGINLCALLEFACEITABIDATASPTRCLOSUREVARCFUNCCHECKNILVARKILLVARLIVEINDREGSPRETJMPGETGEND"
var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 36, 39, 45, 49, 55, 61, 73, 88, 100, 112, 127, 139, 141, 144, 151, 158, 165, 175, 179, 183, 191, 199, 208, 216, 219, 224, 231, 239, 245, 252, 258, 267, 275, 283, 289, 293, 302, 309, 313, 316, 323, 331, 339, 346, 352, 355, 361, 368, 376, 380, 387, 395, 397, 399, 401, 403, 405, 407, 410, 415, 423, 426, 435, 438, 442, 450, 457, 466, 469, 472, 475, 478, 481, 484, 490, 493, 496, 499, 503, 508, 512, 517, 522, 528, 533, 537, 542, 550, 558, 564, 573, 580, 584, 591, 598, 606, 610, 614, 618, 625, 632, 640, 646, 651, 656, 660, 665, 673, 678, 683, 687, 690, 698, 702, 704, 709, 713, 718, 724, 730, 736, 742, 747, 751, 758, 764, 769, 775, 778, 784, 791, 796, 800, 805, 809, 819, 824, 832, 839, 846, 854, 860, 864, 867}
func (i Op) String() string {
if i >= Op(len(_Op_index)-1) {
return fmt.Sprintf("Op(%d)", i)
}
return _Op_name[_Op_index[i]:_Op_index[i+1]]
}
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gc
// auto generated by go tool dist
var opnames = []string{
OXXX: "XXX",
ONAME: "NAME",
ONONAME: "NONAME",
OTYPE: "TYPE",
OPACK: "PACK",
OLITERAL: "LITERAL",
OADD: "ADD",
OSUB: "SUB",
OOR: "OR",
OXOR: "XOR",
OADDSTR: "ADDSTR",
OADDR: "ADDR",
OANDAND: "ANDAND",
OAPPEND: "APPEND",
OARRAYBYTESTR: "ARRAYBYTESTR",
OARRAYBYTESTRTMP: "ARRAYBYTESTRTMP",
OARRAYRUNESTR: "ARRAYRUNESTR",
OSTRARRAYBYTE: "STRARRAYBYTE",
OSTRARRAYBYTETMP: "STRARRAYBYTETMP",
OSTRARRAYRUNE: "STRARRAYRUNE",
OAS: "AS",
OAS2: "AS2",
OAS2FUNC: "AS2FUNC",
OAS2RECV: "AS2RECV",
OAS2MAPR: "AS2MAPR",
OAS2DOTTYPE: "AS2DOTTYPE",
OASOP: "ASOP",
OCALL: "CALL",
OCALLFUNC: "CALLFUNC",
OCALLMETH: "CALLMETH",
OCALLINTER: "CALLINTER",
OCALLPART: "CALLPART",
OCAP: "CAP",
OCLOSE: "CLOSE",
OCLOSURE: "CLOSURE",
OCMPIFACE: "CMPIFACE",
OCMPSTR: "CMPSTR",
OCOMPLIT: "COMPLIT",
OMAPLIT: "MAPLIT",
OSTRUCTLIT: "STRUCTLIT",
OARRAYLIT: "ARRAYLIT",
OSLICELIT: "SLICELIT",
OPTRLIT: "PTRLIT",
OCONV: "CONV",
OCONVIFACE: "CONVIFACE",
OCONVNOP: "CONVNOP",
OCOPY: "COPY",
ODCL: "DCL",
ODCLFUNC: "DCLFUNC",
ODCLFIELD: "DCLFIELD",
ODCLCONST: "DCLCONST",
ODCLTYPE: "DCLTYPE",
ODELETE: "DELETE",
ODOT: "DOT",
ODOTPTR: "DOTPTR",
ODOTMETH: "DOTMETH",
ODOTINTER: "DOTINTER",
OXDOT: "XDOT",
ODOTTYPE: "DOTTYPE",
ODOTTYPE2: "DOTTYPE2",
OEQ: "EQ",
ONE: "NE",
OLT: "LT",
OLE: "LE",
OGE: "GE",
OGT: "GT",
OIND: "IND",
OINDEX: "INDEX",
OINDEXMAP: "INDEXMAP",
OKEY: "KEY",
OSTRUCTKEY: "STRUCTKEY",
OLEN: "LEN",
OMAKE: "MAKE",
OMAKECHAN: "MAKECHAN",
OMAKEMAP: "MAKEMAP",
OMAKESLICE: "MAKESLICE",
OMUL: "MUL",
ODIV: "DIV",
OMOD: "MOD",
OLSH: "LSH",
ORSH: "RSH",
OAND: "AND",
OANDNOT: "ANDNOT",
ONEW: "NEW",
ONOT: "NOT",
OCOM: "COM",
OPLUS: "PLUS",
OMINUS: "MINUS",
OOROR: "OROR",
OPANIC: "PANIC",
OPRINT: "PRINT",
OPRINTN: "PRINTN",
OPAREN: "PAREN",
OSEND: "SEND",
OSLICE: "SLICE",
OSLICEARR: "SLICEARR",
OSLICESTR: "SLICESTR",
OSLICE3: "SLICE3",
OSLICE3ARR: "SLICE3ARR",
ORECOVER: "RECOVER",
ORECV: "RECV",
ORUNESTR: "RUNESTR",
OSELRECV: "SELRECV",
OSELRECV2: "SELRECV2",
OIOTA: "IOTA",
OREAL: "REAL",
OIMAG: "IMAG",
OCOMPLEX: "COMPLEX",
OBLOCK: "BLOCK",
OBREAK: "BREAK",
OCASE: "CASE",
OXCASE: "XCASE",
OCONTINUE: "CONTINUE",
ODEFER: "DEFER",
OEMPTY: "EMPTY",
OFALL: "FALL",
OFOR: "FOR",
OFORUNTIL: "FORUNTIL",
OGOTO: "GOTO",
OIF: "IF",
OLABEL: "LABEL",
OPROC: "PROC",
ORANGE: "RANGE",
ORETURN: "RETURN",
OSELECT: "SELECT",
OSWITCH: "SWITCH",
OTYPESW: "TYPESW",
OTCHAN: "TCHAN",
OTMAP: "TMAP",
OTSTRUCT: "TSTRUCT",
OTINTER: "TINTER",
OTFUNC: "TFUNC",
OTARRAY: "TARRAY",
ODDD: "DDD",
ODDDARG: "DDDARG",
OINLCALL: "INLCALL",
OEFACE: "EFACE",
OITAB: "ITAB",
OIDATA: "IDATA",
OSPTR: "SPTR",
OCLOSUREVAR: "CLOSUREVAR",
OCFUNC: "CFUNC",
OCHECKNIL: "CHECKNIL",
OVARKILL: "VARKILL",
OVARLIVE: "VARLIVE",
OINDREGSP: "INDREGSP",
ORETJMP: "RETJMP",
OGETG: "GETG",
OEND: "END",
}
......@@ -3185,7 +3185,7 @@ func (s *state) intrinsicArgs(n *Node) []*ssa.Value {
temps := map[*Node]*ssa.Value{}
for _, a := range n.List.Slice() {
if a.Op != OAS {
s.Fatalf("non-assignment as a function argument %s", opnames[a.Op])
s.Fatalf("non-assignment as a function argument %v", a.Op)
}
l, r := a.Left, a.Right
switch l.Op {
......@@ -3205,7 +3205,7 @@ func (s *state) intrinsicArgs(n *Node) []*ssa.Value {
}
args = append(args, callArg{l.Xoffset, v})
default:
s.Fatalf("function argument assignment target not allowed: %s", opnames[l.Op])
s.Fatalf("function argument assignment target not allowed: %v", l.Op)
}
}
sort.Sort(byOffset(args))
......
......@@ -496,11 +496,13 @@ func (f *Func) setWBPos(pos src.XPos) {
}
}
//go:generate stringer -type=Op -trimprefix=O
type Op uint8
// Node ops.
const (
OXXX = Op(iota)
OXXX Op = iota
// names
ONAME // var, const or func name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment