types

package
v0.0.0-...-0effba1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package types contains the Plan interpreter, which is used to validate a Plan source file's structure and contents, then store the result in a more constrained representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arch

type Arch uint8

Arch represents an instruction set architecture, which is used to customise types for a particular architecture.

const (
	InvalidArch Arch = iota
	X86_64
)

func (Arch) String

func (a Arch) String() string

type Array

type Array struct {
	Name   Name
	Node   *ast.List
	Docs   Docs
	Groups []Name
	Count  uint64
	Type   Type
}

Array represents a fixed-size sequence of another data type.

func (*Array) Alignment

func (a *Array) Alignment(arch Arch) int

func (*Array) End

func (a *Array) End() token.Position

func (*Array) Parameter

func (a *Array) Parameter(arch Arch) bool

func (*Array) Pos

func (a *Array) Pos() token.Position

func (*Array) Size

func (a *Array) Size(arch Arch) int

func (*Array) String

func (a *Array) String() string

type Bitfield

type Bitfield struct {
	Name   Name
	Node   *ast.List
	Docs   Docs
	Groups []Name
	Type   Integer
	Values []*Value
}

Bitfield represents a numerical type with a constrained set of valid values in a syscalls plan. The values can be combined together, but each value uses one bit in the underlying integer, resulting in a smaller number of individual values than an enumeration of the same size.

func (*Bitfield) Alignment

func (e *Bitfield) Alignment(a Arch) int

func (*Bitfield) End

func (b *Bitfield) End() token.Position

func (*Bitfield) Parameter

func (b *Bitfield) Parameter(a Arch) bool

func (*Bitfield) Pos

func (b *Bitfield) Pos() token.Position

func (*Bitfield) Size

func (e *Bitfield) Size(a Arch) int

func (*Bitfield) String

func (b *Bitfield) String() string

type CodeText

type CodeText string

CodeText represents plain text in a set of documentation that should be formatted as source code.

type Docs

type Docs []DocsItem

Docs represents a set of documentation for a type Plan a source file. The docs are split into lines.

type DocsItem

type DocsItem interface {
	// contains filtered or unexported methods
}

DocsItem represents an item in the set of documentation for a type, syscall, or field.

type Enumeration

type Enumeration struct {
	Name   Name
	Node   *ast.List
	Docs   Docs
	Groups []Name
	Type   Integer
	Embeds []*Enumeration
	Values []*Value
}

Enumeration represents a numerical type with a constrained set of valid values in a syscalls plan.

func (*Enumeration) Alignment

func (e *Enumeration) Alignment(a Arch) int

func (*Enumeration) End

func (e *Enumeration) End() token.Position

func (*Enumeration) Parameter

func (e *Enumeration) Parameter(a Arch) bool

func (*Enumeration) Pos

func (e *Enumeration) Pos() token.Position

func (*Enumeration) Size

func (e *Enumeration) Size(a Arch) int

func (*Enumeration) String

func (e *Enumeration) String() string

type Field

type Field struct {
	Name Name
	Node *ast.List
	Docs Docs
	Type Type
}

Field represents a single field in a structure type.

func (*Field) Alignment

func (f *Field) Alignment(a Arch) int

func (*Field) Register

func (f *Field) Register(a Arch) bool

func (*Field) Size

func (f *Field) Size(a Arch) int

func (*Field) String

func (f *Field) String() string

type File

type File struct {
	// Data structures.
	Arrays       []*Array
	Bitfields    []*Bitfield
	Enumerations []*Enumeration
	NewIntegers  []*NewInteger
	Structures   []*Structure

	// System calls.
	Syscalls []*Syscall

	// Item groups.
	Groups []*Group
}

File represents a parsed syscalls plan.

func Interpret

func Interpret(filename string, file *ast.File, arch Arch) (*File, error)

Interpret processes a Plan source file, producing a structured representation for the interface it defines.

func (*File) DropAST

func (f *File) DropAST()

DropAST can be used to remove the AST nodes from a file, to make it easier to reproduce in tests.

func (*File) SyscallsEnumeration

func (f *File) SyscallsEnumeration() *Enumeration

SyscallsEnumeration returns a synthetic enumeration (with no AST data) describing the set of syscalls. This can be used to iterate over the set of syscalls in a target language.

type Group

type Group struct {
	Name Name
	Node *ast.List
	Docs Docs
	List []*ItemReference
}

Group represents a group of logically related items.

func (*Group) String

func (g *Group) String() string

func (*Group) Syscalls

func (g *Group) Syscalls() []*Syscall

type Integer

type Integer uint8

Integer represents a primitive integer, type.

const (
	InvalidInteger Integer = iota
	Byte
	Uint8
	Uint16
	Uint32
	Uint64
	Sint8
	Sint16
	Sint32
	Sint64
)

func (Integer) Alignment

func (b Integer) Alignment(a Arch) int

func (Integer) Bits

func (b Integer) Bits() int

func (Integer) Docs

func (b Integer) Docs() Docs

func (Integer) Max

func (b Integer) Max() uint64

func (Integer) Min

func (b Integer) Min() int64

func (Integer) Parameter

func (b Integer) Parameter(a Arch) bool

func (Integer) Size

func (b Integer) Size(a Arch) int

func (Integer) String

func (b Integer) String() string

type ItemReference

type ItemReference struct {
	Type       string
	Name       Name
	Node       *ast.List
	Underlying any
}

ItemReference is like Reference, but it names the type of item in Underlying.

type Name

type Name []string

Name represents a name defined in a Plan source file.

func (Name) CamelCase

func (n Name) CamelCase() string

CamelCase returns the name in 'camel case', such as "camelCase".

func (Name) KebabCase

func (n Name) KebabCase() string

KebabCase returns the name in 'kebab case', such as "kebab-case".

func (Name) PascalCase

func (n Name) PascalCase() string

PascalCase returns the name in 'Pascal case', such as "PascalCase".

func (Name) ScreamCase

func (n Name) ScreamCase() string

ScreamCase returns the name in 'scream case', such as "SCREAM_CASE".

func (Name) SnakeCase

func (n Name) SnakeCase() string

SnakeCase returns the name in 'snake case', such as "snake_case".

func (Name) Spaced

func (n Name) Spaced() string

Spaced returns the name, separated by spaces.

func (Name) TrainCase

func (n Name) TrainCase() string

TrainCase returns the name in 'train case', such as "TRAIN-CASE".

type NewInteger

type NewInteger struct {
	Name   Name
	Node   *ast.List
	Docs   Docs
	Groups []Name
	Type   Integer
}

NewInteger represents a new type that has been defined, with an underlying integer type.

func (*NewInteger) Alignment

func (i *NewInteger) Alignment(a Arch) int

func (*NewInteger) End

func (i *NewInteger) End() token.Position

func (*NewInteger) Parameter

func (i *NewInteger) Parameter(a Arch) bool

func (*NewInteger) Pos

func (i *NewInteger) Pos() token.Position

func (*NewInteger) Size

func (i *NewInteger) Size(a Arch) int

func (*NewInteger) String

func (i *NewInteger) String() string

type Newline

type Newline struct{}

Newline represents a line break in the text of a set of documentation.

type Padding

type Padding uint16

Padding represents unused space that is included after a field in a structure to ensure the fields and structure remain correctly aligned.

func (Padding) Alignment

func (p Padding) Alignment(a Arch) int

func (Padding) Parameter

func (p Padding) Parameter(a Arch) bool

func (Padding) Size

func (p Padding) Size(a Arch) int

func (Padding) String

func (p Padding) String() string

type Parameter

type Parameter struct {
	Name Name
	Node *ast.List
	Docs Docs
	Type Type
}

Parameter represents a single argument or result in a function call.

func (*Parameter) Enumeration

func (p *Parameter) Enumeration() *Enumeration

func (*Parameter) String

func (p *Parameter) String() string

type Parameters

type Parameters []*Parameter

Parameters is an ordered set of function parameters, such as its arguments or results.

type Pointer

type Pointer struct {
	Mutable    bool
	Underlying Type
}

Pointer represents a pointer to another data type.

func (*Pointer) Alignment

func (p *Pointer) Alignment(a Arch) int

func (*Pointer) Parameter

func (p *Pointer) Parameter(a Arch) bool

func (*Pointer) Size

func (p *Pointer) Size(a Arch) int

func (*Pointer) String

func (p *Pointer) String() string

type Reference

type Reference struct {
	Name       Name
	Underlying Type
}

Reference represents a name used to reference a type that has already been defined elsewhere.

func (*Reference) Alignment

func (r *Reference) Alignment(a Arch) int

func (*Reference) Parameter

func (r *Reference) Parameter(a Arch) bool

func (*Reference) Size

func (r *Reference) Size(a Arch) int

func (*Reference) String

func (r *Reference) String() string

type ReferenceText

type ReferenceText struct {
	Type
}

ReferenceText represents plain text that refers to a type defined in the Plan document.

This will normally be turned into a link to the relevant type definition when rendered in documentation.

type Structure

type Structure struct {
	Name   Name
	Node   *ast.List
	Docs   Docs
	Groups []Name
	Fields []*Field
}

Structure represents a structure defined in a syscalls plan.

func (*Structure) Alignment

func (s *Structure) Alignment(a Arch) int

func (*Structure) End

func (s *Structure) End() token.Position

func (*Structure) Parameter

func (s *Structure) Parameter(a Arch) bool

func (*Structure) Pos

func (s *Structure) Pos() token.Position

func (*Structure) Size

func (s *Structure) Size(a Arch) int

func (*Structure) String

func (s *Structure) String() string

type Syscall

type Syscall struct {
	Name    Name
	Node    *ast.List
	Docs    Docs
	Groups  []Name
	Args    Parameters
	Results Parameters
}

Syscall describes a system call, including its parameters and results.

func (*Syscall) End

func (s *Syscall) End() token.Position

func (*Syscall) Pos

func (s *Syscall) Pos() token.Position

func (*Syscall) String

func (s *Syscall) String() string

type SyscallReference

type SyscallReference struct {
	Name Name
}

SyscallReference can be used in documentation references to link to a system call and is used internally to prevent syscalls and types clashing in the name space.

func (*SyscallReference) Alignment

func (r *SyscallReference) Alignment(a Arch) int

func (*SyscallReference) Parameter

func (r *SyscallReference) Parameter(a Arch) bool

func (*SyscallReference) Size

func (r *SyscallReference) Size(a Arch) int

func (*SyscallReference) String

func (r *SyscallReference) String() string

type Text

type Text string

Text represents plain text in a set of documentation.

type Type

type Type interface {
	// Alignment returns the memory alignment
	// of the type on the specified architecture.
	//
	// That is, the offset in bytes into a
	// structure at which a field of this type
	// appears must be an exact multiple of its
	// alignment. For example, if type `A` has
	// an alignment of 8, then any structure
	// fields of type `A` must have an offset
	// into the structure that is a multiple of
	// 8.
	//
	// Alignment values must be larger than
	// 0, and must be an exact power of 2.
	Alignment(Arch) int

	// Size returns the number of bytes that
	// a value of the type will consume in
	// memory.
	//
	// Size values must be an exact multiple
	// of the type's alignment, and must be
	// non-negative.
	Size(Arch) int

	// Parameter returns whether the type
	// can be passed in a syscall parameter.
	Parameter(Arch) bool

	// String returns a brief textual
	// representation for the type.
	String() string
}

Type represents any type that can be referenced in a Plan document, including complex structure types.

func Underlying

func Underlying(typ Type) Type

Underlying returns the base type, dereferencing any References if necessary.

type Value

type Value struct {
	Name Name
	Node *ast.List
	Docs Docs
}

Value represents a single value in an enumeration type.

Jump to

Keyboard shortcuts

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