39 #ifdef V8_INTERPRETED_REGEXP
41 RegExpMacroAssemblerIrregexp::RegExpMacroAssemblerIrregexp(Vector<byte> buffer,
43 : RegExpMacroAssembler(zone),
47 advance_current_end_(kInvalidPC) {
51 RegExpMacroAssemblerIrregexp::~RegExpMacroAssemblerIrregexp() {
52 if (backtrack_.is_linked()) backtrack_.Unuse();
53 if (own_buffer_)
buffer_.Dispose();
57 RegExpMacroAssemblerIrregexp::IrregexpImplementation
58 RegExpMacroAssemblerIrregexp::Implementation() {
59 return kBytecodeImplementation;
63 void RegExpMacroAssemblerIrregexp::Bind(Label* l) {
64 advance_current_end_ = kInvalidPC;
71 *
reinterpret_cast<uint32_t*
>(
buffer_.start() + fixup) = pc_;
78 void RegExpMacroAssemblerIrregexp::EmitOrLink(Label* l) {
79 if (l ==
NULL) l = &backtrack_;
93 void RegExpMacroAssemblerIrregexp::PopRegister(
int register_index) {
94 ASSERT(register_index >= 0);
95 ASSERT(register_index <= kMaxRegister);
96 Emit(BC_POP_REGISTER, register_index);
100 void RegExpMacroAssemblerIrregexp::PushRegister(
102 StackCheckFlag check_stack_limit) {
103 ASSERT(register_index >= 0);
104 ASSERT(register_index <= kMaxRegister);
105 Emit(BC_PUSH_REGISTER, register_index);
109 void RegExpMacroAssemblerIrregexp::WriteCurrentPositionToRegister(
110 int register_index,
int cp_offset) {
111 ASSERT(register_index >= 0);
112 ASSERT(register_index <= kMaxRegister);
113 Emit(BC_SET_REGISTER_TO_CP, register_index);
118 void RegExpMacroAssemblerIrregexp::ClearRegisters(
int reg_from,
int reg_to) {
119 ASSERT(reg_from <= reg_to);
120 for (
int reg = reg_from; reg <= reg_to; reg++) {
121 SetRegister(reg, -1);
126 void RegExpMacroAssemblerIrregexp::ReadCurrentPositionFromRegister(
127 int register_index) {
128 ASSERT(register_index >= 0);
129 ASSERT(register_index <= kMaxRegister);
130 Emit(BC_SET_CP_TO_REGISTER, register_index);
134 void RegExpMacroAssemblerIrregexp::WriteStackPointerToRegister(
135 int register_index) {
136 ASSERT(register_index >= 0);
137 ASSERT(register_index <= kMaxRegister);
138 Emit(BC_SET_REGISTER_TO_SP, register_index);
142 void RegExpMacroAssemblerIrregexp::ReadStackPointerFromRegister(
143 int register_index) {
144 ASSERT(register_index >= 0);
145 ASSERT(register_index <= kMaxRegister);
146 Emit(BC_SET_SP_TO_REGISTER, register_index);
150 void RegExpMacroAssemblerIrregexp::SetCurrentPositionFromEnd(
int by) {
152 Emit(BC_SET_CURRENT_POSITION_FROM_END, by);
156 void RegExpMacroAssemblerIrregexp::SetRegister(
int register_index,
int to) {
157 ASSERT(register_index >= 0);
158 ASSERT(register_index <= kMaxRegister);
159 Emit(BC_SET_REGISTER, register_index);
164 void RegExpMacroAssemblerIrregexp::AdvanceRegister(
int register_index,
int by) {
165 ASSERT(register_index >= 0);
166 ASSERT(register_index <= kMaxRegister);
167 Emit(BC_ADVANCE_REGISTER, register_index);
172 void RegExpMacroAssemblerIrregexp::PopCurrentPosition() {
177 void RegExpMacroAssemblerIrregexp::PushCurrentPosition() {
182 void RegExpMacroAssemblerIrregexp::Backtrack() {
187 void RegExpMacroAssemblerIrregexp::GoTo(Label* l) {
188 if (advance_current_end_ == pc_) {
190 pc_ = advance_current_start_;
191 Emit(BC_ADVANCE_CP_AND_GOTO, advance_current_offset_);
193 advance_current_end_ = kInvalidPC;
202 void RegExpMacroAssemblerIrregexp::PushBacktrack(Label* l) {
208 bool RegExpMacroAssemblerIrregexp::Succeed() {
219 void RegExpMacroAssemblerIrregexp::AdvanceCurrentPosition(
int by) {
220 ASSERT(by >= kMinCPOffset);
221 ASSERT(by <= kMaxCPOffset);
222 advance_current_start_ = pc_;
223 advance_current_offset_ = by;
224 Emit(BC_ADVANCE_CP, by);
225 advance_current_end_ = pc_;
229 void RegExpMacroAssemblerIrregexp::CheckGreedyLoop(
230 Label* on_tos_equals_current_position) {
231 Emit(BC_CHECK_GREEDY, 0);
232 EmitOrLink(on_tos_equals_current_position);
236 void RegExpMacroAssemblerIrregexp::LoadCurrentCharacter(
int cp_offset,
240 ASSERT(cp_offset >= kMinCPOffset);
241 ASSERT(cp_offset <= kMaxCPOffset);
244 if (characters == 4) {
245 bytecode = BC_LOAD_4_CURRENT_CHARS;
246 }
else if (characters == 2) {
247 bytecode = BC_LOAD_2_CURRENT_CHARS;
250 bytecode = BC_LOAD_CURRENT_CHAR;
253 if (characters == 4) {
254 bytecode = BC_LOAD_4_CURRENT_CHARS_UNCHECKED;
255 }
else if (characters == 2) {
256 bytecode = BC_LOAD_2_CURRENT_CHARS_UNCHECKED;
259 bytecode = BC_LOAD_CURRENT_CHAR_UNCHECKED;
262 Emit(bytecode, cp_offset);
263 if (check_bounds) EmitOrLink(on_failure);
267 void RegExpMacroAssemblerIrregexp::CheckCharacterLT(
uc16 limit,
269 Emit(BC_CHECK_LT, limit);
274 void RegExpMacroAssemblerIrregexp::CheckCharacterGT(
uc16 limit,
276 Emit(BC_CHECK_GT, limit);
277 EmitOrLink(on_greater);
281 void RegExpMacroAssemblerIrregexp::CheckCharacter(uint32_t c, Label* on_equal) {
283 Emit(BC_CHECK_4_CHARS, 0);
286 Emit(BC_CHECK_CHAR, c);
288 EmitOrLink(on_equal);
292 void RegExpMacroAssemblerIrregexp::CheckAtStart(Label* on_at_start) {
293 Emit(BC_CHECK_AT_START, 0);
294 EmitOrLink(on_at_start);
298 void RegExpMacroAssemblerIrregexp::CheckNotAtStart(Label* on_not_at_start) {
299 Emit(BC_CHECK_NOT_AT_START, 0);
300 EmitOrLink(on_not_at_start);
304 void RegExpMacroAssemblerIrregexp::CheckNotCharacter(uint32_t c,
305 Label* on_not_equal) {
307 Emit(BC_CHECK_NOT_4_CHARS, 0);
310 Emit(BC_CHECK_NOT_CHAR, c);
312 EmitOrLink(on_not_equal);
316 void RegExpMacroAssemblerIrregexp::CheckCharacterAfterAnd(
321 Emit(BC_AND_CHECK_4_CHARS, 0);
324 Emit(BC_AND_CHECK_CHAR, c);
327 EmitOrLink(on_equal);
331 void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterAnd(
334 Label* on_not_equal) {
336 Emit(BC_AND_CHECK_NOT_4_CHARS, 0);
339 Emit(BC_AND_CHECK_NOT_CHAR, c);
342 EmitOrLink(on_not_equal);
346 void RegExpMacroAssemblerIrregexp::CheckNotCharacterAfterMinusAnd(
350 Label* on_not_equal) {
351 Emit(BC_MINUS_AND_CHECK_NOT_CHAR, c);
354 EmitOrLink(on_not_equal);
358 void RegExpMacroAssemblerIrregexp::CheckCharacterInRange(
361 Label* on_in_range) {
362 Emit(BC_CHECK_CHAR_IN_RANGE, 0);
365 EmitOrLink(on_in_range);
369 void RegExpMacroAssemblerIrregexp::CheckCharacterNotInRange(
372 Label* on_not_in_range) {
373 Emit(BC_CHECK_CHAR_NOT_IN_RANGE, 0);
376 EmitOrLink(on_not_in_range);
380 void RegExpMacroAssemblerIrregexp::CheckBitInTable(
381 Handle<ByteArray> table, Label* on_bit_set) {
382 Emit(BC_CHECK_BIT_IN_TABLE, 0);
383 EmitOrLink(on_bit_set);
387 if (table->get(i + j) != 0) byte |= 1 << j;
394 void RegExpMacroAssemblerIrregexp::CheckNotBackReference(
int start_reg,
395 Label* on_not_equal) {
397 ASSERT(start_reg <= kMaxRegister);
398 Emit(BC_CHECK_NOT_BACK_REF, start_reg);
399 EmitOrLink(on_not_equal);
403 void RegExpMacroAssemblerIrregexp::CheckNotBackReferenceIgnoreCase(
405 Label* on_not_equal) {
407 ASSERT(start_reg <= kMaxRegister);
408 Emit(BC_CHECK_NOT_BACK_REF_NO_CASE, start_reg);
409 EmitOrLink(on_not_equal);
413 void RegExpMacroAssemblerIrregexp::CheckCharacters(
414 Vector<const uc16> str,
417 bool check_end_of_string) {
418 ASSERT(cp_offset >= kMinCPOffset);
419 ASSERT(cp_offset + str.length() - 1 <= kMaxCPOffset);
422 for (
int i = str.length() - 1; i >= 0; i--) {
423 if (check_end_of_string && i == str.length() - 1) {
424 Emit(BC_LOAD_CURRENT_CHAR, cp_offset + i);
425 EmitOrLink(on_failure);
427 Emit(BC_LOAD_CURRENT_CHAR_UNCHECKED, cp_offset + i);
429 Emit(BC_CHECK_NOT_CHAR, str[i]);
430 EmitOrLink(on_failure);
435 void RegExpMacroAssemblerIrregexp::IfRegisterLT(
int register_index,
437 Label* on_less_than) {
438 ASSERT(register_index >= 0);
439 ASSERT(register_index <= kMaxRegister);
440 Emit(BC_CHECK_REGISTER_LT, register_index);
442 EmitOrLink(on_less_than);
446 void RegExpMacroAssemblerIrregexp::IfRegisterGE(
int register_index,
448 Label* on_greater_or_equal) {
449 ASSERT(register_index >= 0);
450 ASSERT(register_index <= kMaxRegister);
451 Emit(BC_CHECK_REGISTER_GE, register_index);
453 EmitOrLink(on_greater_or_equal);
457 void RegExpMacroAssemblerIrregexp::IfRegisterEqPos(
int register_index,
459 ASSERT(register_index >= 0);
460 ASSERT(register_index <= kMaxRegister);
461 Emit(BC_CHECK_REGISTER_EQ_POS, register_index);
466 Handle<HeapObject> RegExpMacroAssemblerIrregexp::GetCode(
467 Handle<String> source) {
470 Handle<ByteArray> array =
FACTORY->NewByteArray(length());
471 Copy(array->GetDataStartAddress());
476 int RegExpMacroAssemblerIrregexp::length() {
482 memcpy(a,
buffer_.start(), length());
486 void RegExpMacroAssemblerIrregexp::Expand() {
487 bool old_buffer_was_our_own = own_buffer_;
488 Vector<byte> old_buffer =
buffer_;
491 memcpy(
buffer_.start(), old_buffer.start(), old_buffer.length());
492 if (old_buffer_was_our_own) {
493 old_buffer.Dispose();
497 #endif // V8_INTERPRETED_REGEXP
v8::Handle< v8::Value > Fail(const v8::Arguments &args)
#define ASSERT(condition)
StringInputBuffer *const buffer_
static Vector< T > New(int length)
activate correct semantics for inheriting readonliness false
const unsigned int MAX_FIRST_ARG
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Handle< JSObject > Copy(Handle< JSObject > obj)