//go:build ignore // +build ignore package main import ( "fmt" "os" "strings" "github.com/vsariola/sointu/vm" ) func check(e error) { if e != nil { panic(e) } } func main() { outputFile, err := os.Create("opcodes.go") check(err) defer outputFile.Close() fmt.Fprintln(outputFile, "package vm") fmt.Fprintln(outputFile, "") fmt.Fprintln(outputFile, "// Code generated by go generate; DO NOT EDIT.") fmt.Fprintln(outputFile, "const (") features := vm.AllFeatures{} max := 0 for _, instr := range features.Instructions() { if l := len(instr); max < l { max = l } } for i, instr := range features.Instructions() { format := fmt.Sprintf("\top%%-%vv = %%v\n", max) fmt.Fprintf(outputFile, format, strings.Title(instr), i+1) } fmt.Fprintln(outputFile, ")") fmt.Fprintln(outputFile, "") fmt.Fprintf(outputFile, "var transformCounts = [...]int{") for i, instr := range features.Instructions() { if i > 0 { fmt.Fprintf(outputFile, ", ") } fmt.Fprintf(outputFile, "%v", features.TransformCount(instr)) } fmt.Fprintln(outputFile, "}") }