1635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project/*
2635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
3635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
4635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *
5635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Redistribution and use in source and binary forms, with or without
6635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * modification, are permitted provided that the following conditions
7635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * are met:
8635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *
9635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * 1.  Redistributions of source code must retain the above copyright
10635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     notice, this list of conditions and the following disclaimer.
11635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * 2.  Redistributions in binary form must reproduce the above copyright
12635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     notice, this list of conditions and the following disclaimer in the
13635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     documentation and/or other materials provided with the distribution.
14635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     its contributors may be used to endorse or promote products derived
16635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     from this software without specific prior written permission.
17635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *
18635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project */
29635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
30635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#ifndef Opcode_h
31635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#define Opcode_h
32635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
33635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <algorithm>
34635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <string.h>
35635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
36635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#include <wtf/Assertions.h>
37635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
38635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectnamespace JSC {
39635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
40635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #define FOR_EACH_OPCODE_ID(macro) \
41635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_enter, 1) \
42635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_enter_with_activation, 2) \
435f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_init_arguments, 1) \
44635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_create_arguments, 1) \
45635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_convert_this, 2) \
46635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
47635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_new_object, 2) \
48635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_new_array, 4) \
49635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_new_regexp, 3) \
50635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_mov, 3) \
51635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
52635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_not, 3) \
53635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_eq, 4) \
54635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_eq_null, 3) \
55635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_neq, 4) \
56635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_neq_null, 3) \
57635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_stricteq, 4) \
58635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_nstricteq, 4) \
59635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_less, 4) \
60635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_lesseq, 4) \
61635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
62635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_pre_inc, 2) \
63635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_pre_dec, 2) \
64635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_post_inc, 3) \
65635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_post_dec, 3) \
66635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_to_jsnumber, 3) \
67635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_negate, 3) \
68635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_add, 5) \
69635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_mul, 5) \
700bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        macro(op_div, 5) \
71635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_mod, 4) \
72635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_sub, 5) \
73635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
74635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_lshift, 4) \
75635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_rshift, 4) \
76635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_urshift, 4) \
77635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_bitand, 5) \
78635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_bitxor, 5) \
79635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_bitor, 5) \
80635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_bitnot, 3) \
81635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
82635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_instanceof, 5) \
83635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_typeof, 3) \
84635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_is_undefined, 3) \
85635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_is_boolean, 3) \
86635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_is_number, 3) \
87635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_is_string, 3) \
88635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_is_object, 3) \
89635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_is_function, 3) \
90635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_in, 4) \
91635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
92635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_resolve, 3) \
93635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_resolve_skip, 4) \
94635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_resolve_global, 6) \
95635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_scoped_var, 4) \
96635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_scoped_var, 4) \
97635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_global_var, 4) \
98635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_global_var, 4) \
99635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_resolve_base, 3) \
100635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_resolve_with_base, 4) \
101635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id, 8) \
102635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id_self, 8) \
103635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id_self_list, 8) \
104635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id_proto, 8) \
105635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id_proto_list, 8) \
106635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id_chain, 8) \
107635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_id_generic, 8) \
108635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_array_length, 8) \
109635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_string_length, 8) \
110635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_by_id, 8) \
111635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_by_id_transition, 8) \
112635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_by_id_replace, 8) \
113635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_by_id_generic, 8) \
114635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_del_by_id, 4) \
115635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_get_by_val, 4) \
116cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block        macro(op_get_by_pname, 7) \
117635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_by_val, 4) \
118635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_del_by_val, 4) \
119635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_by_index, 4) \
120635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_getter, 4) \
121635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_put_setter, 4) \
122635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
123635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jmp, 2) \
124635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jtrue, 3) \
125635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jfalse, 3) \
126635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jeq_null, 3) \
127635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jneq_null, 3) \
1285f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_jneq_ptr, 4) \
129635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jnless, 4) \
1305f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_jnlesseq, 4) \
131643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        macro(op_jless, 4) \
132635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jmp_scopes, 3) \
133635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_loop, 2) \
134635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_loop_if_true, 3) \
135643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        macro(op_loop_if_false, 3) \
136635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_loop_if_less, 4) \
137635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_loop_if_lesseq, 4) \
138635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_switch_imm, 4) \
139635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_switch_char, 4) \
140635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_switch_string, 4) \
141635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
142635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_new_func, 3) \
143635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_new_func_exp, 3) \
144635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_call, 5) \
145635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_call_eval, 5) \
1465f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_call_varargs, 5) \
1475f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_load_varargs, 3) \
148635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_tear_off_activation, 2) \
149635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_tear_off_arguments, 1) \
150635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_ret, 2) \
1515f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_method_check, 1) \
152635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
153635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_construct, 7) \
154635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_construct_verify, 3) \
1555f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_strcat, 4) \
1565f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        macro(op_to_primitive, 3) \
157635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
158cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block        macro(op_get_pnames, 6) \
159cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block        macro(op_next_pname, 7) \
160635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
161635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_push_scope, 2) \
162635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_pop_scope, 1) \
163635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_push_new_scope, 4) \
164635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
165635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_catch, 2) \
166635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_throw, 2) \
167635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_new_error, 4) \
168635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
169635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_jsr, 3) \
170635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_sret, 2) \
171635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
172635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_debug, 4) \
173635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_profile_will_call, 2) \
174635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_profile_did_call, 2) \
175635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        \
176635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        macro(op_end, 2) // end must be the last opcode in the list
177635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
178635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #define OPCODE_ID_ENUM(opcode, length) opcode,
179635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        typedef enum { FOR_EACH_OPCODE_ID(OPCODE_ID_ENUM) } OpcodeID;
180635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #undef OPCODE_ID_ENUM
181635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
182635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    const int numOpcodeIDs = op_end + 1;
183635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
184635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #define OPCODE_ID_LENGTHS(id, length) const int id##_length = length;
185635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project         FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS);
1860bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    #undef OPCODE_ID_LENGTHS
187635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
188635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #define OPCODE_LENGTH(opcode) opcode##_length
189635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
190635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #define OPCODE_ID_LENGTH_MAP(opcode, length) length,
191635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        const int opcodeLengths[numOpcodeIDs] = { FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTH_MAP) };
192635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #undef OPCODE_ID_LENGTH_MAP
193635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
194635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #define VERIFY_OPCODE_ID(id, size) COMPILE_ASSERT(id <= op_end, ASSERT_THAT_JS_OPCODE_IDS_ARE_VALID);
195635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        FOR_EACH_OPCODE_ID(VERIFY_OPCODE_ID);
196635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    #undef VERIFY_OPCODE_ID
197635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
198635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#if HAVE(COMPUTED_GOTO)
199d0825bca7fe65beaee391d30da42e937db621564Steve Block#if COMPILER(RVCT)
200635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    typedef void* Opcode;
201635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#else
202d0825bca7fe65beaee391d30da42e937db621564Steve Block    typedef const void* Opcode;
203d0825bca7fe65beaee391d30da42e937db621564Steve Block#endif
204d0825bca7fe65beaee391d30da42e937db621564Steve Block#else
205635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    typedef OpcodeID Opcode;
206635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#endif
207635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
208635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#if ENABLE(OPCODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(OPCODE_STATS)
209635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
210635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#define PADDING_STRING "                                "
211635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#define PADDING_STRING_LENGTH static_cast<unsigned>(strlen(PADDING_STRING))
212635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
213635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    extern const char* const opcodeNames[];
214635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
215635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    inline const char* padOpcodeName(OpcodeID op, unsigned width)
216635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    {
217635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        unsigned pad = width - strlen(opcodeNames[op]);
218635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        pad = std::min(pad, PADDING_STRING_LENGTH);
219635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        return PADDING_STRING + PADDING_STRING_LENGTH - pad;
220635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    }
221635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
222635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#undef PADDING_STRING_LENGTH
223635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#undef PADDING_STRING
224635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
225635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#endif
226635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
227635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#if ENABLE(OPCODE_STATS)
228635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
229635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    struct OpcodeStats {
230635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        OpcodeStats();
231635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        ~OpcodeStats();
232635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        static long long opcodeCounts[numOpcodeIDs];
233635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        static long long opcodePairCounts[numOpcodeIDs][numOpcodeIDs];
234635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        static int lastOpcode;
235635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
236635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        static void recordInstruction(int opcode);
237635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project        static void resetLastInstruction();
238635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project    };
239635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
240635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#endif
241635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
242635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project} // namespace JSC
243635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
244635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project#endif // Opcode_h
245