package gen
import "github.com/mmcloughlin/avo/internal/gen"
Package gen provides code generators based on the instruction database.
Index ¶
- func Action(a inst.Action) string
- func DeclareTestArguments(g *prnt.Generator)
- func Features(i inst.Instruction, f inst.Form) string
- func TestArgumentName(t string) string
- func TestSignature(f inst.Form) api.Signature
- type Builder
- type Enum
- func NewEnum(name string) *Enum
- func (e *Enum) AddValue(value string)
- func (e *Enum) ConstName(value string) string
- func (e *Enum) ConstNames() []string
- func (e *Enum) Doc() []string
- func (e *Enum) Max() int
- func (e *Enum) MaxName() string
- func (e *Enum) Name() string
- func (e *Enum) None() string
- func (e *Enum) Receiver() string
- func (e *Enum) SetDoc(doc ...string)
- func (e *Enum) UnderlyingType() string
- func (e *Enum) Values() []string
- type Func
- type Interface
- func GoFmt(i Interface) Interface
- func NewAsmTest(cfg printer.Config) Interface
- func NewBuild(cfg printer.Config) Interface
- func NewBuildTest(cfg printer.Config) Interface
- func NewCtors(cfg printer.Config) Interface
- func NewCtorsBench(cfg printer.Config) Interface
- func NewCtorsStress(cfg printer.Config) Interface
- func NewCtorsTest(cfg printer.Config) Interface
- func NewGoData(cfg printer.Config) Interface
- func NewGoDataTest(cfg printer.Config) Interface
- func NewMOV(cfg printer.Config) Interface
- func NewOptab(cfg printer.Config) Interface
- type Table
- func NewTable(is []inst.Instruction) *Table
- func (t *Table) ISAs() *Enum
- func (t *Table) ISAsConst(isas []string) string
- func (t *Table) ImplicitRegister() *Enum
- func (t *Table) ImplicitRegisterConst(r string) string
- func (t *Table) Opcode() *Enum
- func (t *Table) OpcodeConst(opcode string) string
- func (t *Table) OperandType() *Enum
- func (t *Table) OperandTypeConst(typ string) string
- func (t *Table) Suffix() *Enum
- func (t *Table) SuffixConst(s inst.Suffix) string
- func (t *Table) SuffixesClass() *Enum
- func (t *Table) SuffixesClassConst(key string) string
- func (t *Table) SuffixesConst(suffixes inst.Suffixes) string
- func (t *Table) SuffixesList(suffixes inst.Suffixes) string
- func (t *Table) SuffixesTypeName() string
Functions ¶
func Action ¶
Action returns code representing the instruction action.
func DeclareTestArguments ¶
DeclareTestArguments prints a block of variables declaring a valid operand of each operand type.
func Features ¶
func Features(i inst.Instruction, f inst.Form) string
Features returns code for the features constant describing the features of the given instruction form.
func TestArgumentName ¶
TestArgumentName returns the name of the variable of operand type t declared by DeclareTestArguments().
func TestSignature ¶
TestSignature returns a function signature with arguments matching the given instruction form. Requires variables declared by DeclareTestArguments().
Types ¶
type Builder ¶
Builder constructs a code generator.
type Enum ¶
type Enum struct {
// contains filtered or unexported fields
}
Enum is a generated enumeration type. This assists with mapping between the conceptual values of the enum, and it's materialization as Go code.
func NewEnum ¶
NewEnum initializes an empty enum type with the given name.
func (*Enum) AddValue ¶
AddValue adds a named enumerator.
func (*Enum) ConstName ¶
ConstName returns the constant name that refers to the given enumerator value.
func (*Enum) ConstNames ¶
ConstNames returns the constant names for all enumerator values.
func (*Enum) Doc ¶
Doc returns the type documentation.
func (*Enum) Max ¶
Max returns the value of the maximum enumerator.
func (*Enum) MaxName ¶
MaxName returns the name of the constant that represents the maximum enumerator. This value is placed at the very end of the enum, so all values will be between the None and Max enumerators.
func (*Enum) Name ¶
Name returns the type name.
func (*Enum) None ¶
None returns the name of the "unset" constant of this enumeration.
func (*Enum) Receiver ¶
Receiver returns the receiver variable name.
func (*Enum) SetDoc ¶
SetDoc sets type documentation, as a list of lines.
func (*Enum) UnderlyingType ¶
UnderlyingType returns the underlying unsigned integer type used for the enumeration. This will be the smallest type that can represent all the values.
func (*Enum) Values ¶
Values returns all enumerators.
type Func ¶
type Func func([]inst.Instruction) ([]byte, error)
Func adapts a function to Interface.
func (Func) Generate ¶
func (f Func) Generate(is []inst.Instruction) ([]byte, error)
Generate calls f.
type Interface ¶
type Interface interface { Generate([]inst.Instruction) ([]byte, error) }
Interface of an instruction code generator.
func GoFmt ¶
GoFmt formats Go code produced from the given generator.
func NewAsmTest ¶
NewAsmTest prints one massive assembly function containing a line for every instruction form in the database. The intention is to pass this to the Go assembler and confirm there are no errors, thus helping to ensure our database is compatible.
func NewBuild ¶
NewBuild builds a printer that will generate instruction functions in the build package. Each instruction will have one method on the build.Context type, and a corresponding wrapper operating on the global Context. These functions are thin wrappers around constructors generated by NewCtors.
func NewBuildTest ¶
NewBuildTest autogenerates tests for instruction methods on the build context.
func NewCtors ¶
NewCtors will build instruction constructors. Each constructor delegates to the optab-based instruction builder, providing it with a candidate list of forms to match against.
func NewCtorsBench ¶
NewCtorsBench autogenerates a benchmark for the instruction constructors.
func NewCtorsStress ¶
NewCtorsStress autogenerates stress tests for instruction constructors.
func NewCtorsTest ¶
NewCtorsTest autogenerates tests for the constructors build by NewCtors.
func NewGoData ¶
NewGoData writes a Go variable containing the instructions database. This is intended to provide a more friendly version of the instruction database, rather than having to use the raw data sources all the time.
func NewGoDataTest ¶
NewGoDataTest writes a test case to confirm that NewGoData faithfully represented the list. The reason for this is that NewGoData uses custom code to "pretty print" the database so it is somewhat human-readable. In the process we could easily mistakenly print the database incorrectly. This test prints the same slice of instructions with the ugly but correct "%#v" format specifier, and confirms that the two arrays agree.
func NewMOV ¶
NewMOV generates a function that will auto-select the correct MOV instruction based on operand types and sizes.
func NewOptab ¶
NewOptab builds the operator table. This contains a more compact representation of the instruction database, containing the data needed for instruction builders to match against provided operands, and build the selected instruction.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents all the types required to represent the instruction operation table (optab).
func NewTable ¶
func NewTable(is []inst.Instruction) *Table
NewTable builds optab types to represent the given instructions.
func (*Table) ISAs ¶
ISAs returns the enumeration for all possible ISA combinations.
func (*Table) ISAsConst ¶
ISAsConst returns the constant name for the given ISA combination.
func (*Table) ImplicitRegister ¶
ImplicitRegister returns the enumeration representing all possible operand types.
func (*Table) ImplicitRegisterConst ¶
ImplicitRegisterConst returns the constant name for the given register.
func (*Table) Opcode ¶
Opcode returns the opcode enumeration.
func (*Table) OpcodeConst ¶
OpcodeConst returns the constant name for the given opcode.
func (*Table) OperandType ¶
OperandType returns the enumeration representing all possible operand types.
func (*Table) OperandTypeConst ¶
OperandTypeConst returns the constant name for the given operand type.
func (*Table) Suffix ¶
Suffix returns the enumeration representing instruction suffixes.
func (*Table) SuffixConst ¶
SuffixConst returns the constant name for the given instruction suffix.
func (*Table) SuffixesClass ¶
SuffixesClass returns the enumeration representing all suffixes classes.
func (*Table) SuffixesClassConst ¶
SuffixesClassConst returns the constant name for a given suffixes class. The key is as returned from inst.SuffixesClasses() function.
func (*Table) SuffixesConst ¶
SuffixesConst returns the constant for a list of suffixes. Suffixes is a generated array type, so the list is a value not slice type.
func (*Table) SuffixesList ¶
SuffixesList returns the constant literal for a list of suffixes, type name not included. Use SuffxesConst if the type is required.
func (*Table) SuffixesTypeName ¶
SuffixesTypeName returns the name of the array type for a list of suffixes.
Source Files ¶
api.go asmtest.go build.go buildtest.go ctors.go ctorstest.go doc.go gen.go godata.go mov.go optab.go testing.go
- Version
- v0.6.0 (latest)
- Published
- Jan 7, 2024
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 1 month ago –
Tools for package owners.