diff options
author | Michaël Zasso <targos@protonmail.com> | 2016-05-27 16:37:42 +0200 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2016-06-29 09:04:28 +0200 |
commit | 2cc29517966de7257a2f1b34c58c77225a21e05d (patch) | |
tree | 210bd177df2f06eec16e1e22edafdbcbffe66f8a /deps/v8/src/regexp | |
parent | bbf3838c70aaec1dd296fa75ae334fd1c7866df3 (diff) | |
download | android-node-v8-2cc29517966de7257a2f1b34c58c77225a21e05d.tar.gz android-node-v8-2cc29517966de7257a2f1b34c58c77225a21e05d.tar.bz2 android-node-v8-2cc29517966de7257a2f1b34c58c77225a21e05d.zip |
deps: update V8 to 5.1.281.69
Pick up the latest branch-head for V8 5.1. This branch brings in
improved language support and performance improvements. For full
details: http://v8project.blogspot.com/2016/04/v8-release-51.html
* Picks up the latest branch head for 5.1 [1]
* Edit v8 gitignore to allow trace_event copy
* Update V8 DEP trace_event as per deps/v8/DEPS [2]
[1] https://chromium.googlesource.com/v8/v8.git/+/dc81244
[2] https://chromium.googlesource.com/chromium/src/base/trace_event/common/+/c8c8665
PR-URL: https://github.com/nodejs/node/pull/7016
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'deps/v8/src/regexp')
-rw-r--r-- | deps/v8/src/regexp/arm/regexp-macro-assembler-arm.cc | 3 | ||||
-rw-r--r-- | deps/v8/src/regexp/arm64/regexp-macro-assembler-arm64.cc | 3 | ||||
-rw-r--r-- | deps/v8/src/regexp/ia32/regexp-macro-assembler-ia32.cc | 6 | ||||
-rw-r--r-- | deps/v8/src/regexp/jsregexp.cc | 9 | ||||
-rw-r--r-- | deps/v8/src/regexp/mips/regexp-macro-assembler-mips.cc | 3 | ||||
-rw-r--r-- | deps/v8/src/regexp/mips64/regexp-macro-assembler-mips64.cc | 3 | ||||
-rw-r--r-- | deps/v8/src/regexp/ppc/regexp-macro-assembler-ppc.cc | 3 | ||||
-rw-r--r-- | deps/v8/src/regexp/regexp-macro-assembler.h | 1 | ||||
-rw-r--r-- | deps/v8/src/regexp/regexp-parser.cc | 148 | ||||
-rw-r--r-- | deps/v8/src/regexp/regexp-parser.h | 3 | ||||
-rw-r--r-- | deps/v8/src/regexp/s390/OWNERS | 5 | ||||
-rw-r--r-- | deps/v8/src/regexp/s390/regexp-macro-assembler-s390.cc | 1256 | ||||
-rw-r--r-- | deps/v8/src/regexp/s390/regexp-macro-assembler-s390.h | 216 | ||||
-rw-r--r-- | deps/v8/src/regexp/x64/regexp-macro-assembler-x64.cc | 2 | ||||
-rw-r--r-- | deps/v8/src/regexp/x87/regexp-macro-assembler-x87.cc | 6 |
15 files changed, 1615 insertions, 52 deletions
diff --git a/deps/v8/src/regexp/arm/regexp-macro-assembler-arm.cc b/deps/v8/src/regexp/arm/regexp-macro-assembler-arm.cc index ce72188ae1..f8dfc97c9c 100644 --- a/deps/v8/src/regexp/arm/regexp-macro-assembler-arm.cc +++ b/deps/v8/src/regexp/arm/regexp-macro-assembler-arm.cc @@ -891,7 +891,8 @@ Handle<HeapObject> RegExpMacroAssemblerARM::GetCode(Handle<String> source) { masm_->GetCode(&code_desc); Handle<Code> code = isolate()->factory()->NewCode( code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - PROFILE(masm_->isolate(), RegExpCodeCreateEvent(*code, *source)); + PROFILE(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/arm64/regexp-macro-assembler-arm64.cc b/deps/v8/src/regexp/arm64/regexp-macro-assembler-arm64.cc index 941cceaa59..e8bdad8e14 100644 --- a/deps/v8/src/regexp/arm64/regexp-macro-assembler-arm64.cc +++ b/deps/v8/src/regexp/arm64/regexp-macro-assembler-arm64.cc @@ -1088,7 +1088,8 @@ Handle<HeapObject> RegExpMacroAssemblerARM64::GetCode(Handle<String> source) { masm_->GetCode(&code_desc); Handle<Code> code = isolate()->factory()->NewCode( code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - PROFILE(masm_->isolate(), RegExpCodeCreateEvent(*code, *source)); + PROFILE(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/ia32/regexp-macro-assembler-ia32.cc b/deps/v8/src/regexp/ia32/regexp-macro-assembler-ia32.cc index 4c22b43f77..9c55af6645 100644 --- a/deps/v8/src/regexp/ia32/regexp-macro-assembler-ia32.cc +++ b/deps/v8/src/regexp/ia32/regexp-macro-assembler-ia32.cc @@ -511,7 +511,8 @@ void RegExpMacroAssemblerIA32::CheckBitInTable( __ and_(ebx, current_character()); index = ebx; } - __ cmpb(FieldOperand(eax, index, times_1, ByteArray::kHeaderSize), 0); + __ cmpb(FieldOperand(eax, index, times_1, ByteArray::kHeaderSize), + Immediate(0)); BranchOrBacktrack(not_equal, on_bit_set); } @@ -936,7 +937,8 @@ Handle<HeapObject> RegExpMacroAssemblerIA32::GetCode(Handle<String> source) { isolate()->factory()->NewCode(code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - PROFILE(isolate(), RegExpCodeCreateEvent(*code, *source)); + PROFILE(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/jsregexp.cc b/deps/v8/src/regexp/jsregexp.cc index 80f48ca1a9..ddb4a16caf 100644 --- a/deps/v8/src/regexp/jsregexp.cc +++ b/deps/v8/src/regexp/jsregexp.cc @@ -41,6 +41,8 @@ #include "src/regexp/arm/regexp-macro-assembler-arm.h" #elif V8_TARGET_ARCH_PPC #include "src/regexp/ppc/regexp-macro-assembler-ppc.h" +#elif V8_TARGET_ARCH_S390 +#include "src/regexp/s390/regexp-macro-assembler-s390.h" #elif V8_TARGET_ARCH_MIPS #include "src/regexp/mips/regexp-macro-assembler-mips.h" #elif V8_TARGET_ARCH_MIPS64 @@ -133,7 +135,7 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re, Handle<String> pattern, JSRegExp::Flags flags) { Isolate* isolate = re->GetIsolate(); - Zone zone; + Zone zone(isolate->allocator()); CompilationCache* compilation_cache = isolate->compilation_cache(); MaybeHandle<FixedArray> maybe_cached = compilation_cache->LookupRegExp(pattern, flags); @@ -344,7 +346,7 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re, bool is_one_byte) { // Compile the RegExp. Isolate* isolate = re->GetIsolate(); - Zone zone; + Zone zone(isolate->allocator()); PostponeInterruptsScope postpone(isolate); // If we had a compilation error the last time this is saved at the // saved code index. @@ -6703,6 +6705,9 @@ RegExpEngine::CompilationResult RegExpEngine::Compile( #elif V8_TARGET_ARCH_ARM64 RegExpMacroAssemblerARM64 macro_assembler(isolate, zone, mode, (data->capture_count + 1) * 2); +#elif V8_TARGET_ARCH_S390 + RegExpMacroAssemblerS390 macro_assembler(isolate, zone, mode, + (data->capture_count + 1) * 2); #elif V8_TARGET_ARCH_PPC RegExpMacroAssemblerPPC macro_assembler(isolate, zone, mode, (data->capture_count + 1) * 2); diff --git a/deps/v8/src/regexp/mips/regexp-macro-assembler-mips.cc b/deps/v8/src/regexp/mips/regexp-macro-assembler-mips.cc index 6197f45452..062d6618e9 100644 --- a/deps/v8/src/regexp/mips/regexp-macro-assembler-mips.cc +++ b/deps/v8/src/regexp/mips/regexp-macro-assembler-mips.cc @@ -905,7 +905,8 @@ Handle<HeapObject> RegExpMacroAssemblerMIPS::GetCode(Handle<String> source) { masm_->GetCode(&code_desc); Handle<Code> code = isolate()->factory()->NewCode( code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - LOG(masm_->isolate(), RegExpCodeCreateEvent(*code, *source)); + LOG(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/mips64/regexp-macro-assembler-mips64.cc b/deps/v8/src/regexp/mips64/regexp-macro-assembler-mips64.cc index bf95a9c97f..e0317dec8a 100644 --- a/deps/v8/src/regexp/mips64/regexp-macro-assembler-mips64.cc +++ b/deps/v8/src/regexp/mips64/regexp-macro-assembler-mips64.cc @@ -942,7 +942,8 @@ Handle<HeapObject> RegExpMacroAssemblerMIPS::GetCode(Handle<String> source) { masm_->GetCode(&code_desc); Handle<Code> code = isolate()->factory()->NewCode( code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - LOG(masm_->isolate(), RegExpCodeCreateEvent(*code, *source)); + LOG(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/ppc/regexp-macro-assembler-ppc.cc b/deps/v8/src/regexp/ppc/regexp-macro-assembler-ppc.cc index c05c580e86..70842f5a2c 100644 --- a/deps/v8/src/regexp/ppc/regexp-macro-assembler-ppc.cc +++ b/deps/v8/src/regexp/ppc/regexp-macro-assembler-ppc.cc @@ -940,7 +940,8 @@ Handle<HeapObject> RegExpMacroAssemblerPPC::GetCode(Handle<String> source) { masm_->GetCode(&code_desc); Handle<Code> code = isolate()->factory()->NewCode( code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - PROFILE(masm_->isolate(), RegExpCodeCreateEvent(*code, *source)); + PROFILE(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/regexp-macro-assembler.h b/deps/v8/src/regexp/regexp-macro-assembler.h index 6f79a16540..2aa439eceb 100644 --- a/deps/v8/src/regexp/regexp-macro-assembler.h +++ b/deps/v8/src/regexp/regexp-macro-assembler.h @@ -40,6 +40,7 @@ class RegExpMacroAssembler { kARMImplementation, kARM64Implementation, kMIPSImplementation, + kS390Implementation, kPPCImplementation, kX64Implementation, kX87Implementation, diff --git a/deps/v8/src/regexp/regexp-parser.cc b/deps/v8/src/regexp/regexp-parser.cc index 46c593c264..d433fc8578 100644 --- a/deps/v8/src/regexp/regexp-parser.cc +++ b/deps/v8/src/regexp/regexp-parser.cc @@ -359,14 +359,17 @@ RegExpTree* RegExpParser::ParseDisjunction() { Advance(2); if (unicode()) { if (FLAG_harmony_regexp_property) { - ZoneList<CharacterRange>* ranges = ParsePropertyClass(); - if (ranges == nullptr) { + ZoneList<CharacterRange>* ranges = + new (zone()) ZoneList<CharacterRange>(2, zone()); + if (!ParsePropertyClass(ranges)) { return ReportError(CStrVector("Invalid property name")); } RegExpCharacterClass* cc = new (zone()) RegExpCharacterClass(ranges, p == 'P'); builder->AddCharacterClass(cc); } else { + // With /u, no identity escapes except for syntax characters + // are allowed. Otherwise, all identity escapes are allowed. return ReportError(CStrVector("Invalid escape")); } } else { @@ -841,54 +844,95 @@ bool RegExpParser::ParseUnicodeEscape(uc32* value) { return result; } -ZoneList<CharacterRange>* RegExpParser::ParsePropertyClass() { #ifdef V8_I18N_SUPPORT - char property_name[3]; - memset(property_name, 0, sizeof(property_name)); - if (current() == '{') { - Advance(); - if (current() < 'A' || current() > 'Z') return nullptr; - property_name[0] = static_cast<char>(current()); - Advance(); - if (current() >= 'a' && current() <= 'z') { - property_name[1] = static_cast<char>(current()); - Advance(); - } - if (current() != '}') return nullptr; - } else if (current() >= 'A' && current() <= 'Z') { - property_name[0] = static_cast<char>(current()); - } else { - return nullptr; +bool IsExactPropertyValueAlias(const char* property_name, UProperty property, + int32_t property_value) { + const char* short_name = + u_getPropertyValueName(property, property_value, U_SHORT_PROPERTY_NAME); + if (short_name != NULL && strcmp(property_name, short_name) == 0) return true; + for (int i = 0;; i++) { + const char* long_name = u_getPropertyValueName( + property, property_value, + static_cast<UPropertyNameChoice>(U_LONG_PROPERTY_NAME + i)); + if (long_name == NULL) break; + if (strcmp(property_name, long_name) == 0) return true; } - Advance(); + return false; +} - int32_t category = - u_getPropertyValueEnum(UCHAR_GENERAL_CATEGORY_MASK, property_name); - if (category == UCHAR_INVALID_CODE) return nullptr; +bool LookupPropertyClass(UProperty property, const char* property_name, + ZoneList<CharacterRange>* result, Zone* zone) { + int32_t property_value = u_getPropertyValueEnum(property, property_name); + if (property_value == UCHAR_INVALID_CODE) return false; + + // We require the property name to match exactly to one of the property value + // aliases. However, u_getPropertyValueEnum uses loose matching. + if (!IsExactPropertyValueAlias(property_name, property, property_value)) { + return false; + } USet* set = uset_openEmpty(); UErrorCode ec = U_ZERO_ERROR; - uset_applyIntPropertyValue(set, UCHAR_GENERAL_CATEGORY_MASK, category, &ec); - ZoneList<CharacterRange>* ranges = nullptr; - if (ec == U_ZERO_ERROR && !uset_isEmpty(set)) { + uset_applyIntPropertyValue(set, property, property_value, &ec); + bool success = ec == U_ZERO_ERROR && !uset_isEmpty(set); + + if (success) { uset_removeAllStrings(set); int item_count = uset_getItemCount(set); - ranges = new (zone()) ZoneList<CharacterRange>(item_count, zone()); int item_result = 0; for (int i = 0; i < item_count; i++) { uc32 start = 0; uc32 end = 0; item_result += uset_getItem(set, i, &start, &end, nullptr, 0, &ec); - ranges->Add(CharacterRange::Range(start, end), zone()); + result->Add(CharacterRange::Range(start, end), zone); } DCHECK_EQ(U_ZERO_ERROR, ec); DCHECK_EQ(0, item_result); } uset_close(set); - return ranges; -#else // V8_I18N_SUPPORT - return nullptr; + return success; +} +#endif // V8_I18N_SUPPORT + +bool RegExpParser::ParsePropertyClass(ZoneList<CharacterRange>* result) { +#ifdef V8_I18N_SUPPORT + List<char> property_name_list; + if (current() == '{') { + for (Advance(); current() != '}'; Advance()) { + if (!has_next()) return false; + property_name_list.Add(static_cast<char>(current())); + } + } else if (current() != kEndMarker) { + property_name_list.Add(static_cast<char>(current())); + } else { + return false; + } + Advance(); + property_name_list.Add(0); // null-terminate string. + + const char* property_name = property_name_list.ToConstVector().start(); + +#define PROPERTY_NAME_LOOKUP(PROPERTY) \ + do { \ + if (LookupPropertyClass(PROPERTY, property_name, result, zone())) { \ + return true; \ + } \ + } while (false) + + // General_Category (gc) found in PropertyValueAliases.txt + PROPERTY_NAME_LOOKUP(UCHAR_GENERAL_CATEGORY_MASK); + // Script (sc) found in Scripts.txt + PROPERTY_NAME_LOOKUP(UCHAR_SCRIPT); + // To disambiguate from script names, block names have an "In"-prefix. + if (property_name_list.length() > 3 && property_name[0] == 'I' && + property_name[1] == 'n') { + // Block (blk) found in Blocks.txt + property_name += 2; + PROPERTY_NAME_LOOKUP(UCHAR_BLOCK); + } +#undef PROPERTY_NAME_LOOKUP #endif // V8_I18N_SUPPORT + return false; } bool RegExpParser::ParseUnlimitedLengthHexNumber(int max_value, uc32* value) { @@ -1068,6 +1112,34 @@ static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges, } } +bool RegExpParser::ParseClassProperty(ZoneList<CharacterRange>* ranges) { + if (!FLAG_harmony_regexp_property) return false; + if (!unicode()) return false; + if (current() != '\\') return false; + uc32 next = Next(); + bool parse_success = false; + if (next == 'p') { + Advance(2); + parse_success = ParsePropertyClass(ranges); + } else if (next == 'P') { + Advance(2); + ZoneList<CharacterRange>* property_class = + new (zone()) ZoneList<CharacterRange>(2, zone()); + parse_success = ParsePropertyClass(property_class); + if (parse_success) { + ZoneList<CharacterRange>* negated = + new (zone()) ZoneList<CharacterRange>(2, zone()); + CharacterRange::Negate(property_class, negated, zone()); + const Vector<CharacterRange> negated_vector = negated->ToVector(); + ranges->AddAll(negated_vector, zone()); + } + } else { + return false; + } + if (!parse_success) + ReportError(CStrVector("Invalid property name in character class")); + return parse_success; +} RegExpTree* RegExpParser::ParseCharacterClass() { static const char* kUnterminated = "Unterminated character class"; @@ -1084,6 +1156,8 @@ RegExpTree* RegExpParser::ParseCharacterClass() { ZoneList<CharacterRange>* ranges = new (zone()) ZoneList<CharacterRange>(2, zone()); while (has_more() && current() != ']') { + bool parsed_property = ParseClassProperty(ranges CHECK_FAILED); + if (parsed_property) continue; uc16 char_class = kNoCharClass; CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); if (current() == '-') { @@ -1356,14 +1430,10 @@ void RegExpBuilder::FlushTerms() { bool RegExpBuilder::NeedsDesugaringForUnicode(RegExpCharacterClass* cc) { if (!unicode()) return false; - switch (cc->standard_type()) { - case 's': // white space - case 'w': // ASCII word character - case 'd': // ASCII digit - return false; // These characters do not need desugaring. - default: - break; - } + // TODO(yangguo): we could be smarter than this. Case-insensitivity does not + // necessarily mean that we need to desugar. It's probably nicer to have a + // separate pass to figure out unicode desugarings. + if (ignore_case()) return true; ZoneList<CharacterRange>* ranges = cc->ranges(zone()); CharacterRange::Canonicalize(ranges); for (int i = ranges->length() - 1; i >= 0; i--) { diff --git a/deps/v8/src/regexp/regexp-parser.h b/deps/v8/src/regexp/regexp-parser.h index acf783cc41..6142a9ea53 100644 --- a/deps/v8/src/regexp/regexp-parser.h +++ b/deps/v8/src/regexp/regexp-parser.h @@ -174,7 +174,7 @@ class RegExpParser BASE_EMBEDDED { bool ParseHexEscape(int length, uc32* value); bool ParseUnicodeEscape(uc32* value); bool ParseUnlimitedLengthHexNumber(int max_value, uc32* value); - ZoneList<CharacterRange>* ParsePropertyClass(); + bool ParsePropertyClass(ZoneList<CharacterRange>* result); uc32 ParseOctalLiteral(); @@ -184,6 +184,7 @@ class RegExpParser BASE_EMBEDDED { // can be reparsed. bool ParseBackReferenceIndex(int* index_out); + bool ParseClassProperty(ZoneList<CharacterRange>* result); CharacterRange ParseClassAtom(uc16* char_class); RegExpTree* ReportError(Vector<const char> message); void Advance(); diff --git a/deps/v8/src/regexp/s390/OWNERS b/deps/v8/src/regexp/s390/OWNERS new file mode 100644 index 0000000000..eb007cb908 --- /dev/null +++ b/deps/v8/src/regexp/s390/OWNERS @@ -0,0 +1,5 @@ +jyan@ca.ibm.com +dstence@us.ibm.com +joransiu@ca.ibm.com +mbrandy@us.ibm.com +michael_dawson@ca.ibm.com diff --git a/deps/v8/src/regexp/s390/regexp-macro-assembler-s390.cc b/deps/v8/src/regexp/s390/regexp-macro-assembler-s390.cc new file mode 100644 index 0000000000..9dac534636 --- /dev/null +++ b/deps/v8/src/regexp/s390/regexp-macro-assembler-s390.cc @@ -0,0 +1,1256 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/v8.h" + +#if V8_TARGET_ARCH_S390 + +#include "src/base/bits.h" +#include "src/code-stubs.h" +#include "src/log.h" +#include "src/macro-assembler.h" +#include "src/profiler/cpu-profiler.h" +#include "src/regexp/regexp-macro-assembler.h" +#include "src/regexp/regexp-stack.h" +#include "src/regexp/s390/regexp-macro-assembler-s390.h" +#include "src/unicode.h" + +namespace v8 { +namespace internal { + +#ifndef V8_INTERPRETED_REGEXP +/* + * This assembler uses the following register assignment convention + * - r6: Temporarily stores the index of capture start after a matching pass + * for a global regexp. + * - r7: Pointer to current code object (Code*) including heap object tag. + * - r8: Current position in input, as negative offset from end of string. + * Please notice that this is the byte offset, not the character offset! + * - r9: Currently loaded character. Must be loaded using + * LoadCurrentCharacter before using any of the dispatch methods. + * - r13: Points to tip of backtrack stack + * - r10: End of input (points to byte after last character in input). + * - r11: Frame pointer. Used to access arguments, local variables and + * RegExp registers. + * - r12: IP register, used by assembler. Very volatile. + * - r15/sp : Points to tip of C stack. + * + * The remaining registers are free for computations. + * Each call to a public method should retain this convention. + * + * The stack will have the following structure: + * - fp[112] Isolate* isolate (address of the current isolate) + * - fp[108] secondary link/return address used by native call. + * - fp[104] direct_call (if 1, direct call from JavaScript code, + * if 0, call through the runtime system). + * - fp[100] stack_area_base (high end of the memory area to use as + * backtracking stack). + * - fp[96] capture array size (may fit multiple sets of matches) + * - fp[0..96] zLinux ABI register saving area + * --- sp when called --- + * --- frame pointer ---- + * - fp[-4] direct_call (if 1, direct call from JavaScript code, + * if 0, call through the runtime system). + * - fp[-8] stack_area_base (high end of the memory area to use as + * backtracking stack). + * - fp[-12] capture array size (may fit multiple sets of matches) + * - fp[-16] int* capture_array (int[num_saved_registers_], for output). + * - fp[-20] end of input (address of end of string). + * - fp[-24] start of input (address of first character in string). + * - fp[-28] start index (character index of start). + * - fp[-32] void* input_string (location of a handle containing the string). + * - fp[-36] success counter (only for global regexps to count matches). + * - fp[-40] Offset of location before start of input (effectively character + * string start - 1). Used to initialize capture registers to a + * non-position. + * - fp[-44] At start (if 1, we are starting at the start of the + * string, otherwise 0) + * - fp[-48] register 0 (Only positions must be stored in the first + * - register 1 num_saved_registers_ registers) + * - ... + * - register num_registers-1 + * --- sp --- + * + * The first num_saved_registers_ registers are initialized to point to + * "character -1" in the string (i.e., char_size() bytes before the first + * character of the string). The remaining registers start out as garbage. + * + * The data up to the return address must be placed there by the calling + * code and the remaining arguments are passed in registers, e.g. by calling the + * code entry as cast to a function with the signature: + * int (*match)(String* input_string, + * int start_index, + * Address start, + * Address end, + * int* capture_output_array, + * byte* stack_area_base, + * Address secondary_return_address, // Only used by native call. + * bool direct_call = false) + * The call is performed by NativeRegExpMacroAssembler::Execute() + * (in regexp-macro-assembler.cc) via the CALL_GENERATED_REGEXP_CODE macro + * in s390/simulator-s390.h. + * When calling as a non-direct call (i.e., from C++ code), the return address + * area is overwritten with the LR register by the RegExp code. When doing a + * direct call from generated code, the return address is placed there by + * the calling code, as in a normal exit frame. + */ + +#define __ ACCESS_MASM(masm_) + +RegExpMacroAssemblerS390::RegExpMacroAssemblerS390(Isolate* isolate, Zone* zone, + Mode mode, + int registers_to_save) + : NativeRegExpMacroAssembler(isolate, zone), + masm_(new MacroAssembler(isolate, NULL, kRegExpCodeSize, + CodeObjectRequired::kYes)), + mode_(mode), + num_registers_(registers_to_save), + num_saved_registers_(registers_to_save), + entry_label_(), + start_label_(), + success_label_(), + backtrack_label_(), + exit_label_(), + internal_failure_label_() { + DCHECK_EQ(0, registers_to_save % 2); + + __ b(&entry_label_); // We'll write the entry code later. + // If the code gets too big or corrupted, an internal exception will be + // raised, and we will exit right away. + __ bind(&internal_failure_label_); + __ LoadImmP(r2, Operand(FAILURE)); + __ Ret(); + __ bind(&start_label_); // And then continue from here. +} + +RegExpMacroAssemblerS390::~RegExpMacroAssemblerS390() { + delete masm_; + // Unuse labels in case we throw away the assembler without calling GetCode. + entry_label_.Unuse(); + start_label_.Unuse(); + success_label_.Unuse(); + backtrack_label_.Unuse(); + exit_label_.Unuse(); + check_preempt_label_.Unuse(); + stack_overflow_label_.Unuse(); + internal_failure_label_.Unuse(); +} + +int RegExpMacroAssemblerS390::stack_limit_slack() { + return RegExpStack::kStackLimitSlack; +} + +void RegExpMacroAssemblerS390::AdvanceCurrentPosition(int by) { + if (by != 0) { + __ AddP(current_input_offset(), Operand(by * char_size())); + } +} + +void RegExpMacroAssemblerS390::AdvanceRegister(int reg, int by) { + DCHECK(reg >= 0); + DCHECK(reg < num_registers_); + if (by != 0) { + if (CpuFeatures::IsSupported(GENERAL_INSTR_EXT) && is_int8(by)) { + __ AddMI(register_location(reg), Operand(by)); + } else { + __ LoadP(r2, register_location(reg), r0); + __ mov(r0, Operand(by)); + __ AddRR(r2, r0); + __ StoreP(r2, register_location(reg)); + } + } +} + +void RegExpMacroAssemblerS390::Backtrack() { + CheckPreemption(); + // Pop Code* offset from backtrack stack, add Code* and jump to location. + Pop(r2); + __ AddP(r2, code_pointer()); + __ b(r2); +} + +void RegExpMacroAssemblerS390::Bind(Label* label) { __ bind(label); } + +void RegExpMacroAssemblerS390::CheckCharacter(uint32_t c, Label* on_equal) { + __ CmpLogicalP(current_character(), Operand(c)); + BranchOrBacktrack(eq, on_equal); +} + +void RegExpMacroAssemblerS390::CheckCharacterGT(uc16 limit, Label* on_greater) { + __ CmpLogicalP(current_character(), Operand(limit)); + BranchOrBacktrack(gt, on_greater); +} + +void RegExpMacroAssemblerS390::CheckAtStart(Label* on_at_start) { + __ LoadP(r3, MemOperand(frame_pointer(), kStringStartMinusOne)); + __ AddP(r2, current_input_offset(), Operand(-char_size())); + __ CmpP(r2, r3); + BranchOrBacktrack(eq, on_at_start); +} + +void RegExpMacroAssemblerS390::CheckNotAtStart(int cp_offset, + Label* on_not_at_start) { + __ LoadP(r3, MemOperand(frame_pointer(), kStringStartMinusOne)); + __ AddP(r2, current_input_offset(), + Operand(-char_size() + cp_offset * char_size())); + __ CmpP(r2, r3); + BranchOrBacktrack(ne, on_not_at_start); +} + +void RegExpMacroAssemblerS390::CheckCharacterLT(uc16 limit, Label* on_less) { + __ CmpLogicalP(current_character(), Operand(limit)); + BranchOrBacktrack(lt, on_less); +} + +void RegExpMacroAssemblerS390::CheckGreedyLoop(Label* on_equal) { + Label backtrack_non_equal; + __ CmpP(current_input_offset(), MemOperand(backtrack_stackpointer(), 0)); + __ bne(&backtrack_non_equal); + __ AddP(backtrack_stackpointer(), Operand(kPointerSize)); + + BranchOrBacktrack(al, on_equal); + __ bind(&backtrack_non_equal); +} + +void RegExpMacroAssemblerS390::CheckNotBackReferenceIgnoreCase( + int start_reg, bool read_backward, bool unicode, Label* on_no_match) { + Label fallthrough; + __ LoadP(r2, register_location(start_reg)); // Index of start of + // capture + __ LoadP(r3, register_location(start_reg + 1)); // Index of end + __ SubP(r3, r3, r2); + + // At this point, the capture registers are either both set or both cleared. + // If the capture length is zero, then the capture is either empty or cleared. + // Fall through in both cases. + __ beq(&fallthrough); + + // Check that there are enough characters left in the input. + if (read_backward) { + __ LoadP(r5, MemOperand(frame_pointer(), kStringStartMinusOne)); + __ AddP(r5, r5, r3); + __ CmpP(current_input_offset(), r5); + BranchOrBacktrack(le, on_no_match); + } else { + __ AddP(r0, r3, current_input_offset()); + BranchOrBacktrack(gt, on_no_match); + } + + if (mode_ == LATIN1) { + Label success; + Label fail; + Label loop_check; + + // r2 - offset of start of capture + // r3 - length of capture + __ AddP(r2, end_of_input_address()); + __ AddP(r4, current_input_offset(), end_of_input_address()); + if (read_backward) { + __ SubP(r4, r4, r3); // Offset by length when matching backwards. + } + __ mov(r1, Operand::Zero()); + + // r1 - Loop index + // r2 - Address of start of capture. + // r4 - Address of current input position. + + Label loop; + __ bind(&loop); + __ LoadlB(r5, MemOperand(r2, r1)); + __ LoadlB(r6, MemOperand(r4, r1)); + + __ CmpP(r6, r5); + __ beq(&loop_check); + + // Mismatch, try case-insensitive match (converting letters to lower-case). + __ Or(r5, Operand(0x20)); // Convert capture character to lower-case. + __ Or(r6, Operand(0x20)); // Also convert input character. + __ CmpP(r6, r5); + __ bne(&fail); + __ SubP(r5, Operand('a')); + __ CmpLogicalP(r5, Operand('z' - 'a')); // Is r5 a lowercase letter? + __ ble(&loop_check); // In range 'a'-'z'. + // Latin-1: Check for values in range [224,254] but not 247. + __ SubP(r5, Operand(224 - 'a')); + __ CmpLogicalP(r5, Operand(254 - 224)); + __ bgt(&fail); // Weren't Latin-1 letters. + __ CmpLogicalP(r5, Operand(247 - 224)); // Check for 247. + __ beq(&fail); + + __ bind(&loop_check); + __ la(r1, MemOperand(r1, char_size())); + __ CmpP(r1, r3); + __ blt(&loop); + __ b(&success); + + __ bind(&fail); + BranchOrBacktrack(al, on_no_match); + + __ bind(&success); + // Compute new value of character position after the matched part. + __ SubP(current_input_offset(), r4, end_of_input_address()); + if (read_backward) { + __ LoadP(r2, register_location(start_reg)); // Index of start of capture + __ LoadP(r3, + register_location(start_reg + 1)); // Index of end of capture + __ AddP(current_input_offset(), current_input_offset(), r2); + __ SubP(current_input_offset(), current_input_offset(), r3); + } + __ AddP(current_input_offset(), r1); + } else { + DCHECK(mode_ == UC16); + int argument_count = 4; + __ PrepareCallCFunction(argument_count, r4); + + // r2 - offset of start of capture + // r3 - length of capture + + // Put arguments into arguments registers. + // Parameters are + // r2: Address byte_offset1 - Address captured substring's start. + // r3: Address byte_offset2 - Address of current character position. + // r4: size_t byte_length - length of capture in bytes(!) + // r5: Isolate* isolate or 0 if unicode flag. + + // Address of start of capture. + __ AddP(r2, end_of_input_address()); + // Length of capture. + __ LoadRR(r4, r3); + // Save length in callee-save register for use on return. + __ LoadRR(r6, r3); + // Address of current input position. + __ AddP(r3, current_input_offset(), end_of_input_address()); + if (read_backward) { + __ SubP(r3, r3, r6); + } +// Isolate. +#ifdef V8_I18N_SUPPORT + if (unicode) { + __ LoadImmP(r5, Operand::Zero()); + } else // NOLINT +#endif // V8_I18N_SUPPORT + { + __ mov(r5, Operand(ExternalReference::isolate_address(isolate()))); + } + + { + AllowExternalCallThatCantCauseGC scope(masm_); + ExternalReference function = + ExternalReference::re_case_insensitive_compare_uc16(isolate()); + __ CallCFunction(function, argument_count); + } + + // Check if function returned non-zero for success or zero for failure. + __ CmpP(r2, Operand::Zero()); + BranchOrBacktrack(eq, on_no_match); + + // On success, advance position by length of capture. + if (read_backward) { + __ SubP(current_input_offset(), current_input_offset(), r6); + } else { + __ AddP(current_input_offset(), current_input_offset(), r6); + } + } + + __ bind(&fallthrough); +} + +void RegExpMacroAssemblerS390::CheckNotBackReference(int start_reg, + bool read_backward, + Label* on_no_match) { + Label fallthrough; + Label success; + + // Find length of back-referenced capture. + __ LoadP(r2, register_location(start_reg)); + __ LoadP(r3, register_location(start_reg + 1)); + __ SubP(r3, r3, r2); // Length to check. + + // At this point, the capture registers are either both set or both cleared. + // If the capture length is zero, then the capture is either empty or cleared. + // Fall through in both cases. + __ beq(&fallthrough); + + // Check that there are enough characters left in the input. + if (read_backward) { + __ LoadP(r5, MemOperand(frame_pointer(), kStringStartMinusOne)); + __ AddP(r5, r5, r3); + __ CmpP(current_input_offset(), r5); + BranchOrBacktrack(lt, on_no_match); + } else { + __ AddP(r0, r3, current_input_offset()); + BranchOrBacktrack(gt, on_no_match, cr0); + } + + // r2 - offset of start of capture + // r3 - length of capture + __ la(r2, MemOperand(r2, end_of_input_address())); + __ la(r4, MemOperand(current_input_offset(), end_of_input_address())); + if (read_backward) { + __ SubP(r4, r4, r3); // Offset by length when matching backwards. + } + __ mov(r1, Operand::Zero()); + + Label loop; + __ bind(&loop); + if (mode_ == LATIN1) { + __ LoadlB(r5, MemOperand(r2, r1)); + __ LoadlB(r6, MemOperand(r4, r1)); + } else { + DCHECK(mode_ == UC16); + __ LoadLogicalHalfWordP(r5, MemOperand(r2, r1)); + __ LoadLogicalHalfWordP(r6, MemOperand(r4, r1)); + } + __ la(r1, MemOperand(r1, char_size())); + __ CmpP(r5, r6); + BranchOrBacktrack(ne, on_no_match); + __ CmpP(r1, r3); + __ blt(&loop); + + // Move current character position to position after match. + __ SubP(current_input_offset(), r4, end_of_input_address()); + if (read_backward) { + __ LoadP(r2, register_location(start_reg)); // Index of start of capture + __ LoadP(r3, register_location(start_reg + 1)); // Index of end of capture + __ AddP(current_input_offset(), current_input_offset(), r2); + __ SubP(current_input_offset(), current_input_offset(), r3); + } + __ AddP(current_input_offset(), r1); + + __ bind(&fallthrough); +} + +void RegExpMacroAssemblerS390::CheckNotCharacter(unsigned c, + Label* on_not_equal) { + __ CmpLogicalP(current_character(), Operand(c)); + BranchOrBacktrack(ne, on_not_equal); +} + +void RegExpMacroAssemblerS390::CheckCharacterAfterAnd(uint32_t c, uint32_t mask, + Label* on_equal) { + __ AndP(r2, current_character(), Operand(mask)); + if (c != 0) { + __ CmpLogicalP(r2, Operand(c)); + } + BranchOrBacktrack(eq, on_equal); +} + +void RegExpMacroAssemblerS390::CheckNotCharacterAfterAnd(unsigned c, + unsigned mask, + Label* on_not_equal) { + __ AndP(r2, current_character(), Operand(mask)); + if (c != 0) { + __ CmpLogicalP(r2, Operand(c)); + } + BranchOrBacktrack(ne, on_not_equal); +} + +void RegExpMacroAssemblerS390::CheckNotCharacterAfterMinusAnd( + uc16 c, uc16 minus, uc16 mask, Label* on_not_equal) { + DCHECK(minus < String::kMaxUtf16CodeUnit); + __ lay(r2, MemOperand(current_character(), -minus)); + __ And(r2, Operand(mask)); + if (c != 0) { + __ CmpLogicalP(r2, Operand(c)); + } + BranchOrBacktrack(ne, on_not_equal); +} + +void RegExpMacroAssemblerS390::CheckCharacterInRange(uc16 from, uc16 to, + Label* on_in_range) { + __ lay(r2, MemOperand(current_character(), -from)); + __ CmpLogicalP(r2, Operand(to - from)); + BranchOrBacktrack(le, on_in_range); // Unsigned lower-or-same condition. +} + +void RegExpMacroAssemblerS390::CheckCharacterNotInRange( + uc16 from, uc16 to, Label* on_not_in_range) { + __ lay(r2, MemOperand(current_character(), -from)); + __ CmpLogicalP(r2, Operand(to - from)); + BranchOrBacktrack(gt, on_not_in_range); // Unsigned higher condition. +} + +void RegExpMacroAssemblerS390::CheckBitInTable(Handle<ByteArray> table, + Label* on_bit_set) { + __ mov(r2, Operand(table)); + Register index = current_character(); + if (mode_ != LATIN1 || kTableMask != String::kMaxOneByteCharCode) { + __ AndP(r3, current_character(), Operand(kTableSize - 1)); + index = r3; + } + __ LoadlB(r2, + MemOperand(r2, index, (ByteArray::kHeaderSize - kHeapObjectTag))); + __ CmpP(r2, Operand::Zero()); + BranchOrBacktrack(ne, on_bit_set); +} + +bool RegExpMacroAssemblerS390::CheckSpecialCharacterClass(uc16 type, + Label* on_no_match) { + // Range checks (c in min..max) are generally implemented by an unsigned + // (c - min) <= (max - min) check + switch (type) { + case 's': + // Match space-characters + if (mode_ == LATIN1) { + // One byte space characters are '\t'..'\r', ' ' and \u00a0. + Label success; + __ CmpP(current_character(), Operand(' ')); + __ beq(&success); + // Check range 0x09..0x0d + __ SubP(r2, current_character(), Operand('\t')); + __ CmpLogicalP(r2, Operand('\r' - '\t')); + __ ble(&success); + // \u00a0 (NBSP). + __ CmpLogicalP(r2, Operand(0x00a0 - '\t')); + BranchOrBacktrack(ne, on_no_match); + __ bind(&success); + return true; + } + return false; + case 'S': + // The emitted code for generic character classes is good enough. + return false; + case 'd': + // Match ASCII digits ('0'..'9') + __ SubP(r2, current_character(), Operand('0')); + __ CmpLogicalP(r2, Operand('9' - '0')); + BranchOrBacktrack(gt, on_no_match); + return true; + case 'D': + // Match non ASCII-digits + __ SubP(r2, current_character(), Operand('0')); + __ CmpLogicalP(r2, Operand('9' - '0')); + BranchOrBacktrack(le, on_no_match); + return true; + case '.': { + // Match non-newlines (not 0x0a('\n'), 0x0d('\r'), 0x2028 and 0x2029) + __ XorP(r2, current_character(), Operand(0x01)); + // See if current character is '\n'^1 or '\r'^1, i.e., 0x0b or 0x0c + __ SubP(r2, Operand(0x0b)); + __ CmpLogicalP(r2, Operand(0x0c - 0x0b)); + BranchOrBacktrack(le, on_no_match); + if (mode_ == UC16) { + // Compare original value to 0x2028 and 0x2029, using the already + // computed (current_char ^ 0x01 - 0x0b). I.e., check for + // 0x201d (0x2028 - 0x0b) or 0x201e. + __ SubP(r2, Operand(0x2028 - 0x0b)); + __ CmpLogicalP(r2, Operand(1)); + BranchOrBacktrack(le, on_no_match); + } + return true; + } + case 'n': { + // Match newlines (0x0a('\n'), 0x0d('\r'), 0x2028 and 0x2029) + __ XorP(r2, current_character(), Operand(0x01)); + // See if current character is '\n'^1 or '\r'^1, i.e., 0x0b or 0x0c + __ SubP(r2, Operand(0x0b)); + __ CmpLogicalP(r2, Operand(0x0c - 0x0b)); + if (mode_ == LATIN1) { + BranchOrBacktrack(gt, on_no_match); + } else { + Label done; + __ ble(&done); + // Compare original value to 0x2028 and 0x2029, using the already + // computed (current_char ^ 0x01 - 0x0b). I.e., check for + // 0x201d (0x2028 - 0x0b) or 0x201e. + __ SubP(r2, Operand(0x2028 - 0x0b)); + __ CmpLogicalP(r2, Operand(1)); + BranchOrBacktrack(gt, on_no_match); + __ bind(&done); + } + return true; + } + case 'w': { + if (mode_ != LATIN1) { + // Table is 1256 entries, so all LATIN1 characters can be tested. + __ CmpP(current_character(), Operand('z')); + BranchOrBacktrack(gt, on_no_match); + } + ExternalReference map = ExternalReference::re_word_character_map(); + __ mov(r2, Operand(map)); + __ LoadlB(r2, MemOperand(r2, current_character())); + __ CmpLogicalP(r2, Operand::Zero()); + BranchOrBacktrack(eq, on_no_match); + return true; + } + case 'W': { + Label done; + if (mode_ != LATIN1) { + // Table is 256 entries, so all LATIN characters can be tested. + __ CmpLogicalP(current_character(), Operand('z')); + __ bgt(&done); + } + ExternalReference map = ExternalReference::re_word_character_map(); + __ mov(r2, Operand(map)); + __ LoadlB(r2, MemOperand(r2, current_character())); + __ CmpLogicalP(r2, Operand::Zero()); + BranchOrBacktrack(ne, on_no_match); + if (mode_ != LATIN1) { + __ bind(&done); + } + return true; + } + case '*': + // Match any character. + return true; + // No custom implementation (yet): s(UC16), S(UC16). + default: + return false; + } +} + +void RegExpMacroAssemblerS390::Fail() { + __ LoadImmP(r2, Operand(FAILURE)); + __ b(&exit_label_); +} + +Handle<HeapObject> RegExpMacroAssemblerS390::GetCode(Handle<String> source) { + Label return_r2; + + // Finalize code - write the entry point code now we know how many + // registers we need. + + // Entry code: + __ bind(&entry_label_); + + // Tell the system that we have a stack frame. Because the type + // is MANUAL, no is generated. + FrameScope scope(masm_, StackFrame::MANUAL); + + // Ensure register assigments are consistent with callee save mask + DCHECK(r6.bit() & kRegExpCalleeSaved); + DCHECK(code_pointer().bit() & kRegExpCalleeSaved); + DCHECK(current_input_offset().bit() & kRegExpCalleeSaved); + DCHECK(current_character().bit() & kRegExpCalleeSaved); + DCHECK(backtrack_stackpointer().bit() & kRegExpCalleeSaved); + DCHECK(end_of_input_address().bit() & kRegExpCalleeSaved); + DCHECK(frame_pointer().bit() & kRegExpCalleeSaved); + + // zLinux ABI + // Incoming parameters: + // r2: input_string + // r3: start_index + // r4: start addr + // r5: end addr + // r6: capture output arrray + // Requires us to save the callee-preserved registers r6-r13 + // General convention is to also save r14 (return addr) and + // sp/r15 as well in a single STM/STMG + __ StoreMultipleP(r6, sp, MemOperand(sp, 6 * kPointerSize)); + + // Load stack parameters from caller stack frame + __ LoadMultipleP(r7, r9, + MemOperand(sp, kStackFrameExtraParamSlot * kPointerSize)); + // r7 = capture array size + // r8 = stack area base + // r9 = direct call + + // Actually emit code to start a new stack frame. + // Push arguments + // Save callee-save registers. + // Start new stack frame. + // Store link register in existing stack-cell. + // Order here should correspond to order of offset constants in header file. + // + // Set frame pointer in space for it if this is not a direct call + // from generated code. + __ LoadRR(frame_pointer(), sp); + __ lay(sp, MemOperand(sp, -10 * kPointerSize)); + __ mov(r1, Operand::Zero()); // success counter + __ LoadRR(r0, r1); // offset of location + __ StoreMultipleP(r0, r9, MemOperand(sp, 0)); + + // Check if we have space on the stack for registers. + Label stack_limit_hit; + Label stack_ok; + + ExternalReference stack_limit = + ExternalReference::address_of_stack_limit(isolate()); + __ mov(r2, Operand(stack_limit)); + __ LoadP(r2, MemOperand(r2)); + __ SubP(r2, sp, r2); + // Handle it if the stack pointer is already below the stack limit. + __ ble(&stack_limit_hit); + // Check if there is room for the variable number of registers above + // the stack limit. + __ CmpLogicalP(r2, Operand(num_registers_ * kPointerSize)); + __ bge(&stack_ok); + // Exit with OutOfMemory exception. There is not enough space on the stack + // for our working registers. + __ mov(r2, Operand(EXCEPTION)); + __ b(&return_r2); + + __ bind(&stack_limit_hit); + CallCheckStackGuardState(r2); + __ CmpP(r2, Operand::Zero()); + // If returned value is non-zero, we exit with the returned value as result. + __ bne(&return_r2); + + __ bind(&stack_ok); + + // Allocate space on stack for registers. + __ lay(sp, MemOperand(sp, (-num_registers_ * kPointerSize))); + // Load string end. + __ LoadP(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd)); + // Load input start. + __ LoadP(r4, MemOperand(frame_pointer(), kInputStart)); + // Find negative length (offset of start relative to end). + __ SubP(current_input_offset(), r4, end_of_input_address()); + __ LoadP(r3, MemOperand(frame_pointer(), kStartIndex)); + // Set r1 to address of char before start of the input string + // (effectively string position -1). + __ LoadRR(r1, r4); + __ SubP(r1, current_input_offset(), Operand(char_size())); + if (mode_ == UC16) { + __ ShiftLeftP(r0, r3, Operand(1)); + __ SubP(r1, r1, r0); + } else { + __ SubP(r1, r1, r3); + } + // Store this value in a local variable, for use when clearing + // position registers. + __ StoreP(r1, MemOperand(frame_pointer(), kStringStartMinusOne)); + + // Initialize code pointer register + __ mov(code_pointer(), Operand(masm_->CodeObject())); + + Label load_char_start_regexp, start_regexp; + // Load newline if index is at start, previous character otherwise. + __ CmpP(r3, Operand::Zero()); + __ bne(&load_char_start_regexp); + __ mov(current_character(), Operand('\n')); + __ b(&start_regexp); + + // Global regexp restarts matching here. + __ bind(&load_char_start_regexp); + // Load previous char as initial value of current character register. + LoadCurrentCharacterUnchecked(-1, 1); + __ bind(&start_regexp); + + // Initialize on-stack registers. + if (num_saved_registers_ > 0) { // Always is, if generated from a regexp. + // Fill saved registers with initial value = start offset - 1 + if (num_saved_registers_ > 8) { + // One slot beyond address of register 0. + __ lay(r3, MemOperand(frame_pointer(), kRegisterZero + kPointerSize)); + __ LoadImmP(r4, Operand(num_saved_registers_)); + Label init_loop; + __ bind(&init_loop); + __ StoreP(r1, MemOperand(r3, -kPointerSize)); + __ lay(r3, MemOperand(r3, -kPointerSize)); + __ BranchOnCount(r4, &init_loop); + } else { + for (int i = 0; i < num_saved_registers_; i++) { + __ StoreP(r1, register_location(i)); + } + } + } + + // Initialize backtrack stack pointer. + __ LoadP(backtrack_stackpointer(), + MemOperand(frame_pointer(), kStackHighEnd)); + + __ b(&start_label_); + + // Exit code: + if (success_label_.is_linked()) { + // Save captures when successful. + __ bind(&success_label_); + if (num_saved_registers_ > 0) { + // copy captures to output + __ LoadP(r0, MemOperand(frame_pointer(), kInputStart)); + __ LoadP(r2, MemOperand(frame_pointer(), kRegisterOutput)); + __ LoadP(r4, MemOperand(frame_pointer(), kStartIndex)); + __ SubP(r0, end_of_input_address(), r0); + // r0 is length of input in bytes. + if (mode_ == UC16) { + __ ShiftRightP(r0, r0, Operand(1)); + } + // r0 is length of input in characters. + __ AddP(r0, r4); + // r0 is length of string in characters. + + DCHECK_EQ(0, num_saved_registers_ % 2); + // Always an even number of capture registers. This allows us to + // unroll the loop once to add an operation between a load of a register + // and the following use of that register. + __ lay(r2, MemOperand(r2, num_saved_registers_ * kIntSize)); + for (int i = 0; i < num_saved_registers_;) { + if (false && i < num_saved_registers_ - 4) { + // TODO(john.yan): Can be optimized by SIMD instructions + __ LoadMultipleP(r3, r6, register_location(i + 3)); + if (mode_ == UC16) { + __ ShiftRightArithP(r3, r3, Operand(1)); + __ ShiftRightArithP(r4, r4, Operand(1)); + __ ShiftRightArithP(r5, r5, Operand(1)); + __ ShiftRightArithP(r6, r6, Operand(1)); + } + __ AddP(r3, r0); + __ AddP(r4, r0); + __ AddP(r5, r0); + __ AddP(r6, r0); + __ StoreW(r3, + MemOperand(r2, -(num_saved_registers_ - i - 3) * kIntSize)); + __ StoreW(r4, + MemOperand(r2, -(num_saved_registers_ - i - 2) * kIntSize)); + __ StoreW(r5, + MemOperand(r2, -(num_saved_registers_ - i - 1) * kIntSize)); + __ StoreW(r6, MemOperand(r2, -(num_saved_registers_ - i) * kIntSize)); + i += 4; + } else { + __ LoadMultipleP(r3, r4, register_location(i + 1)); + if (mode_ == UC16) { + __ ShiftRightArithP(r3, r3, Operand(1)); + __ ShiftRightArithP(r4, r4, Operand(1)); + } + __ AddP(r3, r0); + __ AddP(r4, r0); + __ StoreW(r3, + MemOperand(r2, -(num_saved_registers_ - i - 1) * kIntSize)); + __ StoreW(r4, MemOperand(r2, -(num_saved_registers_ - i) * kIntSize)); + i += 2; + } + } + if (global_with_zero_length_check()) { + // Keep capture start in r6 for the zero-length check later. + __ LoadP(r6, register_location(0)); + } + } + + if (global()) { + // Restart matching if the regular expression is flagged as global. + __ LoadP(r2, MemOperand(frame_pointer(), kSuccessfulCaptures)); + __ LoadP(r3, MemOperand(frame_pointer(), kNumOutputRegisters)); + __ LoadP(r4, MemOperand(frame_pointer(), kRegisterOutput)); + // Increment success counter. + __ AddP(r2, Operand(1)); + __ StoreP(r2, MemOperand(frame_pointer(), kSuccessfulCaptures)); + // Capture results have been stored, so the number of remaining global + // output registers is reduced by the number of stored captures. + __ SubP(r3, Operand(num_saved_registers_)); + // Check whether we have enough room for another set of capture results. + __ CmpP(r3, Operand(num_saved_registers_)); + __ blt(&return_r2); + + __ StoreP(r3, MemOperand(frame_pointer(), kNumOutputRegisters)); + // Advance the location for output. + __ AddP(r4, Operand(num_saved_registers_ * kIntSize)); + __ StoreP(r4, MemOperand(frame_pointer(), kRegisterOutput)); + + // Prepare r2 to initialize registers with its value in the next run. + __ LoadP(r2, MemOperand(frame_pointer(), kStringStartMinusOne)); + + if (global_with_zero_length_check()) { + // Special case for zero-length matches. + // r6: capture start index + __ CmpP(current_input_offset(), r6); + // Not a zero-length match, restart. + __ bne(&load_char_start_regexp); + // Offset from the end is zero if we already reached the end. + __ CmpP(current_input_offset(), Operand::Zero()); + __ beq(&exit_label_); + // Advance current position after a zero-length match. + Label advance; + __ bind(&advance); + __ AddP(current_input_offset(), Operand((mode_ == UC16) ? 2 : 1)); + if (global_unicode()) CheckNotInSurrogatePair(0, &advance); + } + + __ b(&load_char_start_regexp); + } else { + __ LoadImmP(r2, Operand(SUCCESS)); + } + } + + // Exit and return r2 + __ bind(&exit_label_); + if (global()) { + __ LoadP(r2, MemOperand(frame_pointer(), kSuccessfulCaptures)); + } + + __ bind(&return_r2); + // Skip sp past regexp registers and local variables.. + __ LoadRR(sp, frame_pointer()); + // Restore registers r6..r15. + __ LoadMultipleP(r6, sp, MemOperand(sp, 6 * kPointerSize)); + + __ b(r14); + + // Backtrack code (branch target for conditional backtracks). + if (backtrack_label_.is_linked()) { + __ bind(&backtrack_label_); + Backtrack(); + } + + Label exit_with_exception; + + // Preempt-code + if (check_preempt_label_.is_linked()) { + SafeCallTarget(&check_preempt_label_); + + CallCheckStackGuardState(r2); + __ CmpP(r2, Operand::Zero()); + // If returning non-zero, we should end execution with the given + // result as return value. + __ bne(&return_r2); + + // String might have moved: Reload end of string from frame. + __ LoadP(end_of_input_address(), MemOperand(frame_pointer(), kInputEnd)); + SafeReturn(); + } + + // Backtrack stack overflow code. + if (stack_overflow_label_.is_linked()) { + SafeCallTarget(&stack_overflow_label_); + // Reached if the backtrack-stack limit has been hit. + Label grow_failed; + + // Call GrowStack(backtrack_stackpointer(), &stack_base) + static const int num_arguments = 3; + __ PrepareCallCFunction(num_arguments, r2); + __ LoadRR(r2, backtrack_stackpointer()); + __ AddP(r3, frame_pointer(), Operand(kStackHighEnd)); + __ mov(r4, Operand(ExternalReference::isolate_address(isolate()))); + ExternalReference grow_stack = ExternalReference::re_grow_stack(isolate()); + __ CallCFunction(grow_stack, num_arguments); + // If return NULL, we have failed to grow the stack, and + // must exit with a stack-overflow exception. + __ CmpP(r2, Operand::Zero()); + __ beq(&exit_with_exception); + // Otherwise use return value as new stack pointer. + __ LoadRR(backtrack_stackpointer(), r2); + // Restore saved registers and continue. + SafeReturn(); + } + + if (exit_with_exception.is_linked()) { + // If any of the code above needed to exit with an exception. + __ bind(&exit_with_exception); + // Exit with Result EXCEPTION(-1) to signal thrown exception. + __ LoadImmP(r2, Operand(EXCEPTION)); + __ b(&return_r2); + } + + CodeDesc code_desc; + masm_->GetCode(&code_desc); + Handle<Code> code = isolate()->factory()->NewCode( + code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); + PROFILE(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); + return Handle<HeapObject>::cast(code); +} + +void RegExpMacroAssemblerS390::GoTo(Label* to) { BranchOrBacktrack(al, to); } + +void RegExpMacroAssemblerS390::IfRegisterGE(int reg, int comparand, + Label* if_ge) { + __ LoadP(r2, register_location(reg), r0); + __ CmpP(r2, Operand(comparand)); + BranchOrBacktrack(ge, if_ge); +} + +void RegExpMacroAssemblerS390::IfRegisterLT(int reg, int comparand, + Label* if_lt) { + __ LoadP(r2, register_location(reg), r0); + __ CmpP(r2, Operand(comparand)); + BranchOrBacktrack(lt, if_lt); +} + +void RegExpMacroAssemblerS390::IfRegisterEqPos(int reg, Label* if_eq) { + __ LoadP(r2, register_location(reg), r0); + __ CmpP(r2, current_input_offset()); + BranchOrBacktrack(eq, if_eq); +} + +RegExpMacroAssembler::IrregexpImplementation +RegExpMacroAssemblerS390::Implementation() { + return kS390Implementation; +} + +void RegExpMacroAssemblerS390::LoadCurrentCharacter(int cp_offset, + Label* on_end_of_input, + bool check_bounds, + int characters) { + DCHECK(cp_offset < (1 << 30)); // Be sane! (And ensure negation works) + if (check_bounds) { + if (cp_offset >= 0) { + CheckPosition(cp_offset + characters - 1, on_end_of_input); + } else { + CheckPosition(cp_offset, on_end_of_input); + } + } + LoadCurrentCharacterUnchecked(cp_offset, characters); +} + +void RegExpMacroAssemblerS390::PopCurrentPosition() { + Pop(current_input_offset()); +} + +void RegExpMacroAssemblerS390::PopRegister(int register_index) { + Pop(r2); + __ StoreP(r2, register_location(register_index)); +} + +void RegExpMacroAssemblerS390::PushBacktrack(Label* label) { + if (label->is_bound()) { + int target = label->pos(); + __ mov(r2, Operand(target + Code::kHeaderSize - kHeapObjectTag)); + } else { + masm_->load_label_offset(r2, label); + } + Push(r2); + CheckStackLimit(); +} + +void RegExpMacroAssemblerS390::PushCurrentPosition() { + Push(current_input_offset()); +} + +void RegExpMacroAssemblerS390::PushRegister(int register_index, + StackCheckFlag check_stack_limit) { + __ LoadP(r2, register_location(register_index), r0); + Push(r2); + if (check_stack_limit) CheckStackLimit(); +} + +void RegExpMacroAssemblerS390::ReadCurrentPositionFromRegister(int reg) { + __ LoadP(current_input_offset(), register_location(reg), r0); +} + +void RegExpMacroAssemblerS390::ReadStackPointerFromRegister(int reg) { + __ LoadP(backtrack_stackpointer(), register_location(reg), r0); + __ LoadP(r2, MemOperand(frame_pointer(), kStackHighEnd)); + __ AddP(backtrack_stackpointer(), r2); +} + +void RegExpMacroAssemblerS390::SetCurrentPositionFromEnd(int by) { + Label after_position; + __ CmpP(current_input_offset(), Operand(-by * char_size())); + __ bge(&after_position); + __ mov(current_input_offset(), Operand(-by * char_size())); + // On RegExp code entry (where this operation is used), the character before + // the current position is expected to be already loaded. + // We have advanced the position, so it's safe to read backwards. + LoadCurrentCharacterUnchecked(-1, 1); + __ bind(&after_position); +} + +void RegExpMacroAssemblerS390::SetRegister(int register_index, int to) { + DCHECK(register_index >= num_saved_registers_); // Reserved for positions! + __ mov(r2, Operand(to)); + __ StoreP(r2, register_location(register_index)); +} + +bool RegExpMacroAssemblerS390::Succeed() { + __ b(&success_label_); + return global(); +} + +void RegExpMacroAssemblerS390::WriteCurrentPositionToRegister(int reg, + int cp_offset) { + if (cp_offset == 0) { + __ StoreP(current_input_offset(), register_location(reg)); + } else { + __ AddP(r2, current_input_offset(), Operand(cp_offset * char_size())); + __ StoreP(r2, register_location(reg)); + } +} + +void RegExpMacroAssemblerS390::ClearRegisters(int reg_from, int reg_to) { + DCHECK(reg_from <= reg_to); + __ LoadP(r2, MemOperand(frame_pointer(), kStringStartMinusOne)); + for (int reg = reg_from; reg <= reg_to; reg++) { + __ StoreP(r2, register_location(reg)); + } +} + +void RegExpMacroAssemblerS390::WriteStackPointerToRegister(int reg) { + __ LoadP(r3, MemOperand(frame_pointer(), kStackHighEnd)); + __ SubP(r2, backtrack_stackpointer(), r3); + __ StoreP(r2, register_location(reg)); +} + +// Private methods: + +void RegExpMacroAssemblerS390::CallCheckStackGuardState(Register scratch) { + static const int num_arguments = 3; + __ PrepareCallCFunction(num_arguments, scratch); + // RegExp code frame pointer. + __ LoadRR(r4, frame_pointer()); + // Code* of self. + __ mov(r3, Operand(masm_->CodeObject())); + // r2 becomes return address pointer. + __ lay(r2, MemOperand(sp, kStackFrameRASlot * kPointerSize)); + ExternalReference stack_guard_check = + ExternalReference::re_check_stack_guard_state(isolate()); + CallCFunctionUsingStub(stack_guard_check, num_arguments); +} + +// Helper function for reading a value out of a stack frame. +template <typename T> +static T& frame_entry(Address re_frame, int frame_offset) { + DCHECK(sizeof(T) == kPointerSize); +#ifdef V8_TARGET_ARCH_S390X + return reinterpret_cast<T&>(Memory::uint64_at(re_frame + frame_offset)); +#else + return reinterpret_cast<T&>(Memory::uint32_at(re_frame + frame_offset)); +#endif +} + +template <typename T> +static T* frame_entry_address(Address re_frame, int frame_offset) { + return reinterpret_cast<T*>(re_frame + frame_offset); +} + +int RegExpMacroAssemblerS390::CheckStackGuardState(Address* return_address, + Code* re_code, + Address re_frame) { + return NativeRegExpMacroAssembler::CheckStackGuardState( + frame_entry<Isolate*>(re_frame, kIsolate), + frame_entry<intptr_t>(re_frame, kStartIndex), + frame_entry<intptr_t>(re_frame, kDirectCall) == 1, return_address, + re_code, frame_entry_address<String*>(re_frame, kInputString), + frame_entry_address<const byte*>(re_frame, kInputStart), + frame_entry_address<const byte*>(re_frame, kInputEnd)); +} + +MemOperand RegExpMacroAssemblerS390::register_location(int register_index) { + DCHECK(register_index < (1 << 30)); + if (num_registers_ <= register_index) { + num_registers_ = register_index + 1; + } + return MemOperand(frame_pointer(), + kRegisterZero - register_index * kPointerSize); +} + +void RegExpMacroAssemblerS390::CheckPosition(int cp_offset, + Label* on_outside_input) { + if (cp_offset >= 0) { + __ CmpP(current_input_offset(), Operand(-cp_offset * char_size())); + BranchOrBacktrack(ge, on_outside_input); + } else { + __ LoadP(r3, MemOperand(frame_pointer(), kStringStartMinusOne)); + __ AddP(r2, current_input_offset(), Operand(cp_offset * char_size())); + __ CmpP(r2, r3); + BranchOrBacktrack(le, on_outside_input); + } +} + +void RegExpMacroAssemblerS390::BranchOrBacktrack(Condition condition, Label* to, + CRegister cr) { + if (condition == al) { // Unconditional. + if (to == NULL) { + Backtrack(); + return; + } + __ b(to); + return; + } + if (to == NULL) { + __ b(condition, &backtrack_label_); + return; + } + __ b(condition, to); +} + +void RegExpMacroAssemblerS390::SafeCall(Label* to, Condition cond, + CRegister cr) { + Label skip; + __ b(NegateCondition(cond), &skip); + __ b(r14, to); + __ bind(&skip); +} + +void RegExpMacroAssemblerS390::SafeReturn() { + __ pop(r14); + __ mov(ip, Operand(masm_->CodeObject())); + __ AddP(r14, ip); + __ Ret(); +} + +void RegExpMacroAssemblerS390::SafeCallTarget(Label* name) { + __ bind(name); + __ CleanseP(r14); + __ LoadRR(r0, r14); + __ mov(ip, Operand(masm_->CodeObject())); + __ SubP(r0, r0, ip); + __ push(r0); +} + +void RegExpMacroAssemblerS390::Push(Register source) { + DCHECK(!source.is(backtrack_stackpointer())); + __ lay(backtrack_stackpointer(), + MemOperand(backtrack_stackpointer(), -kPointerSize)); + __ StoreP(source, MemOperand(backtrack_stackpointer())); +} + +void RegExpMacroAssemblerS390::Pop(Register target) { + DCHECK(!target.is(backtrack_stackpointer())); + __ LoadP(target, MemOperand(backtrack_stackpointer())); + __ la(backtrack_stackpointer(), + MemOperand(backtrack_stackpointer(), kPointerSize)); +} + +void RegExpMacroAssemblerS390::CheckPreemption() { + // Check for preemption. + ExternalReference stack_limit = + ExternalReference::address_of_stack_limit(isolate()); + __ mov(r2, Operand(stack_limit)); + __ CmpLogicalP(sp, MemOperand(r2)); + SafeCall(&check_preempt_label_, le); +} + +void RegExpMacroAssemblerS390::CheckStackLimit() { + ExternalReference stack_limit = + ExternalReference::address_of_regexp_stack_limit(isolate()); + __ mov(r2, Operand(stack_limit)); + __ CmpLogicalP(backtrack_stackpointer(), MemOperand(r2)); + SafeCall(&stack_overflow_label_, le); +} + +void RegExpMacroAssemblerS390::CallCFunctionUsingStub( + ExternalReference function, int num_arguments) { + // Must pass all arguments in registers. The stub pushes on the stack. + DCHECK(num_arguments <= 8); + __ mov(code_pointer(), Operand(function)); + Label ret; + __ larl(r14, &ret); + __ StoreP(r14, MemOperand(sp, kStackFrameRASlot * kPointerSize)); + __ b(code_pointer()); + __ bind(&ret); + if (base::OS::ActivationFrameAlignment() > kPointerSize) { + __ LoadP(sp, MemOperand(sp, (kNumRequiredStackFrameSlots * kPointerSize))); + } else { + __ la(sp, MemOperand(sp, (kNumRequiredStackFrameSlots * kPointerSize))); + } + __ mov(code_pointer(), Operand(masm_->CodeObject())); +} + +bool RegExpMacroAssemblerS390::CanReadUnaligned() { + return CpuFeatures::IsSupported(UNALIGNED_ACCESSES) && !slow_safe(); +} + +void RegExpMacroAssemblerS390::LoadCurrentCharacterUnchecked(int cp_offset, + int characters) { + DCHECK(characters == 1); + if (mode_ == LATIN1) { + __ LoadlB(current_character(), + MemOperand(current_input_offset(), end_of_input_address(), + cp_offset * char_size())); + } else { + DCHECK(mode_ == UC16); + __ LoadLogicalHalfWordP( + current_character(), + MemOperand(current_input_offset(), end_of_input_address(), + cp_offset * char_size())); + } +} + +#undef __ + +#endif // V8_INTERPRETED_REGEXP +} // namespace internal +} // namespace v8 + +#endif // V8_TARGET_ARCH_S390 diff --git a/deps/v8/src/regexp/s390/regexp-macro-assembler-s390.h b/deps/v8/src/regexp/s390/regexp-macro-assembler-s390.h new file mode 100644 index 0000000000..60ca890f12 --- /dev/null +++ b/deps/v8/src/regexp/s390/regexp-macro-assembler-s390.h @@ -0,0 +1,216 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_S390_REGEXP_MACRO_ASSEMBLER_S390_H_ +#define V8_S390_REGEXP_MACRO_ASSEMBLER_S390_H_ + +#include "src/macro-assembler.h" +#include "src/regexp/regexp-macro-assembler.h" +#include "src/s390/assembler-s390.h" +#include "src/s390/frames-s390.h" + +namespace v8 { +namespace internal { + +#ifndef V8_INTERPRETED_REGEXP +class RegExpMacroAssemblerS390 : public NativeRegExpMacroAssembler { + public: + RegExpMacroAssemblerS390(Isolate* isolate, Zone* zone, Mode mode, + int registers_to_save); + virtual ~RegExpMacroAssemblerS390(); + virtual int stack_limit_slack(); + virtual void AdvanceCurrentPosition(int by); + virtual void AdvanceRegister(int reg, int by); + virtual void Backtrack(); + virtual void Bind(Label* label); + virtual void CheckAtStart(Label* on_at_start); + virtual void CheckCharacter(unsigned c, Label* on_equal); + virtual void CheckCharacterAfterAnd(unsigned c, unsigned mask, + Label* on_equal); + virtual void CheckCharacterGT(uc16 limit, Label* on_greater); + virtual void CheckCharacterLT(uc16 limit, Label* on_less); + // A "greedy loop" is a loop that is both greedy and with a simple + // body. It has a particularly simple implementation. + virtual void CheckGreedyLoop(Label* on_tos_equals_current_position); + virtual void CheckNotAtStart(int cp_offset, Label* on_not_at_start); + virtual void CheckNotBackReference(int start_reg, bool read_backward, + Label* on_no_match); + virtual void CheckNotBackReferenceIgnoreCase(int start_reg, + bool read_backward, bool unicode, + Label* on_no_match); + virtual void CheckNotCharacter(unsigned c, Label* on_not_equal); + virtual void CheckNotCharacterAfterAnd(unsigned c, unsigned mask, + Label* on_not_equal); + virtual void CheckNotCharacterAfterMinusAnd(uc16 c, uc16 minus, uc16 mask, + Label* on_not_equal); + virtual void CheckCharacterInRange(uc16 from, uc16 to, Label* on_in_range); + virtual void CheckCharacterNotInRange(uc16 from, uc16 to, + Label* on_not_in_range); + virtual void CheckBitInTable(Handle<ByteArray> table, Label* on_bit_set); + + // Checks whether the given offset from the current position is before + // the end of the string. + virtual void CheckPosition(int cp_offset, Label* on_outside_input); + virtual bool CheckSpecialCharacterClass(uc16 type, Label* on_no_match); + virtual void Fail(); + virtual Handle<HeapObject> GetCode(Handle<String> source); + virtual void GoTo(Label* label); + virtual void IfRegisterGE(int reg, int comparand, Label* if_ge); + virtual void IfRegisterLT(int reg, int comparand, Label* if_lt); + virtual void IfRegisterEqPos(int reg, Label* if_eq); + virtual IrregexpImplementation Implementation(); + virtual void LoadCurrentCharacter(int cp_offset, Label* on_end_of_input, + bool check_bounds = true, + int characters = 1); + virtual void PopCurrentPosition(); + virtual void PopRegister(int register_index); + virtual void PushBacktrack(Label* label); + virtual void PushCurrentPosition(); + virtual void PushRegister(int register_index, + StackCheckFlag check_stack_limit); + virtual void ReadCurrentPositionFromRegister(int reg); + virtual void ReadStackPointerFromRegister(int reg); + virtual void SetCurrentPositionFromEnd(int by); + virtual void SetRegister(int register_index, int to); + virtual bool Succeed(); + virtual void WriteCurrentPositionToRegister(int reg, int cp_offset); + virtual void ClearRegisters(int reg_from, int reg_to); + virtual void WriteStackPointerToRegister(int reg); + virtual bool CanReadUnaligned(); + + // Called from RegExp if the stack-guard is triggered. + // If the code object is relocated, the return address is fixed before + // returning. + static int CheckStackGuardState(Address* return_address, Code* re_code, + Address re_frame); + + private: + // Offsets from frame_pointer() of function parameters and stored registers. + static const int kFramePointer = 0; + + // Above the frame pointer - Stored registers and stack passed parameters. + // Register 6-15(sp) + static const int kStoredRegisters = kFramePointer; + static const int kCallerFrame = + kStoredRegisters + kCalleeRegisterSaveAreaSize; + // Stack parameters placed by caller. + static const int kCaptureArraySize = kCallerFrame; + static const int kStackAreaBase = kCallerFrame + kPointerSize; + // kDirectCall again + static const int kSecondaryReturnAddress = kStackAreaBase + 2 * kPointerSize; + static const int kIsolate = kSecondaryReturnAddress + kPointerSize; + + // Below the frame pointer. + // Register parameters stored by setup code. + static const int kDirectCall = kFramePointer - kPointerSize; + static const int kStackHighEnd = kDirectCall - kPointerSize; + static const int kNumOutputRegisters = kStackHighEnd - kPointerSize; + static const int kRegisterOutput = kNumOutputRegisters - kPointerSize; + static const int kInputEnd = kRegisterOutput - kPointerSize; + static const int kInputStart = kInputEnd - kPointerSize; + static const int kStartIndex = kInputStart - kPointerSize; + static const int kInputString = kStartIndex - kPointerSize; + // When adding local variables remember to push space for them in + // the frame in GetCode. + static const int kSuccessfulCaptures = kInputString - kPointerSize; + static const int kStringStartMinusOne = kSuccessfulCaptures - kPointerSize; + // First register address. Following registers are below it on the stack. + static const int kRegisterZero = kStringStartMinusOne - kPointerSize; + + // Initial size of code buffer. + static const size_t kRegExpCodeSize = 1024; + + // Load a number of characters at the given offset from the + // current position, into the current-character register. + void LoadCurrentCharacterUnchecked(int cp_offset, int character_count); + + // Check whether preemption has been requested. + void CheckPreemption(); + + // Check whether we are exceeding the stack limit on the backtrack stack. + void CheckStackLimit(); + void CallCFunctionUsingStub(ExternalReference function, int num_arguments); + + // Generate a call to CheckStackGuardState. + void CallCheckStackGuardState(Register scratch); + + // The ebp-relative location of a regexp register. + MemOperand register_location(int register_index); + + // Register holding the current input position as negative offset from + // the end of the string. + inline Register current_input_offset() { return r8; } + + // The register containing the current character after LoadCurrentCharacter. + inline Register current_character() { return r9; } + + // Register holding address of the end of the input string. + inline Register end_of_input_address() { return r10; } + + // Register holding the frame address. Local variables, parameters and + // regexp registers are addressed relative to this. + inline Register frame_pointer() { return fp; } + + // The register containing the backtrack stack top. Provides a meaningful + // name to the register. + inline Register backtrack_stackpointer() { return r13; } + + // Register holding pointer to the current code object. + inline Register code_pointer() { return r7; } + + // Byte size of chars in the string to match (decided by the Mode argument) + inline int char_size() { return static_cast<int>(mode_); } + + // Equivalent to a conditional branch to the label, unless the label + // is NULL, in which case it is a conditional Backtrack. + void BranchOrBacktrack(Condition condition, Label* to, CRegister cr = cr7); + + // Call and return internally in the generated code in a way that + // is GC-safe (i.e., doesn't leave absolute code addresses on the stack) + inline void SafeCall(Label* to, Condition cond = al, CRegister cr = cr7); + inline void SafeReturn(); + inline void SafeCallTarget(Label* name); + + // Pushes the value of a register on the backtrack stack. Decrements the + // stack pointer by a word size and stores the register's value there. + inline void Push(Register source); + + // Pops a value from the backtrack stack. Reads the word at the stack pointer + // and increments it by a word size. + inline void Pop(Register target); + + Isolate* isolate() const { return masm_->isolate(); } + + MacroAssembler* masm_; + + // Which mode to generate code for (Latin1 or UC16). + Mode mode_; + + // One greater than maximal register index actually used. + int num_registers_; + + // Number of registers to output at the end (the saved registers + // are always 0..num_saved_registers_-1) + int num_saved_registers_; + + // Labels used internally. + Label entry_label_; + Label start_label_; + Label success_label_; + Label backtrack_label_; + Label exit_label_; + Label check_preempt_label_; + Label stack_overflow_label_; + Label internal_failure_label_; +}; + +// Set of non-volatile registers saved/restored by generated regexp code. +const RegList kRegExpCalleeSaved = + 1 << 6 | 1 << 7 | 1 << 8 | 1 << 9 | 1 << 10 | 1 << 11 | 1 << 13; + +#endif // V8_INTERPRETED_REGEXP +} // namespace internal +} // namespace v8 + +#endif // V8_S390_REGEXP_MACRO_ASSEMBLER_S390_H_ diff --git a/deps/v8/src/regexp/x64/regexp-macro-assembler-x64.cc b/deps/v8/src/regexp/x64/regexp-macro-assembler-x64.cc index 952034fb0c..5d73b436f8 100644 --- a/deps/v8/src/regexp/x64/regexp-macro-assembler-x64.cc +++ b/deps/v8/src/regexp/x64/regexp-macro-assembler-x64.cc @@ -1008,7 +1008,7 @@ Handle<HeapObject> RegExpMacroAssemblerX64::GetCode(Handle<String> source) { Handle<Code> code = isolate->factory()->NewCode( code_desc, Code::ComputeFlags(Code::REGEXP), masm_.CodeObject()); - PROFILE(isolate, RegExpCodeCreateEvent(*code, *source)); + PROFILE(isolate, RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } diff --git a/deps/v8/src/regexp/x87/regexp-macro-assembler-x87.cc b/deps/v8/src/regexp/x87/regexp-macro-assembler-x87.cc index 6e6209282f..9f15b1c952 100644 --- a/deps/v8/src/regexp/x87/regexp-macro-assembler-x87.cc +++ b/deps/v8/src/regexp/x87/regexp-macro-assembler-x87.cc @@ -510,7 +510,8 @@ void RegExpMacroAssemblerX87::CheckBitInTable( __ and_(ebx, current_character()); index = ebx; } - __ cmpb(FieldOperand(eax, index, times_1, ByteArray::kHeaderSize), 0); + __ cmpb(FieldOperand(eax, index, times_1, ByteArray::kHeaderSize), + Immediate(0)); BranchOrBacktrack(not_equal, on_bit_set); } @@ -935,7 +936,8 @@ Handle<HeapObject> RegExpMacroAssemblerX87::GetCode(Handle<String> source) { isolate()->factory()->NewCode(code_desc, Code::ComputeFlags(Code::REGEXP), masm_->CodeObject()); - PROFILE(isolate(), RegExpCodeCreateEvent(*code, *source)); + PROFILE(masm_->isolate(), + RegExpCodeCreateEvent(AbstractCode::cast(*code), *source)); return Handle<HeapObject>::cast(code); } |