blob: 84b73a4ecb8620b0ceaaf69b1db70bc35b5dfcb6 [file] [log] [blame]
ager@chromium.org71daaf62009-04-01 07:22:49 +00001// Copyright 2009 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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
ager@chromium.org7c537e22008-10-16 08:43:32 +000030#include "bootstrapper.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000031#include "codegen-inl.h"
ager@chromium.orgc4c92722009-11-18 14:12:51 +000032#include "compiler.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000033#include "debug.h"
ager@chromium.org71daaf62009-04-01 07:22:49 +000034#include "oprofile-agent.h"
ager@chromium.org7c537e22008-10-16 08:43:32 +000035#include "prettyprinter.h"
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000036#include "register-allocator-inl.h"
ager@chromium.org71daaf62009-04-01 07:22:49 +000037#include "rewriter.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000038#include "runtime.h"
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000039#include "scopeinfo.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000040#include "stub-cache.h"
sgjesse@chromium.org833cdd72010-02-26 10:06:16 +000041#include "virtual-frame-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000042
kasperl@chromium.org71affb52009-05-26 05:44:31 +000043namespace v8 {
44namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000045
ager@chromium.org5c838252010-02-19 08:53:10 +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
kasperl@chromium.orgb3284ad2009-05-18 06:12:45 +000064
65CodeGenerator* CodeGeneratorScope::top_ = NULL;
66
67
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000068void CodeGenerator::ProcessDeferred() {
69 while (!deferred_.is_empty()) {
70 DeferredCode* code = deferred_.RemoveLast();
ager@chromium.orge2902be2009-06-08 12:21:35 +000071 ASSERT(masm_ == code->masm());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000072 // Record position of deferred code stub.
ager@chromium.orge2902be2009-06-08 12:21:35 +000073 masm_->RecordStatementPosition(code->statement_position());
ager@chromium.org236ad962008-09-25 09:45:57 +000074 if (code->position() != RelocInfo::kNoPosition) {
ager@chromium.orge2902be2009-06-08 12:21:35 +000075 masm_->RecordPosition(code->position());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000076 }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000077 // Generate the code.
ager@chromium.orge2902be2009-06-08 12:21:35 +000078 Comment cmnt(masm_, code->comment());
79 masm_->bind(code->entry_label());
80 code->SaveRegisters();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000081 code->Generate();
ager@chromium.orge2902be2009-06-08 12:21:35 +000082 code->RestoreRegisters();
83 masm_->jmp(code->exit_label());
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000084 }
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();
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000111 frame_ = NULL;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000112 }
113}
114
115
ager@chromium.org5c838252010-02-19 08:53:10 +0000116void CodeGenerator::MakeCodePrologue(CompilationInfo* info) {
ager@chromium.org7c537e22008-10-16 08:43:32 +0000117#ifdef DEBUG
118 bool print_source = false;
119 bool print_ast = false;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000120 bool print_json_ast = false;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000121 const char* ftype;
122
123 if (Bootstrapper::IsActive()) {
124 print_source = FLAG_print_builtin_source;
125 print_ast = FLAG_print_builtin_ast;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000126 print_json_ast = FLAG_print_builtin_json_ast;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000127 ftype = "builtin";
128 } else {
129 print_source = FLAG_print_source;
130 print_ast = FLAG_print_ast;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000131 print_json_ast = FLAG_print_json_ast;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000132 ftype = "user-defined";
133 }
134
135 if (FLAG_trace_codegen || print_source || print_ast) {
136 PrintF("*** Generate code for %s function: ", ftype);
ager@chromium.org5c838252010-02-19 08:53:10 +0000137 info->function()->name()->ShortPrint();
ager@chromium.org7c537e22008-10-16 08:43:32 +0000138 PrintF(" ***\n");
139 }
140
141 if (print_source) {
ager@chromium.org5c838252010-02-19 08:53:10 +0000142 PrintF("--- Source from AST ---\n%s\n",
143 PrettyPrinter().PrintProgram(info->function()));
ager@chromium.org7c537e22008-10-16 08:43:32 +0000144 }
145
146 if (print_ast) {
ager@chromium.org5c838252010-02-19 08:53:10 +0000147 PrintF("--- AST ---\n%s\n",
148 AstPrinter().PrintProgram(info->function()));
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000149 }
150
151 if (print_json_ast) {
152 JsonAstBuilder builder;
ager@chromium.org5c838252010-02-19 08:53:10 +0000153 PrintF("%s", builder.BuildProgram(info->function()));
ager@chromium.org7c537e22008-10-16 08:43:32 +0000154 }
155#endif // DEBUG
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000156}
ager@chromium.org7c537e22008-10-16 08:43:32 +0000157
ager@chromium.org7c537e22008-10-16 08:43:32 +0000158
ager@chromium.org5c838252010-02-19 08:53:10 +0000159Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000160 Code::Flags flags,
ager@chromium.org5c838252010-02-19 08:53:10 +0000161 CompilationInfo* info) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000162 // Allocate and install the code.
ager@chromium.org7c537e22008-10-16 08:43:32 +0000163 CodeDesc desc;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000164 masm->GetCode(&desc);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000165 Handle<Code> code = Factory::NewCode(desc, flags, masm->CodeObject());
ager@chromium.org7c537e22008-10-16 08:43:32 +0000166
ager@chromium.org7c537e22008-10-16 08:43:32 +0000167#ifdef ENABLE_DISASSEMBLER
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000168 bool print_code = Bootstrapper::IsActive()
169 ? FLAG_print_builtin_code
170 : FLAG_print_code;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000171 if (print_code) {
172 // Print the source code if available.
ager@chromium.org5c838252010-02-19 08:53:10 +0000173 Handle<Script> script = info->script();
174 FunctionLiteral* function = info->function();
ager@chromium.org7c537e22008-10-16 08:43:32 +0000175 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
176 PrintF("--- Raw source ---\n");
177 StringInputBuffer stream(String::cast(script->source()));
ager@chromium.org5c838252010-02-19 08:53:10 +0000178 stream.Seek(function->start_position());
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000179 // fun->end_position() points to the last character in the stream. We
ager@chromium.org7c537e22008-10-16 08:43:32 +0000180 // need to compensate by adding one to calculate the length.
ager@chromium.org5c838252010-02-19 08:53:10 +0000181 int source_len =
182 function->end_position() - function->start_position() + 1;
ager@chromium.org7c537e22008-10-16 08:43:32 +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");
ager@chromium.org5c838252010-02-19 08:53:10 +0000189 code->Disassemble(*function->name()->ToCString());
ager@chromium.org7c537e22008-10-16 08:43:32 +0000190 }
191#endif // ENABLE_DISASSEMBLER
192
193 if (!code.is_null()) {
194 Counters::total_compiled_code_size.Increment(code->instruction_size());
195 }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000196 return code;
197}
198
199
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +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.
ager@chromium.org5c838252010-02-19 08:53:10 +0000203Handle<Code> CodeGenerator::MakeCode(CompilationInfo* info) {
ager@chromium.org5c838252010-02-19 08:53:10 +0000204 Handle<Script> script = info->script();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +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 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000209 MakeCodePrologue(info);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000210 // Generate code.
211 const int kInitialBufferSize = 4 * KB;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000212 MacroAssembler masm(NULL, kInitialBufferSize);
ager@chromium.org5c838252010-02-19 08:53:10 +0000213 CodeGenerator cgen(&masm);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000214 CodeGeneratorScope scope(&cgen);
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000215 cgen.Generate(info);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +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);
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000223 return MakeCodeEpilogue(cgen.masm(), flags, info);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000224}
225
226
christian.plesner.hansen@gmail.comaca49682009-01-07 14:29:04 +0000227#ifdef ENABLE_LOGGING_AND_PROFILING
228
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000229bool CodeGenerator::ShouldGenerateLog(Expression* type) {
230 ASSERT(type != NULL);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000231 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false;
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +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
christian.plesner.hansen@gmail.comaca49682009-01-07 14:29:04 +0000241#endif
242
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000243
kasperl@chromium.org71affb52009-05-26 05:44:31 +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 }
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000255 CALL_HEAP_FUNCTION(
256 StubCache::ComputeCallInitialize(argc, in_loop, Code::CALL_IC),
257 Code);
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000258}
259
260
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000261Handle<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
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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 {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000318 Handle<SharedFunctionInfo> function =
319 Compiler::BuildFunctionInfo(node->fun(), script(), this);
kasper.lund212ac232008-07-16 07:07:30 +0000320 // Check for stack-overflow exception.
321 if (HasStackOverflow()) return;
322 array->set(j++, *function);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000323 }
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
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000333// 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.
ager@chromium.org9085a012009-05-11 19:22:57 +0000336
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000337#define INLINE_RUNTIME_ENTRY(Name, argc, ressize) \
338 {&CodeGenerator::Generate##Name, "_" #Name, argc}, \
339
ager@chromium.org9085a012009-05-11 19:22:57 +0000340CodeGenerator::InlineRuntimeLUT CodeGenerator::kInlineRuntimeLUT[] = {
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000341 INLINE_RUNTIME_FUNCTION_LIST(INLINE_RUNTIME_ENTRY)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000342};
343
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000344#undef INLINE_RUNTIME_ENTRY
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000345
ager@chromium.org9085a012009-05-11 19:22:57 +0000346CodeGenerator::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
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000360bool CodeGenerator::CheckForInlineRuntimeCall(CallRuntime* node) {
361 ZoneList<Expression*>* args = node->arguments();
ager@chromium.org870a0b62008-11-04 11:43:05 +0000362 Handle<String> name = node->name();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000363 if (name->length() > 0 && name->Get(0) == '_') {
ager@chromium.org9085a012009-05-11 19:22:57 +0000364 InlineRuntimeLUT* entry = FindInlineRuntimeLUT(name);
365 if (entry != NULL) {
366 ((*this).*(entry->method))(args);
367 return true;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000368 }
369 }
370 return false;
371}
372
373
ager@chromium.org9085a012009-05-11 19:22:57 +0000374bool 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
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000389int 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
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +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
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000416bool CodeGenerator::RecordPositions(MacroAssembler* masm,
417 int pos,
418 bool right_here) {
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000419 if (pos != RelocInfo::kNoPosition) {
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000420 masm->RecordStatementPosition(pos);
421 masm->RecordPosition(pos);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000422 if (right_here) {
423 return masm->WriteRecordedPositions();
424 }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000425 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000426 return false;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000427}
428
429
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000430void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000431 if (FLAG_debug_info) RecordPositions(masm(), fun->start_position(), false);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000432}
433
434
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000435void CodeGenerator::CodeForReturnPosition(FunctionLiteral* fun) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000436 if (FLAG_debug_info) RecordPositions(masm(), fun->end_position(), false);
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000437}
438
439
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000440void CodeGenerator::CodeForStatementPosition(Statement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000441 if (FLAG_debug_info) RecordPositions(masm(), stmt->statement_pos(), false);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000442}
443
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000444
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000445void CodeGenerator::CodeForDoWhileConditionPosition(DoWhileStatement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000446 if (FLAG_debug_info)
447 RecordPositions(masm(), stmt->condition_position(), false);
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000448}
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000449
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000450
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000451void CodeGenerator::CodeForSourcePosition(int pos) {
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000452 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
453 masm()->RecordPosition(pos);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000454 }
455}
456
457
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000458const char* GenericUnaryOpStub::GetName() {
459 switch (op_) {
460 case Token::SUB:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000461 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 }
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000470 case Token::BIT_NOT:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +0000471 return overwrite_ == UNARY_OVERWRITE
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000472 ? "GenericUnaryOpStub_BIT_NOT_Overwrite"
473 : "GenericUnaryOpStub_BIT_NOT_Alloc";
474 default:
475 UNREACHABLE();
476 return "<unknown>";
477 }
478}
479
480
ager@chromium.org7c537e22008-10-16 08:43:32 +0000481void ArgumentsAccessStub::Generate(MacroAssembler* masm) {
482 switch (type_) {
ager@chromium.org7c537e22008-10-16 08:43:32 +0000483 case READ_ELEMENT: GenerateReadElement(masm); break;
484 case NEW_OBJECT: GenerateNewObject(masm); break;
485 }
486}
487
488
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +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
ager@chromium.orgc4c92722009-11-18 14:12:51 +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
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000516} } // namespace v8::internal