1/*
2 * Copyright (C) 2015 Yusuke Suzuki <[email protected]>.
3 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include "Identifier.h"
30#include <wtf/Noncopyable.h>
31
32namespace JSC {
33
34class CommonIdentifiers;
35class BytecodeGenerator;
36class BytecodeIntrinsicNode;
37class RegisterID;
38
39#define JSC_COMMON_BYTECODE_INTRINSIC_FUNCTIONS_EACH_NAME(macro) \
40 macro(argument) \
41 macro(argumentCount) \
42 macro(getByIdDirect) \
43 macro(getByIdDirectPrivate) \
44 macro(idWithProfile) \
45 macro(isObject) \
46 macro(isJSArray) \
47 macro(isProxyObject) \
48 macro(isDerivedArray) \
49 macro(isRegExpObject) \
50 macro(isMap) \
51 macro(isSet) \
52 macro(isUndefinedOrNull) \
53 macro(tailCallForwardArguments) \
54 macro(throwTypeError) \
55 macro(throwRangeError) \
56 macro(throwOutOfMemoryError) \
57 macro(tryGetById) \
58 macro(putByIdDirect) \
59 macro(putByIdDirectPrivate) \
60 macro(putByValDirect) \
61 macro(toNumber) \
62 macro(toString) \
63 macro(toObject) \
64 macro(newArrayWithSize) \
65 macro(defineEnumerableWritableConfigurableDataProperty) \
66
67#define JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_EACH_NAME(macro) \
68 JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_SIMPLE_EACH_NAME(macro) \
69 JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_CUSTOM_EACH_NAME(macro) \
70
71#define JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_SIMPLE_EACH_NAME(macro) \
72 macro(undefined) \
73 macro(Infinity) \
74 macro(iterationKindKey) \
75 macro(iterationKindValue) \
76 macro(iterationKindKeyValue) \
77 macro(MAX_ARRAY_INDEX) \
78 macro(MAX_STRING_LENGTH) \
79 macro(MAX_SAFE_INTEGER) \
80 macro(ModuleFetch) \
81 macro(ModuleTranslate) \
82 macro(ModuleInstantiate) \
83 macro(ModuleSatisfy) \
84 macro(ModuleLink) \
85 macro(ModuleReady) \
86 macro(promiseRejectionReject) \
87 macro(promiseRejectionHandle) \
88 macro(promiseStatePending) \
89 macro(promiseStateFulfilled) \
90 macro(promiseStateRejected) \
91 macro(GeneratorResumeModeNormal) \
92 macro(GeneratorResumeModeThrow) \
93 macro(GeneratorResumeModeReturn) \
94 macro(GeneratorStateCompleted) \
95 macro(GeneratorStateExecuting) \
96 macro(AsyncGeneratorStateCompleted) \
97 macro(AsyncGeneratorStateExecuting) \
98 macro(AsyncGeneratorStateAwaitingReturn) \
99 macro(AsyncGeneratorStateSuspendedStart) \
100 macro(AsyncGeneratorStateSuspendedYield) \
101 macro(AsyncGeneratorSuspendReasonYield) \
102 macro(AsyncGeneratorSuspendReasonAwait) \
103 macro(AsyncGeneratorSuspendReasonNone) \
104
105#define JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_CUSTOM_EACH_NAME(macro) \
106 macro(sentinelMapBucket) \
107 macro(sentinelSetBucket) \
108
109class BytecodeIntrinsicRegistry {
110 WTF_MAKE_FAST_ALLOCATED;
111 WTF_MAKE_NONCOPYABLE(BytecodeIntrinsicRegistry);
112public:
113 explicit BytecodeIntrinsicRegistry(VM&);
114
115 typedef RegisterID* (BytecodeIntrinsicNode::* EmitterType)(BytecodeGenerator&, RegisterID*);
116
117 EmitterType lookup(const Identifier&) const;
118
119#define JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS(name) JSValue name##Value(BytecodeGenerator&);
120 JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_EACH_NAME(JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS)
121#undef JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS
122
123private:
124 VM& m_vm;
125 HashMap<RefPtr<UniquedStringImpl>, EmitterType, IdentifierRepHash> m_bytecodeIntrinsicMap;
126
127#define JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS(name) Strong<Unknown> m_##name;
128 JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_SIMPLE_EACH_NAME(JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS)
129#undef JSC_DECLARE_BYTECODE_INTRINSIC_CONSTANT_GENERATORS
130};
131
132} // namespace JSC
133