1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
28 #ifndef V8_ARM_CODEGEN_ARM_H_
29 #define V8_ARM_CODEGEN_ARM_H_
36 // Forward declarations
37 class CompilationInfo;
39 class RegisterAllocator;
42 enum InitState { CONST_INIT, NOT_CONST_INIT };
43 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
46 // -------------------------------------------------------------------------
49 // A reference is a C++ stack-allocated object that puts a
50 // reference on the virtual frame. The reference may be consumed
51 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
52 // When the lifetime (scope) of a valid reference ends, it must have
53 // been consumed, and be in state UNLOADED.
54 class Reference BASE_EMBEDDED {
56 // The values of the types is important, see size().
57 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
58 Reference(CodeGenerator* cgen,
59 Expression* expression,
60 bool persist_after_get = false);
63 Expression* expression() const { return expression_; }
64 Type type() const { return type_; }
65 void set_type(Type value) {
66 ASSERT_EQ(ILLEGAL, type_);
71 ASSERT_NE(ILLEGAL, type_);
72 ASSERT_NE(UNLOADED, type_);
75 // The size the reference takes up on the stack.
77 return (type_ < SLOT) ? 0 : type_;
80 bool is_illegal() const { return type_ == ILLEGAL; }
81 bool is_slot() const { return type_ == SLOT; }
82 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
83 bool is_unloaded() const { return type_ == UNLOADED; }
85 // Return the name. Only valid for named property references.
86 Handle<String> GetName();
88 // Generate code to push the value of the reference on top of the
89 // expression stack. The reference is expected to be already on top of
90 // the expression stack, and it is consumed by the call unless the
91 // reference is for a compound assignment.
92 // If the reference is not consumed, it is left in place under its value.
95 // Generate code to store the value on top of the expression stack in the
96 // reference. The reference is expected to be immediately below the value
97 // on the expression stack. The value is stored in the location specified
98 // by the reference, and is left on top of the stack, after the reference
99 // is popped from beneath it (unloaded).
100 void SetValue(InitState init_state);
103 CodeGenerator* cgen_;
104 Expression* expression_;
106 // Keep the reference on the stack after get, so it can be used by set later.
107 bool persist_after_get_;
111 // -------------------------------------------------------------------------
112 // Code generation state
114 // The state is passed down the AST by the code generator (and back up, in
115 // the form of the state of the label pair). It is threaded through the
116 // call stack. Constructing a state implicitly pushes it on the owning code
117 // generator's stack of states, and destroying one implicitly pops it.
119 class CodeGenState BASE_EMBEDDED {
121 // Create an initial code generator state. Destroying the initial state
122 // leaves the code generator with a NULL state.
123 explicit CodeGenState(CodeGenerator* owner);
125 // Create a code generator state based on a code generator's current
126 // state. The new state has its own pair of branch labels.
127 CodeGenState(CodeGenerator* owner,
128 JumpTarget* true_target,
129 JumpTarget* false_target);
131 // Destroy a code generator state and restore the owning code generator's
135 JumpTarget* true_target() const { return true_target_; }
136 JumpTarget* false_target() const { return false_target_; }
139 CodeGenerator* owner_;
140 JumpTarget* true_target_;
141 JumpTarget* false_target_;
142 CodeGenState* previous_;
146 // -------------------------------------------------------------------------
147 // Arguments allocation mode
149 enum ArgumentsAllocationMode {
150 NO_ARGUMENTS_ALLOCATION,
151 EAGER_ARGUMENTS_ALLOCATION,
152 LAZY_ARGUMENTS_ALLOCATION
156 // Different nop operations are used by the code generator to detect certain
157 // states of the generated code.
158 enum NopMarkerTypes {
160 PROPERTY_ACCESS_INLINED
164 // -------------------------------------------------------------------------
167 class CodeGenerator: public AstVisitor {
169 // Takes a function literal, generates code for it. This function should only
170 // be called by compiler.cc.
171 static Handle<Code> MakeCode(CompilationInfo* info);
173 // Printing of AST, etc. as requested by flags.
174 static void MakeCodePrologue(CompilationInfo* info);
176 // Allocate and install the code.
177 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
179 CompilationInfo* info);
181 #ifdef ENABLE_LOGGING_AND_PROFILING
182 static bool ShouldGenerateLog(Expression* type);
185 static void SetFunctionInfo(Handle<JSFunction> fun,
186 FunctionLiteral* lit,
188 Handle<Script> script);
190 static void RecordPositions(MacroAssembler* masm, int pos);
193 MacroAssembler* masm() { return masm_; }
194 VirtualFrame* frame() const { return frame_; }
195 inline Handle<Script> script();
197 bool has_valid_frame() const { return frame_ != NULL; }
199 // Set the virtual frame to be new_frame, with non-frame register
200 // reference counts given by non_frame_registers. The non-frame
201 // register reference counts of the old frame are returned in
202 // non_frame_registers.
203 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
207 RegisterAllocator* allocator() const { return allocator_; }
209 CodeGenState* state() { return state_; }
210 void set_state(CodeGenState* state) { state_ = state; }
212 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
214 static const int kUnknownIntValue = -1;
216 // If the name is an inline runtime function call return the number of
217 // expected arguments. Otherwise return -1.
218 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
221 // Construction/Destruction
222 explicit CodeGenerator(MacroAssembler* masm);
225 inline bool is_eval();
226 inline Scope* scope();
228 // Generating deferred code.
229 void ProcessDeferred();
232 bool has_cc() const { return cc_reg_ != al; }
233 JumpTarget* true_target() const { return state_->true_target(); }
234 JumpTarget* false_target() const { return state_->false_target(); }
236 // Track loop nesting level.
237 int loop_nesting() const { return loop_nesting_; }
238 void IncrementLoopNesting() { loop_nesting_++; }
239 void DecrementLoopNesting() { loop_nesting_--; }
242 void VisitStatements(ZoneList<Statement*>* statements);
244 #define DEF_VISIT(type) \
245 void Visit##type(type* node);
246 AST_NODE_LIST(DEF_VISIT)
249 // Visit a statement and then spill the virtual frame if control flow can
250 // reach the end of the statement (ie, it does not exit via break,
251 // continue, return, or throw). This function is used temporarily while
252 // the code generator is being transformed.
253 inline void VisitAndSpill(Statement* statement);
255 // Visit a list of statements and then spill the virtual frame if control
256 // flow can reach the end of the list.
257 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements);
259 // Main code generation function
260 void Generate(CompilationInfo* info);
262 // Returns the arguments allocation mode.
263 ArgumentsAllocationMode ArgumentsMode();
265 // Store the arguments object and allocate it if necessary.
266 void StoreArgumentsObject(bool initial);
268 // The following are used by class Reference.
269 void LoadReference(Reference* ref);
270 void UnloadReference(Reference* ref);
272 static MemOperand ContextOperand(Register context, int index) {
273 return MemOperand(context, Context::SlotOffset(index));
276 MemOperand SlotOperand(Slot* slot, Register tmp);
278 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
284 static MemOperand GlobalObject() {
285 return ContextOperand(cp, Context::GLOBAL_INDEX);
288 void LoadCondition(Expression* x,
289 JumpTarget* true_target,
290 JumpTarget* false_target,
292 void Load(Expression* expr);
294 void LoadGlobalReceiver(Register scratch);
296 // Generate code to push the value of an expression on top of the frame
297 // and then spill the frame fully to memory. This function is used
298 // temporarily while the code generator is being transformed.
299 inline void LoadAndSpill(Expression* expression);
301 // Call LoadCondition and then spill the virtual frame unless control flow
302 // cannot reach the end of the expression (ie, by emitting only
303 // unconditional jumps to the control targets).
304 inline void LoadConditionAndSpill(Expression* expression,
305 JumpTarget* true_target,
306 JumpTarget* false_target,
309 // Read a value from a slot and leave it on top of the expression stack.
310 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
311 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
312 // Store the value on top of the stack to a slot.
313 void StoreToSlot(Slot* slot, InitState init_state);
315 // Load a named property, leaving it in r0. The receiver is passed on the
316 // stack, and remains there.
317 void EmitNamedLoad(Handle<String> name, bool is_contextual);
319 // Load a keyed property, leaving it in r0. The receiver and key are
320 // passed on the stack, and remain there.
321 void EmitKeyedLoad();
323 // Store a keyed property. Key and receiver are on the stack and the value is
324 // in r0. Result is returned in r0.
325 void EmitKeyedStore(StaticType* key_type);
327 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
328 TypeofState typeof_state,
331 // Special code for typeof expressions: Unfortunately, we must
332 // be careful when loading the expression in 'typeof'
333 // expressions. We are not allowed to throw reference errors for
334 // non-existing properties of the global object, so we must make it
335 // look like an explicit property access, instead of an access
336 // through the context chain.
337 void LoadTypeofExpression(Expression* x);
339 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
341 // Generate code that computes a shortcutting logical operation.
342 void GenerateLogicalBooleanOperation(BinaryOperation* node);
344 void GenericBinaryOperation(Token::Value op,
345 OverwriteMode overwrite_mode,
346 int known_rhs = kUnknownIntValue);
347 void VirtualFrameBinaryOperation(Token::Value op,
348 OverwriteMode overwrite_mode,
349 int known_rhs = kUnknownIntValue);
350 void Comparison(Condition cc,
353 bool strict = false);
355 void SmiOperation(Token::Value op,
356 Handle<Object> value,
360 void CallWithArguments(ZoneList<Expression*>* arguments,
361 CallFunctionFlags flags,
364 // An optimized implementation of expressions of the form
365 // x.apply(y, arguments). We call x the applicand and y the receiver.
366 // The optimization avoids allocating an arguments object if possible.
367 void CallApplyLazy(Expression* applicand,
368 Expression* receiver,
369 VariableProxy* arguments,
373 void Branch(bool if_true, JumpTarget* target);
376 struct InlineRuntimeLUT {
377 void (CodeGenerator::*method)(ZoneList<Expression*>*);
382 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
383 bool CheckForInlineRuntimeCall(CallRuntime* node);
384 static bool PatchInlineRuntimeEntry(Handle<String> name,
385 const InlineRuntimeLUT& new_entry,
386 InlineRuntimeLUT* old_entry);
388 static Handle<Code> ComputeLazyCompile(int argc);
389 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
391 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
393 // Declare global variables and functions in the given array of
395 void DeclareGlobals(Handle<FixedArray> pairs);
397 // Instantiate the function based on the shared function info.
398 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
400 // Support for type checks.
401 void GenerateIsSmi(ZoneList<Expression*>* args);
402 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
403 void GenerateIsArray(ZoneList<Expression*>* args);
404 void GenerateIsRegExp(ZoneList<Expression*>* args);
405 void GenerateIsObject(ZoneList<Expression*>* args);
406 void GenerateIsFunction(ZoneList<Expression*>* args);
407 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
409 // Support for construct call checks.
410 void GenerateIsConstructCall(ZoneList<Expression*>* args);
412 // Support for arguments.length and arguments[?].
413 void GenerateArgumentsLength(ZoneList<Expression*>* args);
414 void GenerateArguments(ZoneList<Expression*>* args);
416 // Support for accessing the class and value fields of an object.
417 void GenerateClassOf(ZoneList<Expression*>* args);
418 void GenerateValueOf(ZoneList<Expression*>* args);
419 void GenerateSetValueOf(ZoneList<Expression*>* args);
421 // Fast support for charCodeAt(n).
422 void GenerateFastCharCodeAt(ZoneList<Expression*>* args);
424 // Fast support for string.charAt(n) and string[n].
425 void GenerateCharFromCode(ZoneList<Expression*>* args);
427 // Fast support for object equality testing.
428 void GenerateObjectEquals(ZoneList<Expression*>* args);
430 void GenerateLog(ZoneList<Expression*>* args);
432 // Fast support for Math.random().
433 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
435 // Fast support for StringAdd.
436 void GenerateStringAdd(ZoneList<Expression*>* args);
438 // Fast support for SubString.
439 void GenerateSubString(ZoneList<Expression*>* args);
441 // Fast support for StringCompare.
442 void GenerateStringCompare(ZoneList<Expression*>* args);
444 // Support for direct calls from JavaScript to native RegExp code.
445 void GenerateRegExpExec(ZoneList<Expression*>* args);
447 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
449 // Support for fast native caches.
450 void GenerateGetFromCache(ZoneList<Expression*>* args);
452 // Fast support for number to string.
453 void GenerateNumberToString(ZoneList<Expression*>* args);
455 // Fast swapping of elements.
456 void GenerateSwapElements(ZoneList<Expression*>* args);
458 // Fast call for custom callbacks.
459 void GenerateCallFunction(ZoneList<Expression*>* args);
461 // Fast call to math functions.
462 void GenerateMathPow(ZoneList<Expression*>* args);
463 void GenerateMathSin(ZoneList<Expression*>* args);
464 void GenerateMathCos(ZoneList<Expression*>* args);
465 void GenerateMathSqrt(ZoneList<Expression*>* args);
467 // Simple condition analysis.
468 enum ConditionAnalysis {
473 ConditionAnalysis AnalyzeCondition(Expression* cond);
475 // Methods used to indicate which source code is generated for. Source
476 // positions are collected by the assembler and emitted with the relocation
478 void CodeForFunctionPosition(FunctionLiteral* fun);
479 void CodeForReturnPosition(FunctionLiteral* fun);
480 void CodeForStatementPosition(Statement* node);
481 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
482 void CodeForSourcePosition(int pos);
485 // True if the registers are valid for entry to a block.
486 bool HasValidEntryRegisters();
489 List<DeferredCode*> deferred_;
492 MacroAssembler* masm_; // to generate code
494 CompilationInfo* info_;
496 // Code generation state
497 VirtualFrame* frame_;
498 RegisterAllocator* allocator_;
500 CodeGenState* state_;
504 BreakTarget function_return_;
506 // True if the function return is shadowed (ie, jumping to the target
507 // function_return_ does not jump to the true function return, but rather
508 // to some unlinking code).
509 bool function_return_is_shadowed_;
511 static InlineRuntimeLUT kInlineRuntimeLUT[];
513 friend class VirtualFrame;
514 friend class JumpTarget;
515 friend class Reference;
516 friend class FastCodeGenerator;
517 friend class FullCodeGenerator;
518 friend class FullCodeGenSyntaxChecker;
520 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
524 class GenericBinaryOpStub : public CodeStub {
526 GenericBinaryOpStub(Token::Value op,
530 int constant_rhs = CodeGenerator::kUnknownIntValue)
535 constant_rhs_(constant_rhs),
536 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
537 runtime_operands_type_(BinaryOpIC::DEFAULT),
540 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
541 : op_(OpBits::decode(key)),
542 mode_(ModeBits::decode(key)),
543 lhs_(LhsRegister(RegisterBits::decode(key))),
544 rhs_(RhsRegister(RegisterBits::decode(key))),
545 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
546 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
547 runtime_operands_type_(type_info),
556 bool specialized_on_rhs_;
557 BinaryOpIC::TypeInfo runtime_operands_type_;
560 static const int kMaxKnownRhs = 0x40000000;
561 static const int kKnownRhsKeyBits = 6;
563 // Minor key encoding in 17 bits.
564 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
565 class OpBits: public BitField<Token::Value, 2, 6> {};
566 class TypeInfoBits: public BitField<int, 8, 2> {};
567 class RegisterBits: public BitField<bool, 10, 1> {};
568 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
570 Major MajorKey() { return GenericBinaryOp; }
572 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
573 (lhs_.is(r1) && rhs_.is(r0)));
574 // Encode the parameters in a unique 18 bit value.
575 return OpBits::encode(op_)
576 | ModeBits::encode(mode_)
577 | KnownIntBits::encode(MinorKeyForKnownInt())
578 | TypeInfoBits::encode(runtime_operands_type_)
579 | RegisterBits::encode(lhs_.is(r0));
582 void Generate(MacroAssembler* masm);
583 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
584 void HandleBinaryOpSlowCases(MacroAssembler* masm,
588 const Builtins::JavaScript& builtin);
589 void GenerateTypeTransition(MacroAssembler* masm);
591 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
592 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
593 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
594 if (op == Token::MOD) {
595 if (constant_rhs <= 1) return false;
596 if (constant_rhs <= 10) return true;
597 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
603 int MinorKeyForKnownInt() {
604 if (!specialized_on_rhs_) return 0;
605 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
606 ASSERT(IsPowerOf2(constant_rhs_));
608 int d = constant_rhs_;
609 while ((d & 1) == 0) {
613 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
617 int KnownBitsForMinorKey(int key) {
619 if (key <= 11) return key - 1;
628 Register LhsRegister(bool lhs_is_r0) {
629 return lhs_is_r0 ? r0 : r1;
632 Register RhsRegister(bool lhs_is_r0) {
633 return lhs_is_r0 ? r1 : r0;
636 bool ShouldGenerateSmiCode() {
637 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
638 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
639 runtime_operands_type_ != BinaryOpIC::STRINGS;
642 bool ShouldGenerateFPCode() {
643 return runtime_operands_type_ != BinaryOpIC::STRINGS;
646 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
648 virtual InlineCacheState GetICState() {
649 return BinaryOpIC::ToState(runtime_operands_type_);
652 const char* GetName();
656 if (!specialized_on_rhs_) {
657 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
659 PrintF("GenericBinaryOpStub (%s by %d)\n",
668 class StringHelper : public AllStatic {
670 // Generates fast code for getting a char code out of a string
671 // object at the given index. May bail out for four reasons (in the
673 // * Receiver is not a string (receiver_not_string label).
674 // * Index is not a smi (index_not_smi label).
675 // * Index is out of range (index_out_of_range).
676 // * Some other reason (slow_case label). In this case it's
677 // guaranteed that the above conditions are not violated,
678 // e.g. it's safe to assume the receiver is a string and the
679 // index is a non-negative smi < length.
680 // When successful, object, index, and scratch are clobbered.
681 // Otherwise, scratch and result are clobbered.
682 static void GenerateFastCharCodeAt(MacroAssembler* masm,
687 Label* receiver_not_string,
688 Label* index_not_smi,
689 Label* index_out_of_range,
692 // Generates code for creating a one-char string from the given char
693 // code. May do a runtime call, so any register can be clobbered
694 // and, if the given invoke flag specifies a call, an internal frame
695 // is required. In tail call mode the result must be r0 register.
696 static void GenerateCharFromCode(MacroAssembler* masm,
702 // Generate code for copying characters using a simple loop. This should only
703 // be used in places where the number of characters is small and the
704 // additional setup and checking in GenerateCopyCharactersLong adds too much
705 // overhead. Copying of overlapping regions is not supported.
706 // Dest register ends at the position after the last character written.
707 static void GenerateCopyCharacters(MacroAssembler* masm,
714 // Generate code for copying a large number of characters. This function
715 // is allowed to spend extra time setting up conditions to make copying
716 // faster. Copying of overlapping regions is not supported.
717 // Dest register ends at the position after the last character written.
718 static void GenerateCopyCharactersLong(MacroAssembler* masm,
730 // Probe the symbol table for a two character string. If the string is
731 // not found by probing a jump to the label not_found is performed. This jump
732 // does not guarantee that the string is not in the symbol table. If the
733 // string is found the code falls through with the string in register r0.
734 // Contents of both c1 and c2 registers are modified. At the exit c1 is
735 // guaranteed to contain halfword with low and high bytes equal to
736 // initial contents of c1 and c2 respectively.
737 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
747 // Generate string hash.
748 static void GenerateHashInit(MacroAssembler* masm,
752 static void GenerateHashAddCharacter(MacroAssembler* masm,
756 static void GenerateHashGetHash(MacroAssembler* masm,
760 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
764 // Flag that indicates how to generate code for the stub StringAddStub.
765 enum StringAddFlags {
766 NO_STRING_ADD_FLAGS = 0,
767 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
771 class StringAddStub: public CodeStub {
773 explicit StringAddStub(StringAddFlags flags) {
774 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
778 Major MajorKey() { return StringAdd; }
779 int MinorKey() { return string_check_ ? 0 : 1; }
781 void Generate(MacroAssembler* masm);
783 // Should the stub check whether arguments are strings?
788 class SubStringStub: public CodeStub {
793 Major MajorKey() { return SubString; }
794 int MinorKey() { return 0; }
796 void Generate(MacroAssembler* masm);
801 class StringCompareStub: public CodeStub {
803 StringCompareStub() { }
805 // Compare two flat ASCII strings and returns result in r0.
806 // Does not use the stack.
807 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
816 Major MajorKey() { return StringCompare; }
817 int MinorKey() { return 0; }
819 void Generate(MacroAssembler* masm);
823 // This stub can convert a signed int32 to a heap number (double). It does
824 // not work for int32s that are in Smi range! No GC occurs during this stub
825 // so you don't have to set up the frame.
826 class WriteInt32ToHeapNumberStub : public CodeStub {
828 WriteInt32ToHeapNumberStub(Register the_int,
829 Register the_heap_number,
832 the_heap_number_(the_heap_number),
833 scratch_(scratch) { }
837 Register the_heap_number_;
840 // Minor key encoding in 16 bits.
841 class IntRegisterBits: public BitField<int, 0, 4> {};
842 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
843 class ScratchRegisterBits: public BitField<int, 8, 4> {};
845 Major MajorKey() { return WriteInt32ToHeapNumber; }
847 // Encode the parameters in a unique 16 bit value.
848 return IntRegisterBits::encode(the_int_.code())
849 | HeapNumberRegisterBits::encode(the_heap_number_.code())
850 | ScratchRegisterBits::encode(scratch_.code());
853 void Generate(MacroAssembler* masm);
855 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
858 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
863 class NumberToStringStub: public CodeStub {
865 NumberToStringStub() { }
867 // Generate code to do a lookup in the number string cache. If the number in
868 // the register object is found in the cache the generated code falls through
869 // with the result in the result register. The object and the result register
870 // can be the same. If the number is not found in the cache the code jumps to
871 // the label not_found with only the content of register object unchanged.
872 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
882 Major MajorKey() { return NumberToString; }
883 int MinorKey() { return 0; }
885 void Generate(MacroAssembler* masm);
887 const char* GetName() { return "NumberToStringStub"; }
891 PrintF("NumberToStringStub\n");
897 } } // namespace v8::internal
899 #endif // V8_ARM_CODEGEN_ARM_H_