eval

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: 3 Imported by: 0

Documentation

Overview

Package eval provides an evaluator for arithmetic intermediate representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator evaluates an arithmetic program.

func NewEvaluator

func NewEvaluator(proc Processor) *Evaluator

NewEvaluator constructs an evaluator with empty state.

func (*Evaluator) Execute

func (e *Evaluator) Execute(p *ir.Program) error

Execute the program p.

func (*Evaluator) Register

func (e *Evaluator) Register(r ir.Register) (Value, error)

Register returns the value in the given register.

func (*Evaluator) SetRegister

func (e *Evaluator) SetRegister(r ir.Register, x Value)

SetRegister sets register r to value x.

type Processor

type Processor interface {
	// Bits returns the word size of the processor.
	Bits() uint
	// Const builds the n-bit constant with value x.
	Const(x uint64, n uint) Value
	// ITE returns x if l≡r else y.
	ITE(l, r, x, y Value) Value
	// ADD is addition with carry in/out.
	ADD(x, y, cin Value) (sum, cout Value)
	// SUB is subtraction with borrow in/out.
	SUB(x, y, bin Value) (diff, bout Value)
	// MUL is multiply with upper/lower parts of the result.
	MUL(x, y Value) (hi, lo Value)
	// SHL shifts left by s.
	SHL(x Value, s uint) Value
	// SHR shifts right by s.
	SHR(x Value, s uint) Value
	// Errors returns any accumulated errors.
	Errors() []error
}

Processor is an implementation of the arithmetic instruction set.

type Value

type Value interface {
	// Bits returns the number of bits required to represent the value.
	Bits() uint
}

Value is a value stored in a register.

Directories

Path Synopsis
Package m64 provides a 64-bit arithmetic evaluator.
Package m64 provides a 64-bit arithmetic evaluator.

Jump to

Keyboard shortcuts

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