11cb0ef41Sopenharmony_ci// Copyright 2011 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_REGEXP_REGEXP_BYTECODES_H_ 61cb0ef41Sopenharmony_ci#define V8_REGEXP_REGEXP_BYTECODES_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/base/bounds.h" 91cb0ef41Sopenharmony_ci#include "src/base/macros.h" 101cb0ef41Sopenharmony_ci#include "src/base/strings.h" 111cb0ef41Sopenharmony_ci#include "src/common/globals.h" 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cinamespace v8 { 141cb0ef41Sopenharmony_cinamespace internal { 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci// Maximum number of bytecodes that will be used (next power of 2 of actually 171cb0ef41Sopenharmony_ci// defined bytecodes). 181cb0ef41Sopenharmony_ci// All slots between the last actually defined bytecode and maximum id will be 191cb0ef41Sopenharmony_ci// filled with BREAKs, indicating an invalid operation. This way using 201cb0ef41Sopenharmony_ci// BYTECODE_MASK guarantees no OOB access to the dispatch table. 211cb0ef41Sopenharmony_ciconstexpr int kRegExpPaddedBytecodeCount = 1 << 6; 221cb0ef41Sopenharmony_ciconstexpr int BYTECODE_MASK = kRegExpPaddedBytecodeCount - 1; 231cb0ef41Sopenharmony_ci// The first argument is packed in with the byte code in one word, but so it 241cb0ef41Sopenharmony_ci// has 24 bits, but it can be positive and negative so only use 23 bits for 251cb0ef41Sopenharmony_ci// positive values. 261cb0ef41Sopenharmony_ciconst unsigned int MAX_FIRST_ARG = 0x7fffffu; 271cb0ef41Sopenharmony_ciconst int BYTECODE_SHIFT = 8; 281cb0ef41Sopenharmony_ciSTATIC_ASSERT(1 << BYTECODE_SHIFT > BYTECODE_MASK); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci// The list of bytecodes, in format: V(Name, Code, ByteLength). 311cb0ef41Sopenharmony_ci// TODO(pthier): Argument offsets of bytecodes should be easily accessible by 321cb0ef41Sopenharmony_ci// name or at least by position. 331cb0ef41Sopenharmony_ci// TODO(jgruber): More precise types (e.g. int32/uint32 instead of value32). 341cb0ef41Sopenharmony_ci#define BYTECODE_ITERATOR(V) \ 351cb0ef41Sopenharmony_ci V(BREAK, 0, 4) /* bc8 */ \ 361cb0ef41Sopenharmony_ci V(PUSH_CP, 1, 4) /* bc8 pad24 */ \ 371cb0ef41Sopenharmony_ci V(PUSH_BT, 2, 8) /* bc8 pad24 offset32 */ \ 381cb0ef41Sopenharmony_ci V(PUSH_REGISTER, 3, 4) /* bc8 reg_idx24 */ \ 391cb0ef41Sopenharmony_ci V(SET_REGISTER_TO_CP, 4, 8) /* bc8 reg_idx24 offset32 */ \ 401cb0ef41Sopenharmony_ci V(SET_CP_TO_REGISTER, 5, 4) /* bc8 reg_idx24 */ \ 411cb0ef41Sopenharmony_ci V(SET_REGISTER_TO_SP, 6, 4) /* bc8 reg_idx24 */ \ 421cb0ef41Sopenharmony_ci V(SET_SP_TO_REGISTER, 7, 4) /* bc8 reg_idx24 */ \ 431cb0ef41Sopenharmony_ci V(SET_REGISTER, 8, 8) /* bc8 reg_idx24 value32 */ \ 441cb0ef41Sopenharmony_ci V(ADVANCE_REGISTER, 9, 8) /* bc8 reg_idx24 value32 */ \ 451cb0ef41Sopenharmony_ci V(POP_CP, 10, 4) /* bc8 pad24 */ \ 461cb0ef41Sopenharmony_ci V(POP_BT, 11, 4) /* bc8 pad24 */ \ 471cb0ef41Sopenharmony_ci V(POP_REGISTER, 12, 4) /* bc8 reg_idx24 */ \ 481cb0ef41Sopenharmony_ci V(FAIL, 13, 4) /* bc8 pad24 */ \ 491cb0ef41Sopenharmony_ci V(SUCCEED, 14, 4) /* bc8 pad24 */ \ 501cb0ef41Sopenharmony_ci V(ADVANCE_CP, 15, 4) /* bc8 offset24 */ \ 511cb0ef41Sopenharmony_ci /* Jump to another bytecode given its offset. */ \ 521cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 531cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x10 (fixed) Bytecode */ \ 541cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: 0x00 (unused) Padding */ \ 551cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode to jump to */ \ 561cb0ef41Sopenharmony_ci V(GOTO, 16, 8) /* bc8 pad24 addr32 */ \ 571cb0ef41Sopenharmony_ci /* Check if offset is in range and load character at given offset. */ \ 581cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 591cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x11 (fixed) Bytecode */ \ 601cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: Offset from current position */ \ 611cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode when load is out of range */ \ 621cb0ef41Sopenharmony_ci V(LOAD_CURRENT_CHAR, 17, 8) /* bc8 offset24 addr32 */ \ 631cb0ef41Sopenharmony_ci /* Load character at given offset without range checks. */ \ 641cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 651cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x12 (fixed) Bytecode */ \ 661cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: Offset from current position */ \ 671cb0ef41Sopenharmony_ci V(LOAD_CURRENT_CHAR_UNCHECKED, 18, 4) /* bc8 offset24 */ \ 681cb0ef41Sopenharmony_ci V(LOAD_2_CURRENT_CHARS, 19, 8) /* bc8 offset24 addr32 */ \ 691cb0ef41Sopenharmony_ci V(LOAD_2_CURRENT_CHARS_UNCHECKED, 20, 4) /* bc8 offset24 */ \ 701cb0ef41Sopenharmony_ci V(LOAD_4_CURRENT_CHARS, 21, 8) /* bc8 offset24 addr32 */ \ 711cb0ef41Sopenharmony_ci V(LOAD_4_CURRENT_CHARS_UNCHECKED, 22, 4) /* bc8 offset24 */ \ 721cb0ef41Sopenharmony_ci V(CHECK_4_CHARS, 23, 12) /* bc8 pad24 uint32 addr32 */ \ 731cb0ef41Sopenharmony_ci /* Check if current character is equal to a given character */ \ 741cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 751cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x19 (fixed) Bytecode */ \ 761cb0ef41Sopenharmony_ci /* 0x08 - 0x0F: 0x00 (unused) Padding */ \ 771cb0ef41Sopenharmony_ci /* 0x10 - 0x1F: Character to check */ \ 781cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode when matched */ \ 791cb0ef41Sopenharmony_ci V(CHECK_CHAR, 24, 8) /* bc8 pad8 uint16 addr32 */ \ 801cb0ef41Sopenharmony_ci V(CHECK_NOT_4_CHARS, 25, 12) /* bc8 pad24 uint32 addr32 */ \ 811cb0ef41Sopenharmony_ci V(CHECK_NOT_CHAR, 26, 8) /* bc8 pad8 uint16 addr32 */ \ 821cb0ef41Sopenharmony_ci V(AND_CHECK_4_CHARS, 27, 16) /* bc8 pad24 uint32 uint32 addr32 */ \ 831cb0ef41Sopenharmony_ci /* Checks if the current character combined with mask (bitwise and) */ \ 841cb0ef41Sopenharmony_ci /* matches a character (e.g. used when two characters in a disjunction */ \ 851cb0ef41Sopenharmony_ci /* differ by only a single bit */ \ 861cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 871cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x1c (fixed) Bytecode */ \ 881cb0ef41Sopenharmony_ci /* 0x08 - 0x0F: 0x00 (unused) Padding */ \ 891cb0ef41Sopenharmony_ci /* 0x10 - 0x1F: Character to match against (after mask aplied) */ \ 901cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Bitmask bitwise and combined with current character */ \ 911cb0ef41Sopenharmony_ci /* 0x40 - 0x5F: Address of bytecode when matched */ \ 921cb0ef41Sopenharmony_ci V(AND_CHECK_CHAR, 28, 12) /* bc8 pad8 uint16 uint32 addr32 */ \ 931cb0ef41Sopenharmony_ci V(AND_CHECK_NOT_4_CHARS, 29, 16) /* bc8 pad24 uint32 uint32 addr32 */ \ 941cb0ef41Sopenharmony_ci V(AND_CHECK_NOT_CHAR, 30, 12) /* bc8 pad8 uint16 uint32 addr32 */ \ 951cb0ef41Sopenharmony_ci V(MINUS_AND_CHECK_NOT_CHAR, 31, \ 961cb0ef41Sopenharmony_ci 12) /* bc8 pad8 base::uc16 base::uc16 base::uc16 addr32 */ \ 971cb0ef41Sopenharmony_ci V(CHECK_CHAR_IN_RANGE, 32, 12) /* bc8 pad24 base::uc16 base::uc16 addr32 */ \ 981cb0ef41Sopenharmony_ci V(CHECK_CHAR_NOT_IN_RANGE, 33, \ 991cb0ef41Sopenharmony_ci 12) /* bc8 pad24 base::uc16 base::uc16 addr32 */ \ 1001cb0ef41Sopenharmony_ci /* Checks if the current character matches any of the characters encoded */ \ 1011cb0ef41Sopenharmony_ci /* in a bit table. Similar to/inspired by boyer moore string search */ \ 1021cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1031cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x22 (fixed) Bytecode */ \ 1041cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: 0x00 (unused) Padding */ \ 1051cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode when bit is set */ \ 1061cb0ef41Sopenharmony_ci /* 0x40 - 0xBF: Bit table */ \ 1071cb0ef41Sopenharmony_ci V(CHECK_BIT_IN_TABLE, 34, 24) /* bc8 pad24 addr32 bits128 */ \ 1081cb0ef41Sopenharmony_ci V(CHECK_LT, 35, 8) /* bc8 pad8 base::uc16 addr32 */ \ 1091cb0ef41Sopenharmony_ci V(CHECK_GT, 36, 8) /* bc8 pad8 base::uc16 addr32 */ \ 1101cb0ef41Sopenharmony_ci V(CHECK_NOT_BACK_REF, 37, 8) /* bc8 reg_idx24 addr32 */ \ 1111cb0ef41Sopenharmony_ci V(CHECK_NOT_BACK_REF_NO_CASE, 38, 8) /* bc8 reg_idx24 addr32 */ \ 1121cb0ef41Sopenharmony_ci V(CHECK_NOT_BACK_REF_NO_CASE_UNICODE, 39, 8) \ 1131cb0ef41Sopenharmony_ci V(CHECK_NOT_BACK_REF_BACKWARD, 40, 8) /* bc8 reg_idx24 addr32 */ \ 1141cb0ef41Sopenharmony_ci V(CHECK_NOT_BACK_REF_NO_CASE_BACKWARD, 41, 8) /* bc8 reg_idx24 addr32 */ \ 1151cb0ef41Sopenharmony_ci V(CHECK_NOT_BACK_REF_NO_CASE_UNICODE_BACKWARD, 42, 8) \ 1161cb0ef41Sopenharmony_ci V(CHECK_NOT_REGS_EQUAL, 43, 12) /* bc8 regidx24 reg_idx32 addr32 */ \ 1171cb0ef41Sopenharmony_ci V(CHECK_REGISTER_LT, 44, 12) /* bc8 reg_idx24 value32 addr32 */ \ 1181cb0ef41Sopenharmony_ci V(CHECK_REGISTER_GE, 45, 12) /* bc8 reg_idx24 value32 addr32 */ \ 1191cb0ef41Sopenharmony_ci V(CHECK_REGISTER_EQ_POS, 46, 8) /* bc8 reg_idx24 addr32 */ \ 1201cb0ef41Sopenharmony_ci V(CHECK_AT_START, 47, 8) /* bc8 pad24 addr32 */ \ 1211cb0ef41Sopenharmony_ci V(CHECK_NOT_AT_START, 48, 8) /* bc8 offset24 addr32 */ \ 1221cb0ef41Sopenharmony_ci /* Checks if the current position matches top of backtrack stack */ \ 1231cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1241cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x31 (fixed) Bytecode */ \ 1251cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: 0x00 (unused) Padding */ \ 1261cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode when current matches tos */ \ 1271cb0ef41Sopenharmony_ci V(CHECK_GREEDY, 49, 8) /* bc8 pad24 addr32 */ \ 1281cb0ef41Sopenharmony_ci /* Advance character pointer by given offset and jump to another bytecode.*/ \ 1291cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1301cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x32 (fixed) Bytecode */ \ 1311cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: Number of characters to advance */ \ 1321cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode to jump to */ \ 1331cb0ef41Sopenharmony_ci V(ADVANCE_CP_AND_GOTO, 50, 8) /* bc8 offset24 addr32 */ \ 1341cb0ef41Sopenharmony_ci V(SET_CURRENT_POSITION_FROM_END, 51, 4) /* bc8 idx24 */ \ 1351cb0ef41Sopenharmony_ci /* Checks if current position + given offset is in range. */ \ 1361cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1371cb0ef41Sopenharmony_ci /* 0x00 - 0x07: 0x34 (fixed) Bytecode */ \ 1381cb0ef41Sopenharmony_ci /* 0x08 - 0x1F: Offset from current position */ \ 1391cb0ef41Sopenharmony_ci /* 0x20 - 0x3F: Address of bytecode when position is out of range */ \ 1401cb0ef41Sopenharmony_ci V(CHECK_CURRENT_POSITION, 52, 8) /* bc8 idx24 addr32 */ \ 1411cb0ef41Sopenharmony_ci /* Combination of: */ \ 1421cb0ef41Sopenharmony_ci /* LOAD_CURRENT_CHAR, CHECK_BIT_IN_TABLE and ADVANCE_CP_AND_GOTO */ \ 1431cb0ef41Sopenharmony_ci /* Emitted by RegExpBytecodePeepholeOptimization. */ \ 1441cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1451cb0ef41Sopenharmony_ci /* 0x00 - 0x07 0x35 (fixed) Bytecode */ \ 1461cb0ef41Sopenharmony_ci /* 0x08 - 0x1F Load character offset from current position */ \ 1471cb0ef41Sopenharmony_ci /* 0x20 - 0x3F Number of characters to advance */ \ 1481cb0ef41Sopenharmony_ci /* 0x40 - 0xBF Bit Table */ \ 1491cb0ef41Sopenharmony_ci /* 0xC0 - 0xDF Address of bytecode when character is matched */ \ 1501cb0ef41Sopenharmony_ci /* 0xE0 - 0xFF Address of bytecode when no match */ \ 1511cb0ef41Sopenharmony_ci V(SKIP_UNTIL_BIT_IN_TABLE, 53, 32) \ 1521cb0ef41Sopenharmony_ci /* Combination of: */ \ 1531cb0ef41Sopenharmony_ci /* CHECK_CURRENT_POSITION, LOAD_CURRENT_CHAR_UNCHECKED, AND_CHECK_CHAR */ \ 1541cb0ef41Sopenharmony_ci /* and ADVANCE_CP_AND_GOTO */ \ 1551cb0ef41Sopenharmony_ci /* Emitted by RegExpBytecodePeepholeOptimization. */ \ 1561cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1571cb0ef41Sopenharmony_ci /* 0x00 - 0x07 0x36 (fixed) Bytecode */ \ 1581cb0ef41Sopenharmony_ci /* 0x08 - 0x1F Load character offset from current position */ \ 1591cb0ef41Sopenharmony_ci /* 0x20 - 0x2F Number of characters to advance */ \ 1601cb0ef41Sopenharmony_ci /* 0x30 - 0x3F Character to match against (after mask applied) */ \ 1611cb0ef41Sopenharmony_ci /* 0x40 - 0x5F: Bitmask bitwise and combined with current character */ \ 1621cb0ef41Sopenharmony_ci /* 0x60 - 0x7F Minimum number of characters this pattern consumes */ \ 1631cb0ef41Sopenharmony_ci /* 0x80 - 0x9F Address of bytecode when character is matched */ \ 1641cb0ef41Sopenharmony_ci /* 0xA0 - 0xBF Address of bytecode when no match */ \ 1651cb0ef41Sopenharmony_ci V(SKIP_UNTIL_CHAR_AND, 54, 24) \ 1661cb0ef41Sopenharmony_ci /* Combination of: */ \ 1671cb0ef41Sopenharmony_ci /* LOAD_CURRENT_CHAR, CHECK_CHAR and ADVANCE_CP_AND_GOTO */ \ 1681cb0ef41Sopenharmony_ci /* Emitted by RegExpBytecodePeepholeOptimization. */ \ 1691cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1701cb0ef41Sopenharmony_ci /* 0x00 - 0x07 0x37 (fixed) Bytecode */ \ 1711cb0ef41Sopenharmony_ci /* 0x08 - 0x1F Load character offset from current position */ \ 1721cb0ef41Sopenharmony_ci /* 0x20 - 0x2F Number of characters to advance */ \ 1731cb0ef41Sopenharmony_ci /* 0x30 - 0x3F Character to match */ \ 1741cb0ef41Sopenharmony_ci /* 0x40 - 0x5F Address of bytecode when character is matched */ \ 1751cb0ef41Sopenharmony_ci /* 0x60 - 0x7F Address of bytecode when no match */ \ 1761cb0ef41Sopenharmony_ci V(SKIP_UNTIL_CHAR, 55, 16) \ 1771cb0ef41Sopenharmony_ci /* Combination of: */ \ 1781cb0ef41Sopenharmony_ci /* CHECK_CURRENT_POSITION, LOAD_CURRENT_CHAR_UNCHECKED, CHECK_CHAR */ \ 1791cb0ef41Sopenharmony_ci /* and ADVANCE_CP_AND_GOTO */ \ 1801cb0ef41Sopenharmony_ci /* Emitted by RegExpBytecodePeepholeOptimization. */ \ 1811cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1821cb0ef41Sopenharmony_ci /* 0x00 - 0x07 0x38 (fixed) Bytecode */ \ 1831cb0ef41Sopenharmony_ci /* 0x08 - 0x1F Load character offset from current position */ \ 1841cb0ef41Sopenharmony_ci /* 0x20 - 0x2F Number of characters to advance */ \ 1851cb0ef41Sopenharmony_ci /* 0x30 - 0x3F Character to match */ \ 1861cb0ef41Sopenharmony_ci /* 0x40 - 0x5F Minimum number of characters this pattern consumes */ \ 1871cb0ef41Sopenharmony_ci /* 0x60 - 0x7F Address of bytecode when character is matched */ \ 1881cb0ef41Sopenharmony_ci /* 0x80 - 0x9F Address of bytecode when no match */ \ 1891cb0ef41Sopenharmony_ci V(SKIP_UNTIL_CHAR_POS_CHECKED, 56, 20) \ 1901cb0ef41Sopenharmony_ci /* Combination of: */ \ 1911cb0ef41Sopenharmony_ci /* LOAD_CURRENT_CHAR, CHECK_CHAR, CHECK_CHAR and ADVANCE_CP_AND_GOTO */ \ 1921cb0ef41Sopenharmony_ci /* Emitted by RegExpBytecodePeepholeOptimization. */ \ 1931cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 1941cb0ef41Sopenharmony_ci /* 0x00 - 0x07 0x39 (fixed) Bytecode */ \ 1951cb0ef41Sopenharmony_ci /* 0x08 - 0x1F Load character offset from current position */ \ 1961cb0ef41Sopenharmony_ci /* 0x20 - 0x3F Number of characters to advance */ \ 1971cb0ef41Sopenharmony_ci /* 0x40 - 0x4F Character to match */ \ 1981cb0ef41Sopenharmony_ci /* 0x50 - 0x5F Other Character to match */ \ 1991cb0ef41Sopenharmony_ci /* 0x60 - 0x7F Address of bytecode when either character is matched */ \ 2001cb0ef41Sopenharmony_ci /* 0x80 - 0x9F Address of bytecode when no match */ \ 2011cb0ef41Sopenharmony_ci V(SKIP_UNTIL_CHAR_OR_CHAR, 57, 20) \ 2021cb0ef41Sopenharmony_ci /* Combination of: */ \ 2031cb0ef41Sopenharmony_ci /* LOAD_CURRENT_CHAR, CHECK_GT, CHECK_BIT_IN_TABLE, GOTO and */ \ 2041cb0ef41Sopenharmony_ci /* and ADVANCE_CP_AND_GOTO */ \ 2051cb0ef41Sopenharmony_ci /* Emitted by RegExpBytecodePeepholeOptimization. */ \ 2061cb0ef41Sopenharmony_ci /* Bit Layout: */ \ 2071cb0ef41Sopenharmony_ci /* 0x00 - 0x07 0x3A (fixed) Bytecode */ \ 2081cb0ef41Sopenharmony_ci /* 0x08 - 0x1F Load character offset from current position */ \ 2091cb0ef41Sopenharmony_ci /* 0x20 - 0x2F Number of characters to advance */ \ 2101cb0ef41Sopenharmony_ci /* 0x30 - 0x3F Character to check if it is less than current char */ \ 2111cb0ef41Sopenharmony_ci /* 0x40 - 0xBF Bit Table */ \ 2121cb0ef41Sopenharmony_ci /* 0xC0 - 0xDF Address of bytecode when character is matched */ \ 2131cb0ef41Sopenharmony_ci /* 0xE0 - 0xFF Address of bytecode when no match */ \ 2141cb0ef41Sopenharmony_ci V(SKIP_UNTIL_GT_OR_NOT_BIT_IN_TABLE, 58, 32) 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ci#define COUNT(...) +1 2171cb0ef41Sopenharmony_cistatic constexpr int kRegExpBytecodeCount = BYTECODE_ITERATOR(COUNT); 2181cb0ef41Sopenharmony_ci#undef COUNT 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_ci// Just making sure we assigned values above properly. They should be 2211cb0ef41Sopenharmony_ci// contiguous, strictly increasing, and start at 0. 2221cb0ef41Sopenharmony_ci// TODO(jgruber): Do not explicitly assign values, instead generate them 2231cb0ef41Sopenharmony_ci// implicitly from the list order. 2241cb0ef41Sopenharmony_ciSTATIC_ASSERT(kRegExpBytecodeCount == 59); 2251cb0ef41Sopenharmony_ci 2261cb0ef41Sopenharmony_ci#define DECLARE_BYTECODES(name, code, length) \ 2271cb0ef41Sopenharmony_ci static constexpr int BC_##name = code; 2281cb0ef41Sopenharmony_ciBYTECODE_ITERATOR(DECLARE_BYTECODES) 2291cb0ef41Sopenharmony_ci#undef DECLARE_BYTECODES 2301cb0ef41Sopenharmony_ci 2311cb0ef41Sopenharmony_cistatic constexpr int kRegExpBytecodeLengths[] = { 2321cb0ef41Sopenharmony_ci#define DECLARE_BYTECODE_LENGTH(name, code, length) length, 2331cb0ef41Sopenharmony_ci BYTECODE_ITERATOR(DECLARE_BYTECODE_LENGTH) 2341cb0ef41Sopenharmony_ci#undef DECLARE_BYTECODE_LENGTH 2351cb0ef41Sopenharmony_ci}; 2361cb0ef41Sopenharmony_ci 2371cb0ef41Sopenharmony_ciinline constexpr int RegExpBytecodeLength(int bytecode) { 2381cb0ef41Sopenharmony_ci DCHECK(base::IsInRange(bytecode, 0, kRegExpBytecodeCount - 1)); 2391cb0ef41Sopenharmony_ci return kRegExpBytecodeLengths[bytecode]; 2401cb0ef41Sopenharmony_ci} 2411cb0ef41Sopenharmony_ci 2421cb0ef41Sopenharmony_cistatic constexpr const char* const kRegExpBytecodeNames[] = { 2431cb0ef41Sopenharmony_ci#define DECLARE_BYTECODE_NAME(name, ...) #name, 2441cb0ef41Sopenharmony_ci BYTECODE_ITERATOR(DECLARE_BYTECODE_NAME) 2451cb0ef41Sopenharmony_ci#undef DECLARE_BYTECODE_NAME 2461cb0ef41Sopenharmony_ci}; 2471cb0ef41Sopenharmony_ci 2481cb0ef41Sopenharmony_ciinline constexpr const char* RegExpBytecodeName(int bytecode) { 2491cb0ef41Sopenharmony_ci DCHECK(base::IsInRange(bytecode, 0, kRegExpBytecodeCount - 1)); 2501cb0ef41Sopenharmony_ci return kRegExpBytecodeNames[bytecode]; 2511cb0ef41Sopenharmony_ci} 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_civoid RegExpBytecodeDisassembleSingle(const byte* code_base, const byte* pc); 2541cb0ef41Sopenharmony_civoid RegExpBytecodeDisassemble(const byte* code_base, int length, 2551cb0ef41Sopenharmony_ci const char* pattern); 2561cb0ef41Sopenharmony_ci 2571cb0ef41Sopenharmony_ci} // namespace internal 2581cb0ef41Sopenharmony_ci} // namespace v8 2591cb0ef41Sopenharmony_ci 2601cb0ef41Sopenharmony_ci#endif // V8_REGEXP_REGEXP_BYTECODES_H_ 261