ir

package
v0.0.0-...-3948e75 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package ir defines an intermediate representation for multi-precision arithmetic.

Index

Constants

This section is empty.

Variables

View Source
var Discard = Register("_")

Discard is a special register to ignore an output of an instruction.

View Source
var Zero = Constant(0)

Zero is the zero constant.

Functions

func FormatInstruction

func FormatInstruction(i Instruction) string

FormatInstruction returns a string representation of the instruction.

Types

type ADD

type ADD struct {
	X        Operand
	Y        Operand
	CarryIn  Operand
	Sum      Register
	CarryOut Register
}

ADD is an add with carry instruction.

func (ADD) Operands

func (i ADD) Operands() []Operand

type CMOV

type CMOV struct {
	Source      Operand
	Destination Register
	Flag        Operand
	Equals      Flag
}

CMOV is a conditional move.

func (CMOV) Operands

func (i CMOV) Operands() []Operand

type Constant

type Constant uint64

Constant is a constant operand.

func (Constant) String

func (c Constant) String() string

type Constants

type Constants []Constant

Constants is a multi-precision integer formed of constants.

func NewConstantsFromInt

func NewConstantsFromInt(x *big.Int, s uint) Constants

NewConstantsFromInt represents x as s-bit integers.

func (Constants) Len

func (c Constants) Len() int

func (Constants) Limb

func (c Constants) Limb(i int) Operand

func (Constants) Limbs

func (c Constants) Limbs() Operands

type Flag

type Flag uint64

Flag is a single-bit constant operand.

func (Flag) String

func (f Flag) String() string

type Function

type Function struct {
	*Program

	Name      string
	Signature *Signature
}

type Instruction

type Instruction interface {
	Operands() []Operand
	// contains filtered or unexported methods
}

Instruction in the intermediate representation.

type Int

type Int interface {
	Len() int
	Limb(int) Operand
	Limbs() Operands
}

Int represents a multi-precision integer.

type Integer

type Integer struct {
	K uint // number of limbs
}

Integer is a multi-precision integer type.

type MOV

type MOV struct {
	Source      Operand
	Destination Register
}

MOV is a move instruction.

func (MOV) Operands

func (i MOV) Operands() []Operand

type MUL

type MUL struct {
	X    Operand
	Y    Operand
	High Register
	Low  Register
}

MUL is a multiply instruction providing lower and upper parts of the result.

func (MUL) Operands

func (i MUL) Operands() []Operand

type Module

type Module struct {
	Sections []Section
}

type Operand

type Operand interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Operand is an interface for instruction operands.

func Limb

func Limb(x Int, i int) Operand

Limb returns the i'th limb of x, or zero if i ⩾ x.Len().

type Operands

type Operands []Operand

Operands is a multi-precision integer formed of operands.

func Clone

func Clone(x Int) Operands

Clone returns a copy of x.

func Extend

func Extend(x Int, limbs ...Operand) Operands

Extend returns a new integer with limbs appended to the end.

func (Operands) Len

func (o Operands) Len() int

func (Operands) Limb

func (o Operands) Limb(i int) Operand

func (Operands) Limbs

func (o Operands) Limbs() Operands

type Program

type Program struct {
	Instructions []Instruction
}

Program is a sequence of instructions.

func (*Program) String

func (p *Program) String() string

type Register

type Register string

Register is a machine word operand.

func SelectRegisters

func SelectRegisters(ops []Operand) []Register

SelectRegisters selects the registers from the list of operands.

func (Register) String

func (r Register) String() string

type Registers

type Registers []Register

Registers is a multi-precision integer formed of registers.

func NewRegisters

func NewRegisters(prefix string, k uint) Registers

func (Registers) Len

func (r Registers) Len() int

func (Registers) Limb

func (r Registers) Limb(i int) Operand

func (Registers) Limbs

func (r Registers) Limbs() Operands

type SHL

type SHL struct {
	X      Operand
	Shift  Constant
	Result Register
}

SHL is a shift left instruction.

func (SHL) Operands

func (i SHL) Operands() []Operand

type SHR

type SHR struct {
	X      Operand
	Shift  Constant
	Result Register
}

SHR is a shift right instruction.

func (SHR) Operands

func (i SHR) Operands() []Operand

type SUB

type SUB struct {
	X         Operand
	Y         Operand
	BorrowIn  Operand
	Diff      Register
	BorrowOut Register
}

SUB is an subtract with borrow instruction.

func (SUB) Operands

func (i SUB) Operands() []Operand

type Section

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

type Signature

type Signature struct {
	Params  []*Var
	Results []*Var
}

func (*Signature) Param

func (s *Signature) Param(name string) *Var

Param looks up a parameter by name, returning nil if not found.

func (*Signature) Result

func (s *Signature) Result(name string) *Var

Result looks up a result by name, returning nil if not found.

func (*Signature) Var

func (s *Signature) Var(name string) *Var

Var looks up a variable among parameters and results, returning nil if not found.

func (*Signature) Vars

func (s *Signature) Vars() []*Var

Vars returns all variables in s, with results appearing before parameters.

type Type

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

type Var

type Var struct {
	Name string
	Type Type
}

func NewVar

func NewVar(name string, t Type) *Var

func NewVars

func NewVars(t Type, names ...string) []*Var

Jump to

Keyboard shortcuts

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