2 * Copyright (C) 2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(WEBASSEMBLY)
30 #if COMPILER(GCC) && ASSERT_DISABLED
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wreturn-type"
33 #endif // COMPILER(GCC) && ASSERT_DISABLED
35 namespace JSC { namespace Wasm {
37 #define FOR_EACH_WASM_SECTION(macro) \
38 macro(Type, 1, "Function signature declarations") \
39 macro(Import, 2, "Import declarations") \
40 macro(Function, 3, "Function declarations") \
41 macro(Table, 4, "Indirect function table and other tables") \
42 macro(Memory, 5, "Memory attributes") \
43 macro(Global, 6, "Global declarations") \
44 macro(Export, 7, "Exports") \
45 macro(Start, 8, "Start function declaration") \
46 macro(Element, 9, "Elements section") \
47 macro(Code, 10, "Function bodies (code)") \
48 macro(Data, 11, "Data segments")
50 enum class Section : uint8_t {
51 #define DEFINE_WASM_SECTION_ENUM(NAME, ID, DESCRIPTION) NAME = ID,
52 FOR_EACH_WASM_SECTION(DEFINE_WASM_SECTION_ENUM)
53 #undef DEFINE_WASM_SECTION_ENUM
57 template<typename Int>
58 static inline bool isValidSection(Int section)
61 #define VALIDATE_SECTION(NAME, ID, DESCRIPTION) case static_cast<Int>(Section::NAME): return true;
62 FOR_EACH_WASM_SECTION(VALIDATE_SECTION)
63 #undef VALIDATE_SECTION
69 static inline bool validateOrder(Section previous, Section next)
71 if (previous == Section::Custom)
73 return static_cast<uint8_t>(previous) < static_cast<uint8_t>(next);
76 static inline const char* makeString(Section section)
81 #define STRINGIFY_SECTION_NAME(NAME, ID, DESCRIPTION) case Section::NAME: return #NAME;
82 FOR_EACH_WASM_SECTION(STRINGIFY_SECTION_NAME)
83 #undef STRINGIFY_SECTION_NAME
88 } } // namespace JSC::Wasm
90 #if COMPILER(GCC) && ASSERT_DISABLED
91 #pragma GCC diagnostic pop
92 #endif // COMPILER(GCC) && ASSERT_DISABLED
94 #endif // ENABLE(WEBASSEMBLY)