chromium/v8/src/wasm/function-body-decoder.h

// Copyright 2015 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_FUNCTION_BODY_DECODER_H_
#define V8_WASM_FUNCTION_BODY_DECODER_H_

#include "src/base/compiler-specific.h"
#include "src/base/iterator.h"
#include "src/common/globals.h"
#include "src/wasm/decoder.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-result.h"

namespace v8::internal {
class AccountingAllocator;
class BitVector;
class Zone;
}  // namespace v8::internal

namespace v8::internal::wasm {

class WasmDetectedFeatures;
class WasmEnabledFeatures;
struct WasmModule;  // forward declaration of module interface.

// A wrapper around the signature and bytes of a function.
struct FunctionBody {};

enum class LoadTransformationKind : uint8_t {};

V8_EXPORT_PRIVATE DecodeResult ValidateFunctionBody(
    Zone* zone, WasmEnabledFeatures enabled, const WasmModule* module,
    WasmDetectedFeatures* detected, const FunctionBody& body);

struct BodyLocalDecls {};

// Decode locals; validation is not performed.
V8_EXPORT_PRIVATE void DecodeLocalDecls(WasmEnabledFeatures enabled,
                                        BodyLocalDecls* decls,
                                        const uint8_t* start,
                                        const uint8_t* end, Zone* zone);

// Decode locals, including validation.
V8_EXPORT_PRIVATE bool ValidateAndDecodeLocalDeclsForTesting(
    WasmEnabledFeatures enabled, BodyLocalDecls* decls,
    const WasmModule* module, bool is_shared, const uint8_t* start,
    const uint8_t* end, Zone* zone);

V8_EXPORT_PRIVATE BitVector* AnalyzeLoopAssignmentForTesting(
    Zone* zone, uint32_t num_locals, const uint8_t* start, const uint8_t* end,
    bool* loop_is_innermost);

// Computes the length of the opcode at the given address.
V8_EXPORT_PRIVATE unsigned OpcodeLength(const uint8_t* pc, const uint8_t* end);

// Checks if the underlying hardware supports the Wasm SIMD proposal.
V8_EXPORT_PRIVATE bool CheckHardwareSupportsSimd();

// A simple forward iterator for bytecodes.
class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {};

}  // namespace v8::internal::wasm

#endif  // V8_WASM_FUNCTION_BODY_DECODER_H_