blob: c7e6f1c83f4a18533d915d3ae99ca59f72eaea35 [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;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100142 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
143 if (print_source && !filter.is_empty()) {
144 print_source = info->function()->name()->IsEqualTo(filter);
145 }
146 if (print_ast && !filter.is_empty()) {
147 print_ast = info->function()->name()->IsEqualTo(filter);
148 }
149 if (print_json_ast && !filter.is_empty()) {
150 print_json_ast = info->function()->name()->IsEqualTo(filter);
151 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000152 ftype = "user-defined";
153 }
154
155 if (FLAG_trace_codegen || print_source || print_ast) {
156 PrintF("*** Generate code for %s function: ", ftype);
Andrei Popescu31002712010-02-23 13:46:05 +0000157 info->function()->name()->ShortPrint();
Steve Blocka7e24c12009-10-30 11:49:00 +0000158 PrintF(" ***\n");
159 }
160
161 if (print_source) {
Andrei Popescu31002712010-02-23 13:46:05 +0000162 PrintF("--- Source from AST ---\n%s\n",
163 PrettyPrinter().PrintProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 }
165
166 if (print_ast) {
Andrei Popescu31002712010-02-23 13:46:05 +0000167 PrintF("--- AST ---\n%s\n",
168 AstPrinter().PrintProgram(info->function()));
Steve Block3ce2e202009-11-05 08:53:23 +0000169 }
170
171 if (print_json_ast) {
172 JsonAstBuilder builder;
Andrei Popescu31002712010-02-23 13:46:05 +0000173 PrintF("%s", builder.BuildProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000174 }
175#endif // DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +0000176}
Steve Blocka7e24c12009-10-30 11:49:00 +0000177
Steve Blocka7e24c12009-10-30 11:49:00 +0000178
Andrei Popescu31002712010-02-23 13:46:05 +0000179Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
Steve Block3ce2e202009-11-05 08:53:23 +0000180 Code::Flags flags,
Andrei Popescu31002712010-02-23 13:46:05 +0000181 CompilationInfo* info) {
Steve Block3ce2e202009-11-05 08:53:23 +0000182 // Allocate and install the code.
Steve Blocka7e24c12009-10-30 11:49:00 +0000183 CodeDesc desc;
Steve Block3ce2e202009-11-05 08:53:23 +0000184 masm->GetCode(&desc);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100185 Handle<Code> code = Factory::NewCode(desc, flags, masm->CodeObject());
Steve Blocka7e24c12009-10-30 11:49:00 +0000186
Ben Murdochb0fe1622011-05-05 13:52:32 +0100187 if (!code.is_null()) {
188 Counters::total_compiled_code_size.Increment(code->instruction_size());
189 }
190 return code;
191}
192
193
194void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000195#ifdef ENABLE_DISASSEMBLER
Steve Block3ce2e202009-11-05 08:53:23 +0000196 bool print_code = Bootstrapper::IsActive()
197 ? FLAG_print_builtin_code
Ben Murdochb0fe1622011-05-05 13:52:32 +0100198 : (FLAG_print_code || (info->IsOptimizing() && FLAG_print_opt_code));
199 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
200 FunctionLiteral* function = info->function();
201 bool match = filter.is_empty() || function->debug_name()->IsEqualTo(filter);
202 if (print_code && match) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 // Print the source code if available.
Andrei Popescu31002712010-02-23 13:46:05 +0000204 Handle<Script> script = info->script();
Steve Blocka7e24c12009-10-30 11:49:00 +0000205 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
206 PrintF("--- Raw source ---\n");
207 StringInputBuffer stream(String::cast(script->source()));
Andrei Popescu31002712010-02-23 13:46:05 +0000208 stream.Seek(function->start_position());
Steve Block3ce2e202009-11-05 08:53:23 +0000209 // fun->end_position() points to the last character in the stream. We
Steve Blocka7e24c12009-10-30 11:49:00 +0000210 // need to compensate by adding one to calculate the length.
Andrei Popescu31002712010-02-23 13:46:05 +0000211 int source_len =
212 function->end_position() - function->start_position() + 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 for (int i = 0; i < source_len; i++) {
214 if (stream.has_more()) PrintF("%c", stream.GetNext());
215 }
216 PrintF("\n\n");
217 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100218 if (info->IsOptimizing()) {
219 if (FLAG_print_unopt_code) {
220 PrintF("--- Unoptimized code ---\n");
221 info->closure()->shared()->code()->Disassemble(
222 *function->debug_name()->ToCString());
223 }
224 PrintF("--- Optimized code ---\n");
225 } else {
226 PrintF("--- Code ---\n");
227 }
228 code->Disassemble(*function->debug_name()->ToCString());
Steve Blocka7e24c12009-10-30 11:49:00 +0000229 }
230#endif // ENABLE_DISASSEMBLER
Steve Blocka7e24c12009-10-30 11:49:00 +0000231}
232
233
Ben Murdochf87a2032010-10-22 12:50:53 +0100234// Generate the code. Compile the AST and assemble all the pieces into a
235// Code object.
236bool CodeGenerator::MakeCode(CompilationInfo* info) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100237 // When using Crankshaft the classic backend should never be used.
238 ASSERT(!V8::UseCrankshaft());
Andrei Popescu31002712010-02-23 13:46:05 +0000239 Handle<Script> script = info->script();
Leon Clarked91b9f72010-01-27 17:25:45 +0000240 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
241 int len = String::cast(script->source())->length();
242 Counters::total_old_codegen_source_size.Increment(len);
243 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100244 if (FLAG_trace_codegen) {
245 PrintF("Classic Compiler - ");
246 }
Andrei Popescu31002712010-02-23 13:46:05 +0000247 MakeCodePrologue(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000248 // Generate code.
249 const int kInitialBufferSize = 4 * KB;
Leon Clarke4515c472010-02-03 11:58:03 +0000250 MacroAssembler masm(NULL, kInitialBufferSize);
Ben Murdochb8e0da22011-05-16 14:20:40 +0100251#ifdef ENABLE_GDB_JIT_INTERFACE
252 masm.positions_recorder()->StartGDBJITLineInfoRecording();
253#endif
Andrei Popescu31002712010-02-23 13:46:05 +0000254 CodeGenerator cgen(&masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000255 CodeGeneratorScope scope(&cgen);
Andrei Popescu402d9372010-02-26 13:31:12 +0000256 cgen.Generate(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000257 if (cgen.HasStackOverflow()) {
258 ASSERT(!Top::has_pending_exception());
Ben Murdochf87a2032010-10-22 12:50:53 +0100259 return false;
Steve Block3ce2e202009-11-05 08:53:23 +0000260 }
261
Ben Murdochf87a2032010-10-22 12:50:53 +0100262 InLoopFlag in_loop = info->is_in_loop() ? IN_LOOP : NOT_IN_LOOP;
Steve Block3ce2e202009-11-05 08:53:23 +0000263 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop);
Ben Murdochf87a2032010-10-22 12:50:53 +0100264 Handle<Code> code = MakeCodeEpilogue(cgen.masm(), flags, info);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100265 // There is no stack check table in code generated by the classic backend.
266 code->SetNoStackCheckTable();
267 CodeGenerator::PrintCode(code, info);
Ben Murdochf87a2032010-10-22 12:50:53 +0100268 info->SetCode(code); // May be an empty handle.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100269#ifdef ENABLE_GDB_JIT_INTERFACE
270 if (!code.is_null()) {
271 GDBJITLineInfo* lineinfo =
272 masm.positions_recorder()->DetachGDBJITLineInfo();
273
274 GDBJIT(RegisterDetailedLineInfo(*code, lineinfo));
275 }
276#endif
Ben Murdochf87a2032010-10-22 12:50:53 +0100277 return !code.is_null();
Steve Block3ce2e202009-11-05 08:53:23 +0000278}
279
280
Steve Blocka7e24c12009-10-30 11:49:00 +0000281#ifdef ENABLE_LOGGING_AND_PROFILING
282
283bool CodeGenerator::ShouldGenerateLog(Expression* type) {
284 ASSERT(type != NULL);
Steve Block6ded16b2010-05-10 14:33:55 +0100285 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
287 if (FLAG_log_regexp) {
288 static Vector<const char> kRegexp = CStrVector("regexp");
289 if (name->IsEqualTo(kRegexp))
290 return true;
291 }
292 return false;
293}
294
295#endif
296
297
Steve Blocka7e24c12009-10-30 11:49:00 +0000298void CodeGenerator::ProcessDeclarations(ZoneList<Declaration*>* declarations) {
299 int length = declarations->length();
300 int globals = 0;
301 for (int i = 0; i < length; i++) {
302 Declaration* node = declarations->at(i);
303 Variable* var = node->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100304 Slot* slot = var->AsSlot();
Steve Blocka7e24c12009-10-30 11:49:00 +0000305
306 // If it was not possible to allocate the variable at compile
307 // time, we need to "declare" it at runtime to make sure it
308 // actually exists in the local context.
309 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
310 VisitDeclaration(node);
311 } else {
312 // Count global variables and functions for later processing
313 globals++;
314 }
315 }
316
317 // Return in case of no declared global functions or variables.
318 if (globals == 0) return;
319
320 // Compute array of global variable and function declarations.
321 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED);
322 for (int j = 0, i = 0; i < length; i++) {
323 Declaration* node = declarations->at(i);
324 Variable* var = node->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100325 Slot* slot = var->AsSlot();
Steve Blocka7e24c12009-10-30 11:49:00 +0000326
327 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
328 // Skip - already processed.
329 } else {
330 array->set(j++, *(var->name()));
331 if (node->fun() == NULL) {
332 if (var->mode() == Variable::CONST) {
333 // In case this is const property use the hole.
334 array->set_the_hole(j++);
335 } else {
336 array->set_undefined(j++);
337 }
338 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100339 Handle<SharedFunctionInfo> function =
Ben Murdochf87a2032010-10-22 12:50:53 +0100340 Compiler::BuildFunctionInfo(node->fun(), script());
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 // Check for stack-overflow exception.
Ben Murdochf87a2032010-10-22 12:50:53 +0100342 if (function.is_null()) {
343 SetStackOverflow();
344 return;
345 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000346 array->set(j++, *function);
347 }
348 }
349 }
350
351 // Invoke the platform-dependent code generator to do the actual
352 // declaration the global variables and functions.
353 DeclareGlobals(array);
354}
355
356
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100357void CodeGenerator::VisitIncrementOperation(IncrementOperation* expr) {
358 UNREACHABLE();
359}
360
361
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100362// Lookup table for code generators for special runtime calls which are
363// generated inline.
364#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
365 &CodeGenerator::Generate##Name,
Steve Blocka7e24c12009-10-30 11:49:00 +0000366
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100367const CodeGenerator::InlineFunctionGenerator
368 CodeGenerator::kInlineFunctionGenerators[] = {
369 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
370 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
Steve Blocka7e24c12009-10-30 11:49:00 +0000371};
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100372#undef INLINE_FUNCTION_GENERATOR_ADDRESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000373
374
Steve Blocka7e24c12009-10-30 11:49:00 +0000375bool CodeGenerator::CheckForInlineRuntimeCall(CallRuntime* node) {
376 ZoneList<Expression*>* args = node->arguments();
377 Handle<String> name = node->name();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100378 Runtime::Function* function = node->function();
379 if (function != NULL && function->intrinsic_type == Runtime::INLINE) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100380 int lookup_index = static_cast<int>(function->function_id) -
381 static_cast<int>(Runtime::kFirstInlineFunction);
382 ASSERT(lookup_index >= 0);
383 ASSERT(static_cast<size_t>(lookup_index) <
384 ARRAY_SIZE(kInlineFunctionGenerators));
385 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index];
386 (this->*generator)(args);
387 return true;
Steve Blocka7e24c12009-10-30 11:49:00 +0000388 }
389 return false;
390}
391
392
Steve Block3ce2e202009-11-05 08:53:23 +0000393// Simple condition analysis. ALWAYS_TRUE and ALWAYS_FALSE represent a
394// known result for the test expression, with no side effects.
395CodeGenerator::ConditionAnalysis CodeGenerator::AnalyzeCondition(
396 Expression* cond) {
397 if (cond == NULL) return ALWAYS_TRUE;
398
399 Literal* lit = cond->AsLiteral();
400 if (lit == NULL) return DONT_KNOW;
401
402 if (lit->IsTrue()) {
403 return ALWAYS_TRUE;
404 } else if (lit->IsFalse()) {
405 return ALWAYS_FALSE;
406 }
407
408 return DONT_KNOW;
409}
410
411
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100412bool CodeGenerator::RecordPositions(MacroAssembler* masm,
413 int pos,
414 bool right_here) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000415 if (pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800416 masm->positions_recorder()->RecordStatementPosition(pos);
417 masm->positions_recorder()->RecordPosition(pos);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100418 if (right_here) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800419 return masm->positions_recorder()->WriteRecordedPositions();
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100420 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000421 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100422 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000423}
424
425
426void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100427 if (FLAG_debug_info) RecordPositions(masm(), fun->start_position(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000428}
429
430
431void CodeGenerator::CodeForReturnPosition(FunctionLiteral* fun) {
Ben Murdochbb769b22010-08-11 14:56:33 +0100432 if (FLAG_debug_info) RecordPositions(masm(), fun->end_position() - 1, false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000433}
434
435
436void CodeGenerator::CodeForStatementPosition(Statement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100437 if (FLAG_debug_info) RecordPositions(masm(), stmt->statement_pos(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000438}
439
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100440
Steve Blockd0582a62009-12-15 09:54:21 +0000441void CodeGenerator::CodeForDoWhileConditionPosition(DoWhileStatement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100442 if (FLAG_debug_info)
443 RecordPositions(masm(), stmt->condition_position(), false);
Steve Blockd0582a62009-12-15 09:54:21 +0000444}
Steve Blocka7e24c12009-10-30 11:49:00 +0000445
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100446
Steve Blocka7e24c12009-10-30 11:49:00 +0000447void CodeGenerator::CodeForSourcePosition(int pos) {
448 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800449 masm()->positions_recorder()->RecordPosition(pos);
Steve Blocka7e24c12009-10-30 11:49:00 +0000450 }
451}
452
453
Leon Clarkee46be812010-01-19 14:06:41 +0000454const char* GenericUnaryOpStub::GetName() {
455 switch (op_) {
456 case Token::SUB:
Leon Clarkeac952652010-07-15 11:15:24 +0100457 if (negative_zero_ == kStrictNegativeZero) {
458 return overwrite_ == UNARY_OVERWRITE
459 ? "GenericUnaryOpStub_SUB_Overwrite_Strict0"
460 : "GenericUnaryOpStub_SUB_Alloc_Strict0";
461 } else {
462 return overwrite_ == UNARY_OVERWRITE
463 ? "GenericUnaryOpStub_SUB_Overwrite_Ignore0"
464 : "GenericUnaryOpStub_SUB_Alloc_Ignore0";
465 }
Leon Clarkee46be812010-01-19 14:06:41 +0000466 case Token::BIT_NOT:
Leon Clarkeac952652010-07-15 11:15:24 +0100467 return overwrite_ == UNARY_OVERWRITE
Leon Clarkee46be812010-01-19 14:06:41 +0000468 ? "GenericUnaryOpStub_BIT_NOT_Overwrite"
469 : "GenericUnaryOpStub_BIT_NOT_Alloc";
470 default:
471 UNREACHABLE();
472 return "<unknown>";
473 }
474}
475
476
Steve Blocka7e24c12009-10-30 11:49:00 +0000477void ArgumentsAccessStub::Generate(MacroAssembler* masm) {
478 switch (type_) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000479 case READ_ELEMENT: GenerateReadElement(masm); break;
480 case NEW_OBJECT: GenerateNewObject(masm); break;
481 }
482}
483
484
Leon Clarke4515c472010-02-03 11:58:03 +0000485int CEntryStub::MinorKey() {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100486 ASSERT(result_size_ == 1 || result_size_ == 2);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100487 int result = save_doubles_ ? 1 : 0;
Leon Clarke4515c472010-02-03 11:58:03 +0000488#ifdef _WIN64
Ben Murdochb0fe1622011-05-05 13:52:32 +0100489 return result | ((result_size_ == 1) ? 0 : 2);
Leon Clarke4515c472010-02-03 11:58:03 +0000490#else
Ben Murdochb0fe1622011-05-05 13:52:32 +0100491 return result;
Leon Clarke4515c472010-02-03 11:58:03 +0000492#endif
493}
494
495
Steve Blocka7e24c12009-10-30 11:49:00 +0000496} } // namespace v8::internal