ir

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Overview

Package ir declares an intermediate representation for acc programs.

Index

Constants

This section is empty.

Variables

View Source
var One = Index(0)

One is the first element in the addition chain, which by definition always has the value 1.

Functions

func HasInput

func HasInput(op Op, idx int) bool

HasInput reports whether the given operation takes idx as an input.

Types

type Add

type Add struct {
	X, Y *Operand
}

Add is an addition operation.

func (Add) Clone

func (a Add) Clone() Op

Clone returns a copy of the operation.

func (Add) Inputs

func (a Add) Inputs() []*Operand

Inputs returns the addends.

func (Add) String

func (a Add) String() string

type Double

type Double struct {
	X *Operand
}

Double is a double operation.

func (Double) Clone

func (d Double) Clone() Op

Clone returns a copy of the operation.

func (Double) Inputs

func (d Double) Inputs() []*Operand

Inputs returns the operand.

func (Double) String

func (d Double) String() string

type Instruction

type Instruction struct {
	Output *Operand
	Op     Op
}

Instruction assigns the result of an operation to an operand.

func (Instruction) Clone

func (i Instruction) Clone() *Instruction

Clone returns a copy of the instruction.

func (Instruction) Operands

func (i Instruction) Operands() []*Operand

Operands returns the input and output operands.

func (Instruction) String

func (i Instruction) String() string

type Op

type Op interface {
	Inputs() []*Operand
	Clone() Op
	String() string
}

Op is an operation.

type Operand

type Operand struct {
	Identifier string
	Index      int
}

Operand represents an element of an addition chain, with an optional identifier.

func Index

func Index(i int) *Operand

Index builds an unnamed operand for index i.

func NewOperand

func NewOperand(name string, i int) *Operand

NewOperand builds a named operand for index i.

func (Operand) Clone

func (o Operand) Clone() *Operand

Clone returns a copy of the operand.

func (Operand) String

func (o Operand) String() string

type Program

type Program struct {
	Instructions []*Instruction

	// Pass/analysis results.
	Operands    map[int]*Operand
	ReadCount   map[int]int
	Program     addchain.Program
	Chain       addchain.Chain
	Temporaries []string
}

Program is a sequence of acc instructions.

func (*Program) AddInstruction

func (p *Program) AddInstruction(i *Instruction)

AddInstruction appends an instruction to the program.

func (Program) Clone

func (p Program) Clone() *Program

Clone returns a copy of p. Pass results are not copied and would need to be rerun on the clone.

func (Program) Output

func (p Program) Output() *Operand

Output returns the output of the last instruction.

func (Program) String

func (p Program) String() string

type Shift

type Shift struct {
	X *Operand
	S uint
}

Shift represents a shift-left operation, equivalent to repeat doubling.

func (Shift) Clone

func (s Shift) Clone() Op

Clone returns a copy of the operation.

func (Shift) Inputs

func (s Shift) Inputs() []*Operand

Inputs returns the operand to be shifted.

func (Shift) String

func (s Shift) String() string

Jump to

Keyboard shortcuts

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