00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V8_BUILTINS_H_
00029 #define V8_BUILTINS_H_
00030
00031 namespace v8 { namespace internal {
00032
00033
00034 #define BUILTIN_LIST_C(V) \
00035 V(Illegal) \
00036 \
00037 V(EmptyFunction) \
00038 \
00039 V(ArrayCode) \
00040 \
00041 V(ArrayPush) \
00042 V(ArrayPop) \
00043 \
00044 V(HandleApiCall) \
00045 V(HandleApiCallAsFunction)
00046
00047
00048
00049 #define BUILTIN_LIST_A(V) \
00050 V(ArgumentsAdaptorTrampoline, BUILTIN, UNINITIALIZED) \
00051 V(JSConstructCall, BUILTIN, UNINITIALIZED) \
00052 V(JSEntryTrampoline, BUILTIN, UNINITIALIZED) \
00053 V(JSConstructEntryTrampoline, BUILTIN, UNINITIALIZED) \
00054 \
00055 V(Return_DebugBreak, BUILTIN, DEBUG_BREAK) \
00056 V(Return_DebugBreakEntry, BUILTIN, DEBUG_BREAK) \
00057 V(ConstructCall_DebugBreak, BUILTIN, DEBUG_BREAK) \
00058 V(StubNoRegisters_DebugBreak, BUILTIN, DEBUG_BREAK) \
00059 \
00060 V(LoadIC_Miss, BUILTIN, UNINITIALIZED) \
00061 V(KeyedLoadIC_Miss, BUILTIN, UNINITIALIZED) \
00062 V(StoreIC_Miss, BUILTIN, UNINITIALIZED) \
00063 V(KeyedStoreIC_Miss, BUILTIN, UNINITIALIZED) \
00064 \
00065 V(StoreIC_ExtendStorage, BUILTIN, UNINITIALIZED) \
00066 V(KeyedStoreIC_ExtendStorage, BUILTIN, UNINITIALIZED) \
00067 \
00068 V(LoadIC_Initialize, LOAD_IC, UNINITIALIZED) \
00069 V(LoadIC_PreMonomorphic, LOAD_IC, PREMONOMORPHIC) \
00070 V(LoadIC_Normal, LOAD_IC, MONOMORPHIC) \
00071 V(LoadIC_ArrayLength, LOAD_IC, MONOMORPHIC) \
00072 V(LoadIC_StringLength, LOAD_IC, MONOMORPHIC) \
00073 V(LoadIC_FunctionPrototype, LOAD_IC, MONOMORPHIC) \
00074 V(LoadIC_Megamorphic, LOAD_IC, MEGAMORPHIC) \
00075 V(LoadIC_DebugBreak, LOAD_IC, DEBUG_BREAK) \
00076 \
00077 V(KeyedLoadIC_Initialize, KEYED_LOAD_IC, UNINITIALIZED) \
00078 V(KeyedLoadIC_PreMonomorphic, KEYED_LOAD_IC, PREMONOMORPHIC) \
00079 V(KeyedLoadIC_Generic, KEYED_LOAD_IC, MEGAMORPHIC) \
00080 V(KeyedLoadIC_DebugBreak, KEYED_LOAD_IC, DEBUG_BREAK) \
00081 \
00082 V(StoreIC_Initialize, STORE_IC, UNINITIALIZED) \
00083 V(StoreIC_Megamorphic, STORE_IC, MEGAMORPHIC) \
00084 V(StoreIC_DebugBreak, STORE_IC, DEBUG_BREAK) \
00085 \
00086 V(KeyedStoreIC_Initialize, KEYED_STORE_IC, UNINITIALIZED) \
00087 V(KeyedStoreIC_Generic, KEYED_STORE_IC, MEGAMORPHIC) \
00088 V(KeyedStoreIC_DebugBreak, KEYED_STORE_IC, DEBUG_BREAK) \
00089 \
00090 \
00091 V(FunctionCall, BUILTIN, UNINITIALIZED) \
00092 V(FunctionApply, BUILTIN, UNINITIALIZED)
00093
00094
00095
00096 #define BUILTINS_LIST_JS(V) \
00097 V(EQUALS, 1) \
00098 V(STRICT_EQUALS, 1) \
00099 V(COMPARE, 2) \
00100 V(ADD, 1) \
00101 V(SUB, 1) \
00102 V(MUL, 1) \
00103 V(DIV, 1) \
00104 V(MOD, 1) \
00105 V(INC, 0) \
00106 V(DEC, 0) \
00107 V(BIT_OR, 1) \
00108 V(BIT_AND, 1) \
00109 V(BIT_XOR, 1) \
00110 V(UNARY_MINUS, 0) \
00111 V(BIT_NOT, 0) \
00112 V(SHL, 1) \
00113 V(SAR, 1) \
00114 V(SHR, 1) \
00115 V(DELETE, 1) \
00116 V(IN, 1) \
00117 V(INSTANCE_OF, 1) \
00118 V(GET_KEYS, 0) \
00119 V(FILTER_KEY, 1) \
00120 V(CALL_NON_FUNCTION, 0) \
00121 V(TO_OBJECT, 0) \
00122 V(TO_NUMBER, 0) \
00123 V(TO_STRING, 0) \
00124 V(APPLY_PREPARE, 1) \
00125 V(APPLY_OVERFLOW, 1)
00126
00127
00128 class ObjectVisitor;
00129
00130
00131 class Builtins : public AllStatic {
00132 public:
00133
00134
00135 static void Setup(bool create_heap_objects);
00136 static void TearDown();
00137
00138
00139 static void IterateBuiltins(ObjectVisitor* v);
00140
00141
00142 static const char* Lookup(byte* pc);
00143
00144 enum Name {
00145 #define DEF_ENUM_C(name) name,
00146 #define DEF_ENUM_A(name, kind, state) name,
00147 BUILTIN_LIST_C(DEF_ENUM_C)
00148 BUILTIN_LIST_A(DEF_ENUM_A)
00149 #undef DEF_ENUM_C
00150 #undef DEF_ENUM_A
00151 builtin_count
00152 };
00153
00154 enum CFunctionId {
00155 #define DEF_ENUM_C(name) c_##name,
00156 BUILTIN_LIST_C(DEF_ENUM_C)
00157 #undef DEF_ENUM_C
00158 cfunction_count
00159 };
00160
00161 enum JavaScript {
00162 #define DEF_ENUM(name, ignore) name,
00163 BUILTINS_LIST_JS(DEF_ENUM)
00164 #undef DEF_ENUM
00165 id_count
00166 };
00167
00168 static Code* builtin(Name name) {
00169
00170
00171 return reinterpret_cast<Code*>(builtins_[name]);
00172 }
00173
00174 static Address builtin_address(Name name) {
00175 return reinterpret_cast<Address>(&builtins_[name]);
00176 }
00177
00178 static Address c_function_address(CFunctionId id) {
00179 return c_functions_[id];
00180 }
00181
00182 static const char* GetName(JavaScript id) { return javascript_names_[id]; }
00183 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; }
00184 static Handle<Code> GetCode(JavaScript id, bool* resolved);
00185 static int NumberOfJavaScriptBuiltins() { return id_count; }
00186
00187
00188 static void Generate_CallIC_DebugBreak(MacroAssembler* masm);
00189
00190 static Object* builtin_passed_function;
00191
00192 private:
00193
00194 static Address c_functions_[cfunction_count];
00195
00196
00197
00198
00199 static Object* builtins_[builtin_count];
00200 static const char* names_[builtin_count];
00201 static const char* javascript_names_[id_count];
00202 static int javascript_argc_[id_count];
00203
00204 static void Generate_Adaptor(MacroAssembler* masm, CFunctionId id);
00205 static void Generate_JSConstructCall(MacroAssembler* masm);
00206 static void Generate_JSEntryTrampoline(MacroAssembler* masm);
00207 static void Generate_JSConstructEntryTrampoline(MacroAssembler* masm);
00208 static void Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm);
00209
00210 static void Generate_FunctionCall(MacroAssembler* masm);
00211 static void Generate_FunctionApply(MacroAssembler* masm);
00212
00213 static void Generate_LoadIC_DebugBreak(MacroAssembler* masm);
00214 static void Generate_StoreIC_DebugBreak(MacroAssembler* masm);
00215 static void Generate_KeyedLoadIC_DebugBreak(MacroAssembler* masm);
00216 static void Generate_KeyedStoreIC_DebugBreak(MacroAssembler* masm);
00217 static void Generate_ConstructCall_DebugBreak(MacroAssembler* masm);
00218 static void Generate_Return_DebugBreak(MacroAssembler* masm);
00219 static void Generate_Return_DebugBreakEntry(MacroAssembler* masm);
00220 static void Generate_StubNoRegisters_DebugBreak(MacroAssembler* masm);
00221 };
00222
00223 } }
00224
00225 #endif // V8_BUILTINS_H_