v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
experimental-bytecode.cc
Go to the documentation of this file.
1// Copyright 2020 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#include <iomanip>
9
10namespace v8 {
11namespace internal {
12
13namespace {
14
15std::ostream& PrintAsciiOrHex(std::ostream& os, base::uc16 c) {
16 if (c < 128 && std::isprint(c)) {
17 os << static_cast<char>(c);
18 } else {
19 os << "0x" << std::hex << static_cast<int>(c);
20 }
21 return os;
22}
23
24} // namespace
25
26std::ostream& operator<<(std::ostream& os, const RegExpInstruction& inst) {
27 switch (inst.opcode) {
29 os << "CONSUME_RANGE [";
30 PrintAsciiOrHex(os, inst.payload.consume_range.min);
31 os << ", ";
32 PrintAsciiOrHex(os, inst.payload.consume_range.max);
33 os << "]";
34 break;
35 }
37 os << "RANGE_COUNT " << inst.payload.num_ranges;
38 break;
39 }
41 os << "ASSERTION ";
42 switch (inst.payload.assertion_type) {
44 os << "START_OF_INPUT";
45 break;
47 os << "END_OF_INPUT";
48 break;
50 os << "START_OF_LINE";
51 break;
53 os << "END_OF_LINE";
54 break;
56 os << "BOUNDARY";
57 break;
59 os << "NON_BOUNDARY";
60 break;
61 }
62 break;
64 os << "FORK " << inst.payload.pc;
65 break;
67 os << "JMP " << inst.payload.pc;
68 break;
70 os << "ACCEPT";
71 break;
73 os << "SET_REGISTER_TO_CP " << inst.payload.register_index;
74 break;
76 os << "CLEAR_REGISTER " << inst.payload.register_index;
77 break;
79 os << "SET_QUANTIFIER_TO_CLOCK " << inst.payload.quantifier_id;
80 break;
82 os << "FILTER_QUANTIFIER " << inst.payload.quantifier_id;
83 break;
85 os << "FILTER_GROUP " << inst.payload.group_id;
86 break;
88 os << "FILTER_LOOKAROUND " << inst.payload.lookaround_id;
89 break;
91 os << "FILTER_CHILD " << inst.payload.pc;
92 break;
94 os << "BEGIN_LOOP";
95 break;
97 os << "END_LOOP";
98 break;
100 os << "START_LOOKAROUND " << inst.payload.lookaround;
101 break;
103 os << "END_LOOKAROUND";
104 break;
106 os << "WRITE_LOOKAROUND_TABLE " << inst.payload.lookaround_id;
107 break;
109 os << "READ_LOOKAROUND_TABLE " << inst.payload.lookaround;
110 break;
111 }
112 return os;
113}
114
115namespace {
116
117// The maximum number of digits required to display a non-negative number < n
118// in base 10.
119int DigitsRequiredBelow(int n) {
120 DCHECK_GE(n, 0);
121
122 int result = 1;
123 for (int i = 10; i < n; i *= 10) {
124 result += 1;
125 }
126 return result;
127}
128
129} // namespace
130
131std::ostream& operator<<(std::ostream& os,
133 int inst_num = insts.length();
134 int line_digit_num = DigitsRequiredBelow(inst_num);
135
136 for (int i = 0; i != inst_num; ++i) {
137 const RegExpInstruction& inst = insts[i];
138 os << std::setfill('0') << std::setw(line_digit_num) << i << ": " << inst
139 << std::endl;
140 }
141 return os;
142}
143
144std::ostream& operator<<(std::ostream& os,
146 return os << payload.index() << " ("
147 << (payload.type() == RegExpLookaround::Type::LOOKAHEAD ? "ahead"
148 : "behind")
149 << ", " << (payload.is_positive() ? "positive" : "negative") << ")";
150}
151
152} // namespace internal
153} // namespace v8
int length() const
Definition vector.h:64
ZoneVector< RpoNumber > & result
int n
Definition mul-fft.cc:296
uint16_t uc16
Definition strings.h:18
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
#define DCHECK_GE(v1, v2)
Definition logging.h:488
union v8::internal::RegExpInstruction::@129 payload