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
- type Assign
- func (p *Assign) Execute(state io.State) uint
- func (p *Assign) Lower(pc uint) micro.Instruction
- func (p *Assign) RegistersRead() []io.RegisterId
- func (p *Assign) RegistersWritten() []io.RegisterId
- func (p *Assign) String(fn schema.RegisterMap) string
- func (p *Assign) Validate(fieldWidth uint, fn schema.RegisterMap) error
- type BranchInstruction
- type Call
- func (p *Call) Bus() io.Bus
- func (p *Call) Execute(state io.State) uint
- func (p *Call) Link(bus io.Bus)
- func (p *Call) Lower(pc uint) micro.Instruction
- func (p *Call) RegistersRead() []io.RegisterId
- func (p *Call) RegistersWritten() []io.RegisterId
- func (p *Call) String(fn schema.RegisterMap) string
- func (p *Call) Validate(fieldWidth uint, fn schema.RegisterMap) error
- type Expr
- type Fail
- func (p *Fail) Execute(state io.State) uint
- func (p *Fail) Lower(pc uint) micro.Instruction
- func (p *Fail) RegistersRead() []io.RegisterId
- func (p *Fail) RegistersWritten() []io.RegisterId
- func (p *Fail) String(fn schema.RegisterMap) string
- func (p *Fail) Validate(fieldWidth uint, fn schema.RegisterMap) error
- type Goto
- func (p *Goto) Bind(labels []uint)
- func (p *Goto) Execute(state io.State) uint
- func (p *Goto) Lower(pc uint) micro.Instruction
- func (p *Goto) RegistersRead() []io.RegisterId
- func (p *Goto) RegistersWritten() []io.RegisterId
- func (p *Goto) String(fn schema.RegisterMap) string
- func (p *Goto) Validate(fieldWidth uint, fn schema.RegisterMap) error
- type IfGoto
- func (p *IfGoto) Bind(labels []uint)
- func (p *IfGoto) Execute(state io.State) uint
- func (p *IfGoto) Lower(pc uint) micro.Instruction
- func (p *IfGoto) RegistersRead() []io.RegisterId
- func (p *IfGoto) RegistersWritten() []io.RegisterId
- func (p *IfGoto) String(fn schema.RegisterMap) string
- func (p *IfGoto) Validate(fieldWidth uint, fn schema.RegisterMap) error
- type IfThenElse
- func (p *IfThenElse) Execute(state io.State) uint
- func (p *IfThenElse) Lower(pc uint) micro.Instruction
- func (p *IfThenElse) RegistersRead() []io.RegisterId
- func (p *IfThenElse) RegistersWritten() []io.RegisterId
- func (p *IfThenElse) String(fn schema.RegisterMap) string
- func (p *IfThenElse) Validate(fieldWidth uint, fn schema.RegisterMap) error
- type Instruction
- type Register
- type Return
- func (p *Return) Execute(state io.State) uint
- func (p *Return) Lower(pc uint) micro.Instruction
- func (p *Return) RegistersRead() []io.RegisterId
- func (p *Return) RegistersWritten() []io.RegisterId
- func (p *Return) String(fn schema.RegisterMap) string
- func (p *Return) Validate(fieldWidth uint, fn schema.RegisterMap) error
Constants ¶
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
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.
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 (*Call) Bus ¶
Bus returns information about the bus. Observe that prior to Link being called, this will return an unlinked bus.
func (*Call) Execute ¶
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 (*Call) Link ¶
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.
type Expr ¶ added in v1.1.21
Expr represents an arbitrary expression used within an instruction.
func Constant ¶ added in v1.1.21
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
ConstantAccess constructs an expression representing an access of a labelled constant value.
func Product ¶ added in v1.1.21
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.
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
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.
type Goto ¶
type Goto struct {
Target uint
}
Goto provides an unconditional branching instruction to a given instructon.
func (*Goto) Execute ¶
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.
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) Execute ¶
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.
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 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 ¶
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.