11cb0ef41Sopenharmony_ci// Copyright 2008-2009 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_
61cb0ef41Sopenharmony_ci#define V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/regexp/regexp-bytecode-generator.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/regexp/regexp-bytecodes.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_civoid RegExpBytecodeGenerator::Emit(uint32_t byte, uint32_t twenty_four_bits) {
161cb0ef41Sopenharmony_ci  DCHECK(is_uint24(twenty_four_bits));
171cb0ef41Sopenharmony_ci  Emit32((twenty_four_bits << BYTECODE_SHIFT) | byte);
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_civoid RegExpBytecodeGenerator::Emit(uint32_t byte, int32_t twenty_four_bits) {
211cb0ef41Sopenharmony_ci  DCHECK(is_int24(twenty_four_bits));
221cb0ef41Sopenharmony_ci  Emit32((static_cast<uint32_t>(twenty_four_bits) << BYTECODE_SHIFT) | byte);
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_civoid RegExpBytecodeGenerator::Emit16(uint32_t word) {
261cb0ef41Sopenharmony_ci  DCHECK(pc_ <= static_cast<int>(buffer_.size()));
271cb0ef41Sopenharmony_ci  if (pc_ + 1 >= static_cast<int>(buffer_.size())) {
281cb0ef41Sopenharmony_ci    ExpandBuffer();
291cb0ef41Sopenharmony_ci  }
301cb0ef41Sopenharmony_ci  *reinterpret_cast<uint16_t*>(buffer_.data() + pc_) = word;
311cb0ef41Sopenharmony_ci  pc_ += 2;
321cb0ef41Sopenharmony_ci}
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_civoid RegExpBytecodeGenerator::Emit8(uint32_t word) {
351cb0ef41Sopenharmony_ci  DCHECK(pc_ <= static_cast<int>(buffer_.size()));
361cb0ef41Sopenharmony_ci  if (pc_ == static_cast<int>(buffer_.size())) {
371cb0ef41Sopenharmony_ci    ExpandBuffer();
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci  *reinterpret_cast<unsigned char*>(buffer_.data() + pc_) = word;
401cb0ef41Sopenharmony_ci  pc_ += 1;
411cb0ef41Sopenharmony_ci}
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_civoid RegExpBytecodeGenerator::Emit32(uint32_t word) {
441cb0ef41Sopenharmony_ci  DCHECK(pc_ <= static_cast<int>(buffer_.size()));
451cb0ef41Sopenharmony_ci  if (pc_ + 3 >= static_cast<int>(buffer_.size())) {
461cb0ef41Sopenharmony_ci    ExpandBuffer();
471cb0ef41Sopenharmony_ci  }
481cb0ef41Sopenharmony_ci  *reinterpret_cast<uint32_t*>(buffer_.data() + pc_) = word;
491cb0ef41Sopenharmony_ci  pc_ += 4;
501cb0ef41Sopenharmony_ci}
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci}  // namespace internal
531cb0ef41Sopenharmony_ci}  // namespace v8
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci#endif  // V8_REGEXP_REGEXP_BYTECODE_GENERATOR_INL_H_
56