regexp-bytecode-generator-inl.h 1.53 KB
Newer Older
1
// Copyright 2008-2009 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_
#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

13 14
namespace v8 {
namespace internal {
15

16
void RegExpBytecodeGenerator::Emit(uint32_t byte, uint32_t twenty_four_bits) {
17 18 19 20 21 22 23
  DCHECK(is_uint24(twenty_four_bits));
  Emit32((twenty_four_bits << BYTECODE_SHIFT) | byte);
}

void RegExpBytecodeGenerator::Emit(uint32_t byte, int32_t twenty_four_bits) {
  DCHECK(is_int24(twenty_four_bits));
  Emit32((static_cast<uint32_t>(twenty_four_bits) << BYTECODE_SHIFT) | byte);
24 25
}

26
void RegExpBytecodeGenerator::Emit16(uint32_t word) {
27
  DCHECK(pc_ <= buffer_.length());
28 29 30
  if (pc_ + 1 >= buffer_.length()) {
    Expand();
  }
31
  *reinterpret_cast<uint16_t*>(buffer_.begin() + pc_) = word;
32 33 34
  pc_ += 2;
}

35
void RegExpBytecodeGenerator::Emit8(uint32_t word) {
36
  DCHECK(pc_ <= buffer_.length());
37 38 39
  if (pc_ == buffer_.length()) {
    Expand();
  }
40
  *reinterpret_cast<unsigned char*>(buffer_.begin() + pc_) = word;
41 42 43
  pc_ += 1;
}

44
void RegExpBytecodeGenerator::Emit32(uint32_t word) {
45
  DCHECK(pc_ <= buffer_.length());
46 47 48
  if (pc_ + 3 >= buffer_.length()) {
    Expand();
  }
49
  *reinterpret_cast<uint32_t*>(buffer_.begin() + pc_) = word;
50 51 52
  pc_ += 4;
}

53 54
}  // namespace internal
}  // namespace v8
55

56
#endif  // V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_