#ifndef V8_WASM_WASM_CONSTANTS_H_
#define V8_WASM_WASM_CONSTANTS_H_
#if !V8_ENABLE_WEBASSEMBLY
#error This header should only be included if WebAssembly is enabled.
#endif
#include <cstddef>
#include <cstdint>
#include "src/common/globals.h"
namespace v8 {
namespace internal {
namespace wasm {
constexpr uint32_t kWasmMagic = 0x6d736100;
constexpr uint32_t kWasmVersion = 0x01;
enum ValueTypeCode : uint8_t {
kVoidCode = 0x40,
kI32Code = 0x7f,
kI64Code = 0x7e,
kF32Code = 0x7d,
kF64Code = 0x7c,
kS128Code = 0x7b,
kI8Code = 0x78,
kI16Code = 0x77,
kF16Code = 0x76,
kNoExnCode = 0x74,
kNoFuncCode = 0x73,
kNoExternCode = 0x72,
kNoneCode = 0x71,
kFuncRefCode = 0x70,
kExternRefCode = 0x6f,
kAnyRefCode = 0x6e,
kEqRefCode = 0x6d,
kI31RefCode = 0x6c,
kStructRefCode = 0x6b,
kArrayRefCode = 0x6a,
kRefCode = 0x64,
kRefNullCode = 0x63,
kExactCode = 0x62,
kExnRefCode = 0x69,
kContRefCode = 0x68,
kNoContCode = 0x75,
kStringRefCode = 0x67,
kStringViewWtf8Code = 0x66,
kStringViewWtf16Code = 0x60,
kStringViewIterCode = 0x61,
kFirstHeapTypeCode = kStringViewWtf16Code,
kLastHeapTypeCode = kNoContCode,
};
constexpr uint8_t kSharedFlagCode = 0x65;
constexpr uint8_t kWasmFunctionTypeCode = 0x60;
constexpr uint8_t kWasmStructTypeCode = 0x5f;
constexpr uint8_t kWasmArrayTypeCode = 0x5e;
constexpr uint8_t kWasmContTypeCode = 0x5d;
constexpr uint8_t kWasmSubtypeCode = 0x50;
constexpr uint8_t kWasmSubtypeFinalCode = 0x4f;
constexpr uint8_t kWasmRecursiveTypeGroupCode = 0x4e;
constexpr uint8_t kWasmDescriptorCode = 0x4d;
constexpr uint8_t kWasmDescribesCode = 0x4c;
constexpr uint8_t kExternalExactBit = 1 << 5;
enum ImportExportKindCode : uint8_t {
kExternalFunction = 0,
kExternalTable = 1,
kExternalMemory = 2,
kExternalGlobal = 3,
kExternalTag = 4,
kExternalExactFunction = kExternalFunction | kExternalExactBit,
};
enum LimitsFlags : uint8_t {
kNoMaximum = 0x00,
kWithMaximum = 0x01,
kSharedNoMaximum = 0x02,
kSharedWithMaximum = 0x03,
kMemory64NoMaximum = 0x04,
kMemory64WithMaximum = 0x05,
kMemory64SharedNoMaximum = 0x06,
kMemory64SharedWithMaximum = 0x07
};
enum SegmentFlags : uint8_t {
kActiveNoIndex = 0,
kPassive = 1,
kActiveWithIndex = 2,
};
enum SectionCode : int8_t {
kUnknownSectionCode = 0,
kTypeSectionCode = 1,
kImportSectionCode = 2,
kFunctionSectionCode = 3,
kTableSectionCode = 4,
kMemorySectionCode = 5,
kGlobalSectionCode = 6,
kExportSectionCode = 7,
kStartSectionCode = 8,
kElementSectionCode = 9,
kCodeSectionCode = 10,
kDataSectionCode = 11,
kDataCountSectionCode = 12,
kTagSectionCode = 13,
kStringRefSectionCode = 14,
kNameSectionCode,
kSourceMappingURLSectionCode,
kDebugInfoSectionCode,
kExternalDebugInfoSectionCode,
kBuildIdSectionCode,
kInstTraceSectionCode,
kBranchHintsSectionCode,
kCompilationPrioritySectionCode,
kInstFrequenciesSectionCode,
kCallTargetsSectionCode,
kDescriptorsSectionCode,
kFirstSectionInModule = kTypeSectionCode,
kLastKnownModuleSection = kStringRefSectionCode,
kFirstUnorderedSection = kDataCountSectionCode,
};
constexpr char kNameString[] = "name";
constexpr char kSourceMappingURLString[] = "sourceMappingURL";
constexpr char kInstTraceString[] = "metadata.code.trace_inst";
constexpr char kBranchHintsString[] = "metadata.code.branch_hint";
#if V8_CC_GNU
__attribute__((used))
#endif
constexpr char kCompilationPriorityString[] =
"metadata.code.compilation_priority";
constexpr char kInstructionFrequenciesString[] = "metadata.code.instr_freq";
constexpr char kCallTargetsString[] = "metadata.code.call_targets";
constexpr char kDebugInfoString[] = ".debug_info";
constexpr char kExternalDebugInfoString[] = "external_debug_info";
constexpr char kBuildIdString[] = "build_id";
constexpr char kDescriptorsString[] = "experimental-descriptors";
enum NameSectionKindCode : uint8_t {
kModuleCode = 0,
kFunctionCode = 1,
kLocalCode = 2,
kLabelCode = 3,
kTypeCode = 4,
kTableCode = 5,
kMemoryCode = 6,
kGlobalCode = 7,
kElementSegmentCode = 8,
kDataSegmentCode = 9,
kFieldCode = 10,
kTagCode = 11,
};
enum CatchKind : uint8_t {
kCatch = 0x0,
kCatchRef = 0x1,
kCatchAll = 0x2,
kCatchAllRef = 0x3,
kLastCatchKind = kCatchAllRef,
};
enum SwitchKind : uint8_t {
kOnSuspend = 0x0,
kSwitch = 0x1,
kLastSwitchKind = kSwitch,
};
enum MemoryOrdering : uint8_t { kAtomicSeqCst, kAtomicAcqRel };
constexpr size_t kWasmPageSize = 0x10000;
constexpr uint32_t kWasmPageSizeLog2 = 16;
static_assert(kWasmPageSize == size_t{1} << kWasmPageSizeLog2, "consistency");
using WasmCodePosition = int;
constexpr WasmCodePosition kNoCodePosition = -1;
constexpr uint32_t kExceptionAttribute = 0;
constexpr int kAnonymousFuncIndex = -1;
constexpr uint32_t kInvalidCanonicalIndex = static_cast<uint32_t>(-1);
static_assert(static_cast<uint32_t>(Internals::SmiValue(Internals::IntToSmi(
static_cast<int>(kInvalidCanonicalIndex)))) ==
kInvalidCanonicalIndex);
constexpr uint32_t kGenericWrapperBudget = 1000;
constexpr uint32_t kMinimumSupertypeArraySize = 3;
constexpr int kMaxPolymorphism = 4;
constexpr int kMaxStructFieldIndexForImplicitNullCheck = 4000;
constexpr int kOptimizationPriorityExecutedOnceSentinel = 127;
constexpr int kOptimizationPriorityNotSpecifiedSentinel = -1;
#if V8_TARGET_ARCH_X64
constexpr int32_t kOSRTargetOffset = 4 * kSystemPointerSize;
#endif
}
}
}
#endif