parser

package
v0.0.0-...-dd4b663 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package parser implements a SPIR-V assembly parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsResult

func IsResult(k *schema.OperandKind) bool

IsResult returns true if k is used to store the result of an instruction.

Types

type Diagnostic

type Diagnostic struct {
	Range    Range
	Severity Severity
	Message  string
}

Diagnostic holds a single diagnostic message that was generated while parsing.

type Identifier

type Identifier struct {
	Definition *Instruction // where the identifier was defined
	References []*Token     // all the places the identifier was referenced
}

Identifier describes a single, unique SPIR-V identifier (i.e. %32)

type Instruction

type Instruction struct {
	Tokens   []*Token       // all the tokens that make up the instruction
	Result   *Token         // the token that represents the result of the instruction, or nil
	Operands []*Operand     // the operands of the instruction
	Range    Range          // the textual range of the instruction
	Opcode   *schema.Opcode // the opcode for the instruction
}

Instruction describes a single instruction instance

type Operand

type Operand struct {
	Name       string              // name of the operand
	Kind       *schema.OperandKind // kind of the operand
	Tokens     []*Token            // all the tokens that make up the operand
	Parameters []*Operand          // all the parameters for the operand
}

Operand describes a single operand instance

type Position

type Position struct {
	Line, Column int
}

Position holds a line and column position in a text file.

func (Position) GreaterThan

func (p Position) GreaterThan(o Position) bool

GreaterThan returns true iff o is greater than p.

func (Position) IsValid

func (p Position) IsValid() bool

IsValid returns true if the position has a line and column greater than 1.

func (Position) LessThan

func (p Position) LessThan(o Position) bool

LessThan returns true iff o is before p.

func (Position) String

func (p Position) String() string

type Range

type Range struct {
	Start Position
	End   Position
}

Range represents an interval in a text file.

func (Range) Contains

func (r Range) Contains(p Position) bool

Contains returns true if p is in r.

func (Range) String

func (r Range) String() string

func (Range) Text

func (r Range) Text(lines []string) string

Text returns the text for the given Range in the provided lines.

type Results

type Results struct {
	Lines       []string
	Tokens      []*Token
	Diagnostics []Diagnostic
	Identifiers map[string]*Identifier // identifiers by name
	Mappings    map[*Token]interface{} // tokens to semantic map
}

Results holds the output of Parse().

func Parse

func Parse(source string) (Results, error)

Parse parses the SPIR-V assembly string source, returning the parse results.

type Severity

type Severity int

Severity is an enumerator of diagnostic severities

const (
	SeverityError Severity = iota
	SeverityWarning
	SeverityInformation
	SeverityHint
)

Severity levels

type Token

type Token struct {
	Type  Type
	Range Range
}

Token represents a single lexed token.

func (Token) String

func (t Token) String() string

func (Token) Text

func (t Token) Text(lines []string) string

Text returns the tokens text from the source.

type Type

type Type int

Type is an enumerator of token types.

const (
	Ident  Type = iota // Foo
	PIdent             // %32, %foo
	Integer
	Float
	String
	Operator
	Comment
	Newline
)

Type enumerators

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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