ir

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: BSD-3-Clause Imports: 6 Imported by: 10

Documentation

Overview

Package ir provides the intermediate representation of avo programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Lines []string
}

Comment represents a multi-line comment.

func NewComment

func NewComment(lines ...string) *Comment

NewComment builds a Comment consisting of the provided lines.

type Datum

type Datum struct {
	Offset int
	Value  operand.Constant
}

Datum represents a data element at a particular offset of a data section.

func NewDatum

func NewDatum(offset int, v operand.Constant) Datum

NewDatum builds a Datum from the given constant.

func (Datum) Interval

func (d Datum) Interval() (int, int)

Interval returns the range of bytes this datum will occupy within its section.

func (Datum) Overlaps

func (d Datum) Overlaps(other Datum) bool

Overlaps returns true

type File

type File struct {
	Constraints buildtags.Constraints
	Includes    []string
	Sections    []Section
}

File represents an assembly file.

func NewFile

func NewFile() *File

NewFile initializes an empty file.

func (*File) AddSection

func (f *File) AddSection(s Section)

AddSection appends a Section to the file.

func (*File) Functions

func (f *File) Functions() []*Function

Functions returns all functions in the file.

type Function

type Function struct {
	Name       string
	Attributes attr.Attribute
	Pragmas    []Pragma
	Doc        []string
	Signature  *gotypes.Signature
	LocalSize  int

	Nodes []Node

	// LabelTarget maps from label name to the following instruction.
	LabelTarget map[Label]*Instruction

	// Register allocation.
	Allocation reg.Allocation

	// ISA is the list of required instruction set extensions.
	ISA []string
}

Function represents an assembly function.

func NewFunction

func NewFunction(name string) *Function

NewFunction builds an empty function of the given name.

func (*Function) AddComment

func (f *Function) AddComment(lines ...string)

AddComment adds comment lines to f.

func (*Function) AddInstruction

func (f *Function) AddInstruction(i *Instruction)

AddInstruction appends an instruction to f.

func (*Function) AddLabel

func (f *Function) AddLabel(l Label)

AddLabel appends a label to f.

func (*Function) AddNode

func (f *Function) AddNode(n Node)

AddNode appends a Node to f.

func (*Function) AddPragma

func (f *Function) AddPragma(directive string, args ...string)

AddPragma adds a pragma to this function.

func (*Function) AllocLocal

func (f *Function) AllocLocal(size int) operand.Mem

AllocLocal allocates size bytes in this function's stack. Returns a reference to the base pointer for the newly allocated region.

func (*Function) ArgumentBytes

func (f *Function) ArgumentBytes() int

ArgumentBytes returns the size of the arguments in bytes.

func (*Function) FrameBytes

func (f *Function) FrameBytes() int

FrameBytes returns the size of the stack frame in bytes.

func (*Function) Instructions

func (f *Function) Instructions() []*Instruction

Instructions returns just the list of instruction nodes.

func (*Function) Labels

func (f *Function) Labels() []Label

Labels returns just the list of label nodes.

func (*Function) SetSignature

func (f *Function) SetSignature(s *gotypes.Signature)

SetSignature sets the function signature.

func (*Function) Stub

func (f *Function) Stub() string

Stub returns the Go function declaration.

type Global

type Global struct {
	Symbol     operand.Symbol
	Attributes attr.Attribute
	Data       []Datum
	Size       int
}

Global represents a DATA section.

func NewGlobal

func NewGlobal(sym operand.Symbol) *Global

NewGlobal constructs an empty DATA section.

func NewStaticGlobal

func NewStaticGlobal(name string) *Global

NewStaticGlobal is a convenience for building a static DATA section.

func (*Global) AddDatum

func (g *Global) AddDatum(d Datum) error

AddDatum adds d to this data section, growing it if necessary. Errors if the datum overlaps with existing data.

func (*Global) Append

func (g *Global) Append(v operand.Constant)

Append the constant to the end of the data section.

func (*Global) Base

func (g *Global) Base() operand.Mem

Base returns a pointer to the start of the data section.

func (*Global) Grow

func (g *Global) Grow(size int)

Grow ensures that the data section has at least the given size.

type Instruction

type Instruction struct {
	Opcode   string
	Operands []operand.Op

	Inputs  []operand.Op
	Outputs []operand.Op

	IsTerminal       bool
	IsBranch         bool
	IsConditional    bool
	CancellingInputs bool

	// ISA is the list of required instruction set extensions.
	ISA []string

	// CFG.
	Pred []*Instruction
	Succ []*Instruction

	// LiveIn/LiveOut are sets of live register IDs pre/post execution.
	LiveIn  reg.MaskSet
	LiveOut reg.MaskSet
}

Instruction is a single instruction in a function.

func (Instruction) InputRegisters

func (i Instruction) InputRegisters() []reg.Register

InputRegisters returns all registers read by this instruction.

func (Instruction) IsUnconditionalBranch

func (i Instruction) IsUnconditionalBranch() bool

IsUnconditionalBranch reports whether i is an unconditional branch.

func (Instruction) OutputRegisters

func (i Instruction) OutputRegisters() []reg.Register

OutputRegisters returns all registers written by this instruction.

func (Instruction) Registers

func (i Instruction) Registers() []reg.Register

Registers returns all registers involved in the instruction.

func (Instruction) TargetLabel

func (i Instruction) TargetLabel() *Label

TargetLabel returns the label referenced by this instruction. Returns nil if no label is referenced.

type Label

type Label string

Label within a function.

type Node

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

Node is a part of a Function.

type Pragma

type Pragma struct {
	Directive string
	Arguments []string
}

Pragma represents a function compiler directive.

type Section

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

Section is a part of a file.

Jump to

Keyboard shortcuts

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