gen

package
v0.0.0-...-81a76c0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 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

func Action(a inst.Action) string

Action returns code representing the instruction action.

func DeclareTestArguments

func DeclareTestArguments(g *prnt.Generator)

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

func TestArgumentName(t string) string

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

func TestSignature

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

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

func NewEnum(name string) *Enum

NewEnum initializes an empty enum type with the given name.

func (*Enum) AddValue

func (e *Enum) AddValue(value string)

AddValue adds a named enumerator.

func (*Enum) ConstName

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

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

func (*Enum) ConstNames

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

ConstNames returns the constant names for all enumerator values.

func (*Enum) Doc

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

Doc returns the type documentation.

func (*Enum) Max

func (e *Enum) Max() int

Max returns the value of the maximum enumerator.

func (*Enum) MaxName

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

func (e *Enum) Name() string

Name returns the type name.

func (*Enum) None

func (e *Enum) None() string

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

func (*Enum) Receiver

func (e *Enum) Receiver() string

Receiver returns the receiver variable name.

func (*Enum) SetDoc

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

SetDoc sets type documentation, as a list of lines.

func (*Enum) UnderlyingType

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

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

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

func NewCtorsBench(cfg printer.Config) Interface

NewCtorsBench autogenerates a benchmark for the instruction constructors.

func NewCtorsStress

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 and sizes.

func NewOptab

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

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

func (t *Table) ISAs() *Enum

ISAs returns the enumeration for all possible ISA combinations.

func (*Table) ISAsConst

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

ISAsConst returns the constant name for the given ISA combination.

func (*Table) ImplicitRegister

func (t *Table) ImplicitRegister() *Enum

ImplicitRegister returns the enumeration representing all possible operand types.

func (*Table) ImplicitRegisterConst

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

ImplicitRegisterConst returns the constant name for the given register.

func (*Table) Opcode

func (t *Table) Opcode() *Enum

Opcode returns the opcode enumeration.

func (*Table) OpcodeConst

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

OpcodeConst returns the constant name for the given opcode.

func (*Table) OperandType

func (t *Table) OperandType() *Enum

OperandType returns the enumeration representing all possible operand types.

func (*Table) OperandTypeConst

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

OperandTypeConst returns the constant name for the given operand type.

func (*Table) Suffix

func (t *Table) Suffix() *Enum

Suffix returns the enumeration representing instruction suffixes.

func (*Table) SuffixConst

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

SuffixConst returns the constant name for the given instruction suffix.

func (*Table) SuffixesClass

func (t *Table) SuffixesClass() *Enum

SuffixesClass returns the enumeration representing all suffixes classes.

func (*Table) SuffixesClassConst

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

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

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

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