kwasm.validation

Kwasm.validation

package kwasm.validation

Classes

Name Description
sealed class ValidationContext

Represents the context accrued throughout the validation process.

ValidationContext objects contain the current AstNode being validated, as well as additional context as specified in the WebAssembly Spec.

From the docs:

Validity of an individual definition is specified relative to a context, which collects relevant information about the surrounding module and the definitions in scope:

  • Types: the list of types defined in the current module.
  • Functions: the list of functions declared in the current module, represented by their function type.
  • Tables: the list of tables declared in the current module, represented by their table type.
  • Memories: the list of memories declared in the current module, represented by their memory type.
  • Globals: the list of globals declared in the current module, represented by their global type.
  • Locals: the list of locals declared in the current function (including parameters), represented by their value type.
  • Labels: the stack of labels accessible from the current position, represented by their result type.
  • Return: (the return type of the current function, represented as an optional result type that is absent when no return is allowed, as in free-standing expressions.

In other words, a context contains a sequence of suitable types for each index space, describing each defined entry in that space. Locals, labels and return type are only used for validating instructions in function bodies, and are left empty elsewhere. The label stack is the only part of the context that changes as validation of an instruction sequence proceeds.

data class ValidationException

Exception thrown during the validation process when an invalid WasmProgram is being analyzed.

interface ValidationVisitor

Base visitor interface used during validation.

T is the class of AstNode this ValidationVisitor is capable of validating, Context is the required ValidationContext type needed to perform validation.

interface ModuleValidationVisitor

Describes a ValidationVisitor intended for validating module-level AstNodes. (e.g. kwasm.ast.Table, kwasm.ast.Memory, or kwasm.ast.WasmFunction).

interface FunctionBodyValidationVisitor

Describes a ValidationVisitor intended for validating parts of the body of a kwasm.ast.WasmFunction or an kwasm.ast.Expression.

Subpackages

Methods

ValidationContext

fun ValidationContext(module: WasmModule): Module

Given a WasmModule, creates a new ValidationContext.

Parameters

Name Description
module: WasmModule

ReturnValue

Name Description
Module

validate

fun validate(condition: Boolean, parseContext: ParseContext?, message: String)

Validates a given condition, and throws a ValidationException if the condition is false.

Parameters

Name Description
condition: Boolean
parseContext: ParseContext?
message: String

ReturnValue

Name Description
Unit

validate

inline fun validate(condition: Boolean, parseContext: ParseContext?, crossinline block: ()->String)

Validates a given condition, and throws a ValidationException if the condition is false.

Parameters

Name Description
condition: Boolean
parseContext: ParseContext?
crossinline block: ()->String

ReturnValue

Name Description
Unit

validateNotNull

fun <T> validateNotNull(value: T?, parseContext: ParseContext?, message: String): T

Validates that the given value is non-null and returns a non-nullable reference to it.

Parameters

Name Description
value: T?
parseContext: ParseContext?
message: String

ReturnValue

Name Description
T

validateNotNull

inline fun <T> validateNotNull(value: T?, parseContext: ParseContext?, crossinline block: ()->String): T

Validates that the given value is non-null and returns a non-nullable reference to it.

Parameters

Name Description
value: T?
parseContext: ParseContext?
crossinline block: ()->String

ReturnValue

Name Description
T

upcastThrown

inline fun <T> upcastThrown(context: ParseContext?, crossinline block: ()->T): T

Upcasts any Throwables thrown by the block to ValidationExceptions.

Parameters

Name Description
context: ParseContext?
crossinline block: ()->T

ReturnValue

Name Description
T