package gen import ( "io" "strings" "github.com/mmcloughlin/avo/internal/inst" ) type LoaderTest struct{} func (l LoaderTest) Generate(w io.Writer, is []*inst.Instruction) error { p := &printer{w: w} p.printf("TEXT loadertest(SB), 0, $0\n") for _, i := range is { p.printf("\t// %s %s\n", i.Opcode, i.Summary) for _, f := range i.Forms { as := args(f.Operands) p.printf("\t// %#v\n", f.Operands) if as == nil { p.printf("\t// skip\n") continue } p.printf("\t%s\t%s\n", i.Opcode, strings.Join(as, ", ")) } p.printf("\n") } p.printf("\tRET\n") return p.Err() } func args(ops []inst.Operand) []string { as := make([]string, len(ops)) for i, op := range ops { a := arg(op.Type) if a == "" { return nil } as[i] = a } return as } // arg generates an argument for an operand of the given type. func arg(t string) string { m := map[string]string{ // // // // // // // // // // // // // // // // // // // "r64": "R8", // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // } return m[t] }