Initial QSfera import
This commit is contained in:
Generated
Vendored
+183
@@ -0,0 +1,183 @@
|
||||
// Copyright 2018 The OPA Authors. All rights reserved.
|
||||
// Use of this source code is governed by an Apache2
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package instruction
|
||||
|
||||
import (
|
||||
"github.com/open-policy-agent/opa/internal/wasm/opcode"
|
||||
"github.com/open-policy-agent/opa/internal/wasm/types"
|
||||
)
|
||||
|
||||
// !!! If you find yourself adding support for more control
|
||||
// instructions (br_table, if, ...), please adapt the
|
||||
// `withControlInstr` functions of
|
||||
// `compiler/wasm/optimizations.go`
|
||||
|
||||
// Unreachable represents a WASM unreachable instruction.
|
||||
type Unreachable struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Unreachable) Op() opcode.Opcode {
|
||||
return opcode.Unreachable
|
||||
}
|
||||
|
||||
// Nop represents a WASM no-op instruction.
|
||||
type Nop struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Nop) Op() opcode.Opcode {
|
||||
return opcode.Nop
|
||||
}
|
||||
|
||||
// Block represents a WASM block instruction.
|
||||
type Block struct {
|
||||
NoImmediateArgs
|
||||
Type *types.ValueType
|
||||
Instrs []Instruction
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction
|
||||
func (Block) Op() opcode.Opcode {
|
||||
return opcode.Block
|
||||
}
|
||||
|
||||
// BlockType returns the type of the block's return value.
|
||||
func (i Block) BlockType() *types.ValueType {
|
||||
return i.Type
|
||||
}
|
||||
|
||||
// Instructions returns the instructions contained in the block.
|
||||
func (i Block) Instructions() []Instruction {
|
||||
return i.Instrs
|
||||
}
|
||||
|
||||
// If represents a WASM if instruction.
|
||||
// NOTE(sr): we only use if with one branch so far!
|
||||
type If struct {
|
||||
NoImmediateArgs
|
||||
Type *types.ValueType
|
||||
Instrs []Instruction
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (If) Op() opcode.Opcode {
|
||||
return opcode.If
|
||||
}
|
||||
|
||||
// BlockType returns the type of the if's THEN branch.
|
||||
func (i If) BlockType() *types.ValueType {
|
||||
return i.Type
|
||||
}
|
||||
|
||||
// Instructions represents the instructions contained in the if's THEN branch.
|
||||
func (i If) Instructions() []Instruction {
|
||||
return i.Instrs
|
||||
}
|
||||
|
||||
// Loop represents a WASM loop instruction.
|
||||
type Loop struct {
|
||||
NoImmediateArgs
|
||||
Type *types.ValueType
|
||||
Instrs []Instruction
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Loop) Op() opcode.Opcode {
|
||||
return opcode.Loop
|
||||
}
|
||||
|
||||
// BlockType returns the type of the loop's return value.
|
||||
func (i Loop) BlockType() *types.ValueType {
|
||||
return i.Type
|
||||
}
|
||||
|
||||
// Instructions represents the instructions contained in the loop.
|
||||
func (i Loop) Instructions() []Instruction {
|
||||
return i.Instrs
|
||||
}
|
||||
|
||||
// Br represents a WASM br instruction.
|
||||
type Br struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Br) Op() opcode.Opcode {
|
||||
return opcode.Br
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the block index to break to.
|
||||
func (i Br) ImmediateArgs() []any {
|
||||
return []any{i.Index}
|
||||
}
|
||||
|
||||
// BrIf represents a WASM br_if instruction.
|
||||
type BrIf struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (BrIf) Op() opcode.Opcode {
|
||||
return opcode.BrIf
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the block index to break to.
|
||||
func (i BrIf) ImmediateArgs() []any {
|
||||
return []any{i.Index}
|
||||
}
|
||||
|
||||
// Call represents a WASM call instruction.
|
||||
type Call struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Call) Op() opcode.Opcode {
|
||||
return opcode.Call
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the function index.
|
||||
func (i Call) ImmediateArgs() []any {
|
||||
return []any{i.Index}
|
||||
}
|
||||
|
||||
// CallIndirect represents a WASM call_indirect instruction.
|
||||
type CallIndirect struct {
|
||||
Index uint32 // type index
|
||||
Reserved byte // zero for now
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (CallIndirect) Op() opcode.Opcode {
|
||||
return opcode.CallIndirect
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the function index.
|
||||
func (i CallIndirect) ImmediateArgs() []any {
|
||||
return []any{i.Index, i.Reserved}
|
||||
}
|
||||
|
||||
// Return represents a WASM return instruction.
|
||||
type Return struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Return) Op() opcode.Opcode {
|
||||
return opcode.Return
|
||||
}
|
||||
|
||||
// End represents the special WASM end instruction.
|
||||
type End struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (End) Op() opcode.Opcode {
|
||||
return opcode.End
|
||||
}
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// Copyright 2018 The OPA Authors. All rights reserved.
|
||||
// Use of this source code is governed by an Apache2
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package instruction defines WASM instruction types.
|
||||
package instruction
|
||||
|
||||
import (
|
||||
"github.com/open-policy-agent/opa/internal/wasm/opcode"
|
||||
"github.com/open-policy-agent/opa/internal/wasm/types"
|
||||
)
|
||||
|
||||
// NoImmediateArgs indicates the instruction has no immediate arguments.
|
||||
type NoImmediateArgs struct {
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the immedate arguments of an instruction.
|
||||
func (NoImmediateArgs) ImmediateArgs() []any {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Instruction represents a single WASM instruction.
|
||||
type Instruction interface {
|
||||
Op() opcode.Opcode
|
||||
ImmediateArgs() []any
|
||||
}
|
||||
|
||||
// StructuredInstruction represents a structured control instruction like br_if.
|
||||
type StructuredInstruction interface {
|
||||
Instruction
|
||||
BlockType() *types.ValueType
|
||||
Instructions() []Instruction
|
||||
}
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
// Copyright 2019 The OPA Authors. All rights reserved.
|
||||
// Use of this source code is governed by an Apache2
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package instruction
|
||||
|
||||
import "github.com/open-policy-agent/opa/internal/wasm/opcode"
|
||||
|
||||
// I32Load represents the WASM i32.load instruction.
|
||||
type I32Load struct {
|
||||
Offset int32
|
||||
Align int32 // expressed as a power of two
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Load) Op() opcode.Opcode {
|
||||
return opcode.I32Load
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the static offset and alignment operands.
|
||||
func (i I32Load) ImmediateArgs() []any {
|
||||
return []any{i.Align, i.Offset}
|
||||
}
|
||||
|
||||
// I32Store represents the WASM i32.store instruction.
|
||||
type I32Store struct {
|
||||
Offset int32
|
||||
Align int32 // expressed as a power of two
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Store) Op() opcode.Opcode {
|
||||
return opcode.I32Store
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the static offset and alignment operands.
|
||||
func (i I32Store) ImmediateArgs() []any {
|
||||
return []any{i.Align, i.Offset}
|
||||
}
|
||||
Generated
Vendored
+199
@@ -0,0 +1,199 @@
|
||||
// Copyright 2018 The OPA Authors. All rights reserved.
|
||||
// Use of this source code is governed by an Apache2
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package instruction
|
||||
|
||||
import (
|
||||
"github.com/open-policy-agent/opa/internal/wasm/opcode"
|
||||
)
|
||||
|
||||
// I32Const represents the WASM i32.const instruction.
|
||||
type I32Const struct {
|
||||
Value int32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Const) Op() opcode.Opcode {
|
||||
return opcode.I32Const
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the i32 value to push onto the stack.
|
||||
func (i I32Const) ImmediateArgs() []any {
|
||||
return []any{i.Value}
|
||||
}
|
||||
|
||||
// I64Const represents the WASM i64.const instruction.
|
||||
type I64Const struct {
|
||||
Value int64
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I64Const) Op() opcode.Opcode {
|
||||
return opcode.I64Const
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the i64 value to push onto the stack.
|
||||
func (i I64Const) ImmediateArgs() []any {
|
||||
return []any{i.Value}
|
||||
}
|
||||
|
||||
// F32Const represents the WASM f32.const instruction.
|
||||
type F32Const struct {
|
||||
Value int32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (F32Const) Op() opcode.Opcode {
|
||||
return opcode.F32Const
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the f32 value to push onto the stack.
|
||||
func (i F32Const) ImmediateArgs() []any {
|
||||
return []any{i.Value}
|
||||
}
|
||||
|
||||
// F64Const represents the WASM f64.const instruction.
|
||||
type F64Const struct {
|
||||
Value float64
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (F64Const) Op() opcode.Opcode {
|
||||
return opcode.F64Const
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the f64 value to push onto the stack.
|
||||
func (i F64Const) ImmediateArgs() []any {
|
||||
return []any{i.Value}
|
||||
}
|
||||
|
||||
// I32Eqz represents the WASM i32.eqz instruction.
|
||||
type I32Eqz struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Eqz) Op() opcode.Opcode {
|
||||
return opcode.I32Eqz
|
||||
}
|
||||
|
||||
// I32Eq represents the WASM i32.eq instruction.
|
||||
type I32Eq struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Eq) Op() opcode.Opcode {
|
||||
return opcode.I32Eq
|
||||
}
|
||||
|
||||
// I32Ne represents the WASM i32.ne instruction.
|
||||
type I32Ne struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Ne) Op() opcode.Opcode {
|
||||
return opcode.I32Ne
|
||||
}
|
||||
|
||||
// I32GtS represents the WASM i32.gt_s instruction.
|
||||
type I32GtS struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32GtS) Op() opcode.Opcode {
|
||||
return opcode.I32GtS
|
||||
}
|
||||
|
||||
// I32GeS represents the WASM i32.ge_s instruction.
|
||||
type I32GeS struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32GeS) Op() opcode.Opcode {
|
||||
return opcode.I32GeS
|
||||
}
|
||||
|
||||
// I32LtS represents the WASM i32.lt_s instruction.
|
||||
type I32LtS struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32LtS) Op() opcode.Opcode {
|
||||
return opcode.I32LtS
|
||||
}
|
||||
|
||||
// I32LeS represents the WASM i32.le_s instruction.
|
||||
type I32LeS struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32LeS) Op() opcode.Opcode {
|
||||
return opcode.I32LeS
|
||||
}
|
||||
|
||||
// I32Add represents the WASM i32.add instruction.
|
||||
type I32Add struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Add) Op() opcode.Opcode {
|
||||
return opcode.I32Add
|
||||
}
|
||||
|
||||
// I64Add represents the WASM i64.add instruction.
|
||||
type I64Add struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I64Add) Op() opcode.Opcode {
|
||||
return opcode.I64Add
|
||||
}
|
||||
|
||||
// F32Add represents the WASM f32.add instruction.
|
||||
type F32Add struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (F32Add) Op() opcode.Opcode {
|
||||
return opcode.F32Add
|
||||
}
|
||||
|
||||
// F64Add represents the WASM f64.add instruction.
|
||||
type F64Add struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (F64Add) Op() opcode.Opcode {
|
||||
return opcode.F64Add
|
||||
}
|
||||
|
||||
// I32Mul represents the WASM i32.mul instruction.
|
||||
type I32Mul struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Mul) Op() opcode.Opcode {
|
||||
return opcode.I32Mul
|
||||
}
|
||||
|
||||
// I32Sub represents the WASM i32.sub instruction.
|
||||
type I32Sub struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (I32Sub) Op() opcode.Opcode {
|
||||
return opcode.I32Sub
|
||||
}
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
// Copyright 2021 The OPA Authors. All rights reserved.
|
||||
// Use of this source code is governed by an Apache2
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package instruction
|
||||
|
||||
import (
|
||||
"github.com/open-policy-agent/opa/internal/wasm/opcode"
|
||||
)
|
||||
|
||||
// Drop reprsents a WASM drop instruction.
|
||||
type Drop struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Drop) Op() opcode.Opcode {
|
||||
return opcode.Drop
|
||||
}
|
||||
|
||||
// Select reprsents a WASM select instruction.
|
||||
type Select struct {
|
||||
NoImmediateArgs
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (Select) Op() opcode.Opcode {
|
||||
return opcode.Select
|
||||
}
|
||||
Generated
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
// Copyright 2018 The OPA Authors. All rights reserved.
|
||||
// Use of this source code is governed by an Apache2
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package instruction
|
||||
|
||||
import "github.com/open-policy-agent/opa/internal/wasm/opcode"
|
||||
|
||||
// GetLocal represents the WASM get_local instruction.
|
||||
type GetLocal struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (GetLocal) Op() opcode.Opcode {
|
||||
return opcode.GetLocal
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the index of the local variable to push onto the stack.
|
||||
func (i GetLocal) ImmediateArgs() []any {
|
||||
return []any{i.Index}
|
||||
}
|
||||
|
||||
// SetLocal represents the WASM set_local instruction.
|
||||
type SetLocal struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (SetLocal) Op() opcode.Opcode {
|
||||
return opcode.SetLocal
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the index of the local variable to set with the top of
|
||||
// the stack.
|
||||
func (i SetLocal) ImmediateArgs() []any {
|
||||
return []any{i.Index}
|
||||
}
|
||||
|
||||
// TeeLocal represents the WASM tee_local instruction.
|
||||
type TeeLocal struct {
|
||||
Index uint32
|
||||
}
|
||||
|
||||
// Op returns the opcode of the instruction.
|
||||
func (TeeLocal) Op() opcode.Opcode {
|
||||
return opcode.TeeLocal
|
||||
}
|
||||
|
||||
// ImmediateArgs returns the index of the local variable to "tee" with the top of
|
||||
// the stack (like set, but retaining the top of the stack).
|
||||
func (i TeeLocal) ImmediateArgs() []any {
|
||||
return []any{i.Index}
|
||||
}
|
||||
Reference in New Issue
Block a user