Documentation
¶
Overview ¶
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
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
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
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
- Variables
- func BitwiseAnd[W vm.Word[W]](values ...W) W
- func BitwiseOr[W vm.Word[W]](values ...W) W
- func BitwiseShl[W vm.Word[W]](bitwidth uint, values ...W) W
- func BitwiseShr[W vm.Word[W]](values ...W) W
- func BitwiseXor[W vm.Word[W]](values ...W) W
- func Product[W vm.Word[W]](bitwidth uint, values ...W) (W, bool)
- func Quotient[W vm.Word[W]](values ...W) W
- func Remainder[W vm.Word[W]](values ...W) W
- func Subtract[W vm.Word[W]](bitwidth uint, values ...W) (W, bool)
- func Sum[W vm.Word[W]](bitwidth uint, values ...W) (W, bool)
- type Bytecode
- type BytecodeVector
- type Compiler
- type Condition
- type Config
- func (p Config) FastMode(flag bool) Config
- func (p Config) Field(field field.Config) Config
- func (p Config) GetField() field.Config
- func (p Config) GetMaxStaticDepth() uint
- func (p Config) Inlining(flag bool) Config
- func (p Config) IsFastMode() bool
- func (p Config) MaxStaticDepth(depth uint) Config
- func (p Config) SplitRegisters(flag bool) Config
- func (p Config) Verbose(flag bool) Config
- func (p Config) Word(word vm.WordConfig) Config
- type ConstantEvaluator
- type Declaration
- type Expr
- type LVal
- type MultiTranslator
- type RegisterId
- type Stmt
- type StmtCompiler
- type UnitTranslator
- type VariableDescriptor
Constants ¶
const DEFAULT_MAX_STATIC_DEPTH uint = 65536
DEFAULT_MAX_STATIC_DEPTH is the default maximum depth (i.e. number of rows) of static tables, used when no override is supplied. It is 2^16.
Variables ¶
var DEFAULT_CONFIG = Config{ // contains filtered or unexported fields }
DEFAULT_CONFIG is the configuration used when no overrides are supplied. Vectorisation is enabled, which matches the behaviour expected by the downstream prover; callers wanting to disable individual passes (for debugging, for example) should derive a custom Config via the chainable setters below.
Functions ¶
func BitwiseAnd ¶
BitwiseAnd computes the bitwise AND of a set of words.
func BitwiseShl ¶
BitwiseShl computes a left-shift chain over a set of words.
func BitwiseShr ¶
BitwiseShr computes a right-shift chain over a set of words.
func BitwiseXor ¶
BitwiseXor computes the bitwise XOR of a set of words.
Types ¶
type Bytecode ¶ added in v1.2.21
Bytecode provides a convenient alias for a single bytecode instruction emitted by codegen.
type BytecodeVector ¶ added in v1.2.21
type BytecodeVector = vm.BytecodeVector[vm.Uint]
BytecodeVector provides a convenient alias for a vector (trace line) of bytecode instructions.
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler is responsible for compiling high-level programs into low-level machines which can be used (for example) to execute this program with some given inputs. A compile is configurable in certain aspects.
func NewCompiler ¶
NewCompiler constructs a code generator parameterised by a configuration, the resolved type environment, and the source maps recorded by earlier pipeline stages. The configuration controls optional passes such as vectorisation; cfg=DEFAULT_CONFIG matches the prover-facing defaults. The environment supplies type information needed when lowering expressions (e.g. bit-widths of named types), and the source maps allow generated instructions and any errors raised during compilation to be tied back to their originating source positions.
func (*Compiler) Compile ¶
func (p *Compiler) Compile(declarations []Declaration) (vm.Program[vm.Uint], []source.SyntaxError)
Compile attempts to compile a given high-level program into a low-level machine which can be used (for example) to execute this program with some given inputs.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config captures the tunable aspects of the ZkC code generator. Instances are immutable: each setter (e.g. Vectorize) returns a new Config rather than mutating the receiver, so a Config can be safely shared between concurrent compilations.
func (Config) FastMode ¶
FastMode returns a copy of this Config with fast-mode execution enabled (flag=true) or disabled (flag=false).
func (Config) GetMaxStaticDepth ¶ added in v1.2.21
GetMaxStaticDepth returns the maximum depth (ie nb of rows) of static tables.
func (Config) Inlining ¶
Inlining returns a copy of this Config in which function inlining is either enabled (flag=true) or disabled (flag=false). When enabled, functions marked with the #[inline] annotation are inlined at their call sites.
func (Config) IsFastMode ¶ added in v1.2.21
IsFastMode determines whether or not fast mode is enabled.
func (Config) MaxStaticDepth ¶ added in v1.2.21
MaxStaticDepth sets the maximum depth (ie nb of rows) of static tables.
func (Config) SplitRegisters ¶
SplitRegisters returns a copy of this Config in which register splitting is either enabled (flag=true) or disabled (flag=false).
type ConstantEvaluator ¶
type ConstantEvaluator struct {
// contains filtered or unexported fields
}
ConstantEvaluator provides machinery for evaluating compile-time constant expression using the provided declaration list and type environment. It is used during function code generation and when initialising static memory contents, and also during typing (for array type size expressions). As a result of the latter, it must be robust against error. That is, it may be called on a malformed expression and, hence, it must handle this gracefully.
func NewConstantEvaluator ¶
func NewConstantEvaluator(field field.Config, env data.ResolvedEnvironment, declarations ...Declaration, ) ConstantEvaluator
NewConstantEvaluator constructs a new constant evaluator.
type Declaration ¶
type Declaration = decl.Declaration[symbol.Resolved]
Declaration represents a declaration which can contain macro instructions and where external identifiers are otherwise resolved. As such, it should not be possible that such a declaration refers to unknown (or otherwise incorrect) external components.
type MultiTranslator ¶
type MultiTranslator[T any] = func(T, []uint, []RegisterId) []Bytecode
MultiTranslator is for multi-way instructions which cannot target a vector instruction.
type RegisterId ¶ added in v1.2.21
type RegisterId = vm.RegisterId
RegisterId is the register identifier used throughout codegen. It is the bytecode-layer RegisterId, so compiled instructions need no register-type conversion.
type StmtCompiler ¶
type StmtCompiler struct {
// contains filtered or unexported fields
}
StmtCompiler provides a working environment for compiling individual statements within a given function. For example, it provides the ability to allocate new temporary registers as required.
type UnitTranslator ¶
type UnitTranslator[T any] = func(T, uint, []uint, RegisterId) []Bytecode
UnitTranslator is for unit instructions which cannot target a vector instruction.
type VariableDescriptor ¶
type VariableDescriptor = variable.Descriptor[symbol.Resolved]
VariableDescriptor represents a descriptor whose external identifiers are otherwise resolved. As such, it should not be possible that such a declaration refers to unknown (or otherwise incorrect) external components.