macro

package
v1.1.23 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// EQ indicates an equality condition
	EQ uint8 = 0
	// NEQ indicates a non-equality condition
	NEQ uint8 = 1
	// LT indicates a less-than condition
	LT uint8 = 2
	// GT indicates a greater-than condition
	GT uint8 = 3
	// LTEQ indicates a less-than-or-equals condition
	LTEQ uint8 = 4
	// GTEQ indicates a greater-than-or-equals condition
	GTEQ uint8 = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Assign added in v1.1.21

type Assign struct {
	// Target registers for assignment
	Targets []io.RegisterId
	// Source expresion for assignment
	Source Expr
}

Assign represents a generic assignment of the following form:

tn, .., t0 := e

Here, t0 .. tn are the *target registers*, of which tn is the *most significant*. These must be disjoint as we cannot assign simultaneously to the same register. Likewise, e is the source expression. For example, consider this case:

c, r0 := r1 + 1

Suppose that r0 and r1 are 16bit registers, whilst c is a 1bit register. The result of r1 + 1 occupies 17bits, of which the first 16 are written to r0 with the most significant (i.e. 16th) bit written to c. Thus, in this particular example, c represents a carry flag.

func (*Assign) Execute added in v1.1.21

func (p *Assign) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (*Assign) Lower added in v1.1.21

func (p *Assign) Lower(pc uint) micro.Instruction

Lower this instruction into a exactly one more micro instruction.

func (*Assign) RegistersRead added in v1.1.21

func (p *Assign) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*Assign) RegistersWritten added in v1.1.21

func (p *Assign) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*Assign) String added in v1.1.21

func (p *Assign) String(fn schema.RegisterMap) string

func (*Assign) Validate added in v1.1.21

func (p *Assign) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction is correctly balanced.

type BranchInstruction

type BranchInstruction interface {
	// Bind any labels contained within this instruction using the given label map.
	Bind(labels []uint)
}

BranchInstruction captures those instructions which may branch to some location.

type Call

type Call struct {
	// Bus identifies the relevant IoBus for this instruction.
	IoBus io.Bus
	// Target registers for addition
	Targets []io.RegisterId
	// Source expressions (i.e. arguments) for call
	Sources []Expr
}

Call represents a function call providing one or more arguments and accepting zero or more values in return. A function call requires a "bus" to read and write its arguments / returns. A bus is a set of dedicated registers providing an I/O communication channel to a given peripheral (in this case, another function).

func NewCall

func NewCall(bus io.Bus, targets []io.RegisterId, sources []Expr) *Call

NewCall constructs a new call instruction.

func (*Call) Bus

func (p *Call) Bus() io.Bus

Bus returns information about the bus. Observe that prior to Link being called, this will return an unlinked bus.

func (*Call) Execute

func (p *Call) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (p *Call) Link(bus io.Bus)

Link links the bus. Observe that this can only be called once on any given instruction.

func (*Call) Lower

func (p *Call) Lower(pc uint) micro.Instruction

Lower this instruction into a exactly one more micro instruction.

func (*Call) RegistersRead

func (p *Call) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*Call) RegistersWritten

func (p *Call) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*Call) String

func (p *Call) String(fn schema.RegisterMap) string

func (*Call) Validate

func (p *Call) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction well-formed.

type Expr added in v1.1.21

type Expr = expr.Expr

Expr represents an arbitrary expression used within an instruction.

func Constant added in v1.1.21

func Constant(constant big.Int, base uint) Expr

Constant constructs an expression representing a constant value, along with a base (which is used for pretty printing, etc).

func ConstantAccess added in v1.1.22

func ConstantAccess(constant string) Expr

ConstantAccess constructs an expression representing an access of a labelled constant value.

func Product added in v1.1.21

func Product(exprs ...Expr) Expr

Product constructs an expression representing the product of one or more values.

func RegisterAccess added in v1.1.21

func RegisterAccess(reg io.RegisterId) Expr

RegisterAccess constructs an expression representing a register access.

func Subtract added in v1.1.21

func Subtract(exprs ...Expr) Expr

Subtract constructs an expression representing the subtraction of one or more values.

func Sum added in v1.1.21

func Sum(exprs ...Expr) Expr

Sum constructs an expression representing the sum of one or more values.

type Fail added in v1.1.17

type Fail struct {
	// dummy is included to force Return structs to be stored in the heap.
	//nolint
	Dummy uint
}

Fail signals an exceptional return from the enclosing function.

func (*Fail) Execute added in v1.1.17

func (p *Fail) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (*Fail) Lower added in v1.1.17

func (p *Fail) Lower(pc uint) micro.Instruction

Lower this instruction into a exactly one more micro instruction.

func (*Fail) RegistersRead added in v1.1.17

func (p *Fail) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*Fail) RegistersWritten added in v1.1.17

func (p *Fail) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*Fail) String added in v1.1.17

func (p *Fail) String(fn schema.RegisterMap) string

func (*Fail) Validate added in v1.1.17

func (p *Fail) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction is correctly balanced.

type Goto

type Goto struct {
	Target uint
}

Goto provides an unconditional branching instruction to a given instructon.

func (*Goto) Bind

func (p *Goto) Bind(labels []uint)

Bind any labels contained within this instruction using the given label map.

func (*Goto) Execute

func (p *Goto) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (*Goto) Lower

func (p *Goto) Lower(pc uint) micro.Instruction

Lower this instruction into a exactly one more micro instruction.

func (*Goto) RegistersRead

func (p *Goto) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*Goto) RegistersWritten

func (p *Goto) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*Goto) String

func (p *Goto) String(fn schema.RegisterMap) string

func (*Goto) Validate

func (p *Goto) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction is correctly balanced.

type IfGoto

type IfGoto struct {
	// Cond indicates the condition
	Cond uint8
	// Left and right comparisons
	Left, Right io.RegisterId
	// Constant value (when rhs is unused)
	Constant big.Int
	// Constant label
	Label string
	// Target identifies target PC
	Target uint
}

IfGoto describes a conditional branch, which is either jeq ("Jump if equal") or jne ("Jump if not equal"). This has two variants: register-register; and, register-constant. The latter is indiciated when the right register is marked as UNUSED.

func (*IfGoto) Bind

func (p *IfGoto) Bind(labels []uint)

Bind any labels contained within this instruction using the given label map.

func (*IfGoto) Execute

func (p *IfGoto) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (*IfGoto) Lower

func (p *IfGoto) Lower(pc uint) micro.Instruction

Lower this (macro) instruction into a sequence of one or more micro instructions.

func (*IfGoto) RegistersRead

func (p *IfGoto) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*IfGoto) RegistersWritten

func (p *IfGoto) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*IfGoto) String

func (p *IfGoto) String(fn schema.RegisterMap) string

func (*IfGoto) Validate

func (p *IfGoto) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction is correctly balanced.

type IfThenElse added in v1.1.22

type IfThenElse struct {
	Targets []io.RegisterId
	// Cond indicates the condition
	Cond uint8
	// Left-hand side
	Left io.RegisterId
	// Right-hand side
	Right big.Int
	// Then/Else branches
	Then, Else big.Int
}

IfThenElse represents a ternary operation.

func (*IfThenElse) Execute added in v1.1.22

func (p *IfThenElse) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (*IfThenElse) Lower added in v1.1.22

func (p *IfThenElse) Lower(pc uint) micro.Instruction

Lower this instruction into a exactly one more micro instruction.

func (*IfThenElse) RegistersRead added in v1.1.22

func (p *IfThenElse) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*IfThenElse) RegistersWritten added in v1.1.22

func (p *IfThenElse) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*IfThenElse) String added in v1.1.22

func (p *IfThenElse) String(fn schema.RegisterMap) string

func (*IfThenElse) Validate added in v1.1.22

func (p *IfThenElse) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction is correctly balanced.

type Instruction

type Instruction interface {
	io.Instruction[Instruction]
	// Lower this (macro) instruction into a sequence of one or more micro
	// instructions.
	Lower(pc uint) micro.Instruction
}

Instruction provides an abstract notion of a macro "machine instruction". Here, macro is intended to imply that the instruction may break down into multiple underlying "micro instructions".

type Register

type Register = io.Register

Register is an alias for insn.Register

type Return

type Return struct {
	// dummy is included to force Return structs to be stored in the heap.
	//nolint
	Dummy uint
}

Return signals a return from the enclosing function.

func (*Return) Execute

func (p *Return) Execute(state io.State) uint

Execute this instruction with the given local and global state. The next program counter position is returned, or io.RETURN if the enclosing function has terminated (i.e. because a return instruction was encountered).

func (*Return) Lower

func (p *Return) Lower(pc uint) micro.Instruction

Lower this instruction into a exactly one more micro instruction.

func (*Return) RegistersRead

func (p *Return) RegistersRead() []io.RegisterId

RegistersRead returns the set of registers read by this instruction.

func (*Return) RegistersWritten

func (p *Return) RegistersWritten() []io.RegisterId

RegistersWritten returns the set of registers written by this instruction.

func (*Return) String

func (p *Return) String(fn schema.RegisterMap) string

func (*Return) Validate

func (p *Return) Validate(fieldWidth uint, fn schema.RegisterMap) error

Validate checks whether or not this instruction is correctly balanced.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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