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_
37 // Forward declarations
38 class CompilationInfo;
41 class RegisterAllocator;
44 enum InitState { CONST_INIT, NOT_CONST_INIT };
45 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
48 // -------------------------------------------------------------------------
51 // A reference is a C++ stack-allocated object that puts a
52 // reference on the virtual frame. The reference may be consumed
53 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
54 // When the lifetime (scope) of a valid reference ends, it must have
55 // been consumed, and be in state UNLOADED.
56 class Reference BASE_EMBEDDED {
58 // The values of the types is important, see size().
59 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
60 Reference(CodeGenerator* cgen,
61 Expression* expression,
62 bool persist_after_get = false);
65 Expression* expression() const { return expression_; }
66 Type type() const { return type_; }
67 void set_type(Type value) {
68 ASSERT_EQ(ILLEGAL, type_);
73 ASSERT_NE(ILLEGAL, type_);
74 ASSERT_NE(UNLOADED, type_);
77 // The size the reference takes up on the stack.
79 return (type_ < SLOT) ? 0 : type_;
82 bool is_illegal() const { return type_ == ILLEGAL; }
83 bool is_slot() const { return type_ == SLOT; }
84 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
85 bool is_unloaded() const { return type_ == UNLOADED; }
87 // Return the name. Only valid for named property references.
88 Handle<String> GetName();
90 // Generate code to push the value of the reference on top of the
91 // expression stack. The reference is expected to be already on top of
92 // the expression stack, and it is consumed by the call unless the
93 // reference is for a compound assignment.
94 // If the reference is not consumed, it is left in place under its value.
97 // Generate code to store the value on top of the expression stack in the
98 // reference. The reference is expected to be immediately below the value
99 // on the expression stack. The value is stored in the location specified
100 // by the reference, and is left on top of the stack, after the reference
101 // is popped from beneath it (unloaded).
102 void SetValue(InitState init_state);
104 // This is in preparation for something that uses the reference on the stack.
105 // If we need this reference afterwards get then dup it now. Otherwise mark
107 inline void DupIfPersist();
110 CodeGenerator* cgen_;
111 Expression* expression_;
113 // Keep the reference on the stack after get, so it can be used by set later.
114 bool persist_after_get_;
118 // -------------------------------------------------------------------------
119 // Code generation state
121 // The state is passed down the AST by the code generator (and back up, in
122 // the form of the state of the label pair). It is threaded through the
123 // call stack. Constructing a state implicitly pushes it on the owning code
124 // generator's stack of states, and destroying one implicitly pops it.
126 class CodeGenState BASE_EMBEDDED {
128 // Create an initial code generator state. Destroying the initial state
129 // leaves the code generator with a NULL state.
130 explicit CodeGenState(CodeGenerator* owner);
132 // Create a code generator state based on a code generator's current
133 // state. The new state has its own pair of branch labels.
134 CodeGenState(CodeGenerator* owner,
135 JumpTarget* true_target,
136 JumpTarget* false_target);
138 // Destroy a code generator state and restore the owning code generator's
142 JumpTarget* true_target() const { return true_target_; }
143 JumpTarget* false_target() const { return false_target_; }
146 CodeGenerator* owner_;
147 JumpTarget* true_target_;
148 JumpTarget* false_target_;
149 CodeGenState* previous_;
153 // -------------------------------------------------------------------------
154 // Arguments allocation mode
156 enum ArgumentsAllocationMode {
157 NO_ARGUMENTS_ALLOCATION,
158 EAGER_ARGUMENTS_ALLOCATION,
159 LAZY_ARGUMENTS_ALLOCATION
163 // Different nop operations are used by the code generator to detect certain
164 // states of the generated code.
165 enum NopMarkerTypes {
167 PROPERTY_ACCESS_INLINED
171 // -------------------------------------------------------------------------
174 class CodeGenerator: public AstVisitor {
176 // Takes a function literal, generates code for it. This function should only
177 // be called by compiler.cc.
178 static Handle<Code> MakeCode(CompilationInfo* info);
180 // Printing of AST, etc. as requested by flags.
181 static void MakeCodePrologue(CompilationInfo* info);
183 // Allocate and install the code.
184 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
186 CompilationInfo* info);
188 #ifdef ENABLE_LOGGING_AND_PROFILING
189 static bool ShouldGenerateLog(Expression* type);
192 static void SetFunctionInfo(Handle<JSFunction> fun,
193 FunctionLiteral* lit,
195 Handle<Script> script);
197 static void RecordPositions(MacroAssembler* masm, int pos);
200 MacroAssembler* masm() { return masm_; }
201 VirtualFrame* frame() const { return frame_; }
202 inline Handle<Script> script();
204 bool has_valid_frame() const { return frame_ != NULL; }
206 // Set the virtual frame to be new_frame, with non-frame register
207 // reference counts given by non_frame_registers. The non-frame
208 // register reference counts of the old frame are returned in
209 // non_frame_registers.
210 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
214 RegisterAllocator* allocator() const { return allocator_; }
216 CodeGenState* state() { return state_; }
217 void set_state(CodeGenState* state) { state_ = state; }
219 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
221 static const int kUnknownIntValue = -1;
223 // If the name is an inline runtime function call return the number of
224 // expected arguments. Otherwise return -1.
225 static int InlineRuntimeCallArgumentsCount(Handle<String> name);
227 // Constants related to patching of inlined load/store.
228 static const int kInlinedKeyedLoadInstructionsAfterPatch = 19;
229 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
232 // Construction/Destruction
233 explicit CodeGenerator(MacroAssembler* masm);
236 inline bool is_eval();
237 inline Scope* scope();
239 // Generating deferred code.
240 void ProcessDeferred();
243 bool has_cc() const { return cc_reg_ != al; }
244 JumpTarget* true_target() const { return state_->true_target(); }
245 JumpTarget* false_target() const { return state_->false_target(); }
247 // Track loop nesting level.
248 int loop_nesting() const { return loop_nesting_; }
249 void IncrementLoopNesting() { loop_nesting_++; }
250 void DecrementLoopNesting() { loop_nesting_--; }
253 void VisitStatements(ZoneList<Statement*>* statements);
255 #define DEF_VISIT(type) \
256 void Visit##type(type* node);
257 AST_NODE_LIST(DEF_VISIT)
260 // Visit a statement and then spill the virtual frame if control flow can
261 // reach the end of the statement (ie, it does not exit via break,
262 // continue, return, or throw). This function is used temporarily while
263 // the code generator is being transformed.
264 inline void VisitAndSpill(Statement* statement);
266 // Visit a list of statements and then spill the virtual frame if control
267 // flow can reach the end of the list.
268 inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements);
270 // Main code generation function
271 void Generate(CompilationInfo* info);
273 // Returns the arguments allocation mode.
274 ArgumentsAllocationMode ArgumentsMode();
276 // Store the arguments object and allocate it if necessary.
277 void StoreArgumentsObject(bool initial);
279 // The following are used by class Reference.
280 void LoadReference(Reference* ref);
281 void UnloadReference(Reference* ref);
283 static MemOperand ContextOperand(Register context, int index) {
284 return MemOperand(context, Context::SlotOffset(index));
287 MemOperand SlotOperand(Slot* slot, Register tmp);
289 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
295 static MemOperand GlobalObject() {
296 return ContextOperand(cp, Context::GLOBAL_INDEX);
299 void LoadCondition(Expression* x,
300 JumpTarget* true_target,
301 JumpTarget* false_target,
303 void Load(Expression* expr);
305 void LoadGlobalReceiver(Register scratch);
307 // Call LoadCondition and then spill the virtual frame unless control flow
308 // cannot reach the end of the expression (ie, by emitting only
309 // unconditional jumps to the control targets).
310 inline void LoadConditionAndSpill(Expression* expression,
311 JumpTarget* true_target,
312 JumpTarget* false_target,
315 // Read a value from a slot and leave it on top of the expression stack.
316 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
317 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
319 // Store the value on top of the stack to a slot.
320 void StoreToSlot(Slot* slot, InitState init_state);
322 // Support for compiling assignment expressions.
323 void EmitSlotAssignment(Assignment* node);
324 void EmitNamedPropertyAssignment(Assignment* node);
325 void EmitKeyedPropertyAssignment(Assignment* node);
327 // Load a named property, returning it in r0. The receiver is passed on the
328 // stack, and remains there.
329 void EmitNamedLoad(Handle<String> name, bool is_contextual);
331 // Store to a named property. If the store is contextual, value is passed on
332 // the frame and consumed. Otherwise, receiver and value are passed on the
333 // frame and consumed. The result is returned in r0.
334 void EmitNamedStore(Handle<String> name, bool is_contextual);
336 // Load a keyed property, leaving it in r0. The receiver and key are
337 // passed on the stack, and remain there.
338 void EmitKeyedLoad();
340 // Store a keyed property. Key and receiver are on the stack and the value is
341 // in r0. Result is returned in r0.
342 void EmitKeyedStore(StaticType* key_type);
344 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
345 TypeofState typeof_state,
348 // Support for loading from local/global variables and arguments
349 // whose location is known unless they are shadowed by
350 // eval-introduced bindings. Generates no code for unsupported slot
351 // types and therefore expects to fall through to the slow jump target.
352 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
353 TypeofState typeof_state,
357 // Special code for typeof expressions: Unfortunately, we must
358 // be careful when loading the expression in 'typeof'
359 // expressions. We are not allowed to throw reference errors for
360 // non-existing properties of the global object, so we must make it
361 // look like an explicit property access, instead of an access
362 // through the context chain.
363 void LoadTypeofExpression(Expression* x);
365 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
367 // Generate code that computes a shortcutting logical operation.
368 void GenerateLogicalBooleanOperation(BinaryOperation* node);
370 void GenericBinaryOperation(Token::Value op,
371 OverwriteMode overwrite_mode,
372 int known_rhs = kUnknownIntValue);
373 void VirtualFrameBinaryOperation(Token::Value op,
374 OverwriteMode overwrite_mode,
375 int known_rhs = kUnknownIntValue);
376 void Comparison(Condition cc,
379 bool strict = false);
381 void SmiOperation(Token::Value op,
382 Handle<Object> value,
386 void CallWithArguments(ZoneList<Expression*>* arguments,
387 CallFunctionFlags flags,
390 // An optimized implementation of expressions of the form
391 // x.apply(y, arguments). We call x the applicand and y the receiver.
392 // The optimization avoids allocating an arguments object if possible.
393 void CallApplyLazy(Expression* applicand,
394 Expression* receiver,
395 VariableProxy* arguments,
399 void Branch(bool if_true, JumpTarget* target);
402 struct InlineRuntimeLUT {
403 void (CodeGenerator::*method)(ZoneList<Expression*>*);
408 static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
409 bool CheckForInlineRuntimeCall(CallRuntime* node);
410 static bool PatchInlineRuntimeEntry(Handle<String> name,
411 const InlineRuntimeLUT& new_entry,
412 InlineRuntimeLUT* old_entry);
414 static Handle<Code> ComputeLazyCompile(int argc);
415 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
417 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
419 // Declare global variables and functions in the given array of
421 void DeclareGlobals(Handle<FixedArray> pairs);
423 // Instantiate the function based on the shared function info.
424 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
426 // Support for type checks.
427 void GenerateIsSmi(ZoneList<Expression*>* args);
428 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
429 void GenerateIsArray(ZoneList<Expression*>* args);
430 void GenerateIsRegExp(ZoneList<Expression*>* args);
431 void GenerateIsObject(ZoneList<Expression*>* args);
432 void GenerateIsFunction(ZoneList<Expression*>* args);
433 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
435 // Support for construct call checks.
436 void GenerateIsConstructCall(ZoneList<Expression*>* args);
438 // Support for arguments.length and arguments[?].
439 void GenerateArgumentsLength(ZoneList<Expression*>* args);
440 void GenerateArguments(ZoneList<Expression*>* args);
442 // Support for accessing the class and value fields of an object.
443 void GenerateClassOf(ZoneList<Expression*>* args);
444 void GenerateValueOf(ZoneList<Expression*>* args);
445 void GenerateSetValueOf(ZoneList<Expression*>* args);
447 // Fast support for charCodeAt(n).
448 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
450 // Fast support for string.charAt(n) and string[n].
451 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
453 // Fast support for string.charAt(n) and string[n].
454 void GenerateStringCharAt(ZoneList<Expression*>* args);
456 // Fast support for object equality testing.
457 void GenerateObjectEquals(ZoneList<Expression*>* args);
459 void GenerateLog(ZoneList<Expression*>* args);
461 // Fast support for Math.random().
462 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
464 // Fast support for StringAdd.
465 void GenerateStringAdd(ZoneList<Expression*>* args);
467 // Fast support for SubString.
468 void GenerateSubString(ZoneList<Expression*>* args);
470 // Fast support for StringCompare.
471 void GenerateStringCompare(ZoneList<Expression*>* args);
473 // Support for direct calls from JavaScript to native RegExp code.
474 void GenerateRegExpExec(ZoneList<Expression*>* args);
476 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
478 // Support for fast native caches.
479 void GenerateGetFromCache(ZoneList<Expression*>* args);
481 // Fast support for number to string.
482 void GenerateNumberToString(ZoneList<Expression*>* args);
484 // Fast swapping of elements.
485 void GenerateSwapElements(ZoneList<Expression*>* args);
487 // Fast call for custom callbacks.
488 void GenerateCallFunction(ZoneList<Expression*>* args);
490 // Fast call to math functions.
491 void GenerateMathPow(ZoneList<Expression*>* args);
492 void GenerateMathSin(ZoneList<Expression*>* args);
493 void GenerateMathCos(ZoneList<Expression*>* args);
494 void GenerateMathSqrt(ZoneList<Expression*>* args);
496 // Simple condition analysis.
497 enum ConditionAnalysis {
502 ConditionAnalysis AnalyzeCondition(Expression* cond);
504 // Methods used to indicate which source code is generated for. Source
505 // positions are collected by the assembler and emitted with the relocation
507 void CodeForFunctionPosition(FunctionLiteral* fun);
508 void CodeForReturnPosition(FunctionLiteral* fun);
509 void CodeForStatementPosition(Statement* node);
510 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
511 void CodeForSourcePosition(int pos);
514 // True if the registers are valid for entry to a block.
515 bool HasValidEntryRegisters();
518 List<DeferredCode*> deferred_;
521 MacroAssembler* masm_; // to generate code
523 CompilationInfo* info_;
525 // Code generation state
526 VirtualFrame* frame_;
527 RegisterAllocator* allocator_;
529 CodeGenState* state_;
533 BreakTarget function_return_;
535 // True if the function return is shadowed (ie, jumping to the target
536 // function_return_ does not jump to the true function return, but rather
537 // to some unlinking code).
538 bool function_return_is_shadowed_;
540 static InlineRuntimeLUT kInlineRuntimeLUT[];
542 friend class VirtualFrame;
543 friend class JumpTarget;
544 friend class Reference;
545 friend class FastCodeGenerator;
546 friend class FullCodeGenerator;
547 friend class FullCodeGenSyntaxChecker;
549 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
553 class GenericBinaryOpStub : public CodeStub {
555 GenericBinaryOpStub(Token::Value op,
559 int constant_rhs = CodeGenerator::kUnknownIntValue)
564 constant_rhs_(constant_rhs),
565 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)),
566 runtime_operands_type_(BinaryOpIC::DEFAULT),
569 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info)
570 : op_(OpBits::decode(key)),
571 mode_(ModeBits::decode(key)),
572 lhs_(LhsRegister(RegisterBits::decode(key))),
573 rhs_(RhsRegister(RegisterBits::decode(key))),
574 constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))),
575 specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)),
576 runtime_operands_type_(type_info),
585 bool specialized_on_rhs_;
586 BinaryOpIC::TypeInfo runtime_operands_type_;
589 static const int kMaxKnownRhs = 0x40000000;
590 static const int kKnownRhsKeyBits = 6;
592 // Minor key encoding in 17 bits.
593 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
594 class OpBits: public BitField<Token::Value, 2, 6> {};
595 class TypeInfoBits: public BitField<int, 8, 2> {};
596 class RegisterBits: public BitField<bool, 10, 1> {};
597 class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {};
599 Major MajorKey() { return GenericBinaryOp; }
601 ASSERT((lhs_.is(r0) && rhs_.is(r1)) ||
602 (lhs_.is(r1) && rhs_.is(r0)));
603 // Encode the parameters in a unique 18 bit value.
604 return OpBits::encode(op_)
605 | ModeBits::encode(mode_)
606 | KnownIntBits::encode(MinorKeyForKnownInt())
607 | TypeInfoBits::encode(runtime_operands_type_)
608 | RegisterBits::encode(lhs_.is(r0));
611 void Generate(MacroAssembler* masm);
612 void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs);
613 void HandleBinaryOpSlowCases(MacroAssembler* masm,
617 const Builtins::JavaScript& builtin);
618 void GenerateTypeTransition(MacroAssembler* masm);
620 static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) {
621 if (constant_rhs == CodeGenerator::kUnknownIntValue) return false;
622 if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3;
623 if (op == Token::MOD) {
624 if (constant_rhs <= 1) return false;
625 if (constant_rhs <= 10) return true;
626 if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true;
632 int MinorKeyForKnownInt() {
633 if (!specialized_on_rhs_) return 0;
634 if (constant_rhs_ <= 10) return constant_rhs_ + 1;
635 ASSERT(IsPowerOf2(constant_rhs_));
637 int d = constant_rhs_;
638 while ((d & 1) == 0) {
642 ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits));
646 int KnownBitsForMinorKey(int key) {
648 if (key <= 11) return key - 1;
657 Register LhsRegister(bool lhs_is_r0) {
658 return lhs_is_r0 ? r0 : r1;
661 Register RhsRegister(bool lhs_is_r0) {
662 return lhs_is_r0 ? r1 : r0;
665 bool ShouldGenerateSmiCode() {
666 return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) &&
667 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
668 runtime_operands_type_ != BinaryOpIC::STRINGS;
671 bool ShouldGenerateFPCode() {
672 return runtime_operands_type_ != BinaryOpIC::STRINGS;
675 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
677 virtual InlineCacheState GetICState() {
678 return BinaryOpIC::ToState(runtime_operands_type_);
681 const char* GetName();
685 if (!specialized_on_rhs_) {
686 PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_));
688 PrintF("GenericBinaryOpStub (%s by %d)\n",
697 class StringHelper : public AllStatic {
699 // Generate code for copying characters using a simple loop. This should only
700 // be used in places where the number of characters is small and the
701 // additional setup and checking in GenerateCopyCharactersLong adds too much
702 // overhead. Copying of overlapping regions is not supported.
703 // Dest register ends at the position after the last character written.
704 static void GenerateCopyCharacters(MacroAssembler* masm,
711 // Generate code for copying a large number of characters. This function
712 // is allowed to spend extra time setting up conditions to make copying
713 // faster. Copying of overlapping regions is not supported.
714 // Dest register ends at the position after the last character written.
715 static void GenerateCopyCharactersLong(MacroAssembler* masm,
727 // Probe the symbol table for a two character string. If the string is
728 // not found by probing a jump to the label not_found is performed. This jump
729 // does not guarantee that the string is not in the symbol table. If the
730 // string is found the code falls through with the string in register r0.
731 // Contents of both c1 and c2 registers are modified. At the exit c1 is
732 // guaranteed to contain halfword with low and high bytes equal to
733 // initial contents of c1 and c2 respectively.
734 static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm,
744 // Generate string hash.
745 static void GenerateHashInit(MacroAssembler* masm,
749 static void GenerateHashAddCharacter(MacroAssembler* masm,
753 static void GenerateHashGetHash(MacroAssembler* masm,
757 DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper);
761 // Flag that indicates how to generate code for the stub StringAddStub.
762 enum StringAddFlags {
763 NO_STRING_ADD_FLAGS = 0,
764 NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub.
768 class StringAddStub: public CodeStub {
770 explicit StringAddStub(StringAddFlags flags) {
771 string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0);
775 Major MajorKey() { return StringAdd; }
776 int MinorKey() { return string_check_ ? 0 : 1; }
778 void Generate(MacroAssembler* masm);
780 // Should the stub check whether arguments are strings?
785 class SubStringStub: public CodeStub {
790 Major MajorKey() { return SubString; }
791 int MinorKey() { return 0; }
793 void Generate(MacroAssembler* masm);
798 class StringCompareStub: public CodeStub {
800 StringCompareStub() { }
802 // Compare two flat ASCII strings and returns result in r0.
803 // Does not use the stack.
804 static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
813 Major MajorKey() { return StringCompare; }
814 int MinorKey() { return 0; }
816 void Generate(MacroAssembler* masm);
820 // This stub can convert a signed int32 to a heap number (double). It does
821 // not work for int32s that are in Smi range! No GC occurs during this stub
822 // so you don't have to set up the frame.
823 class WriteInt32ToHeapNumberStub : public CodeStub {
825 WriteInt32ToHeapNumberStub(Register the_int,
826 Register the_heap_number,
829 the_heap_number_(the_heap_number),
830 scratch_(scratch) { }
834 Register the_heap_number_;
837 // Minor key encoding in 16 bits.
838 class IntRegisterBits: public BitField<int, 0, 4> {};
839 class HeapNumberRegisterBits: public BitField<int, 4, 4> {};
840 class ScratchRegisterBits: public BitField<int, 8, 4> {};
842 Major MajorKey() { return WriteInt32ToHeapNumber; }
844 // Encode the parameters in a unique 16 bit value.
845 return IntRegisterBits::encode(the_int_.code())
846 | HeapNumberRegisterBits::encode(the_heap_number_.code())
847 | ScratchRegisterBits::encode(scratch_.code());
850 void Generate(MacroAssembler* masm);
852 const char* GetName() { return "WriteInt32ToHeapNumberStub"; }
855 void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); }
860 class NumberToStringStub: public CodeStub {
862 NumberToStringStub() { }
864 // Generate code to do a lookup in the number string cache. If the number in
865 // the register object is found in the cache the generated code falls through
866 // with the result in the result register. The object and the result register
867 // can be the same. If the number is not found in the cache the code jumps to
868 // the label not_found with only the content of register object unchanged.
869 static void GenerateLookupNumberStringCache(MacroAssembler* masm,
879 Major MajorKey() { return NumberToString; }
880 int MinorKey() { return 0; }
882 void Generate(MacroAssembler* masm);
884 const char* GetName() { return "NumberToStringStub"; }
888 PrintF("NumberToStringStub\n");
894 class RecordWriteStub : public CodeStub {
896 RecordWriteStub(Register object, Register offset, Register scratch)
897 : object_(object), offset_(offset), scratch_(scratch) { }
899 void Generate(MacroAssembler* masm);
908 PrintF("RecordWriteStub (object reg %d), (offset reg %d),"
909 " (scratch reg %d)\n",
910 object_.code(), offset_.code(), scratch_.code());
914 // Minor key encoding in 12 bits. 4 bits for each of the three
915 // registers (object, offset and scratch) OOOOAAAASSSS.
916 class ScratchBits: public BitField<uint32_t, 0, 4> {};
917 class OffsetBits: public BitField<uint32_t, 4, 4> {};
918 class ObjectBits: public BitField<uint32_t, 8, 4> {};
920 Major MajorKey() { return RecordWrite; }
923 // Encode the registers.
924 return ObjectBits::encode(object_.code()) |
925 OffsetBits::encode(offset_.code()) |
926 ScratchBits::encode(scratch_.code());
931 } } // namespace v8::internal
933 #endif // V8_ARM_CODEGEN_ARM_H_