mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
2e122c9e69
* wasm: read/write custom sections (incl. dwarf)
I've extended the roundtrip OPA test to have some assertions
on custom sections that work for both debug and non-debug
wasm builds.
Without debugging enabled, we had still been stripping the
`names` and `producers` sections. This changes therefore
increases the size of wasm modules. For a simple policy,
package test
default allow = false
allow {
input.foo == "bar"
}
the size generated is 544K (master) vs 620K (this commit).
With debugging enabled (and the opa binary rebuilt), the
size becomes 6.1M.
* wasm/encoding: treat 'name' custom section separately
This roundtrips module, functions, and locals, as per
https://webassembly.github.io/spec/core/appendix/custom.html#name-section
There is currently no use of module and locals, afaict.
* compiler/wasm: record function names in 'name' custom section
Quality-of-life improvement when dealing with our generated WASM
code.
Before:
local.get 2
local.get 3
call 1172
local.set 6
After:
local.get 2
local.get 3
call $g0.data.foo.p
local.set 6
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
// 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 constant contains WASM constant definitions.
|
|
package constant
|
|
|
|
// Magic bytes at the beginning of every WASM file ("\0asm").
|
|
const Magic = uint32(0x6D736100)
|
|
|
|
// Version defines the WASM version.
|
|
const Version = uint32(1)
|
|
|
|
// WASM module section IDs.
|
|
const (
|
|
CustomSectionID uint8 = iota
|
|
TypeSectionID
|
|
ImportSectionID
|
|
FunctionSectionID
|
|
TableSectionID
|
|
MemorySectionID
|
|
GlobalSectionID
|
|
ExportSectionID
|
|
StartSectionID
|
|
ElementSectionID
|
|
CodeSectionID
|
|
DataSectionID
|
|
)
|
|
|
|
// FunctionTypeID indicates the start of a function type definition.
|
|
const FunctionTypeID = byte(0x60)
|
|
|
|
// ValueType represents an intrinsic value type in WASM.
|
|
const (
|
|
ValueTypeF64 byte = iota + 0x7C
|
|
ValueTypeF32
|
|
ValueTypeI64
|
|
ValueTypeI32
|
|
)
|
|
|
|
// WASM import descriptor types.
|
|
const (
|
|
ImportDescType byte = iota
|
|
ImportDescTable
|
|
ImportDescMem
|
|
ImportDescGlobal
|
|
)
|
|
|
|
// WASM export descriptor types.
|
|
const (
|
|
ExportDescType byte = iota
|
|
ExportDescTable
|
|
ExportDescMem
|
|
ExportDescGlobal
|
|
)
|
|
|
|
// ElementTypeAnyFunc indicates the type of a table import.
|
|
const ElementTypeAnyFunc byte = 0x70
|
|
|
|
// BlockTypeEmpty represents a block type.
|
|
const BlockTypeEmpty byte = 0x40
|
|
|
|
// WASM global varialbe mutability flag.
|
|
const (
|
|
Const byte = iota
|
|
Mutable
|
|
)
|
|
|
|
// NameSectionCustomID is the ID of the "Name" section Custom Section
|
|
const NameSectionCustomID = "name"
|
|
|
|
// Subtypes of the 'name' custom section
|
|
const (
|
|
NameSectionModuleType byte = iota
|
|
NameSectionFunctionsType
|
|
NameSectionLocalsType
|
|
)
|