X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/4e4e5a6f2694187498445a6ac6f1634ce8141119..refs/heads/master:/bytecode/Opcode.h diff --git a/bytecode/Opcode.h b/bytecode/Opcode.h index 67f5e70..1ed48c2 100644 --- a/bytecode/Opcode.h +++ b/bytecode/Opcode.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009, 2013, 2014 Apple Inc. All rights reserved. * Copyright (C) 2008 Cameron Zwarich * * Redistribution and use in source and binary forms, with or without @@ -11,7 +11,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -30,6 +30,9 @@ #ifndef Opcode_h #define Opcode_h +#include "Bytecodes.h" +#include "LLIntOpcode.h" + #include #include @@ -37,220 +40,92 @@ namespace JSC { - #define FOR_EACH_OPCODE_ID(macro) \ - macro(op_enter, 1) \ - macro(op_enter_with_activation, 2) \ - macro(op_init_arguments, 1) \ - macro(op_create_arguments, 1) \ - macro(op_convert_this, 2) \ - \ - macro(op_new_object, 2) \ - macro(op_new_array, 4) \ - macro(op_new_regexp, 3) \ - macro(op_mov, 3) \ - \ - macro(op_not, 3) \ - macro(op_eq, 4) \ - macro(op_eq_null, 3) \ - macro(op_neq, 4) \ - macro(op_neq_null, 3) \ - macro(op_stricteq, 4) \ - macro(op_nstricteq, 4) \ - macro(op_less, 4) \ - macro(op_lesseq, 4) \ - \ - macro(op_pre_inc, 2) \ - macro(op_pre_dec, 2) \ - macro(op_post_inc, 3) \ - macro(op_post_dec, 3) \ - macro(op_to_jsnumber, 3) \ - macro(op_negate, 3) \ - macro(op_add, 5) \ - macro(op_mul, 5) \ - macro(op_div, 5) \ - macro(op_mod, 4) \ - macro(op_sub, 5) \ - \ - macro(op_lshift, 4) \ - macro(op_rshift, 4) \ - macro(op_urshift, 4) \ - macro(op_bitand, 5) \ - macro(op_bitxor, 5) \ - macro(op_bitor, 5) \ - macro(op_bitnot, 3) \ - \ - macro(op_instanceof, 5) \ - macro(op_typeof, 3) \ - macro(op_is_undefined, 3) \ - macro(op_is_boolean, 3) \ - macro(op_is_number, 3) \ - macro(op_is_string, 3) \ - macro(op_is_object, 3) \ - macro(op_is_function, 3) \ - macro(op_in, 4) \ - \ - macro(op_resolve, 3) \ - macro(op_resolve_skip, 4) \ - macro(op_resolve_global, 6) \ - macro(op_resolve_global_dynamic, 7) \ - macro(op_get_scoped_var, 4) \ - macro(op_put_scoped_var, 4) \ - macro(op_get_global_var, 4) \ - macro(op_put_global_var, 4) \ - macro(op_resolve_base, 3) \ - macro(op_resolve_with_base, 4) \ - macro(op_get_by_id, 8) \ - macro(op_get_by_id_self, 8) \ - macro(op_get_by_id_self_list, 8) \ - macro(op_get_by_id_proto, 8) \ - macro(op_get_by_id_proto_list, 8) \ - macro(op_get_by_id_chain, 8) \ - macro(op_get_by_id_getter_self, 8) \ - macro(op_get_by_id_getter_self_list, 8) \ - macro(op_get_by_id_getter_proto, 8) \ - macro(op_get_by_id_getter_proto_list, 8) \ - macro(op_get_by_id_getter_chain, 8) \ - macro(op_get_by_id_custom_self, 8) \ - macro(op_get_by_id_custom_self_list, 8) \ - macro(op_get_by_id_custom_proto, 8) \ - macro(op_get_by_id_custom_proto_list, 8) \ - macro(op_get_by_id_custom_chain, 8) \ - macro(op_get_by_id_generic, 8) \ - macro(op_get_array_length, 8) \ - macro(op_get_string_length, 8) \ - macro(op_put_by_id, 9) \ - macro(op_put_by_id_transition, 9) \ - macro(op_put_by_id_replace, 9) \ - macro(op_put_by_id_generic, 9) \ - macro(op_del_by_id, 4) \ - macro(op_get_by_val, 4) \ - macro(op_get_by_pname, 7) \ - macro(op_put_by_val, 4) \ - macro(op_del_by_val, 4) \ - macro(op_put_by_index, 4) \ - macro(op_put_getter, 4) \ - macro(op_put_setter, 4) \ - \ - macro(op_jmp, 2) \ - macro(op_jtrue, 3) \ - macro(op_jfalse, 3) \ - macro(op_jeq_null, 3) \ - macro(op_jneq_null, 3) \ - macro(op_jneq_ptr, 4) \ - macro(op_jnless, 4) \ - macro(op_jnlesseq, 4) \ - macro(op_jless, 4) \ - macro(op_jlesseq, 4) \ - macro(op_jmp_scopes, 3) \ - macro(op_loop, 2) \ - macro(op_loop_if_true, 3) \ - macro(op_loop_if_false, 3) \ - macro(op_loop_if_less, 4) \ - macro(op_loop_if_lesseq, 4) \ - macro(op_switch_imm, 4) \ - macro(op_switch_char, 4) \ - macro(op_switch_string, 4) \ - \ - macro(op_new_func, 3) \ - macro(op_new_func_exp, 3) \ - macro(op_call, 5) \ - macro(op_call_eval, 5) \ - macro(op_call_varargs, 5) \ - macro(op_load_varargs, 3) \ - macro(op_tear_off_activation, 2) \ - macro(op_tear_off_arguments, 1) \ - macro(op_ret, 2) \ - macro(op_method_check, 1) \ - \ - macro(op_construct, 7) \ - macro(op_construct_verify, 3) \ - macro(op_strcat, 4) \ - macro(op_to_primitive, 3) \ - \ - macro(op_get_pnames, 6) \ - macro(op_next_pname, 7) \ - \ - macro(op_push_scope, 2) \ - macro(op_pop_scope, 1) \ - macro(op_push_new_scope, 4) \ - \ - macro(op_catch, 2) \ - macro(op_throw, 2) \ - macro(op_new_error, 4) \ - \ - macro(op_jsr, 3) \ - macro(op_sret, 2) \ - \ - macro(op_debug, 4) \ - macro(op_profile_will_call, 2) \ - macro(op_profile_did_call, 2) \ - \ - macro(op_end, 2) // end must be the last opcode in the list - - #define OPCODE_ID_ENUM(opcode, length) opcode, - typedef enum { FOR_EACH_OPCODE_ID(OPCODE_ID_ENUM) } OpcodeID; - #undef OPCODE_ID_ENUM +#define FOR_EACH_CORE_OPCODE_ID_WITH_EXTENSION(macro, extension__) \ + FOR_EACH_BYTECODE_ID(macro) \ + extension__ - const int numOpcodeIDs = op_end + 1; +#define FOR_EACH_CORE_OPCODE_ID(macro) \ + FOR_EACH_CORE_OPCODE_ID_WITH_EXTENSION(macro, /* No extension */ ) - #define OPCODE_ID_LENGTHS(id, length) const int id##_length = length; - FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS); - #undef OPCODE_ID_LENGTHS - - #define OPCODE_LENGTH(opcode) opcode##_length +#define FOR_EACH_OPCODE_ID(macro) \ + FOR_EACH_CORE_OPCODE_ID_WITH_EXTENSION( \ + macro, \ + FOR_EACH_LLINT_OPCODE_EXTENSION(macro) \ + ) - #define OPCODE_ID_LENGTH_MAP(opcode, length) length, - const int opcodeLengths[numOpcodeIDs] = { FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTH_MAP) }; - #undef OPCODE_ID_LENGTH_MAP - #define VERIFY_OPCODE_ID(id, size) COMPILE_ASSERT(id <= op_end, ASSERT_THAT_JS_OPCODE_IDS_ARE_VALID); - FOR_EACH_OPCODE_ID(VERIFY_OPCODE_ID); - #undef VERIFY_OPCODE_ID +#define OPCODE_ID_ENUM(opcode, length) opcode, + typedef enum { FOR_EACH_OPCODE_ID(OPCODE_ID_ENUM) } OpcodeID; +#undef OPCODE_ID_ENUM -#if ENABLE(COMPUTED_GOTO_INTERPRETER) -#if COMPILER(RVCT) - typedef void* Opcode; +const int maxOpcodeLength = 9; +#if !ENABLE(JIT) +const int numOpcodeIDs = NUMBER_OF_BYTECODE_IDS + NUMBER_OF_CLOOP_BYTECODE_HELPER_IDS + NUMBER_OF_BYTECODE_HELPER_IDS; #else - typedef const void* Opcode; +const int numOpcodeIDs = NUMBER_OF_BYTECODE_IDS + NUMBER_OF_BYTECODE_HELPER_IDS; #endif + +#define OPCODE_ID_LENGTHS(id, length) const int id##_length = length; + FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS); +#undef OPCODE_ID_LENGTHS + +#define OPCODE_LENGTH(opcode) opcode##_length + +#define OPCODE_ID_LENGTH_MAP(opcode, length) length, + const int opcodeLengths[numOpcodeIDs] = { FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTH_MAP) }; +#undef OPCODE_ID_LENGTH_MAP + +#define VERIFY_OPCODE_ID(id, size) COMPILE_ASSERT(id <= numOpcodeIDs, ASSERT_THAT_JS_OPCODE_IDS_ARE_VALID); + FOR_EACH_OPCODE_ID(VERIFY_OPCODE_ID); +#undef VERIFY_OPCODE_ID + +#if ENABLE(COMPUTED_GOTO_OPCODES) +typedef void* Opcode; #else - typedef OpcodeID Opcode; +typedef OpcodeID Opcode; #endif -#if ENABLE(OPCODE_SAMPLING) || ENABLE(CODEBLOCK_SAMPLING) || ENABLE(OPCODE_STATS) - #define PADDING_STRING " " #define PADDING_STRING_LENGTH static_cast(strlen(PADDING_STRING)) - extern const char* const opcodeNames[]; +extern const char* const opcodeNames[]; - inline const char* padOpcodeName(OpcodeID op, unsigned width) - { - unsigned pad = width - strlen(opcodeNames[op]); - pad = std::min(pad, PADDING_STRING_LENGTH); - return PADDING_STRING + PADDING_STRING_LENGTH - pad; - } +inline const char* padOpcodeName(OpcodeID op, unsigned width) +{ + unsigned pad = width - strlen(opcodeNames[op]); + pad = std::min(pad, PADDING_STRING_LENGTH); + return PADDING_STRING + PADDING_STRING_LENGTH - pad; +} #undef PADDING_STRING_LENGTH #undef PADDING_STRING -#endif - #if ENABLE(OPCODE_STATS) - struct OpcodeStats { - OpcodeStats(); - ~OpcodeStats(); - static long long opcodeCounts[numOpcodeIDs]; - static long long opcodePairCounts[numOpcodeIDs][numOpcodeIDs]; - static int lastOpcode; - - static void recordInstruction(int opcode); - static void resetLastInstruction(); - }; +struct OpcodeStats { + OpcodeStats(); + ~OpcodeStats(); + static long long opcodeCounts[numOpcodeIDs]; + static long long opcodePairCounts[numOpcodeIDs][numOpcodeIDs]; + static int lastOpcode; + + static void recordInstruction(int opcode); + static void resetLastInstruction(); +}; #endif +inline size_t opcodeLength(OpcodeID opcode) +{ + switch (opcode) { +#define OPCODE_ID_LENGTHS(id, length) case id: return OPCODE_LENGTH(id); + FOR_EACH_OPCODE_ID(OPCODE_ID_LENGTHS) +#undef OPCODE_ID_LENGTHS + } + RELEASE_ASSERT_NOT_REACHED(); + return 0; +} + } // namespace JSC #endif // Opcode_h