v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
regexp-bytecodes.cc
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <cctype>
8
9#include "src/utils/utils.h"
10
11namespace v8 {
12namespace internal {
13
14void RegExpBytecodeDisassembleSingle(const uint8_t* code_base,
15 const uint8_t* pc) {
16 int bytecode = *reinterpret_cast<const int32_t*>(pc) & BYTECODE_MASK;
17 PrintF("%s", RegExpBytecodeName(bytecode));
18
19 // Args and the bytecode as hex.
20 for (int i = 0; i < RegExpBytecodeLength(bytecode); i++) {
21 PrintF(", %02x", pc[i]);
22 }
23 PrintF(" ");
24
25 // Args as ascii.
26 for (int i = 1; i < RegExpBytecodeLength(bytecode); i++) {
27 unsigned char b = pc[i];
28 PrintF("%c", std::isprint(b) ? b : '.');
29 }
30 PrintF("\n");
31}
32
33void RegExpBytecodeDisassemble(const uint8_t* code_base, int length,
34 const char* pattern) {
35 PrintF("[generated bytecode for regexp pattern: '%s']\n", pattern);
36
37 ptrdiff_t offset = 0;
38
39 while (offset < length) {
40 const uint8_t* const pc = code_base + offset;
41 PrintF("%p %4" V8PRIxPTRDIFF " ", pc, offset);
44 }
45}
46
47} // namespace internal
48} // namespace v8
int32_t offset
std::string pattern
constexpr int RegExpBytecodeLength(int bytecode)
constexpr const char * RegExpBytecodeName(int bytecode)
void PrintF(const char *format,...)
Definition utils.cc:39
void RegExpBytecodeDisassembleSingle(const uint8_t *code_base, const uint8_t *pc)
constexpr int BYTECODE_MASK
void RegExpBytecodeDisassemble(const uint8_t *code_base, int length, const char *pattern)
#define V8PRIxPTRDIFF
Definition macros.h:349