blob: bd906fea153a21ef34b9d8b885130311599070d0 [file] [log] [blame]
Rubin Xu6e1e26a2021-02-10 00:04:48 +00001// Copyright 2008-2009 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#ifndef V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_
6#define V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_
7
8#include "src/regexp/regexp-bytecode-generator.h"
9
10#include "src/ast/ast.h"
11#include "src/regexp/regexp-bytecodes.h"
12
13namespace v8 {
14namespace internal {
15
16void RegExpBytecodeGenerator::Emit(uint32_t byte, uint32_t twenty_four_bits) {
17 uint32_t word = ((twenty_four_bits << BYTECODE_SHIFT) | byte);
18 DCHECK(pc_ <= buffer_.length());
19 if (pc_ + 3 >= buffer_.length()) {
20 Expand();
21 }
22 *reinterpret_cast<uint32_t*>(buffer_.begin() + pc_) = word;
23 pc_ += 4;
24}
25
26void RegExpBytecodeGenerator::Emit16(uint32_t word) {
27 DCHECK(pc_ <= buffer_.length());
28 if (pc_ + 1 >= buffer_.length()) {
29 Expand();
30 }
31 *reinterpret_cast<uint16_t*>(buffer_.begin() + pc_) = word;
32 pc_ += 2;
33}
34
35void RegExpBytecodeGenerator::Emit8(uint32_t word) {
36 DCHECK(pc_ <= buffer_.length());
37 if (pc_ == buffer_.length()) {
38 Expand();
39 }
40 *reinterpret_cast<unsigned char*>(buffer_.begin() + pc_) = word;
41 pc_ += 1;
42}
43
44void RegExpBytecodeGenerator::Emit32(uint32_t word) {
45 DCHECK(pc_ <= buffer_.length());
46 if (pc_ + 3 >= buffer_.length()) {
47 Expand();
48 }
49 *reinterpret_cast<uint32_t*>(buffer_.begin() + pc_) = word;
50 pc_ += 4;
51}
52
53} // namespace internal
54} // namespace v8
55
56#endif // V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_