Debian Codegraph @

internal/gen/testing.go

raw symbols SCIP
1 package genscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/
2
3 import (
4 "github.com/mmcloughlin/avo/internal/apiscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/api`/"
5 "github.com/mmcloughlin/avo/internal/instscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/inst`/"
6 "github.com/mmcloughlin/avo/internal/prntscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/prnt`/"
7 )
8
9 // DeclareTestArguments prints a block of variables declaring a valid operand of
10 // each operand type.
11 func DeclareTestArgumentsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/DeclareTestArguments().(g *prntscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/prnt`/.Generatorscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/prnt`/Generator#) {
12 g.Printfscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/prnt`/Generator#Printf().("var (\n")
13 for _, arg := range validArgsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/validArgs. {
14 g.Printfscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/prnt`/Generator#Printf().("\t%s operand.Op = %s\n", TestArgumentNamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/TestArgumentName().(arg.Typescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/validArgs:Type.), arg.Codescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/validArgs:Code.)
15 }
16 g.Printfscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/prnt`/Generator#Printf().(")\n")
17 }
18
19 // TestSignature returns a function signature with arguments matching the given
20 // instruction form. Requires variables declared by DeclareTestArguments().
21 func TestSignaturescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/TestSignature().(f instscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/inst`/.Formscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/inst`/Form#) apiscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/api`/.Signaturescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/api`/Signature# {
22 var names []string
23 for _, op := range f.Operandsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/inst`/Form#Operands. {
24 names = append(names, TestArgumentNamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/TestArgumentName().(op.Typescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/inst`/Operand#Type.))
25 }
26 return apiscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/api`/.ArgsListscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/api`/ArgsList().(names)
27 }
28
29 // TestArgumentName returns the name of the variable of operand type t declared
30 // by DeclareTestArguments().
31 func TestArgumentNamescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/TestArgumentName().(t string) string {
32 return "op" + t
33 }
34
35 var validArgsscip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/validArgs. = []struct {
36 Typescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/validArgs:Type. string
37 Codescip-go gomod github.com/mmcloughlin/avo . `github.com/mmcloughlin/avo/internal/gen`/validArgs:Code. string
38 }{
39 // Immediates
40 {"1", "operand.Imm(1)"},
41 {"3", "operand.Imm(3)"},
42 {"imm2u", "operand.Imm(3)"},
43 {"imm8", "operand.Imm(math.MaxInt8)"},
44 {"imm16", "operand.Imm(math.MaxInt16)"},
45 {"imm32", "operand.Imm(math.MaxInt32)"},
46 {"imm64", "operand.Imm(math.MaxInt64)"},
47
48 // Registers
49 {"al", "reg.AL"},
50 {"cl", "reg.CL"},
51 {"ax", "reg.AX"},
52 {"eax", "reg.EAX"},
53 {"rax", "reg.RAX"},
54 {"r8", "reg.CH"},
55 {"r16", "reg.R9W"},
56 {"r32", "reg.R10L"},
57 {"r64", "reg.R11"},
58 {"xmm0", "reg.X0"},
59 {"xmm", "reg.X7"},
60 {"ymm", "reg.Y15"},
61 {"zmm", "reg.Z31"},
62 {"k", "reg.K7"},
63
64 // Memory
65 {"m", "operand.Mem{Base: reg.BX, Index: reg.CX, Scale: 2}"},
66 {"m8", "operand.Mem{Base: reg.BL, Index: reg.CH, Scale: 1}"},
67 {"m16", "operand.Mem{Base: reg.BX, Index: reg.CX, Scale: 2}"},
68 {"m32", "operand.Mem{Base: reg.EBX, Index: reg.ECX, Scale: 4}"},
69 {"m64", "operand.Mem{Base: reg.RBX, Index: reg.RCX, Scale: 8}"},
70 {"m128", "operand.Mem{Base: reg.RBX, Index: reg.RCX, Scale: 8}"},
71 {"m256", "operand.Mem{Base: reg.RBX, Index: reg.RCX, Scale: 8}"},
72 {"m512", "operand.Mem{Base: reg.RBX, Index: reg.RCX, Scale: 8}"},
73
74 // Vector memory
75 {"vm32x", "operand.Mem{Base: reg.R13, Index: reg.X4, Scale: 1}"},
76 {"vm64x", "operand.Mem{Base: reg.R13, Index: reg.X8, Scale: 1}"},
77 {"vm32y", "operand.Mem{Base: reg.R13, Index: reg.Y4, Scale: 1}"},
78 {"vm64y", "operand.Mem{Base: reg.R13, Index: reg.Y8, Scale: 1}"},
79 {"vm32z", "operand.Mem{Base: reg.R13, Index: reg.Z4, Scale: 1}"},
80 {"vm64z", "operand.Mem{Base: reg.R13, Index: reg.Z8, Scale: 1}"},
81
82 // Relative
83 {"rel8", "operand.Rel(math.MaxInt8)"},
84 {"rel32", "operand.LabelRef(\"lbl\")"},
85 }