The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.

Please select the desired protocol below to get the URL.

This URL has Read-Only access.

Statistics
| Branch: | Revision:

main_repo / deps / v8 / src / builtins.h @ 40c0f755

History | View | Annotate | Download (8.77 KB)

1
// Copyright 2006-2008 the V8 project authors. All rights reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
4
// met:
5
//
6
//     * Redistributions of source code must retain the above copyright
7
//       notice, this list of conditions and the following disclaimer.
8
//     * Redistributions in binary form must reproduce the above
9
//       copyright notice, this list of conditions and the following
10
//       disclaimer in the documentation and/or other materials provided
11
//       with the distribution.
12
//     * Neither the name of Google Inc. nor the names of its
13
//       contributors may be used to endorse or promote products derived
14
//       from this software without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27

    
28
#ifndef V8_BUILTINS_H_
29
#define V8_BUILTINS_H_
30

    
31
namespace v8 { namespace internal {
32

    
33
// Define list of builtins implemented in C.
34
#define BUILTIN_LIST_C(V)                          \
35
  V(Illegal)                                       \
36
                                                   \
37
  V(EmptyFunction)                                 \
38
                                                   \
39
  V(ArrayCode)                                     \
40
                                                   \
41
  V(ArrayPush)                                     \
42
  V(ArrayPop)                                      \
43
                                                   \
44
  V(HandleApiCall)                                 \
45
  V(HandleApiCallAsFunction)
46

    
47

    
48
// Define list of builtins implemented in assembly.
49
#define BUILTIN_LIST_A(V)                                      \
50
  V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED)        \
51
  V(JSConstructCall,            BUILTIN, UNINITIALIZED)        \
52
  V(JSEntryTrampoline,          BUILTIN, UNINITIALIZED)        \
53
  V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED)        \
54
                                                               \
55
  V(LoadIC_Miss,                BUILTIN, UNINITIALIZED)        \
56
  V(KeyedLoadIC_Miss,           BUILTIN, UNINITIALIZED)        \
57
  V(StoreIC_Miss,               BUILTIN, UNINITIALIZED)        \
58
  V(KeyedStoreIC_Miss,          BUILTIN, UNINITIALIZED)        \
59
                                                               \
60
  V(StoreIC_ExtendStorage,      BUILTIN, UNINITIALIZED)        \
61
  V(KeyedStoreIC_ExtendStorage, BUILTIN, UNINITIALIZED)        \
62
                                                               \
63
  V(LoadIC_Initialize,          LOAD_IC, UNINITIALIZED)        \
64
  V(LoadIC_PreMonomorphic,      LOAD_IC, PREMONOMORPHIC)       \
65
  V(LoadIC_Normal,              LOAD_IC, MONOMORPHIC)          \
66
  V(LoadIC_ArrayLength,         LOAD_IC, MONOMORPHIC)          \
67
  V(LoadIC_StringLength,        LOAD_IC, MONOMORPHIC)          \
68
  V(LoadIC_FunctionPrototype,   LOAD_IC, MONOMORPHIC)          \
69
  V(LoadIC_Megamorphic,         LOAD_IC, MEGAMORPHIC)          \
70
                                                               \
71
  V(KeyedLoadIC_Initialize,     KEYED_LOAD_IC, UNINITIALIZED)  \
72
  V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC) \
73
  V(KeyedLoadIC_Generic,        KEYED_LOAD_IC, MEGAMORPHIC)    \
74
                                                               \
75
  V(StoreIC_Initialize,         STORE_IC, UNINITIALIZED)       \
76
  V(StoreIC_Megamorphic,        STORE_IC, MEGAMORPHIC)         \
77
                                                               \
78
  V(KeyedStoreIC_Initialize,    KEYED_STORE_IC, UNINITIALIZED) \
79
  V(KeyedStoreIC_Generic,       KEYED_STORE_IC, MEGAMORPHIC)   \
80
                                                               \
81
  /* Uses KeyedLoadIC_Initialize; must be after in list. */    \
82
  V(FunctionCall,               BUILTIN, UNINITIALIZED)        \
83
  V(FunctionApply,              BUILTIN, UNINITIALIZED)
84

    
85

    
86
// Define list of builtins used by the debugger implemented in assembly.
87
#define BUILTIN_LIST_DEBUG_A(V)                                \
88
  V(Return_DebugBreak,          BUILTIN, DEBUG_BREAK)          \
89
  V(Return_DebugBreakEntry,     BUILTIN, DEBUG_BREAK)          \
90
  V(ConstructCall_DebugBreak,   BUILTIN, DEBUG_BREAK)          \
91
  V(StubNoRegisters_DebugBreak, BUILTIN, DEBUG_BREAK)          \
92
  V(LoadIC_DebugBreak,          LOAD_IC, DEBUG_BREAK)          \
93
  V(KeyedLoadIC_DebugBreak,     KEYED_LOAD_IC, DEBUG_BREAK)    \
94
  V(StoreIC_DebugBreak,         STORE_IC, DEBUG_BREAK)         \
95
  V(KeyedStoreIC_DebugBreak,    KEYED_STORE_IC, DEBUG_BREAK)
96

    
97

    
98
// Define list of builtins implemented in JavaScript.
99
#define BUILTINS_LIST_JS(V)    \
100
  V(EQUALS, 1)                 \
101
  V(STRICT_EQUALS, 1)          \
102
  V(COMPARE, 2)                \
103
  V(ADD, 1)                    \
104
  V(SUB, 1)                    \
105
  V(MUL, 1)                    \
106
  V(DIV, 1)                    \
107
  V(MOD, 1)                    \
108
  V(BIT_OR, 1)                 \
109
  V(BIT_AND, 1)                \
110
  V(BIT_XOR, 1)                \
111
  V(UNARY_MINUS, 0)            \
112
  V(BIT_NOT, 0)                \
113
  V(SHL, 1)                    \
114
  V(SAR, 1)                    \
115
  V(SHR, 1)                    \
116
  V(DELETE, 1)                 \
117
  V(IN, 1)                     \
118
  V(INSTANCE_OF, 1)            \
119
  V(GET_KEYS, 0)               \
120
  V(FILTER_KEY, 1)             \
121
  V(CALL_NON_FUNCTION, 0)      \
122
  V(TO_OBJECT, 0)              \
123
  V(TO_NUMBER, 0)              \
124
  V(TO_STRING, 0)              \
125
  V(STRING_ADD_LEFT, 1)        \
126
  V(STRING_ADD_RIGHT, 1)       \
127
  V(APPLY_PREPARE, 1)          \
128
  V(APPLY_OVERFLOW, 1)
129

    
130

    
131
class ObjectVisitor;
132

    
133

    
134
class Builtins : public AllStatic {
135
 public:
136
  // Generate all builtin code objects. Should be called once during
137
  // VM initialization.
138
  static void Setup(bool create_heap_objects);
139
  static void TearDown();
140

    
141
  // Garbage collection support.
142
  static void IterateBuiltins(ObjectVisitor* v);
143

    
144
  // Disassembler support.
145
  static const char* Lookup(byte* pc);
146

    
147
  enum Name {
148
#define DEF_ENUM_C(name) name,
149
#define DEF_ENUM_A(name, kind, state) name,
150
    BUILTIN_LIST_C(DEF_ENUM_C)
151
    BUILTIN_LIST_A(DEF_ENUM_A)
152
    BUILTIN_LIST_DEBUG_A(DEF_ENUM_A)
153
#undef DEF_ENUM_C
154
#undef DEF_ENUM_A
155
    builtin_count
156
  };
157

    
158
  enum CFunctionId {
159
#define DEF_ENUM_C(name) c_##name,
160
    BUILTIN_LIST_C(DEF_ENUM_C)
161
#undef DEF_ENUM_C
162
    cfunction_count
163
  };
164

    
165
  enum JavaScript {
166
#define DEF_ENUM(name, ignore) name,
167
    BUILTINS_LIST_JS(DEF_ENUM)
168
#undef DEF_ENUM
169
    id_count
170
  };
171

    
172
  static Code* builtin(Name name) {
173
    // Code::cast cannot be used here since we access builtins
174
    // during the marking phase of mark sweep. See IC::Clear.
175
    return reinterpret_cast<Code*>(builtins_[name]);
176
  }
177

    
178
  static Address builtin_address(Name name) {
179
    return reinterpret_cast<Address>(&builtins_[name]);
180
  }
181

    
182
  static Address c_function_address(CFunctionId id) {
183
    return c_functions_[id];
184
  }
185

    
186
  static const char* GetName(JavaScript id) { return javascript_names_[id]; }
187
  static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; }
188
  static Handle<Code> GetCode(JavaScript id, bool* resolved);
189
  static int NumberOfJavaScriptBuiltins() { return id_count; }
190

    
191
  static Object* builtin_passed_function;
192

    
193
 private:
194
  // The external C++ functions called from the code.
195
  static Address c_functions_[cfunction_count];
196

    
197
  // Note: These are always Code objects, but to conform with
198
  // IterateBuiltins() above which assumes Object**'s for the callback
199
  // function f, we use an Object* array here.
200
  static Object* builtins_[builtin_count];
201
  static const char* names_[builtin_count];
202
  static const char* javascript_names_[id_count];
203
  static int javascript_argc_[id_count];
204

    
205
  static void Generate_Adaptor(MacroAssembler* masm, CFunctionId id);
206
  static void Generate_JSConstructCall(MacroAssembler* masm);
207
  static void Generate_JSEntryTrampoline(MacroAssembler* masm);
208
  static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
209
  static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
210

    
211
  static void Generate_FunctionCall(MacroAssembler* masm);
212
  static void Generate_FunctionApply(MacroAssembler* masm);
213
};
214

    
215
} }  // namespace v8::internal
216

    
217
#endif  // V8_BUILTINS_H_