llvm/llvm/include/llvm/BinaryFormat/Wasm.h

//===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines manifest constants for the wasm object file format.
// See: https://github.com/WebAssembly/design/blob/main/BinaryEncoding.md
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_BINARYFORMAT_WASM_H
#define LLVM_BINARYFORMAT_WASM_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <optional>

namespace llvm {
namespace wasm {

// Object file magic string.
const char WasmMagic[] =;
// Wasm binary format version
const uint32_t WasmVersion =;
// Wasm linking metadata version
const uint32_t WasmMetadataVersion =;
// Wasm uses a 64k page size
const uint32_t WasmPageSize =;

enum : unsigned {};

// Type immediate encodings used in various contexts.
enum : unsigned {};

// Kinds of externals (for imports and exports).
enum : unsigned {};

// Opcodes used in initializer expressions.
enum : unsigned {};

// Opcodes in the GC-prefixed space (0xfb)
enum : unsigned {};

// Opcodes used in synthetic functions.
enum : unsigned {};

// Sub-opcodes for catch clauses in a try_table instruction
enum : unsigned {};

enum : unsigned {};

enum : unsigned {};

enum : unsigned {};
const unsigned WASM_ELEM_SEGMENT_MASK_HAS_ELEM_KIND =;

// Feature policy prefixes used in the custom "target_features" section
enum : uint8_t {};

// Kind codes used in the custom "name" section
enum : unsigned {};

// Kind codes used in the custom "linking" section
enum : unsigned {};

// Kind codes used in the custom "dylink" section
enum : unsigned {};

// Kind codes used in the custom "linking" section in the WASM_COMDAT_INFO
enum : unsigned {};

// Kind codes used in the custom "linking" section in the WASM_SYMBOL_TABLE
enum WasmSymbolType : unsigned {};

enum WasmSegmentFlag : unsigned {};

// Kinds of tag attributes.
enum WasmTagAttribute : uint8_t {};

const unsigned WASM_SYMBOL_BINDING_MASK =;
const unsigned WASM_SYMBOL_VISIBILITY_MASK =;

const unsigned WASM_SYMBOL_BINDING_GLOBAL =;
const unsigned WASM_SYMBOL_BINDING_WEAK =;
const unsigned WASM_SYMBOL_BINDING_LOCAL =;
const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT =;
const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN =;
const unsigned WASM_SYMBOL_UNDEFINED =;
const unsigned WASM_SYMBOL_EXPORTED =;
const unsigned WASM_SYMBOL_EXPLICIT_NAME =;
const unsigned WASM_SYMBOL_NO_STRIP =;
const unsigned WASM_SYMBOL_TLS =;
const unsigned WASM_SYMBOL_ABSOLUTE =;

#define WASM_RELOC

enum : unsigned {};

#undef WASM_RELOC

struct WasmObjectHeader {};

// Subset of types that a value can have
enum class ValType {};

struct WasmDylinkImportInfo {};

struct WasmDylinkExportInfo {};

struct WasmDylinkInfo {};

struct WasmProducerInfo {};

struct WasmFeatureEntry {};

struct WasmExport {};

struct WasmLimits {};

struct WasmTableType {};

struct WasmTable {};

struct WasmInitExprMVP {};

// Extended-const init exprs and exprs with GC types are not explicitly
// modeled, but the raw body of the expr is attached.
struct WasmInitExpr {};

struct WasmGlobalType {};

struct WasmGlobal {};

struct WasmTag {};

struct WasmImport {};

struct WasmLocalDecl {};

struct WasmFunction {};

struct WasmDataSegment {};

// Represents a Wasm element segment, with some limitations compared the spec:
// 1) Does not model passive or declarative segments (Segment will end up with
// an Offset field of i32.const 0)
// 2) Does not model init exprs (Segment will get an empty Functions list)
// 3) Does not model types other than basic funcref/externref/exnref (see
// ValType)
struct WasmElemSegment {};

// Represents the location of a Wasm data symbol within a WasmDataSegment, as
// the index of the segment, and the offset and size within the segment.
struct WasmDataReference {};

struct WasmRelocation {};

struct WasmInitFunc {};

struct WasmSymbolInfo {};

enum class NameType {};

struct WasmDebugName {};

// Info from the linking metadata section of a wasm object file.
struct WasmLinkingData {};

struct WasmSignature {};

// Useful comparison operators
inline bool operator==(const WasmSignature &LHS, const WasmSignature &RHS) {}

inline bool operator!=(const WasmSignature &LHS, const WasmSignature &RHS) {}

inline bool operator==(const WasmGlobalType &LHS, const WasmGlobalType &RHS) {}

inline bool operator!=(const WasmGlobalType &LHS, const WasmGlobalType &RHS) {}

inline bool operator==(const WasmLimits &LHS, const WasmLimits &RHS) {}

inline bool operator==(const WasmTableType &LHS, const WasmTableType &RHS) {}

llvm::StringRef toString(WasmSymbolType type);
llvm::StringRef relocTypetoString(uint32_t type);
llvm::StringRef sectionTypeToString(uint32_t type);
bool relocTypeHasAddend(uint32_t type);

} // end namespace wasm
} // end namespace llvm

#endif