Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/code-stubs.h

Issue 3169049: Remove dependence of code-stubs on codegen, the virtual frame code generator.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm/regexp-macro-assembler-arm.cc ('k') | src/codegen.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 11 matching lines...) Expand all
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_CODE_STUBS_H_ 28 #ifndef V8_CODE_STUBS_H_
29 #define V8_CODE_STUBS_H_ 29 #define V8_CODE_STUBS_H_
30 30
31 #include "globals.h" 31 #include "globals.h"
32 #include "macro-assembler.h"
32 33
33 namespace v8 { 34 namespace v8 {
34 namespace internal { 35 namespace internal {
35 36
36 // List of code stubs used on all platforms. The order in this list is important 37 // List of code stubs used on all platforms. The order in this list is important
37 // as only the stubs up to and including RecordWrite allows nested stub calls. 38 // as only the stubs up to and including RecordWrite allows nested stub calls.
38 #define CODE_STUB_LIST_ALL_PLATFORMS(V) \ 39 #define CODE_STUB_LIST_ALL_PLATFORMS(V) \
39 V(CallFunction) \ 40 V(CallFunction) \
40 V(GenericBinaryOp) \ 41 V(GenericBinaryOp) \
41 V(StringAdd) \ 42 V(StringAdd) \
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 V(RegExpCEntry) 74 V(RegExpCEntry)
74 #else 75 #else
75 #define CODE_STUB_LIST_ARM(V) 76 #define CODE_STUB_LIST_ARM(V)
76 #endif 77 #endif
77 78
78 // Combined list of code stubs. 79 // Combined list of code stubs.
79 #define CODE_STUB_LIST(V) \ 80 #define CODE_STUB_LIST(V) \
80 CODE_STUB_LIST_ALL_PLATFORMS(V) \ 81 CODE_STUB_LIST_ALL_PLATFORMS(V) \
81 CODE_STUB_LIST_ARM(V) 82 CODE_STUB_LIST_ARM(V)
82 83
84 // Types of uncatchable exceptions.
85 enum UncatchableExceptionType { OUT_OF_MEMORY, TERMINATION };
86
87 // Mode to overwrite BinaryExpression values.
88 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
89 enum UnaryOverwriteMode { UNARY_OVERWRITE, UNARY_NO_OVERWRITE };
90
91
83 // Stub is base classes of all stubs. 92 // Stub is base classes of all stubs.
84 class CodeStub BASE_EMBEDDED { 93 class CodeStub BASE_EMBEDDED {
85 public: 94 public:
86 enum Major { 95 enum Major {
87 #define DEF_ENUM(name) name, 96 #define DEF_ENUM(name) name,
88 CODE_STUB_LIST(DEF_ENUM) 97 CODE_STUB_LIST(DEF_ENUM)
89 #undef DEF_ENUM 98 #undef DEF_ENUM
90 NoCache, // marker for stubs that do custom caching 99 NoCache, // marker for stubs that do custom caching
91 NUMBER_OF_IDS 100 NUMBER_OF_IDS
92 }; 101 };
93 102
94 // Retrieve the code for the stub. Generate the code if needed. 103 // Retrieve the code for the stub. Generate the code if needed.
95 Handle<Code> GetCode(); 104 Handle<Code> GetCode();
96 105
97 // Retrieve the code for the stub if already generated. Do not 106 // Retrieve the code for the stub if already generated. Do not
98 // generate the code if not already generated and instead return a 107 // generate the code if not already generated and instead return a
99 // retry after GC Failure object. 108 // retry after GC Failure object.
100 Object* TryGetCode(); 109 Object* TryGetCode();
101 110
102 static Major MajorKeyFromKey(uint32_t key) { 111 static Major MajorKeyFromKey(uint32_t key) {
103 return static_cast<Major>(MajorKeyBits::decode(key)); 112 return static_cast<Major>(MajorKeyBits::decode(key));
104 }; 113 };
105 static int MinorKeyFromKey(uint32_t key) { 114 static int MinorKeyFromKey(uint32_t key) {
106 return MinorKeyBits::decode(key); 115 return MinorKeyBits::decode(key);
107 }; 116 };
117
118 // Gets the major key from a code object that is a code stub or binary op IC.
119 static Major GetMajorKey(Code* code_stub) {
120 return static_cast<Major>(code_stub->major_key());
121 }
122
108 static const char* MajorName(Major major_key, bool allow_unknown_keys); 123 static const char* MajorName(Major major_key, bool allow_unknown_keys);
109 124
110 virtual ~CodeStub() {} 125 virtual ~CodeStub() {}
111 126
112 // Override these methods to provide a custom caching mechanism for 127 // Override these methods to provide a custom caching mechanism for
113 // an individual type of code stub. 128 // an individual type of code stub.
114 virtual bool GetCustomCache(Code** code_out) { return false; } 129 virtual bool GetCustomCache(Code** code_out) { return false; }
115 virtual void SetCustomCache(Code* value) { } 130 virtual void SetCustomCache(Code* value) { }
116 virtual bool has_custom_cache() { return false; } 131 virtual bool has_custom_cache() { return false; }
117 132
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 180 }
166 181
167 bool AllowsStubCalls() { return MajorKey() <= RecordWrite; } 182 bool AllowsStubCalls() { return MajorKey() <= RecordWrite; }
168 183
169 class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {}; 184 class MajorKeyBits: public BitField<uint32_t, 0, kMajorBits> {};
170 class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {}; 185 class MinorKeyBits: public BitField<uint32_t, kMajorBits, kMinorBits> {};
171 186
172 friend class BreakPointIterator; 187 friend class BreakPointIterator;
173 }; 188 };
174 189
190
191 // Helper interface to prepare to/restore after making runtime calls.
192 class RuntimeCallHelper {
193 public:
194 virtual ~RuntimeCallHelper() {}
195
196 virtual void BeforeCall(MacroAssembler* masm) const = 0;
197
198 virtual void AfterCall(MacroAssembler* masm) const = 0;
199
200 protected:
201 RuntimeCallHelper() {}
202
203 private:
204 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
205 };
206
175 } } // namespace v8::internal 207 } } // namespace v8::internal
176 208
209 #if V8_TARGET_ARCH_IA32
210 #include "ia32/code-stubs-ia32.h"
211 #elif V8_TARGET_ARCH_X64
212 #include "x64/code-stubs-x64.h"
213 #elif V8_TARGET_ARCH_ARM
214 #include "arm/code-stubs-arm.h"
215 #elif V8_TARGET_ARCH_MIPS
216 #include "mips/code-stubs-mips.h"
217 #else
218 #error Unsupported target architecture.
219 #endif
220
221 namespace v8 {
222 namespace internal {
223
224
225 // RuntimeCallHelper implementation used in IC stubs: enters/leaves a
226 // newly created internal frame before/after the runtime call.
227 class ICRuntimeCallHelper : public RuntimeCallHelper {
228 public:
229 ICRuntimeCallHelper() {}
230
231 virtual void BeforeCall(MacroAssembler* masm) const;
232
233 virtual void AfterCall(MacroAssembler* masm) const;
234 };
235
236
237 // Trivial RuntimeCallHelper implementation.
238 class NopRuntimeCallHelper : public RuntimeCallHelper {
239 public:
240 NopRuntimeCallHelper() {}
241
242 virtual void BeforeCall(MacroAssembler* masm) const {}
243
244 virtual void AfterCall(MacroAssembler* masm) const {}
245 };
246
247
248 class StackCheckStub : public CodeStub {
249 public:
250 StackCheckStub() { }
251
252 void Generate(MacroAssembler* masm);
253
254 private:
255
256 const char* GetName() { return "StackCheckStub"; }
257
258 Major MajorKey() { return StackCheck; }
259 int MinorKey() { return 0; }
260 };
261
262
263 class FastNewClosureStub : public CodeStub {
264 public:
265 void Generate(MacroAssembler* masm);
266
267 private:
268 const char* GetName() { return "FastNewClosureStub"; }
269 Major MajorKey() { return FastNewClosure; }
270 int MinorKey() { return 0; }
271 };
272
273
274 class FastNewContextStub : public CodeStub {
275 public:
276 static const int kMaximumSlots = 64;
277
278 explicit FastNewContextStub(int slots) : slots_(slots) {
279 ASSERT(slots_ > 0 && slots <= kMaximumSlots);
280 }
281
282 void Generate(MacroAssembler* masm);
283
284 private:
285 int slots_;
286
287 const char* GetName() { return "FastNewContextStub"; }
288 Major MajorKey() { return FastNewContext; }
289 int MinorKey() { return slots_; }
290 };
291
292
293 class FastCloneShallowArrayStub : public CodeStub {
294 public:
295 // Maximum length of copied elements array.
296 static const int kMaximumClonedLength = 8;
297
298 enum Mode {
299 CLONE_ELEMENTS,
300 COPY_ON_WRITE_ELEMENTS
301 };
302
303 FastCloneShallowArrayStub(Mode mode, int length)
304 : mode_(mode),
305 length_((mode == COPY_ON_WRITE_ELEMENTS) ? 0 : length) {
306 ASSERT(length_ >= 0);
307 ASSERT(length_ <= kMaximumClonedLength);
308 }
309
310 void Generate(MacroAssembler* masm);
311
312 private:
313 Mode mode_;
314 int length_;
315
316 const char* GetName() { return "FastCloneShallowArrayStub"; }
317 Major MajorKey() { return FastCloneShallowArray; }
318 int MinorKey() {
319 ASSERT(mode_ == 0 || mode_ == 1);
320 return (length_ << 1) | mode_;
321 }
322 };
323
324
325 class InstanceofStub: public CodeStub {
326 public:
327 InstanceofStub() { }
328
329 void Generate(MacroAssembler* masm);
330
331 private:
332 Major MajorKey() { return Instanceof; }
333 int MinorKey() { return 0; }
334 };
335
336
337 enum NegativeZeroHandling {
338 kStrictNegativeZero,
339 kIgnoreNegativeZero
340 };
341
342
343 class GenericUnaryOpStub : public CodeStub {
344 public:
345 GenericUnaryOpStub(Token::Value op,
346 UnaryOverwriteMode overwrite,
347 NegativeZeroHandling negative_zero = kStrictNegativeZero)
348 : op_(op), overwrite_(overwrite), negative_zero_(negative_zero) { }
349
350 private:
351 Token::Value op_;
352 UnaryOverwriteMode overwrite_;
353 NegativeZeroHandling negative_zero_;
354
355 class OverwriteField: public BitField<UnaryOverwriteMode, 0, 1> {};
356 class NegativeZeroField: public BitField<NegativeZeroHandling, 1, 1> {};
357 class OpField: public BitField<Token::Value, 2, kMinorBits - 2> {};
358
359 Major MajorKey() { return GenericUnaryOp; }
360 int MinorKey() {
361 return OpField::encode(op_) |
362 OverwriteField::encode(overwrite_) |
363 NegativeZeroField::encode(negative_zero_);
364 }
365
366 void Generate(MacroAssembler* masm);
367
368 const char* GetName();
369 };
370
371
372 enum NaNInformation {
373 kBothCouldBeNaN,
374 kCantBothBeNaN
375 };
376
377
378 class CompareStub: public CodeStub {
379 public:
380 CompareStub(Condition cc,
381 bool strict,
382 NaNInformation nan_info = kBothCouldBeNaN,
383 bool include_number_compare = true,
384 Register lhs = no_reg,
385 Register rhs = no_reg) :
386 cc_(cc),
387 strict_(strict),
388 never_nan_nan_(nan_info == kCantBothBeNaN),
389 include_number_compare_(include_number_compare),
390 lhs_(lhs),
391 rhs_(rhs),
392 name_(NULL) { }
393
394 void Generate(MacroAssembler* masm);
395
396 private:
397 Condition cc_;
398 bool strict_;
399 // Only used for 'equal' comparisons. Tells the stub that we already know
400 // that at least one side of the comparison is not NaN. This allows the
401 // stub to use object identity in the positive case. We ignore it when
402 // generating the minor key for other comparisons to avoid creating more
403 // stubs.
404 bool never_nan_nan_;
405 // Do generate the number comparison code in the stub. Stubs without number
406 // comparison code is used when the number comparison has been inlined, and
407 // the stub will be called if one of the operands is not a number.
408 bool include_number_compare_;
409 // Register holding the left hand side of the comparison if the stub gives
410 // a choice, no_reg otherwise.
411 Register lhs_;
412 // Register holding the right hand side of the comparison if the stub gives
413 // a choice, no_reg otherwise.
414 Register rhs_;
415
416 // Encoding of the minor key CCCCCCCCCCCCRCNS.
417 class StrictField: public BitField<bool, 0, 1> {};
418 class NeverNanNanField: public BitField<bool, 1, 1> {};
419 class IncludeNumberCompareField: public BitField<bool, 2, 1> {};
420 class RegisterField: public BitField<bool, 3, 1> {};
421 class ConditionField: public BitField<int, 4, 12> {};
422
423 Major MajorKey() { return Compare; }
424
425 int MinorKey();
426
427 // Branch to the label if the given object isn't a symbol.
428 void BranchIfNonSymbol(MacroAssembler* masm,
429 Label* label,
430 Register object,
431 Register scratch);
432
433 // Unfortunately you have to run without snapshots to see most of these
434 // names in the profile since most compare stubs end up in the snapshot.
435 char* name_;
436 const char* GetName();
437 #ifdef DEBUG
438 void Print() {
439 PrintF("CompareStub (cc %d), (strict %s), "
440 "(never_nan_nan %s), (number_compare %s) ",
441 static_cast<int>(cc_),
442 strict_ ? "true" : "false",
443 never_nan_nan_ ? "true" : "false",
444 include_number_compare_ ? "included" : "not included");
445
446 if (!lhs_.is(no_reg) && !rhs_.is(no_reg)) {
447 PrintF("(lhs r%d), (rhs r%d)\n", lhs_.code(), rhs_.code());
448 } else {
449 PrintF("\n");
450 }
451 }
452 #endif
453 };
454
455
456 class CEntryStub : public CodeStub {
457 public:
458 explicit CEntryStub(int result_size) : result_size_(result_size) { }
459
460 void Generate(MacroAssembler* masm);
461
462 private:
463 void GenerateCore(MacroAssembler* masm,
464 Label* throw_normal_exception,
465 Label* throw_termination_exception,
466 Label* throw_out_of_memory_exception,
467 bool do_gc,
468 bool always_allocate_scope,
469 int alignment_skew = 0);
470 void GenerateThrowTOS(MacroAssembler* masm);
471 void GenerateThrowUncatchable(MacroAssembler* masm,
472 UncatchableExceptionType type);
473
474 // Number of pointers/values returned.
475 const int result_size_;
476
477 Major MajorKey() { return CEntry; }
478 // Minor key must differ if different result_size_ values means different
479 // code is generated.
480 int MinorKey();
481
482 const char* GetName() { return "CEntryStub"; }
483 };
484
485
486 class ApiGetterEntryStub : public CodeStub {
487 public:
488 ApiGetterEntryStub(Handle<AccessorInfo> info,
489 ApiFunction* fun)
490 : info_(info),
491 fun_(fun) { }
492 void Generate(MacroAssembler* masm);
493 virtual bool has_custom_cache() { return true; }
494 virtual bool GetCustomCache(Code** code_out);
495 virtual void SetCustomCache(Code* value);
496
497 static const int kStackSpace = 5;
498 static const int kArgc = 4;
499 private:
500 Handle<AccessorInfo> info() { return info_; }
501 ApiFunction* fun() { return fun_; }
502 Major MajorKey() { return NoCache; }
503 int MinorKey() { return 0; }
504 const char* GetName() { return "ApiEntryStub"; }
505 // The accessor info associated with the function.
506 Handle<AccessorInfo> info_;
507 // The function to be called.
508 ApiFunction* fun_;
509 };
510
511
512 class JSEntryStub : public CodeStub {
513 public:
514 JSEntryStub() { }
515
516 void Generate(MacroAssembler* masm) { GenerateBody(masm, false); }
517
518 protected:
519 void GenerateBody(MacroAssembler* masm, bool is_construct);
520
521 private:
522 Major MajorKey() { return JSEntry; }
523 int MinorKey() { return 0; }
524
525 const char* GetName() { return "JSEntryStub"; }
526 };
527
528
529 class JSConstructEntryStub : public JSEntryStub {
530 public:
531 JSConstructEntryStub() { }
532
533 void Generate(MacroAssembler* masm) { GenerateBody(masm, true); }
534
535 private:
536 int MinorKey() { return 1; }
537
538 const char* GetName() { return "JSConstructEntryStub"; }
539 };
540
541
542 class ArgumentsAccessStub: public CodeStub {
543 public:
544 enum Type {
545 READ_ELEMENT,
546 NEW_OBJECT
547 };
548
549 explicit ArgumentsAccessStub(Type type) : type_(type) { }
550
551 private:
552 Type type_;
553
554 Major MajorKey() { return ArgumentsAccess; }
555 int MinorKey() { return type_; }
556
557 void Generate(MacroAssembler* masm);
558 void GenerateReadElement(MacroAssembler* masm);
559 void GenerateNewObject(MacroAssembler* masm);
560
561 const char* GetName() { return "ArgumentsAccessStub"; }
562
563 #ifdef DEBUG
564 void Print() {
565 PrintF("ArgumentsAccessStub (type %d)\n", type_);
566 }
567 #endif
568 };
569
570
571 class RegExpExecStub: public CodeStub {
572 public:
573 RegExpExecStub() { }
574
575 private:
576 Major MajorKey() { return RegExpExec; }
577 int MinorKey() { return 0; }
578
579 void Generate(MacroAssembler* masm);
580
581 const char* GetName() { return "RegExpExecStub"; }
582
583 #ifdef DEBUG
584 void Print() {
585 PrintF("RegExpExecStub\n");
586 }
587 #endif
588 };
589
590
591 class CallFunctionStub: public CodeStub {
592 public:
593 CallFunctionStub(int argc, InLoopFlag in_loop, CallFunctionFlags flags)
594 : argc_(argc), in_loop_(in_loop), flags_(flags) { }
595
596 void Generate(MacroAssembler* masm);
597
598 private:
599 int argc_;
600 InLoopFlag in_loop_;
601 CallFunctionFlags flags_;
602
603 #ifdef DEBUG
604 void Print() {
605 PrintF("CallFunctionStub (args %d, in_loop %d, flags %d)\n",
606 argc_,
607 static_cast<int>(in_loop_),
608 static_cast<int>(flags_));
609 }
610 #endif
611
612 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
613 class InLoopBits: public BitField<InLoopFlag, 0, 1> {};
614 class FlagBits: public BitField<CallFunctionFlags, 1, 1> {};
615 class ArgcBits: public BitField<int, 2, 32 - 2> {};
616
617 Major MajorKey() { return CallFunction; }
618 int MinorKey() {
619 // Encode the parameters in a unique 32 bit value.
620 return InLoopBits::encode(in_loop_)
621 | FlagBits::encode(flags_)
622 | ArgcBits::encode(argc_);
623 }
624
625 InLoopFlag InLoop() { return in_loop_; }
626 bool ReceiverMightBeValue() {
627 return (flags_ & RECEIVER_MIGHT_BE_VALUE) != 0;
628 }
629
630 public:
631 static int ExtractArgcFromMinorKey(int minor_key) {
632 return ArgcBits::decode(minor_key);
633 }
634 };
635
636
637 enum StringIndexFlags {
638 // Accepts smis or heap numbers.
639 STRING_INDEX_IS_NUMBER,
640
641 // Accepts smis or heap numbers that are valid array indices
642 // (ECMA-262 15.4). Invalid indices are reported as being out of
643 // range.
644 STRING_INDEX_IS_ARRAY_INDEX
645 };
646
647
648 // Generates code implementing String.prototype.charCodeAt.
649 //
650 // Only supports the case when the receiver is a string and the index
651 // is a number (smi or heap number) that is a valid index into the
652 // string. Additional index constraints are specified by the
653 // flags. Otherwise, bails out to the provided labels.
654 //
655 // Register usage: |object| may be changed to another string in a way
656 // that doesn't affect charCodeAt/charAt semantics, |index| is
657 // preserved, |scratch| and |result| are clobbered.
658 class StringCharCodeAtGenerator {
659 public:
660 StringCharCodeAtGenerator(Register object,
661 Register index,
662 Register scratch,
663 Register result,
664 Label* receiver_not_string,
665 Label* index_not_number,
666 Label* index_out_of_range,
667 StringIndexFlags index_flags)
668 : object_(object),
669 index_(index),
670 scratch_(scratch),
671 result_(result),
672 receiver_not_string_(receiver_not_string),
673 index_not_number_(index_not_number),
674 index_out_of_range_(index_out_of_range),
675 index_flags_(index_flags) {
676 ASSERT(!scratch_.is(object_));
677 ASSERT(!scratch_.is(index_));
678 ASSERT(!scratch_.is(result_));
679 ASSERT(!result_.is(object_));
680 ASSERT(!result_.is(index_));
681 }
682
683 // Generates the fast case code. On the fallthrough path |result|
684 // register contains the result.
685 void GenerateFast(MacroAssembler* masm);
686
687 // Generates the slow case code. Must not be naturally
688 // reachable. Expected to be put after a ret instruction (e.g., in
689 // deferred code). Always jumps back to the fast case.
690 void GenerateSlow(MacroAssembler* masm,
691 const RuntimeCallHelper& call_helper);
692
693 private:
694 Register object_;
695 Register index_;
696 Register scratch_;
697 Register result_;
698
699 Label* receiver_not_string_;
700 Label* index_not_number_;
701 Label* index_out_of_range_;
702
703 StringIndexFlags index_flags_;
704
705 Label call_runtime_;
706 Label index_not_smi_;
707 Label got_smi_index_;
708 Label exit_;
709
710 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
711 };
712
713
714 // Generates code for creating a one-char string from a char code.
715 class StringCharFromCodeGenerator {
716 public:
717 StringCharFromCodeGenerator(Register code,
718 Register result)
719 : code_(code),
720 result_(result) {
721 ASSERT(!code_.is(result_));
722 }
723
724 // Generates the fast case code. On the fallthrough path |result|
725 // register contains the result.
726 void GenerateFast(MacroAssembler* masm);
727
728 // Generates the slow case code. Must not be naturally
729 // reachable. Expected to be put after a ret instruction (e.g., in
730 // deferred code). Always jumps back to the fast case.
731 void GenerateSlow(MacroAssembler* masm,
732 const RuntimeCallHelper& call_helper);
733
734 private:
735 Register code_;
736 Register result_;
737
738 Label slow_case_;
739 Label exit_;
740
741 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
742 };
743
744
745 // Generates code implementing String.prototype.charAt.
746 //
747 // Only supports the case when the receiver is a string and the index
748 // is a number (smi or heap number) that is a valid index into the
749 // string. Additional index constraints are specified by the
750 // flags. Otherwise, bails out to the provided labels.
751 //
752 // Register usage: |object| may be changed to another string in a way
753 // that doesn't affect charCodeAt/charAt semantics, |index| is
754 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
755 class StringCharAtGenerator {
756 public:
757 StringCharAtGenerator(Register object,
758 Register index,
759 Register scratch1,
760 Register scratch2,
761 Register result,
762 Label* receiver_not_string,
763 Label* index_not_number,
764 Label* index_out_of_range,
765 StringIndexFlags index_flags)
766 : char_code_at_generator_(object,
767 index,
768 scratch1,
769 scratch2,
770 receiver_not_string,
771 index_not_number,
772 index_out_of_range,
773 index_flags),
774 char_from_code_generator_(scratch2, result) {}
775
776 // Generates the fast case code. On the fallthrough path |result|
777 // register contains the result.
778 void GenerateFast(MacroAssembler* masm);
779
780 // Generates the slow case code. Must not be naturally
781 // reachable. Expected to be put after a ret instruction (e.g., in
782 // deferred code). Always jumps back to the fast case.
783 void GenerateSlow(MacroAssembler* masm,
784 const RuntimeCallHelper& call_helper);
785
786 private:
787 StringCharCodeAtGenerator char_code_at_generator_;
788 StringCharFromCodeGenerator char_from_code_generator_;
789
790 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
791 };
792
793 } } // namespace v8::internal
794
177 #endif // V8_CODE_STUBS_H_ 795 #endif // V8_CODE_STUBS_H_
OLDNEW
« no previous file with comments | « src/arm/regexp-macro-assembler-arm.cc ('k') | src/codegen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698