1 // Copyright 2011 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 // A simple interpreter for the Irregexp byte code. 6 7 #ifndef V8_REGEXP_REGEXP_INTERPRETER_H_ 8 #define V8_REGEXP_REGEXP_INTERPRETER_H_ 9 10 #include "src/regexp/regexp.h" 11 12 namespace v8 { 13 namespace internal { 14 15 class ByteArray; 16 17 class V8_EXPORT_PRIVATE IrregexpInterpreter : public AllStatic { 18 public: 19 enum Result { 20 FAILURE = RegExp::kInternalRegExpFailure, 21 SUCCESS = RegExp::kInternalRegExpSuccess, 22 EXCEPTION = RegExp::kInternalRegExpException, 23 RETRY = RegExp::kInternalRegExpRetry, 24 FALLBACK_TO_EXPERIMENTAL = RegExp::kInternalRegExpFallbackToExperimental, 25 }; 26 27 // In case a StackOverflow occurs, a StackOverflowException is created and 28 // EXCEPTION is returned. 29 static Result MatchForCallFromRuntime( 30 Isolate* isolate, Handle<JSRegExp> regexp, Handle<String> subject_string, 31 int* output_registers, int output_register_count, int start_position); 32 33 // In case a StackOverflow occurs, EXCEPTION is returned. The caller is 34 // responsible for creating the exception. 35 // 36 // RETRY is returned if a retry through the runtime is needed (e.g. when 37 // interrupts have been scheduled or the regexp is marked for tier-up). 38 // 39 // Arguments input_start and input_end are unused. They are only passed to 40 // match the signature of the native irregex code. 41 // 42 // Arguments output_registers and output_register_count describe the results 43 // array, which will contain register values of all captures if SUCCESS is 44 // returned. For all other return codes, the results array remains unmodified. 45 static Result MatchForCallFromJs(Address subject, int32_t start_position, 46 Address input_start, Address input_end, 47 int* output_registers, 48 int32_t output_register_count, 49 RegExp::CallOrigin call_origin, 50 Isolate* isolate, Address regexp); 51 52 static Result MatchInternal(Isolate* isolate, ByteArray code_array, 53 String subject_string, int* output_registers, 54 int output_register_count, 55 int total_register_count, int start_position, 56 RegExp::CallOrigin call_origin, 57 uint32_t backtrack_limit); 58 59 private: 60 static Result Match(Isolate* isolate, JSRegExp regexp, String subject_string, 61 int* output_registers, int output_register_count, 62 int start_position, RegExp::CallOrigin call_origin); 63 }; 64 65 } // namespace internal 66 } // namespace v8 67 68 #endif // V8_REGEXP_REGEXP_INTERPRETER_H_ 69