regexp-bytecodes.cc (1331B)
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 5 #include "irregexp/imported/regexp-bytecodes.h" 6 7 #include <cctype> 8 9 10 namespace v8 { 11 namespace internal { 12 13 void RegExpBytecodeDisassembleSingle(const uint8_t* code_base, 14 const uint8_t* pc) { 15 int bytecode = *reinterpret_cast<const int32_t*>(pc) & BYTECODE_MASK; 16 PrintF("%s", RegExpBytecodeName(bytecode)); 17 18 // Args and the bytecode as hex. 19 for (int i = 0; i < RegExpBytecodeLength(bytecode); i++) { 20 PrintF(", %02x", pc[i]); 21 } 22 PrintF(" "); 23 24 // Args as ascii. 25 for (int i = 1; i < RegExpBytecodeLength(bytecode); i++) { 26 unsigned char b = pc[i]; 27 PrintF("%c", std::isprint(b) ? b : '.'); 28 } 29 PrintF("\n"); 30 } 31 32 void RegExpBytecodeDisassemble(const uint8_t* code_base, int length, 33 const char* pattern) { 34 PrintF("[generated bytecode for regexp pattern: '%s']\n", pattern); 35 36 ptrdiff_t offset = 0; 37 38 while (offset < length) { 39 const uint8_t* const pc = code_base + offset; 40 PrintF("%p %4" V8PRIxPTRDIFF " ", pc, offset); 41 RegExpBytecodeDisassembleSingle(code_base, pc); 42 offset += RegExpBytecodeLength(*pc); 43 } 44 } 45 46 } // namespace internal 47 } // namespace v8