gen

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package gen provides code generators based on the instruction database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Action added in v0.4.0

func Action(a inst.Action) string

Action returns code representing the instruction action.

func DeclareTestArguments added in v0.4.0

func DeclareTestArguments(g *prnt.Generator)

DeclareTestArguments prints a block of variables declaring a valid operand of each operand type.

func Features added in v0.4.0

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 added in v0.4.0

func TestArgumentName(t string) string

TestArgumentName returns the name of the variable of operand type t declared by DeclareTestArguments().

func TestSignature added in v0.4.0

func TestSignature(f inst.Form) api.Signature

TestSignature returns a function signature with arguments matching the given instruction form. Requires variables declared by DeclareTestArguments().

Types

type Builder

type Builder func(printer.Config) Interface

Builder constructs a code generator.

type Enum added in v0.4.0

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 added in v0.4.0

func NewEnum(name string) *Enum

NewEnum initializes an empty enum type with the given name.

func (*Enum) AddValue added in v0.4.0

func (e *Enum) AddValue(value string)

AddValue adds a named enumerator.

func (*Enum) ConstName added in v0.4.0

func (e *Enum) ConstName(value string) string

ConstName returns the constant name that refers to the given enumerator value.

func (*Enum) ConstNames added in v0.4.0

func (e *Enum) ConstNames() []string

ConstNames returns the constant names for all enumerator values.

func (*Enum) Doc added in v0.4.0

func (e *Enum) Doc() []string

Doc returns the type documentation.

func (*Enum) Max added in v0.4.0

func (e *Enum) Max() int

Max returns the value of the maximum enumerator.

func (*Enum) MaxName added in v0.4.0

func (e *Enum) MaxName() string

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 added in v0.4.0

func (e *Enum) Name() string

Name returns the type name.

func (*Enum) None added in v0.4.0

func (e *Enum) None() string

None returns the name of the "unset" constant of this enumeration.

func (*Enum) Receiver added in v0.4.0

func (e *Enum) Receiver() string

Receiver returns the receiver variable name.

func (*Enum) SetDoc added in v0.4.0

func (e *Enum) SetDoc(doc ...string)

SetDoc sets type documentation, as a list of lines.

func (*Enum) UnderlyingType added in v0.4.0

func (e *Enum) UnderlyingType() string

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 added in v0.4.0

func (e *Enum) Values() []string

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

func GoFmt(i Interface) Interface

GoFmt formats Go code produced from the given generator.

func NewAsmTest

func NewAsmTest(cfg printer.Config) Interface

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

func NewBuild(cfg printer.Config) Interface

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 added in v0.4.0

func NewBuildTest(cfg printer.Config) Interface

NewBuildTest autogenerates tests for instruction methods on the build context.

func NewCtors

func NewCtors(cfg printer.Config) Interface

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 added in v0.4.0

func NewCtorsBench(cfg printer.Config) Interface

NewCtorsBench autogenerates a benchmark for the instruction constructors.

func NewCtorsStress added in v0.4.0

func NewCtorsStress(cfg printer.Config) Interface

NewCtorsStress autogenerates stress tests for instruction constructors.

func NewCtorsTest

func NewCtorsTest(cfg printer.Config) Interface

NewCtorsTest autogenerates tests for the constructors build by NewCtors.

func NewGoData

func NewGoData(cfg printer.Config) Interface

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

func NewGoDataTest(cfg printer.Config) Interface

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

func NewMOV(cfg printer.Config) Interface

NewMOV generates a function that will auto-select the correct MOV instruction based on operand types and sizes.

func NewOptab added in v0.4.0

func NewOptab(cfg printer.Config) Interface

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 added in v0.4.0

type Table struct {
	// contains filtered or unexported fields
}

Table represents all the types required to represent the instruction operation table (optab).

func NewTable added in v0.4.0

func NewTable(is []inst.Instruction) *Table

NewTable builds optab types to represent the given instructions.

func (*Table) ISAs added in v0.4.0

func (t *Table) ISAs() *Enum

ISAs returns the enumeration for all possible ISA combinations.

func (*Table) ISAsConst added in v0.4.0

func (t *Table) ISAsConst(isas []string) string

ISAsConst returns the constant name for the given ISA combination.

func (*Table) ImplicitRegister added in v0.4.0

func (t *Table) ImplicitRegister() *Enum

ImplicitRegister returns the enumeration representing all possible operand types.

func (*Table) ImplicitRegisterConst added in v0.4.0

func (t *Table) ImplicitRegisterConst(r string) string

ImplicitRegisterConst returns the constant name for the given register.

func (*Table) Opcode added in v0.4.0

func (t *Table) Opcode() *Enum

Opcode returns the opcode enumeration.

func (*Table) OpcodeConst added in v0.4.0

func (t *Table) OpcodeConst(opcode string) string

OpcodeConst returns the constant name for the given opcode.

func (*Table) OperandType added in v0.4.0

func (t *Table) OperandType() *Enum

OperandType returns the enumeration representing all possible operand types.

func (*Table) OperandTypeConst added in v0.4.0

func (t *Table) OperandTypeConst(typ string) string

OperandTypeConst returns the constant name for the given operand type.

func (*Table) Suffix added in v0.4.0

func (t *Table) Suffix() *Enum

Suffix returns the enumeration representing instruction suffixes.

func (*Table) SuffixConst added in v0.4.0

func (t *Table) SuffixConst(s inst.Suffix) string

SuffixConst returns the constant name for the given instruction suffix.

func (*Table) SuffixesClass added in v0.4.0

func (t *Table) SuffixesClass() *Enum

SuffixesClass returns the enumeration representing all suffixes classes.

func (*Table) SuffixesClassConst added in v0.4.0

func (t *Table) SuffixesClassConst(key string) string

SuffixesClassConst returns the constant name for a given suffixes class. The key is as returned from inst.SuffixesClasses() function.

func (*Table) SuffixesConst added in v0.4.0

func (t *Table) SuffixesConst(suffixes inst.Suffixes) string

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 added in v0.5.0

func (t *Table) SuffixesList(suffixes inst.Suffixes) string

SuffixesList returns the constant literal for a list of suffixes, type name not included. Use SuffxesConst if the type is required.

func (*Table) SuffixesTypeName added in v0.4.0

func (t *Table) SuffixesTypeName() string

SuffixesTypeName returns the name of the array type for a list of suffixes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL