blob: 84b73a4ecb8620b0ceaaf69b1db70bc35b5dfcb6 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2009 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
4// met:
5//
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.
15//
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.
27
28#include "v8.h"
29
30#include "bootstrapper.h"
31#include "codegen-inl.h"
Steve Blockd0582a62009-12-15 09:54:21 +000032#include "compiler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000033#include "debug.h"
34#include "oprofile-agent.h"
35#include "prettyprinter.h"
36#include "register-allocator-inl.h"
37#include "rewriter.h"
38#include "runtime.h"
39#include "scopeinfo.h"
40#include "stub-cache.h"
Steve Block6ded16b2010-05-10 14:33:55 +010041#include "virtual-frame-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000042
43namespace v8 {
44namespace internal {
45
Andrei Popescu31002712010-02-23 13:46:05 +000046#define __ ACCESS_MASM(masm_)
47
48#ifdef DEBUG
49
50Comment::Comment(MacroAssembler* masm, const char* msg)
51 : masm_(masm), msg_(msg) {
52 __ RecordComment(msg);
53}
54
55
56Comment::~Comment() {
57 if (msg_[0] == '[') __ RecordComment("]");
58}
59
60#endif // DEBUG
61
62#undef __
63
Steve Blocka7e24c12009-10-30 11:49:00 +000064
65CodeGenerator* CodeGeneratorScope::top_ = NULL;
66
67
Steve Blocka7e24c12009-10-30 11:49:00 +000068void CodeGenerator::ProcessDeferred() {
69 while (!deferred_.is_empty()) {
70 DeferredCode* code = deferred_.RemoveLast();
71 ASSERT(masm_ == code->masm());
72 // Record position of deferred code stub.
73 masm_->RecordStatementPosition(code->statement_position());
74 if (code->position() != RelocInfo::kNoPosition) {
75 masm_->RecordPosition(code->position());
76 }
77 // Generate the code.
78 Comment cmnt(masm_, code->comment());
79 masm_->bind(code->entry_label());
80 code->SaveRegisters();
81 code->Generate();
82 code->RestoreRegisters();
83 masm_->jmp(code->exit_label());
84 }
85}
86
87
88void CodeGenerator::SetFrame(VirtualFrame* new_frame,
89 RegisterFile* non_frame_registers) {
90 RegisterFile saved_counts;
91 if (has_valid_frame()) {
92 frame_->DetachFromCodeGenerator();
93 // The remaining register reference counts are the non-frame ones.
94 allocator_->SaveTo(&saved_counts);
95 }
96
97 if (new_frame != NULL) {
98 // Restore the non-frame register references that go with the new frame.
99 allocator_->RestoreFrom(non_frame_registers);
100 new_frame->AttachToCodeGenerator();
101 }
102
103 frame_ = new_frame;
104 saved_counts.CopyTo(non_frame_registers);
105}
106
107
108void CodeGenerator::DeleteFrame() {
109 if (has_valid_frame()) {
110 frame_->DetachFromCodeGenerator();
111 frame_ = NULL;
112 }
113}
114
115
Andrei Popescu31002712010-02-23 13:46:05 +0000116void CodeGenerator::MakeCodePrologue(CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000117#ifdef DEBUG
118 bool print_source = false;
119 bool print_ast = false;
Steve Block3ce2e202009-11-05 08:53:23 +0000120 bool print_json_ast = false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 const char* ftype;
122
123 if (Bootstrapper::IsActive()) {
124 print_source = FLAG_print_builtin_source;
125 print_ast = FLAG_print_builtin_ast;
Steve Block3ce2e202009-11-05 08:53:23 +0000126 print_json_ast = FLAG_print_builtin_json_ast;
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 ftype = "builtin";
128 } else {
129 print_source = FLAG_print_source;
130 print_ast = FLAG_print_ast;
Steve Block3ce2e202009-11-05 08:53:23 +0000131 print_json_ast = FLAG_print_json_ast;
Steve Blocka7e24c12009-10-30 11:49:00 +0000132 ftype = "user-defined";
133 }
134
135 if (FLAG_trace_codegen || print_source || print_ast) {
136 PrintF("*** Generate code for %s function: ", ftype);
Andrei Popescu31002712010-02-23 13:46:05 +0000137 info->function()->name()->ShortPrint();
Steve Blocka7e24c12009-10-30 11:49:00 +0000138 PrintF(" ***\n");
139 }
140
141 if (print_source) {
Andrei Popescu31002712010-02-23 13:46:05 +0000142 PrintF("--- Source from AST ---\n%s\n",
143 PrettyPrinter().PrintProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000144 }
145
146 if (print_ast) {
Andrei Popescu31002712010-02-23 13:46:05 +0000147 PrintF("--- AST ---\n%s\n",
148 AstPrinter().PrintProgram(info->function()));
Steve Block3ce2e202009-11-05 08:53:23 +0000149 }
150
151 if (print_json_ast) {
152 JsonAstBuilder builder;
Andrei Popescu31002712010-02-23 13:46:05 +0000153 PrintF("%s", builder.BuildProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000154 }
155#endif // DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +0000156}
Steve Blocka7e24c12009-10-30 11:49:00 +0000157
Steve Blocka7e24c12009-10-30 11:49:00 +0000158
Andrei Popescu31002712010-02-23 13:46:05 +0000159Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
Steve Block3ce2e202009-11-05 08:53:23 +0000160 Code::Flags flags,
Andrei Popescu31002712010-02-23 13:46:05 +0000161 CompilationInfo* info) {
Steve Block3ce2e202009-11-05 08:53:23 +0000162 // Allocate and install the code.
Steve Blocka7e24c12009-10-30 11:49:00 +0000163 CodeDesc desc;
Steve Block3ce2e202009-11-05 08:53:23 +0000164 masm->GetCode(&desc);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100165 Handle<Code> code = Factory::NewCode(desc, flags, masm->CodeObject());
Steve Blocka7e24c12009-10-30 11:49:00 +0000166
Steve Blocka7e24c12009-10-30 11:49:00 +0000167#ifdef ENABLE_DISASSEMBLER
Steve Block3ce2e202009-11-05 08:53:23 +0000168 bool print_code = Bootstrapper::IsActive()
169 ? FLAG_print_builtin_code
170 : FLAG_print_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 if (print_code) {
172 // Print the source code if available.
Andrei Popescu31002712010-02-23 13:46:05 +0000173 Handle<Script> script = info->script();
174 FunctionLiteral* function = info->function();
Steve Blocka7e24c12009-10-30 11:49:00 +0000175 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
176 PrintF("--- Raw source ---\n");
177 StringInputBuffer stream(String::cast(script->source()));
Andrei Popescu31002712010-02-23 13:46:05 +0000178 stream.Seek(function->start_position());
Steve Block3ce2e202009-11-05 08:53:23 +0000179 // fun->end_position() points to the last character in the stream. We
Steve Blocka7e24c12009-10-30 11:49:00 +0000180 // need to compensate by adding one to calculate the length.
Andrei Popescu31002712010-02-23 13:46:05 +0000181 int source_len =
182 function->end_position() - function->start_position() + 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000183 for (int i = 0; i < source_len; i++) {
184 if (stream.has_more()) PrintF("%c", stream.GetNext());
185 }
186 PrintF("\n\n");
187 }
188 PrintF("--- Code ---\n");
Andrei Popescu31002712010-02-23 13:46:05 +0000189 code->Disassemble(*function->name()->ToCString());
Steve Blocka7e24c12009-10-30 11:49:00 +0000190 }
191#endif // ENABLE_DISASSEMBLER
192
193 if (!code.is_null()) {
194 Counters::total_compiled_code_size.Increment(code->instruction_size());
195 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000196 return code;
197}
198
199
Steve Block3ce2e202009-11-05 08:53:23 +0000200// Generate the code. Takes a function literal, generates code for it, assemble
201// all the pieces into a Code object. This function is only to be called by
202// the compiler.cc code.
Andrei Popescu31002712010-02-23 13:46:05 +0000203Handle<Code> CodeGenerator::MakeCode(CompilationInfo* info) {
204 Handle<Script> script = info->script();
Leon Clarked91b9f72010-01-27 17:25:45 +0000205 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
206 int len = String::cast(script->source())->length();
207 Counters::total_old_codegen_source_size.Increment(len);
208 }
Andrei Popescu31002712010-02-23 13:46:05 +0000209 MakeCodePrologue(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000210 // Generate code.
211 const int kInitialBufferSize = 4 * KB;
Leon Clarke4515c472010-02-03 11:58:03 +0000212 MacroAssembler masm(NULL, kInitialBufferSize);
Andrei Popescu31002712010-02-23 13:46:05 +0000213 CodeGenerator cgen(&masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000214 CodeGeneratorScope scope(&cgen);
Andrei Popescu402d9372010-02-26 13:31:12 +0000215 cgen.Generate(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000216 if (cgen.HasStackOverflow()) {
217 ASSERT(!Top::has_pending_exception());
218 return Handle<Code>::null();
219 }
220
221 InLoopFlag in_loop = (cgen.loop_nesting() != 0) ? IN_LOOP : NOT_IN_LOOP;
222 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop);
Steve Block6ded16b2010-05-10 14:33:55 +0100223 return MakeCodeEpilogue(cgen.masm(), flags, info);
Steve Block3ce2e202009-11-05 08:53:23 +0000224}
225
226
Steve Blocka7e24c12009-10-30 11:49:00 +0000227#ifdef ENABLE_LOGGING_AND_PROFILING
228
229bool CodeGenerator::ShouldGenerateLog(Expression* type) {
230 ASSERT(type != NULL);
Steve Block6ded16b2010-05-10 14:33:55 +0100231 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
233 if (FLAG_log_regexp) {
234 static Vector<const char> kRegexp = CStrVector("regexp");
235 if (name->IsEqualTo(kRegexp))
236 return true;
237 }
238 return false;
239}
240
241#endif
242
243
Steve Blocka7e24c12009-10-30 11:49:00 +0000244Handle<Code> CodeGenerator::ComputeCallInitialize(
245 int argc,
246 InLoopFlag in_loop) {
247 if (in_loop == IN_LOOP) {
248 // Force the creation of the corresponding stub outside loops,
249 // because it may be used when clearing the ICs later - it is
250 // possible for a series of IC transitions to lose the in-loop
251 // information, and the IC clearing code can't generate a stub
252 // that it needs so we need to ensure it is generated already.
253 ComputeCallInitialize(argc, NOT_IN_LOOP);
254 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100255 CALL_HEAP_FUNCTION(
256 StubCache::ComputeCallInitialize(argc, in_loop, Code::CALL_IC),
257 Code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000258}
259
260
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100261Handle<Code> CodeGenerator::ComputeKeyedCallInitialize(
262 int argc,
263 InLoopFlag in_loop) {
264 if (in_loop == IN_LOOP) {
265 // Force the creation of the corresponding stub outside loops,
266 // because it may be used when clearing the ICs later - it is
267 // possible for a series of IC transitions to lose the in-loop
268 // information, and the IC clearing code can't generate a stub
269 // that it needs so we need to ensure it is generated already.
270 ComputeKeyedCallInitialize(argc, NOT_IN_LOOP);
271 }
272 CALL_HEAP_FUNCTION(
273 StubCache::ComputeCallInitialize(argc, in_loop, Code::KEYED_CALL_IC),
274 Code);
275}
276
Steve Blocka7e24c12009-10-30 11:49:00 +0000277void CodeGenerator::ProcessDeclarations(ZoneList<Declaration*>* declarations) {
278 int length = declarations->length();
279 int globals = 0;
280 for (int i = 0; i < length; i++) {
281 Declaration* node = declarations->at(i);
282 Variable* var = node->proxy()->var();
283 Slot* slot = var->slot();
284
285 // If it was not possible to allocate the variable at compile
286 // time, we need to "declare" it at runtime to make sure it
287 // actually exists in the local context.
288 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
289 VisitDeclaration(node);
290 } else {
291 // Count global variables and functions for later processing
292 globals++;
293 }
294 }
295
296 // Return in case of no declared global functions or variables.
297 if (globals == 0) return;
298
299 // Compute array of global variable and function declarations.
300 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED);
301 for (int j = 0, i = 0; i < length; i++) {
302 Declaration* node = declarations->at(i);
303 Variable* var = node->proxy()->var();
304 Slot* slot = var->slot();
305
306 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
307 // Skip - already processed.
308 } else {
309 array->set(j++, *(var->name()));
310 if (node->fun() == NULL) {
311 if (var->mode() == Variable::CONST) {
312 // In case this is const property use the hole.
313 array->set_the_hole(j++);
314 } else {
315 array->set_undefined(j++);
316 }
317 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100318 Handle<SharedFunctionInfo> function =
319 Compiler::BuildFunctionInfo(node->fun(), script(), this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000320 // Check for stack-overflow exception.
321 if (HasStackOverflow()) return;
322 array->set(j++, *function);
323 }
324 }
325 }
326
327 // Invoke the platform-dependent code generator to do the actual
328 // declaration the global variables and functions.
329 DeclareGlobals(array);
330}
331
332
Steve Block6ded16b2010-05-10 14:33:55 +0100333// List of special runtime calls which are generated inline. For some of these
334// functions the code will be generated inline, and for others a call to a code
335// stub will be inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000336
Steve Block6ded16b2010-05-10 14:33:55 +0100337#define INLINE_RUNTIME_ENTRY(Name, argc, ressize) \
338 {&CodeGenerator::Generate##Name, "_" #Name, argc}, \
339
Steve Blocka7e24c12009-10-30 11:49:00 +0000340CodeGenerator::InlineRuntimeLUT CodeGenerator::kInlineRuntimeLUT[] = {
Steve Block6ded16b2010-05-10 14:33:55 +0100341 INLINE_RUNTIME_FUNCTION_LIST(INLINE_RUNTIME_ENTRY)
Steve Blocka7e24c12009-10-30 11:49:00 +0000342};
343
Steve Block6ded16b2010-05-10 14:33:55 +0100344#undef INLINE_RUNTIME_ENTRY
Steve Blocka7e24c12009-10-30 11:49:00 +0000345
346CodeGenerator::InlineRuntimeLUT* CodeGenerator::FindInlineRuntimeLUT(
347 Handle<String> name) {
348 const int entries_count =
349 sizeof(kInlineRuntimeLUT) / sizeof(InlineRuntimeLUT);
350 for (int i = 0; i < entries_count; i++) {
351 InlineRuntimeLUT* entry = &kInlineRuntimeLUT[i];
352 if (name->IsEqualTo(CStrVector(entry->name))) {
353 return entry;
354 }
355 }
356 return NULL;
357}
358
359
360bool CodeGenerator::CheckForInlineRuntimeCall(CallRuntime* node) {
361 ZoneList<Expression*>* args = node->arguments();
362 Handle<String> name = node->name();
363 if (name->length() > 0 && name->Get(0) == '_') {
364 InlineRuntimeLUT* entry = FindInlineRuntimeLUT(name);
365 if (entry != NULL) {
366 ((*this).*(entry->method))(args);
367 return true;
368 }
369 }
370 return false;
371}
372
373
374bool CodeGenerator::PatchInlineRuntimeEntry(Handle<String> name,
375 const CodeGenerator::InlineRuntimeLUT& new_entry,
376 CodeGenerator::InlineRuntimeLUT* old_entry) {
377 InlineRuntimeLUT* entry = FindInlineRuntimeLUT(name);
378 if (entry == NULL) return false;
379 if (old_entry != NULL) {
380 old_entry->name = entry->name;
381 old_entry->method = entry->method;
382 }
383 entry->name = new_entry.name;
384 entry->method = new_entry.method;
385 return true;
386}
387
388
Steve Block6ded16b2010-05-10 14:33:55 +0100389int CodeGenerator::InlineRuntimeCallArgumentsCount(Handle<String> name) {
390 CodeGenerator::InlineRuntimeLUT* f =
391 CodeGenerator::FindInlineRuntimeLUT(name);
392 if (f != NULL) return f->nargs;
393 return -1;
394}
395
396
Steve Block3ce2e202009-11-05 08:53:23 +0000397// Simple condition analysis. ALWAYS_TRUE and ALWAYS_FALSE represent a
398// known result for the test expression, with no side effects.
399CodeGenerator::ConditionAnalysis CodeGenerator::AnalyzeCondition(
400 Expression* cond) {
401 if (cond == NULL) return ALWAYS_TRUE;
402
403 Literal* lit = cond->AsLiteral();
404 if (lit == NULL) return DONT_KNOW;
405
406 if (lit->IsTrue()) {
407 return ALWAYS_TRUE;
408 } else if (lit->IsFalse()) {
409 return ALWAYS_FALSE;
410 }
411
412 return DONT_KNOW;
413}
414
415
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100416bool CodeGenerator::RecordPositions(MacroAssembler* masm,
417 int pos,
418 bool right_here) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000419 if (pos != RelocInfo::kNoPosition) {
Steve Block3ce2e202009-11-05 08:53:23 +0000420 masm->RecordStatementPosition(pos);
421 masm->RecordPosition(pos);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100422 if (right_here) {
423 return masm->WriteRecordedPositions();
424 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100426 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000427}
428
429
430void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100431 if (FLAG_debug_info) RecordPositions(masm(), fun->start_position(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000432}
433
434
435void CodeGenerator::CodeForReturnPosition(FunctionLiteral* fun) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100436 if (FLAG_debug_info) RecordPositions(masm(), fun->end_position(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000437}
438
439
440void CodeGenerator::CodeForStatementPosition(Statement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100441 if (FLAG_debug_info) RecordPositions(masm(), stmt->statement_pos(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000442}
443
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100444
Steve Blockd0582a62009-12-15 09:54:21 +0000445void CodeGenerator::CodeForDoWhileConditionPosition(DoWhileStatement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100446 if (FLAG_debug_info)
447 RecordPositions(masm(), stmt->condition_position(), false);
Steve Blockd0582a62009-12-15 09:54:21 +0000448}
Steve Blocka7e24c12009-10-30 11:49:00 +0000449
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100450
Steve Blocka7e24c12009-10-30 11:49:00 +0000451void CodeGenerator::CodeForSourcePosition(int pos) {
452 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
453 masm()->RecordPosition(pos);
454 }
455}
456
457
Leon Clarkee46be812010-01-19 14:06:41 +0000458const char* GenericUnaryOpStub::GetName() {
459 switch (op_) {
460 case Token::SUB:
Leon Clarkeac952652010-07-15 11:15:24 +0100461 if (negative_zero_ == kStrictNegativeZero) {
462 return overwrite_ == UNARY_OVERWRITE
463 ? "GenericUnaryOpStub_SUB_Overwrite_Strict0"
464 : "GenericUnaryOpStub_SUB_Alloc_Strict0";
465 } else {
466 return overwrite_ == UNARY_OVERWRITE
467 ? "GenericUnaryOpStub_SUB_Overwrite_Ignore0"
468 : "GenericUnaryOpStub_SUB_Alloc_Ignore0";
469 }
Leon Clarkee46be812010-01-19 14:06:41 +0000470 case Token::BIT_NOT:
Leon Clarkeac952652010-07-15 11:15:24 +0100471 return overwrite_ == UNARY_OVERWRITE
Leon Clarkee46be812010-01-19 14:06:41 +0000472 ? "GenericUnaryOpStub_BIT_NOT_Overwrite"
473 : "GenericUnaryOpStub_BIT_NOT_Alloc";
474 default:
475 UNREACHABLE();
476 return "<unknown>";
477 }
478}
479
480
Steve Blocka7e24c12009-10-30 11:49:00 +0000481void ArgumentsAccessStub::Generate(MacroAssembler* masm) {
482 switch (type_) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000483 case READ_ELEMENT: GenerateReadElement(masm); break;
484 case NEW_OBJECT: GenerateNewObject(masm); break;
485 }
486}
487
488
Leon Clarke4515c472010-02-03 11:58:03 +0000489int CEntryStub::MinorKey() {
490 ASSERT(result_size_ <= 2);
491#ifdef _WIN64
492 return ExitFrameModeBits::encode(mode_)
493 | IndirectResultBits::encode(result_size_ > 1);
494#else
495 return ExitFrameModeBits::encode(mode_);
496#endif
497}
498
499
Steve Blockd0582a62009-12-15 09:54:21 +0000500bool ApiGetterEntryStub::GetCustomCache(Code** code_out) {
501 Object* cache = info()->load_stub_cache();
502 if (cache->IsUndefined()) {
503 return false;
504 } else {
505 *code_out = Code::cast(cache);
506 return true;
507 }
508}
509
510
511void ApiGetterEntryStub::SetCustomCache(Code* value) {
512 info()->set_load_stub_cache(value);
513}
514
515
Steve Blocka7e24c12009-10-30 11:49:00 +0000516} } // namespace v8::internal