chromium/v8/src/wasm/constant-expression.h

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif  // !V8_ENABLE_WEBASSEMBLY

#ifndef V8_WASM_CONSTANT_EXPRESSION_H_
#define V8_WASM_CONSTANT_EXPRESSION_H_

#include <stdint.h>

#include <variant>

#include "src/base/bit-field.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-value.h"

namespace v8 {
namespace internal {

enum class MessageTemplate;
class WasmTrustedInstanceData;
class Zone;

namespace wasm {

class WireBytesRef;

// A representation of a constant expression. The most common expression types
// are hard-coded, while the rest are represented as a {WireBytesRef}.
class ConstantExpression {};

// Verify that the default constructor initializes the {kind()} to {kEmpty}.
static_assert;

// We want to keep {ConstantExpression} small to reduce memory usage during
// compilation/instantiation.
static_assert;

ValueOrError;

V8_INLINE bool is_error(ValueOrError result) {}
V8_INLINE MessageTemplate to_error(ValueOrError result) {}
V8_INLINE WasmValue to_value(ValueOrError result) {}

// Evaluates a constant expression.
// Returns a {WasmValue} if the evaluation succeeds, or an error as a
// {MessageTemplate} if it fails.
// Resets {zone} so make sure it contains no useful data.
ValueOrError EvaluateConstantExpression(
    Zone* zone, ConstantExpression expr, ValueType expected, Isolate* isolate,
    Handle<WasmTrustedInstanceData> trusted_instance_data,
    Handle<WasmTrustedInstanceData> shared_trusted_instance_data);

}  // namespace wasm
}  // namespace internal
}  // namespace v8

#endif  // V8_WASM_CONSTANT_EXPRESSION_H_