]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/Opcode.h
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <wtf/Assertions.h>
40 #define FOR_EACH_OPCODE_ID(macro) \
42 macro(op_enter_with_activation, 2) \
43 macro(op_create_arguments, 1) \
44 macro(op_convert_this, 2) \
46 macro(op_unexpected_load, 3) \
47 macro(op_new_object, 2) \
48 macro(op_new_array, 4) \
49 macro(op_new_regexp, 3) \
54 macro(op_eq_null, 3) \
56 macro(op_neq_null, 3) \
57 macro(op_stricteq, 4) \
58 macro(op_nstricteq, 4) \
62 macro(op_pre_inc, 2) \
63 macro(op_pre_dec, 2) \
64 macro(op_post_inc, 3) \
65 macro(op_post_dec, 3) \
66 macro(op_to_jsnumber, 3) \
76 macro(op_urshift, 4) \
82 macro(op_instanceof, 5) \
84 macro(op_is_undefined, 3) \
85 macro(op_is_boolean, 3) \
86 macro(op_is_number, 3) \
87 macro(op_is_string, 3) \
88 macro(op_is_object, 3) \
89 macro(op_is_function, 3) \
92 macro(op_resolve, 3) \
93 macro(op_resolve_skip, 4) \
94 macro(op_resolve_global, 6) \
95 macro(op_get_scoped_var, 4) \
96 macro(op_put_scoped_var, 4) \
97 macro(op_get_global_var, 4) \
98 macro(op_put_global_var, 4) \
99 macro(op_resolve_base, 3) \
100 macro(op_resolve_with_base, 4) \
101 macro(op_resolve_func, 4) \
102 macro(op_get_by_id, 8) \
103 macro(op_get_by_id_self, 8) \
104 macro(op_get_by_id_self_list, 8) \
105 macro(op_get_by_id_proto, 8) \
106 macro(op_get_by_id_proto_list, 8) \
107 macro(op_get_by_id_chain, 8) \
108 macro(op_get_by_id_generic, 8) \
109 macro(op_get_array_length, 8) \
110 macro(op_get_string_length, 8) \
111 macro(op_put_by_id, 8) \
112 macro(op_put_by_id_transition, 8) \
113 macro(op_put_by_id_replace, 8) \
114 macro(op_put_by_id_generic, 8) \
115 macro(op_del_by_id, 4) \
116 macro(op_get_by_val, 4) \
117 macro(op_put_by_val, 4) \
118 macro(op_del_by_val, 4) \
119 macro(op_put_by_index, 4) \
120 macro(op_put_getter, 4) \
121 macro(op_put_setter, 4) \
125 macro(op_jfalse, 3) \
126 macro(op_jeq_null, 3) \
127 macro(op_jneq_null, 3) \
128 macro(op_jnless, 4) \
129 macro(op_jmp_scopes, 3) \
131 macro(op_loop_if_true, 3) \
132 macro(op_loop_if_less, 4) \
133 macro(op_loop_if_lesseq, 4) \
134 macro(op_switch_imm, 4) \
135 macro(op_switch_char, 4) \
136 macro(op_switch_string, 4) \
138 macro(op_new_func, 3) \
139 macro(op_new_func_exp, 3) \
141 macro(op_call_eval, 5) \
142 macro(op_tear_off_activation, 2) \
143 macro(op_tear_off_arguments, 1) \
146 macro(op_construct, 7) \
147 macro(op_construct_verify, 3) \
149 macro(op_get_pnames, 3) \
150 macro(op_next_pname, 4) \
152 macro(op_push_scope, 2) \
153 macro(op_pop_scope, 1) \
154 macro(op_push_new_scope, 4) \
158 macro(op_new_error, 4) \
164 macro(op_profile_will_call, 2) \
165 macro(op_profile_did_call, 2) \
167 macro(op_end, 2) // end must be the last opcode in the list
169 #define OPCODE_ID_ENUM(opcode, length) opcode,
170 typedef enum { FOR_EACH_OPCODE_ID(OPCODE_ID_ENUM
) } OpcodeID
;
171 #undef OPCODE_ID_ENUM
173 const int numOpcodeIDs
= op_end
+ 1;
175 #define OPCODE_ID_LENGTHS(id, length) const int id##_length = length;
176 FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS
);
177 #undef OPCODE_ID_SIZES
179 #define OPCODE_LENGTH(opcode) opcode##_length
181 #define OPCODE_ID_LENGTH_MAP(opcode, length) length,
182 const int opcodeLengths
[numOpcodeIDs
] = { FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTH_MAP
) };
183 #undef OPCODE_ID_LENGTH_MAP
185 #define VERIFY_OPCODE_ID(id, size) COMPILE_ASSERT(id <= op_end, ASSERT_THAT_JS_OPCODE_IDS_ARE_VALID);
186 FOR_EACH_OPCODE_ID(VERIFY_OPCODE_ID
);
187 #undef VERIFY_OPCODE_ID
189 #if HAVE(COMPUTED_GOTO)
190 typedef void* Opcode
;
192 typedef OpcodeID Opcode
;
195 #if ENABLE(OPCODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(OPCODE_STATS)
197 #define PADDING_STRING " "
198 #define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING))
200 extern const char* const opcodeNames
[];
202 inline const char* padOpcodeName(OpcodeID op
, unsigned width
)
204 unsigned pad
= width
- strlen(opcodeNames
[op
]);
205 pad
= std::min(pad
, PADDING_STRING_LENGTH
);
206 return PADDING_STRING
+ PADDING_STRING_LENGTH
- pad
;
209 #undef PADDING_STRING_LENGTH
210 #undef PADDING_STRING
214 #if ENABLE(OPCODE_STATS)
219 static long long opcodeCounts
[numOpcodeIDs
];
220 static long long opcodePairCounts
[numOpcodeIDs
][numOpcodeIDs
];
221 static int lastOpcode
;
223 static void recordInstruction(int opcode
);
224 static void resetLastInstruction();