1// Copyright 2008-2009 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
29#ifndef V8_BYTECODES_IRREGEXP_H_
30#define V8_BYTECODES_IRREGEXP_H_
31
32namespace v8 {
33namespace internal {
34
35
36static const int BYTECODE_MASK = 0xff;
37// The first argument is packed in with the byte code in one word, but so it
38// has 24 bits, but it can be positive and negative so only use 23 bits for
39// positive values.
40static const unsigned int MAX_FIRST_ARG = 0x7fffffu;
41static const int BYTECODE_SHIFT = 8;
42
43#define BYTECODE_ITERATOR(V)                                                   \
44V(BREAK,              0, 4)   /* bc8                                        */ \
45V(PUSH_CP,            1, 4)   /* bc8 pad24                                  */ \
46V(PUSH_BT,            2, 8)   /* bc8 pad24 offset32                         */ \
47V(PUSH_REGISTER,      3, 4)   /* bc8 reg_idx24                              */ \
48V(SET_REGISTER_TO_CP, 4, 8)   /* bc8 reg_idx24 offset32                     */ \
49V(SET_CP_TO_REGISTER, 5, 4)   /* bc8 reg_idx24                              */ \
50V(SET_REGISTER_TO_SP, 6, 4)   /* bc8 reg_idx24                              */ \
51V(SET_SP_TO_REGISTER, 7, 4)   /* bc8 reg_idx24                              */ \
52V(SET_REGISTER,       8, 8)   /* bc8 reg_idx24 value32                      */ \
53V(ADVANCE_REGISTER,   9, 8)   /* bc8 reg_idx24 value32                      */ \
54V(POP_CP,            10, 4)   /* bc8 pad24                                  */ \
55V(POP_BT,            11, 4)   /* bc8 pad24                                  */ \
56V(POP_REGISTER,      12, 4)   /* bc8 reg_idx24                              */ \
57V(FAIL,              13, 4)   /* bc8 pad24                                  */ \
58V(SUCCEED,           14, 4)   /* bc8 pad24                                  */ \
59V(ADVANCE_CP,        15, 4)   /* bc8 offset24                               */ \
60V(GOTO,              16, 8)   /* bc8 pad24 addr32                           */ \
61V(LOAD_CURRENT_CHAR, 17, 8)   /* bc8 offset24 addr32                        */ \
62V(LOAD_CURRENT_CHAR_UNCHECKED, 18, 4) /* bc8 offset24                       */ \
63V(LOAD_2_CURRENT_CHARS, 19, 8) /* bc8 offset24 addr32                       */ \
64V(LOAD_2_CURRENT_CHARS_UNCHECKED, 20, 4) /* bc8 offset24                    */ \
65V(LOAD_4_CURRENT_CHARS, 21, 8) /* bc8 offset24 addr32                       */ \
66V(LOAD_4_CURRENT_CHARS_UNCHECKED, 22, 4) /* bc8 offset24                    */ \
67V(CHECK_4_CHARS,     23, 12)  /* bc8 pad24 uint32 addr32                    */ \
68V(CHECK_CHAR,        24, 8)   /* bc8 pad8 uint16 addr32                     */ \
69V(CHECK_NOT_4_CHARS, 25, 12)  /* bc8 pad24 uint32 addr32                    */ \
70V(CHECK_NOT_CHAR,    26, 8)   /* bc8 pad8 uint16 addr32                     */ \
71V(AND_CHECK_4_CHARS, 27, 16)  /* bc8 pad24 uint32 uint32 addr32             */ \
72V(AND_CHECK_CHAR,    28, 12)  /* bc8 pad8 uint16 uint32 addr32              */ \
73V(AND_CHECK_NOT_4_CHARS, 29, 16) /* bc8 pad24 uint32 uint32 addr32          */ \
74V(AND_CHECK_NOT_CHAR, 30, 12) /* bc8 pad8 uint16 uint32 addr32              */ \
75V(MINUS_AND_CHECK_NOT_CHAR, 31, 12) /* bc8 pad8 uc16 uc16 addr32            */ \
76V(CHECK_LT,          32, 8)   /* bc8 pad8 uc16 addr32                       */ \
77V(CHECK_GT,          33, 8)   /* bc8 pad8 uc16 addr32                       */ \
78V(CHECK_NOT_BACK_REF, 34, 8)  /* bc8 reg_idx24 addr32                       */ \
79V(CHECK_NOT_BACK_REF_NO_CASE, 35, 8) /* bc8 reg_idx24 addr32                */ \
80V(CHECK_NOT_REGS_EQUAL, 36, 12) /* bc8 regidx24 reg_idx32 addr32            */ \
81V(LOOKUP_MAP1,       37, 12)  /* bc8 pad8 start16 bit_map_addr32 addr32     */ \
82V(LOOKUP_MAP2,       38, 96)  /* bc8 pad8 start16 half_nibble_map_addr32*   */ \
83V(LOOKUP_MAP8,       39, 96)  /* bc8 pad8  start16 byte_map addr32*         */ \
84V(LOOKUP_HI_MAP8,    40, 96)  /* bc8 start24 byte_map_addr32 addr32*        */ \
85V(CHECK_REGISTER_LT, 41, 12)  /* bc8 reg_idx24 value32 addr32               */ \
86V(CHECK_REGISTER_GE, 42, 12)  /* bc8 reg_idx24 value32 addr32               */ \
87V(CHECK_REGISTER_EQ_POS, 43, 8) /* bc8 reg_idx24 addr32                     */ \
88V(CHECK_AT_START,    44, 8)   /* bc8 pad24 addr32                           */ \
89V(CHECK_NOT_AT_START, 45, 8)  /* bc8 pad24 addr32                           */ \
90V(CHECK_GREEDY,      46, 8)   /* bc8 pad24 addr32                           */ \
91V(ADVANCE_CP_AND_GOTO, 47, 8) /* bc8 offset24 addr32                        */
92
93#define DECLARE_BYTECODES(name, code, length) \
94  static const int BC_##name = code;
95BYTECODE_ITERATOR(DECLARE_BYTECODES)
96#undef DECLARE_BYTECODES
97
98#define DECLARE_BYTECODE_LENGTH(name, code, length) \
99  static const int BC_##name##_LENGTH = length;
100BYTECODE_ITERATOR(DECLARE_BYTECODE_LENGTH)
101#undef DECLARE_BYTECODE_LENGTH
102} }
103
104#endif  // V8_BYTECODES_IRREGEXP_H_
105