blob: 2e32418034bea4d55ae8fb01c7eb403e6cd68a4d [file] [log] [blame]
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001// Copyright 2010 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// 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.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -080073 masm_->positions_recorder()->RecordStatementPosition(
74 code->statement_position());
Steve Blocka7e24c12009-10-30 11:49:00 +000075 if (code->position() != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -080076 masm_->positions_recorder()->RecordPosition(code->position());
Steve Blocka7e24c12009-10-30 11:49:00 +000077 }
78 // Generate the code.
79 Comment cmnt(masm_, code->comment());
80 masm_->bind(code->entry_label());
Iain Merrick75681382010-08-19 15:07:18 +010081 if (code->AutoSaveAndRestore()) {
82 code->SaveRegisters();
83 }
Steve Blocka7e24c12009-10-30 11:49:00 +000084 code->Generate();
Iain Merrick75681382010-08-19 15:07:18 +010085 if (code->AutoSaveAndRestore()) {
86 code->RestoreRegisters();
87 code->Exit();
88 }
Steve Blocka7e24c12009-10-30 11:49:00 +000089 }
90}
91
92
Iain Merrick75681382010-08-19 15:07:18 +010093void DeferredCode::Exit() {
94 masm_->jmp(exit_label());
95}
96
97
Steve Blocka7e24c12009-10-30 11:49:00 +000098void CodeGenerator::SetFrame(VirtualFrame* new_frame,
99 RegisterFile* non_frame_registers) {
100 RegisterFile saved_counts;
101 if (has_valid_frame()) {
102 frame_->DetachFromCodeGenerator();
103 // The remaining register reference counts are the non-frame ones.
104 allocator_->SaveTo(&saved_counts);
105 }
106
107 if (new_frame != NULL) {
108 // Restore the non-frame register references that go with the new frame.
109 allocator_->RestoreFrom(non_frame_registers);
110 new_frame->AttachToCodeGenerator();
111 }
112
113 frame_ = new_frame;
114 saved_counts.CopyTo(non_frame_registers);
115}
116
117
118void CodeGenerator::DeleteFrame() {
119 if (has_valid_frame()) {
120 frame_->DetachFromCodeGenerator();
121 frame_ = NULL;
122 }
123}
124
125
Andrei Popescu31002712010-02-23 13:46:05 +0000126void CodeGenerator::MakeCodePrologue(CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000127#ifdef DEBUG
128 bool print_source = false;
129 bool print_ast = false;
Steve Block3ce2e202009-11-05 08:53:23 +0000130 bool print_json_ast = false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000131 const char* ftype;
132
133 if (Bootstrapper::IsActive()) {
134 print_source = FLAG_print_builtin_source;
135 print_ast = FLAG_print_builtin_ast;
Steve Block3ce2e202009-11-05 08:53:23 +0000136 print_json_ast = FLAG_print_builtin_json_ast;
Steve Blocka7e24c12009-10-30 11:49:00 +0000137 ftype = "builtin";
138 } else {
139 print_source = FLAG_print_source;
140 print_ast = FLAG_print_ast;
Steve Block3ce2e202009-11-05 08:53:23 +0000141 print_json_ast = FLAG_print_json_ast;
Steve Blocka7e24c12009-10-30 11:49:00 +0000142 ftype = "user-defined";
143 }
144
145 if (FLAG_trace_codegen || print_source || print_ast) {
146 PrintF("*** Generate code for %s function: ", ftype);
Andrei Popescu31002712010-02-23 13:46:05 +0000147 info->function()->name()->ShortPrint();
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 PrintF(" ***\n");
149 }
150
151 if (print_source) {
Andrei Popescu31002712010-02-23 13:46:05 +0000152 PrintF("--- Source from AST ---\n%s\n",
153 PrettyPrinter().PrintProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000154 }
155
156 if (print_ast) {
Andrei Popescu31002712010-02-23 13:46:05 +0000157 PrintF("--- AST ---\n%s\n",
158 AstPrinter().PrintProgram(info->function()));
Steve Block3ce2e202009-11-05 08:53:23 +0000159 }
160
161 if (print_json_ast) {
162 JsonAstBuilder builder;
Andrei Popescu31002712010-02-23 13:46:05 +0000163 PrintF("%s", builder.BuildProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 }
165#endif // DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +0000166}
Steve Blocka7e24c12009-10-30 11:49:00 +0000167
Steve Blocka7e24c12009-10-30 11:49:00 +0000168
Andrei Popescu31002712010-02-23 13:46:05 +0000169Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
Steve Block3ce2e202009-11-05 08:53:23 +0000170 Code::Flags flags,
Andrei Popescu31002712010-02-23 13:46:05 +0000171 CompilationInfo* info) {
Steve Block3ce2e202009-11-05 08:53:23 +0000172 // Allocate and install the code.
Steve Blocka7e24c12009-10-30 11:49:00 +0000173 CodeDesc desc;
Steve Block3ce2e202009-11-05 08:53:23 +0000174 masm->GetCode(&desc);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100175 Handle<Code> code = Factory::NewCode(desc, flags, masm->CodeObject());
Steve Blocka7e24c12009-10-30 11:49:00 +0000176
Steve Blocka7e24c12009-10-30 11:49:00 +0000177#ifdef ENABLE_DISASSEMBLER
Steve Block3ce2e202009-11-05 08:53:23 +0000178 bool print_code = Bootstrapper::IsActive()
179 ? FLAG_print_builtin_code
180 : FLAG_print_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000181 if (print_code) {
182 // Print the source code if available.
Andrei Popescu31002712010-02-23 13:46:05 +0000183 Handle<Script> script = info->script();
184 FunctionLiteral* function = info->function();
Steve Blocka7e24c12009-10-30 11:49:00 +0000185 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
186 PrintF("--- Raw source ---\n");
187 StringInputBuffer stream(String::cast(script->source()));
Andrei Popescu31002712010-02-23 13:46:05 +0000188 stream.Seek(function->start_position());
Steve Block3ce2e202009-11-05 08:53:23 +0000189 // fun->end_position() points to the last character in the stream. We
Steve Blocka7e24c12009-10-30 11:49:00 +0000190 // need to compensate by adding one to calculate the length.
Andrei Popescu31002712010-02-23 13:46:05 +0000191 int source_len =
192 function->end_position() - function->start_position() + 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000193 for (int i = 0; i < source_len; i++) {
194 if (stream.has_more()) PrintF("%c", stream.GetNext());
195 }
196 PrintF("\n\n");
197 }
198 PrintF("--- Code ---\n");
Andrei Popescu31002712010-02-23 13:46:05 +0000199 code->Disassemble(*function->name()->ToCString());
Steve Blocka7e24c12009-10-30 11:49:00 +0000200 }
201#endif // ENABLE_DISASSEMBLER
202
203 if (!code.is_null()) {
204 Counters::total_compiled_code_size.Increment(code->instruction_size());
205 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 return code;
207}
208
209
Ben Murdochf87a2032010-10-22 12:50:53 +0100210// Generate the code. Compile the AST and assemble all the pieces into a
211// Code object.
212bool CodeGenerator::MakeCode(CompilationInfo* info) {
Andrei Popescu31002712010-02-23 13:46:05 +0000213 Handle<Script> script = info->script();
Leon Clarked91b9f72010-01-27 17:25:45 +0000214 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
215 int len = String::cast(script->source())->length();
216 Counters::total_old_codegen_source_size.Increment(len);
217 }
Andrei Popescu31002712010-02-23 13:46:05 +0000218 MakeCodePrologue(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000219 // Generate code.
220 const int kInitialBufferSize = 4 * KB;
Leon Clarke4515c472010-02-03 11:58:03 +0000221 MacroAssembler masm(NULL, kInitialBufferSize);
Andrei Popescu31002712010-02-23 13:46:05 +0000222 CodeGenerator cgen(&masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000223 CodeGeneratorScope scope(&cgen);
Andrei Popescu402d9372010-02-26 13:31:12 +0000224 cgen.Generate(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000225 if (cgen.HasStackOverflow()) {
226 ASSERT(!Top::has_pending_exception());
Ben Murdochf87a2032010-10-22 12:50:53 +0100227 return false;
Steve Block3ce2e202009-11-05 08:53:23 +0000228 }
229
Ben Murdochf87a2032010-10-22 12:50:53 +0100230 InLoopFlag in_loop = info->is_in_loop() ? IN_LOOP : NOT_IN_LOOP;
Steve Block3ce2e202009-11-05 08:53:23 +0000231 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop);
Ben Murdochf87a2032010-10-22 12:50:53 +0100232 Handle<Code> code = MakeCodeEpilogue(cgen.masm(), flags, info);
233 info->SetCode(code); // May be an empty handle.
234 return !code.is_null();
Steve Block3ce2e202009-11-05 08:53:23 +0000235}
236
237
Steve Blocka7e24c12009-10-30 11:49:00 +0000238#ifdef ENABLE_LOGGING_AND_PROFILING
239
240bool CodeGenerator::ShouldGenerateLog(Expression* type) {
241 ASSERT(type != NULL);
Steve Block6ded16b2010-05-10 14:33:55 +0100242 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000243 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
244 if (FLAG_log_regexp) {
245 static Vector<const char> kRegexp = CStrVector("regexp");
246 if (name->IsEqualTo(kRegexp))
247 return true;
248 }
249 return false;
250}
251
252#endif
253
254
Steve Blocka7e24c12009-10-30 11:49:00 +0000255Handle<Code> CodeGenerator::ComputeCallInitialize(
256 int argc,
257 InLoopFlag in_loop) {
258 if (in_loop == IN_LOOP) {
259 // Force the creation of the corresponding stub outside loops,
260 // because it may be used when clearing the ICs later - it is
261 // possible for a series of IC transitions to lose the in-loop
262 // information, and the IC clearing code can't generate a stub
263 // that it needs so we need to ensure it is generated already.
264 ComputeCallInitialize(argc, NOT_IN_LOOP);
265 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100266 CALL_HEAP_FUNCTION(
267 StubCache::ComputeCallInitialize(argc, in_loop, Code::CALL_IC),
268 Code);
Steve Blocka7e24c12009-10-30 11:49:00 +0000269}
270
271
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100272Handle<Code> CodeGenerator::ComputeKeyedCallInitialize(
273 int argc,
274 InLoopFlag in_loop) {
275 if (in_loop == IN_LOOP) {
276 // Force the creation of the corresponding stub outside loops,
277 // because it may be used when clearing the ICs later - it is
278 // possible for a series of IC transitions to lose the in-loop
279 // information, and the IC clearing code can't generate a stub
280 // that it needs so we need to ensure it is generated already.
281 ComputeKeyedCallInitialize(argc, NOT_IN_LOOP);
282 }
283 CALL_HEAP_FUNCTION(
284 StubCache::ComputeCallInitialize(argc, in_loop, Code::KEYED_CALL_IC),
285 Code);
286}
287
Steve Blocka7e24c12009-10-30 11:49:00 +0000288void CodeGenerator::ProcessDeclarations(ZoneList<Declaration*>* declarations) {
289 int length = declarations->length();
290 int globals = 0;
291 for (int i = 0; i < length; i++) {
292 Declaration* node = declarations->at(i);
293 Variable* var = node->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100294 Slot* slot = var->AsSlot();
Steve Blocka7e24c12009-10-30 11:49:00 +0000295
296 // If it was not possible to allocate the variable at compile
297 // time, we need to "declare" it at runtime to make sure it
298 // actually exists in the local context.
299 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
300 VisitDeclaration(node);
301 } else {
302 // Count global variables and functions for later processing
303 globals++;
304 }
305 }
306
307 // Return in case of no declared global functions or variables.
308 if (globals == 0) return;
309
310 // Compute array of global variable and function declarations.
311 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED);
312 for (int j = 0, i = 0; i < length; i++) {
313 Declaration* node = declarations->at(i);
314 Variable* var = node->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100315 Slot* slot = var->AsSlot();
Steve Blocka7e24c12009-10-30 11:49:00 +0000316
317 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
318 // Skip - already processed.
319 } else {
320 array->set(j++, *(var->name()));
321 if (node->fun() == NULL) {
322 if (var->mode() == Variable::CONST) {
323 // In case this is const property use the hole.
324 array->set_the_hole(j++);
325 } else {
326 array->set_undefined(j++);
327 }
328 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100329 Handle<SharedFunctionInfo> function =
Ben Murdochf87a2032010-10-22 12:50:53 +0100330 Compiler::BuildFunctionInfo(node->fun(), script());
Steve Blocka7e24c12009-10-30 11:49:00 +0000331 // Check for stack-overflow exception.
Ben Murdochf87a2032010-10-22 12:50:53 +0100332 if (function.is_null()) {
333 SetStackOverflow();
334 return;
335 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000336 array->set(j++, *function);
337 }
338 }
339 }
340
341 // Invoke the platform-dependent code generator to do the actual
342 // declaration the global variables and functions.
343 DeclareGlobals(array);
344}
345
346
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100347void CodeGenerator::VisitIncrementOperation(IncrementOperation* expr) {
348 UNREACHABLE();
349}
350
351
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100352// Lookup table for code generators for special runtime calls which are
353// generated inline.
354#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
355 &CodeGenerator::Generate##Name,
Steve Blocka7e24c12009-10-30 11:49:00 +0000356
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100357const CodeGenerator::InlineFunctionGenerator
358 CodeGenerator::kInlineFunctionGenerators[] = {
359 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
360 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
Steve Blocka7e24c12009-10-30 11:49:00 +0000361};
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100362#undef INLINE_FUNCTION_GENERATOR_ADDRESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000363
364
Steve Blocka7e24c12009-10-30 11:49:00 +0000365bool CodeGenerator::CheckForInlineRuntimeCall(CallRuntime* node) {
366 ZoneList<Expression*>* args = node->arguments();
367 Handle<String> name = node->name();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100368 Runtime::Function* function = node->function();
369 if (function != NULL && function->intrinsic_type == Runtime::INLINE) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100370 int lookup_index = static_cast<int>(function->function_id) -
371 static_cast<int>(Runtime::kFirstInlineFunction);
372 ASSERT(lookup_index >= 0);
373 ASSERT(static_cast<size_t>(lookup_index) <
374 ARRAY_SIZE(kInlineFunctionGenerators));
375 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index];
376 (this->*generator)(args);
377 return true;
Steve Blocka7e24c12009-10-30 11:49:00 +0000378 }
379 return false;
380}
381
382
Steve Block3ce2e202009-11-05 08:53:23 +0000383// Simple condition analysis. ALWAYS_TRUE and ALWAYS_FALSE represent a
384// known result for the test expression, with no side effects.
385CodeGenerator::ConditionAnalysis CodeGenerator::AnalyzeCondition(
386 Expression* cond) {
387 if (cond == NULL) return ALWAYS_TRUE;
388
389 Literal* lit = cond->AsLiteral();
390 if (lit == NULL) return DONT_KNOW;
391
392 if (lit->IsTrue()) {
393 return ALWAYS_TRUE;
394 } else if (lit->IsFalse()) {
395 return ALWAYS_FALSE;
396 }
397
398 return DONT_KNOW;
399}
400
401
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100402bool CodeGenerator::RecordPositions(MacroAssembler* masm,
403 int pos,
404 bool right_here) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000405 if (pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800406 masm->positions_recorder()->RecordStatementPosition(pos);
407 masm->positions_recorder()->RecordPosition(pos);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100408 if (right_here) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800409 return masm->positions_recorder()->WriteRecordedPositions();
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100410 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000411 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100412 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000413}
414
415
416void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100417 if (FLAG_debug_info) RecordPositions(masm(), fun->start_position(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000418}
419
420
421void CodeGenerator::CodeForReturnPosition(FunctionLiteral* fun) {
Ben Murdochbb769b22010-08-11 14:56:33 +0100422 if (FLAG_debug_info) RecordPositions(masm(), fun->end_position() - 1, false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000423}
424
425
426void CodeGenerator::CodeForStatementPosition(Statement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100427 if (FLAG_debug_info) RecordPositions(masm(), stmt->statement_pos(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000428}
429
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100430
Steve Blockd0582a62009-12-15 09:54:21 +0000431void CodeGenerator::CodeForDoWhileConditionPosition(DoWhileStatement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100432 if (FLAG_debug_info)
433 RecordPositions(masm(), stmt->condition_position(), false);
Steve Blockd0582a62009-12-15 09:54:21 +0000434}
Steve Blocka7e24c12009-10-30 11:49:00 +0000435
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100436
Steve Blocka7e24c12009-10-30 11:49:00 +0000437void CodeGenerator::CodeForSourcePosition(int pos) {
438 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800439 masm()->positions_recorder()->RecordPosition(pos);
Steve Blocka7e24c12009-10-30 11:49:00 +0000440 }
441}
442
443
Leon Clarkee46be812010-01-19 14:06:41 +0000444const char* GenericUnaryOpStub::GetName() {
445 switch (op_) {
446 case Token::SUB:
Leon Clarkeac952652010-07-15 11:15:24 +0100447 if (negative_zero_ == kStrictNegativeZero) {
448 return overwrite_ == UNARY_OVERWRITE
449 ? "GenericUnaryOpStub_SUB_Overwrite_Strict0"
450 : "GenericUnaryOpStub_SUB_Alloc_Strict0";
451 } else {
452 return overwrite_ == UNARY_OVERWRITE
453 ? "GenericUnaryOpStub_SUB_Overwrite_Ignore0"
454 : "GenericUnaryOpStub_SUB_Alloc_Ignore0";
455 }
Leon Clarkee46be812010-01-19 14:06:41 +0000456 case Token::BIT_NOT:
Leon Clarkeac952652010-07-15 11:15:24 +0100457 return overwrite_ == UNARY_OVERWRITE
Leon Clarkee46be812010-01-19 14:06:41 +0000458 ? "GenericUnaryOpStub_BIT_NOT_Overwrite"
459 : "GenericUnaryOpStub_BIT_NOT_Alloc";
460 default:
461 UNREACHABLE();
462 return "<unknown>";
463 }
464}
465
466
Steve Blocka7e24c12009-10-30 11:49:00 +0000467void ArgumentsAccessStub::Generate(MacroAssembler* masm) {
468 switch (type_) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 case READ_ELEMENT: GenerateReadElement(masm); break;
470 case NEW_OBJECT: GenerateNewObject(masm); break;
471 }
472}
473
474
Leon Clarke4515c472010-02-03 11:58:03 +0000475int CEntryStub::MinorKey() {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100476 ASSERT(result_size_ == 1 || result_size_ == 2);
Leon Clarke4515c472010-02-03 11:58:03 +0000477#ifdef _WIN64
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100478 return result_size_ == 1 ? 0 : 1;
Leon Clarke4515c472010-02-03 11:58:03 +0000479#else
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100480 return 0;
Leon Clarke4515c472010-02-03 11:58:03 +0000481#endif
482}
483
484
Steve Blockd0582a62009-12-15 09:54:21 +0000485bool ApiGetterEntryStub::GetCustomCache(Code** code_out) {
486 Object* cache = info()->load_stub_cache();
487 if (cache->IsUndefined()) {
488 return false;
489 } else {
490 *code_out = Code::cast(cache);
491 return true;
492 }
493}
494
495
496void ApiGetterEntryStub::SetCustomCache(Code* value) {
497 info()->set_load_stub_cache(value);
498}
499
500
Steve Blocka7e24c12009-10-30 11:49:00 +0000501} } // namespace v8::internal