mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.ssa] cmd/compile/internal/gc: reduce genValue redundancy
Add an asm field to opcodeTable containing the Prog's as field. Then instructions that fill the Prog the same way can be collapsed into a single switch case. I'm still thinking of a better way to reduce redundancy, but I think this might be a good temporary solution to prevent duplication from getting out of control. What do you think? Change-Id: I0c4a0992741f908bd357ee2707edb82e76e4ce61 Reviewed-on: https://go-review.googlesource.com/11130 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
3b817ef8f8
commit
703ef06039
5 changed files with 75 additions and 127 deletions
|
|
@ -9,6 +9,8 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/obj/x86"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io/ioutil"
|
||||
|
|
@ -25,6 +27,7 @@ type arch struct {
|
|||
type opData struct {
|
||||
name string
|
||||
reg regInfo
|
||||
asm int16
|
||||
}
|
||||
|
||||
type blockData struct {
|
||||
|
|
@ -60,12 +63,15 @@ func main() {
|
|||
genOp()
|
||||
genLower()
|
||||
}
|
||||
|
||||
func genOp() {
|
||||
w := new(bytes.Buffer)
|
||||
fmt.Fprintf(w, "// autogenerated: do not edit!\n")
|
||||
fmt.Fprintf(w, "// generated from gen/*Ops.go\n")
|
||||
fmt.Fprintln(w, "package ssa")
|
||||
|
||||
fmt.Fprintln(w, "import \"cmd/internal/obj/x86\"")
|
||||
|
||||
// generate Block* declarations
|
||||
fmt.Fprintln(w, "const (")
|
||||
fmt.Fprintln(w, "blockInvalid BlockKind = iota")
|
||||
|
|
@ -108,6 +114,9 @@ func genOp() {
|
|||
for _, v := range a.ops {
|
||||
fmt.Fprintln(w, "{")
|
||||
fmt.Fprintf(w, "name:\"%s\",\n", v.name)
|
||||
if v.asm != 0 {
|
||||
fmt.Fprintf(w, "asm: x86.A%s,\n", x86.Anames[v.asm-obj.ABaseAMD64])
|
||||
}
|
||||
fmt.Fprintln(w, "reg:regInfo{")
|
||||
fmt.Fprintln(w, "inputs: []regMask{")
|
||||
for _, r := range v.reg.inputs {
|
||||
|
|
@ -129,6 +138,8 @@ func genOp() {
|
|||
}
|
||||
fmt.Fprintln(w, "}")
|
||||
|
||||
fmt.Fprintln(w, "func (o Op) Asm() int {return opcodeTable[o].asm}")
|
||||
|
||||
// generate op string method
|
||||
fmt.Fprintln(w, "func (o Op) String() string {return opcodeTable[o].name }")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue