Commit 260cd876 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

Eliminate the code that handles fallback to JSCRE. The only way to get

JSCRE now is to use the --noirregexp flag.  Also add code to check that
we react sensibly to some very large regexps.
Review URL: http://codereview.chromium.org/18587

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1166 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 34b47563
......@@ -203,7 +203,6 @@ DEFINE_bool(preemption, false,
DEFINE_bool(irregexp, true, "new regular expression code")
DEFINE_bool(trace_regexps, false, "trace Irregexp execution")
DEFINE_bool(irregexp_native, true, "use native code Irregexp implementation (IA32 only)")
DEFINE_bool(disable_jscre, true, "abort if JSCRE is used. Only useful with --irregexp")
// Testing flags test/cctest/test-{flags,api,serialization}.cc
DEFINE_bool(testing_bool_flag, true, "testing_bool_flag")
......
This diff is collapsed.
......@@ -588,9 +588,7 @@ class RegExpNode: public ZoneObject {
virtual ~RegExpNode();
virtual void Accept(NodeVisitor* visitor) = 0;
// Generates a goto to this node or actually generates the code at this point.
// Until the implementation is complete we will return true for success and
// false for failure.
virtual bool Emit(RegExpCompiler* compiler, Trace* trace) = 0;
virtual void Emit(RegExpCompiler* compiler, Trace* trace) = 0;
// How many characters must this node consume at a minimum in order to
// succeed. If we have found at least 'still_to_find' characters that
// must be consumed there is no need to ask any following nodes whether
......@@ -637,7 +635,7 @@ class RegExpNode: public ZoneObject {
void set_siblings(SiblingList* other) { siblings_ = *other; }
protected:
enum LimitResult { DONE, FAIL, CONTINUE };
enum LimitResult { DONE, CONTINUE };
LimitResult LimitVersions(RegExpCompiler* compiler, Trace* trace);
// Returns a sibling of this node whose interests and assumptions
......@@ -738,7 +736,7 @@ class ActionNode: public SeqRegExpNode {
int repetition_limit,
RegExpNode* on_success);
virtual void Accept(NodeVisitor* visitor);
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth);
virtual void GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
......@@ -800,7 +798,7 @@ class TextNode: public SeqRegExpNode {
elms_->Add(TextElement::CharClass(that));
}
virtual void Accept(NodeVisitor* visitor);
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth);
virtual void GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
......@@ -858,7 +856,7 @@ class AssertionNode: public SeqRegExpNode {
return new AssertionNode(AFTER_NEWLINE, on_success);
}
virtual void Accept(NodeVisitor* visitor);
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth);
virtual void GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
......@@ -885,7 +883,7 @@ class BackReferenceNode: public SeqRegExpNode {
virtual void Accept(NodeVisitor* visitor);
int start_register() { return start_reg_; }
int end_register() { return end_reg_; }
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth);
virtual void GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
......@@ -905,7 +903,7 @@ class EndNode: public RegExpNode {
enum Action { ACCEPT, BACKTRACK, NEGATIVE_SUBMATCH_SUCCESS };
explicit EndNode(Action action) : action_(action) { }
virtual void Accept(NodeVisitor* visitor);
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth) { return 0; }
virtual void GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
......@@ -931,7 +929,7 @@ class NegativeSubmatchSuccess: public EndNode {
current_position_register_(position_reg),
clear_capture_count_(clear_capture_count),
clear_capture_start_(clear_capture_start) { }
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
private:
int stack_pointer_register_;
......@@ -986,7 +984,7 @@ class ChoiceNode: public RegExpNode {
void AddAlternative(GuardedAlternative node) { alternatives()->Add(node); }
ZoneList<GuardedAlternative>* alternatives() { return alternatives_; }
DispatchTable* GetTable(bool ignore_case);
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth);
int EatsAtLeastHelper(int still_to_find,
int recursion_depth,
......@@ -1011,7 +1009,7 @@ class ChoiceNode: public RegExpNode {
Guard *guard,
Trace* trace);
int CalculatePreloadCharacters(RegExpCompiler* compiler);
bool EmitOutOfLineContinuation(RegExpCompiler* compiler,
void EmitOutOfLineContinuation(RegExpCompiler* compiler,
Trace* trace,
GuardedAlternative alternative,
AlternativeGeneration* alt_gen,
......@@ -1052,7 +1050,7 @@ class LoopChoiceNode: public ChoiceNode {
body_can_be_zero_length_(body_can_be_zero_length) { }
void AddLoopAlternative(GuardedAlternative alt);
void AddContinueAlternative(GuardedAlternative alt);
virtual bool Emit(RegExpCompiler* compiler, Trace* trace);
virtual void Emit(RegExpCompiler* compiler, Trace* trace);
virtual int EatsAtLeast(int still_to_find, int recursion_depth);
virtual void GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
......@@ -1157,7 +1155,7 @@ class Trace {
// and pushing a backtrack location onto the backtrack stack. Once this is
// done we can start a new trace or go to one that has already been
// generated.
bool Flush(RegExpCompiler* compiler, RegExpNode* successor);
void Flush(RegExpCompiler* compiler, RegExpNode* successor);
int cp_offset() { return cp_offset_; }
DeferredAction* actions() { return actions_; }
// A trivial trace is one that has no deferred actions or other state that
......@@ -1205,7 +1203,7 @@ class Trace {
quick_check_performed_ = *d;
}
void InvalidateCurrentCharacter();
void AdvanceCurrentPositionInTrace(int by, bool ascii);
void AdvanceCurrentPositionInTrace(int by, RegExpCompiler* compiler);
private:
int FindAffectedRegisters(OutSet* affected_registers);
void PerformDeferredActions(RegExpMacroAssembler* macro,
......
......@@ -84,6 +84,8 @@ void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) {
void RegExpMacroAssemblerIrregexp::PopRegister(int register_index) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_POP_REGISTER, register_index);
}
......@@ -92,6 +94,7 @@ void RegExpMacroAssemblerIrregexp::PushRegister(
int register_index,
StackCheckFlag check_stack_limit) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_PUSH_REGISTER, register_index);
}
......@@ -99,6 +102,7 @@ void RegExpMacroAssemblerIrregexp::PushRegister(
void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister(
int register_index, int cp_offset) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_SET_REGISTER_TO_CP, register_index);
Emit32(cp_offset); // Current position offset.
}
......@@ -115,6 +119,7 @@ void RegExpMacroAssemblerIrregexp::ClearRegisters(int reg_from, int reg_to) {
void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister(
int register_index) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_SET_CP_TO_REGISTER, register_index);
}
......@@ -122,6 +127,7 @@ void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister(
void RegExpMacroAssemblerIrregexp::WriteStackPointerToRegister(
int register_index) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_SET_REGISTER_TO_SP, register_index);
}
......@@ -129,12 +135,14 @@ void RegExpMacroAssemblerIrregexp::WriteStackPointerToRegister(
void RegExpMacroAssemblerIrregexp::ReadStackPointerFromRegister(
int register_index) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_SET_SP_TO_REGISTER, register_index);
}
void RegExpMacroAssemblerIrregexp::SetRegister(int register_index, int to) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_SET_REGISTER, register_index);
Emit32(to);
}
......@@ -142,6 +150,7 @@ void RegExpMacroAssemblerIrregexp::SetRegister(int register_index, int to) {
void RegExpMacroAssemblerIrregexp::AdvanceRegister(int register_index, int by) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_ADVANCE_REGISTER, register_index);
Emit32(by);
}
......@@ -185,6 +194,8 @@ void RegExpMacroAssemblerIrregexp::Fail() {
void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(int by) {
ASSERT(by >= kMinCPOffset);
ASSERT(by <= kMaxCPOffset);
Emit(BC_ADVANCE_CP, by);
}
......@@ -200,6 +211,8 @@ void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(int cp_offset,
Label* on_failure,
bool check_bounds,
int characters) {
ASSERT(cp_offset >= kMinCPOffset);
ASSERT(cp_offset <= kMaxCPOffset);
int bytecode;
if (check_bounds) {
if (characters == 4) {
......@@ -318,6 +331,8 @@ void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterMinusAnd(
void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg,
Label* on_not_equal) {
ASSERT(start_reg >= 0);
ASSERT(start_reg <= kMaxRegister);
Emit(BC_CHECK_NOT_BACK_REF, start_reg);
EmitOrLink(on_not_equal);
}
......@@ -326,6 +341,8 @@ void RegExpMacroAssemblerIrregexp::CheckNotBackReference(int start_reg,
void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase(
int start_reg,
Label* on_not_equal) {
ASSERT(start_reg >= 0);
ASSERT(start_reg <= kMaxRegister);
Emit(BC_CHECK_NOT_BACK_REF_NO_CASE, start_reg);
EmitOrLink(on_not_equal);
}
......@@ -334,6 +351,8 @@ void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase(
void RegExpMacroAssemblerIrregexp::CheckNotRegistersEqual(int reg1,
int reg2,
Label* on_not_equal) {
ASSERT(reg1 >= 0);
ASSERT(reg1 <= kMaxRegister);
Emit(BC_CHECK_NOT_REGS_EQUAL, reg1);
Emit32(reg2);
EmitOrLink(on_not_equal);
......@@ -376,6 +395,8 @@ void RegExpMacroAssemblerIrregexp::CheckCharacters(
int cp_offset,
Label* on_failure,
bool check_end_of_string) {
ASSERT(cp_offset >= kMinCPOffset);
ASSERT(cp_offset + str.length() - 1 <= kMaxCPOffset);
// It is vital that this loop is backwards due to the unchecked character
// load below.
for (int i = str.length() - 1; i >= 0; i--) {
......@@ -394,7 +415,8 @@ void RegExpMacroAssemblerIrregexp::CheckCharacters(
void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index,
int comparand,
Label* on_less_than) {
ASSERT(comparand >= 0 && comparand <= 65535);
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_CHECK_REGISTER_LT, register_index);
Emit32(comparand);
EmitOrLink(on_less_than);
......@@ -404,7 +426,8 @@ void RegExpMacroAssemblerIrregexp::IfRegisterLT(int register_index,
void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index,
int comparand,
Label* on_greater_or_equal) {
ASSERT(comparand >= 0 && comparand <= 65535);
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_CHECK_REGISTER_GE, register_index);
Emit32(comparand);
EmitOrLink(on_greater_or_equal);
......@@ -413,6 +436,8 @@ void RegExpMacroAssemblerIrregexp::IfRegisterGE(int register_index,
void RegExpMacroAssemblerIrregexp::IfRegisterEqPos(int register_index,
Label* on_eq) {
ASSERT(register_index >= 0);
ASSERT(register_index <= kMaxRegister);
Emit(BC_CHECK_REGISTER_EQ_POS, register_index);
EmitOrLink(on_eq);
}
......
......@@ -38,6 +38,10 @@ struct DisjunctDecisionRow {
class RegExpMacroAssembler {
public:
// The implementation must be able to handle at least:
static const int kMaxRegister = (1 << 16) - 1;
static const int kMaxCPOffset = (1 << 15) - 1;
static const int kMinCPOffset = -(1 << 15);
enum IrregexpImplementation {
kIA32Implementation,
kARMImplementation,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment