blob: e6fcecde7bfd301a4ccd4573840d100a72cd01f4 [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"
Steve Blocka7e24c12009-10-30 11:49:00 +000034#include "prettyprinter.h"
35#include "register-allocator-inl.h"
36#include "rewriter.h"
37#include "runtime.h"
38#include "scopeinfo.h"
39#include "stub-cache.h"
Steve Block6ded16b2010-05-10 14:33:55 +010040#include "virtual-frame-inl.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000041
42namespace v8 {
43namespace internal {
44
Andrei Popescu31002712010-02-23 13:46:05 +000045#define __ ACCESS_MASM(masm_)
46
47#ifdef DEBUG
48
49Comment::Comment(MacroAssembler* masm, const char* msg)
50 : masm_(masm), msg_(msg) {
51 __ RecordComment(msg);
52}
53
54
55Comment::~Comment() {
56 if (msg_[0] == '[') __ RecordComment("]");
57}
58
59#endif // DEBUG
60
61#undef __
62
Steve Blocka7e24c12009-10-30 11:49:00 +000063
64CodeGenerator* CodeGeneratorScope::top_ = NULL;
65
66
Steve Blocka7e24c12009-10-30 11:49:00 +000067void CodeGenerator::ProcessDeferred() {
68 while (!deferred_.is_empty()) {
69 DeferredCode* code = deferred_.RemoveLast();
70 ASSERT(masm_ == code->masm());
71 // Record position of deferred code stub.
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -080072 masm_->positions_recorder()->RecordStatementPosition(
73 code->statement_position());
Steve Blocka7e24c12009-10-30 11:49:00 +000074 if (code->position() != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -080075 masm_->positions_recorder()->RecordPosition(code->position());
Steve Blocka7e24c12009-10-30 11:49:00 +000076 }
77 // Generate the code.
78 Comment cmnt(masm_, code->comment());
79 masm_->bind(code->entry_label());
Iain Merrick75681382010-08-19 15:07:18 +010080 if (code->AutoSaveAndRestore()) {
81 code->SaveRegisters();
82 }
Steve Blocka7e24c12009-10-30 11:49:00 +000083 code->Generate();
Iain Merrick75681382010-08-19 15:07:18 +010084 if (code->AutoSaveAndRestore()) {
85 code->RestoreRegisters();
86 code->Exit();
87 }
Steve Blocka7e24c12009-10-30 11:49:00 +000088 }
89}
90
91
Iain Merrick75681382010-08-19 15:07:18 +010092void DeferredCode::Exit() {
93 masm_->jmp(exit_label());
94}
95
96
Steve Blocka7e24c12009-10-30 11:49:00 +000097void CodeGenerator::SetFrame(VirtualFrame* new_frame,
98 RegisterFile* non_frame_registers) {
99 RegisterFile saved_counts;
100 if (has_valid_frame()) {
101 frame_->DetachFromCodeGenerator();
102 // The remaining register reference counts are the non-frame ones.
103 allocator_->SaveTo(&saved_counts);
104 }
105
106 if (new_frame != NULL) {
107 // Restore the non-frame register references that go with the new frame.
108 allocator_->RestoreFrom(non_frame_registers);
109 new_frame->AttachToCodeGenerator();
110 }
111
112 frame_ = new_frame;
113 saved_counts.CopyTo(non_frame_registers);
114}
115
116
117void CodeGenerator::DeleteFrame() {
118 if (has_valid_frame()) {
119 frame_->DetachFromCodeGenerator();
120 frame_ = NULL;
121 }
122}
123
124
Andrei Popescu31002712010-02-23 13:46:05 +0000125void CodeGenerator::MakeCodePrologue(CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000126#ifdef DEBUG
127 bool print_source = false;
128 bool print_ast = false;
Steve Block3ce2e202009-11-05 08:53:23 +0000129 bool print_json_ast = false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000130 const char* ftype;
131
132 if (Bootstrapper::IsActive()) {
133 print_source = FLAG_print_builtin_source;
134 print_ast = FLAG_print_builtin_ast;
Steve Block3ce2e202009-11-05 08:53:23 +0000135 print_json_ast = FLAG_print_builtin_json_ast;
Steve Blocka7e24c12009-10-30 11:49:00 +0000136 ftype = "builtin";
137 } else {
138 print_source = FLAG_print_source;
139 print_ast = FLAG_print_ast;
Steve Block3ce2e202009-11-05 08:53:23 +0000140 print_json_ast = FLAG_print_json_ast;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100141 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
142 if (print_source && !filter.is_empty()) {
143 print_source = info->function()->name()->IsEqualTo(filter);
144 }
145 if (print_ast && !filter.is_empty()) {
146 print_ast = info->function()->name()->IsEqualTo(filter);
147 }
148 if (print_json_ast && !filter.is_empty()) {
149 print_json_ast = info->function()->name()->IsEqualTo(filter);
150 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000151 ftype = "user-defined";
152 }
153
154 if (FLAG_trace_codegen || print_source || print_ast) {
155 PrintF("*** Generate code for %s function: ", ftype);
Andrei Popescu31002712010-02-23 13:46:05 +0000156 info->function()->name()->ShortPrint();
Steve Blocka7e24c12009-10-30 11:49:00 +0000157 PrintF(" ***\n");
158 }
159
160 if (print_source) {
Andrei Popescu31002712010-02-23 13:46:05 +0000161 PrintF("--- Source from AST ---\n%s\n",
162 PrettyPrinter().PrintProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000163 }
164
165 if (print_ast) {
Andrei Popescu31002712010-02-23 13:46:05 +0000166 PrintF("--- AST ---\n%s\n",
167 AstPrinter().PrintProgram(info->function()));
Steve Block3ce2e202009-11-05 08:53:23 +0000168 }
169
170 if (print_json_ast) {
171 JsonAstBuilder builder;
Andrei Popescu31002712010-02-23 13:46:05 +0000172 PrintF("%s", builder.BuildProgram(info->function()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000173 }
174#endif // DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +0000175}
Steve Blocka7e24c12009-10-30 11:49:00 +0000176
Steve Blocka7e24c12009-10-30 11:49:00 +0000177
Andrei Popescu31002712010-02-23 13:46:05 +0000178Handle<Code> CodeGenerator::MakeCodeEpilogue(MacroAssembler* masm,
Steve Block3ce2e202009-11-05 08:53:23 +0000179 Code::Flags flags,
Andrei Popescu31002712010-02-23 13:46:05 +0000180 CompilationInfo* info) {
Steve Block3ce2e202009-11-05 08:53:23 +0000181 // Allocate and install the code.
Steve Blocka7e24c12009-10-30 11:49:00 +0000182 CodeDesc desc;
Steve Block3ce2e202009-11-05 08:53:23 +0000183 masm->GetCode(&desc);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100184 Handle<Code> code = Factory::NewCode(desc, flags, masm->CodeObject());
Steve Blocka7e24c12009-10-30 11:49:00 +0000185
Ben Murdochb0fe1622011-05-05 13:52:32 +0100186 if (!code.is_null()) {
187 Counters::total_compiled_code_size.Increment(code->instruction_size());
188 }
189 return code;
190}
191
192
193void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000194#ifdef ENABLE_DISASSEMBLER
Steve Block3ce2e202009-11-05 08:53:23 +0000195 bool print_code = Bootstrapper::IsActive()
196 ? FLAG_print_builtin_code
Ben Murdochb0fe1622011-05-05 13:52:32 +0100197 : (FLAG_print_code || (info->IsOptimizing() && FLAG_print_opt_code));
198 Vector<const char> filter = CStrVector(FLAG_hydrogen_filter);
199 FunctionLiteral* function = info->function();
200 bool match = filter.is_empty() || function->debug_name()->IsEqualTo(filter);
201 if (print_code && match) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000202 // Print the source code if available.
Andrei Popescu31002712010-02-23 13:46:05 +0000203 Handle<Script> script = info->script();
Steve Blocka7e24c12009-10-30 11:49:00 +0000204 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
205 PrintF("--- Raw source ---\n");
206 StringInputBuffer stream(String::cast(script->source()));
Andrei Popescu31002712010-02-23 13:46:05 +0000207 stream.Seek(function->start_position());
Steve Block3ce2e202009-11-05 08:53:23 +0000208 // fun->end_position() points to the last character in the stream. We
Steve Blocka7e24c12009-10-30 11:49:00 +0000209 // need to compensate by adding one to calculate the length.
Andrei Popescu31002712010-02-23 13:46:05 +0000210 int source_len =
211 function->end_position() - function->start_position() + 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000212 for (int i = 0; i < source_len; i++) {
213 if (stream.has_more()) PrintF("%c", stream.GetNext());
214 }
215 PrintF("\n\n");
216 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100217 if (info->IsOptimizing()) {
218 if (FLAG_print_unopt_code) {
219 PrintF("--- Unoptimized code ---\n");
220 info->closure()->shared()->code()->Disassemble(
221 *function->debug_name()->ToCString());
222 }
223 PrintF("--- Optimized code ---\n");
224 } else {
225 PrintF("--- Code ---\n");
226 }
227 code->Disassemble(*function->debug_name()->ToCString());
Steve Blocka7e24c12009-10-30 11:49:00 +0000228 }
229#endif // ENABLE_DISASSEMBLER
Steve Blocka7e24c12009-10-30 11:49:00 +0000230}
231
232
Ben Murdochf87a2032010-10-22 12:50:53 +0100233// Generate the code. Compile the AST and assemble all the pieces into a
234// Code object.
235bool CodeGenerator::MakeCode(CompilationInfo* info) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100236 // When using Crankshaft the classic backend should never be used.
237 ASSERT(!V8::UseCrankshaft());
Andrei Popescu31002712010-02-23 13:46:05 +0000238 Handle<Script> script = info->script();
Leon Clarked91b9f72010-01-27 17:25:45 +0000239 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
240 int len = String::cast(script->source())->length();
241 Counters::total_old_codegen_source_size.Increment(len);
242 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100243 if (FLAG_trace_codegen) {
244 PrintF("Classic Compiler - ");
245 }
Andrei Popescu31002712010-02-23 13:46:05 +0000246 MakeCodePrologue(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000247 // Generate code.
248 const int kInitialBufferSize = 4 * KB;
Leon Clarke4515c472010-02-03 11:58:03 +0000249 MacroAssembler masm(NULL, kInitialBufferSize);
Ben Murdochb8e0da22011-05-16 14:20:40 +0100250#ifdef ENABLE_GDB_JIT_INTERFACE
251 masm.positions_recorder()->StartGDBJITLineInfoRecording();
252#endif
Andrei Popescu31002712010-02-23 13:46:05 +0000253 CodeGenerator cgen(&masm);
Steve Block3ce2e202009-11-05 08:53:23 +0000254 CodeGeneratorScope scope(&cgen);
Andrei Popescu402d9372010-02-26 13:31:12 +0000255 cgen.Generate(info);
Steve Block3ce2e202009-11-05 08:53:23 +0000256 if (cgen.HasStackOverflow()) {
257 ASSERT(!Top::has_pending_exception());
Ben Murdochf87a2032010-10-22 12:50:53 +0100258 return false;
Steve Block3ce2e202009-11-05 08:53:23 +0000259 }
260
Ben Murdochf87a2032010-10-22 12:50:53 +0100261 InLoopFlag in_loop = info->is_in_loop() ? IN_LOOP : NOT_IN_LOOP;
Steve Block3ce2e202009-11-05 08:53:23 +0000262 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop);
Ben Murdochf87a2032010-10-22 12:50:53 +0100263 Handle<Code> code = MakeCodeEpilogue(cgen.masm(), flags, info);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100264 // There is no stack check table in code generated by the classic backend.
265 code->SetNoStackCheckTable();
266 CodeGenerator::PrintCode(code, info);
Ben Murdochf87a2032010-10-22 12:50:53 +0100267 info->SetCode(code); // May be an empty handle.
Ben Murdochb8e0da22011-05-16 14:20:40 +0100268#ifdef ENABLE_GDB_JIT_INTERFACE
Steve Block1e0659c2011-05-24 12:43:12 +0100269 if (FLAG_gdbjit && !code.is_null()) {
Ben Murdochb8e0da22011-05-16 14:20:40 +0100270 GDBJITLineInfo* lineinfo =
271 masm.positions_recorder()->DetachGDBJITLineInfo();
272
273 GDBJIT(RegisterDetailedLineInfo(*code, lineinfo));
274 }
275#endif
Ben Murdochf87a2032010-10-22 12:50:53 +0100276 return !code.is_null();
Steve Block3ce2e202009-11-05 08:53:23 +0000277}
278
279
Steve Blocka7e24c12009-10-30 11:49:00 +0000280#ifdef ENABLE_LOGGING_AND_PROFILING
281
282bool CodeGenerator::ShouldGenerateLog(Expression* type) {
283 ASSERT(type != NULL);
Steve Block6ded16b2010-05-10 14:33:55 +0100284 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
286 if (FLAG_log_regexp) {
287 static Vector<const char> kRegexp = CStrVector("regexp");
288 if (name->IsEqualTo(kRegexp))
289 return true;
290 }
291 return false;
292}
293
294#endif
295
296
Steve Blocka7e24c12009-10-30 11:49:00 +0000297void CodeGenerator::ProcessDeclarations(ZoneList<Declaration*>* declarations) {
298 int length = declarations->length();
299 int globals = 0;
300 for (int i = 0; i < length; i++) {
301 Declaration* node = declarations->at(i);
302 Variable* var = node->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100303 Slot* slot = var->AsSlot();
Steve Blocka7e24c12009-10-30 11:49:00 +0000304
305 // If it was not possible to allocate the variable at compile
306 // time, we need to "declare" it at runtime to make sure it
307 // actually exists in the local context.
308 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
309 VisitDeclaration(node);
310 } else {
311 // Count global variables and functions for later processing
312 globals++;
313 }
314 }
315
316 // Return in case of no declared global functions or variables.
317 if (globals == 0) return;
318
319 // Compute array of global variable and function declarations.
320 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED);
321 for (int j = 0, i = 0; i < length; i++) {
322 Declaration* node = declarations->at(i);
323 Variable* var = node->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100324 Slot* slot = var->AsSlot();
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
326 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
327 // Skip - already processed.
328 } else {
329 array->set(j++, *(var->name()));
330 if (node->fun() == NULL) {
331 if (var->mode() == Variable::CONST) {
332 // In case this is const property use the hole.
333 array->set_the_hole(j++);
334 } else {
335 array->set_undefined(j++);
336 }
337 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100338 Handle<SharedFunctionInfo> function =
Ben Murdochf87a2032010-10-22 12:50:53 +0100339 Compiler::BuildFunctionInfo(node->fun(), script());
Steve Blocka7e24c12009-10-30 11:49:00 +0000340 // Check for stack-overflow exception.
Ben Murdochf87a2032010-10-22 12:50:53 +0100341 if (function.is_null()) {
342 SetStackOverflow();
343 return;
344 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 array->set(j++, *function);
346 }
347 }
348 }
349
350 // Invoke the platform-dependent code generator to do the actual
351 // declaration the global variables and functions.
352 DeclareGlobals(array);
353}
354
355
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100356void CodeGenerator::VisitIncrementOperation(IncrementOperation* expr) {
357 UNREACHABLE();
358}
359
360
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100361// Lookup table for code generators for special runtime calls which are
362// generated inline.
363#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
364 &CodeGenerator::Generate##Name,
Steve Blocka7e24c12009-10-30 11:49:00 +0000365
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100366const CodeGenerator::InlineFunctionGenerator
367 CodeGenerator::kInlineFunctionGenerators[] = {
368 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
369 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
Steve Blocka7e24c12009-10-30 11:49:00 +0000370};
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100371#undef INLINE_FUNCTION_GENERATOR_ADDRESS
Steve Blocka7e24c12009-10-30 11:49:00 +0000372
373
Steve Blocka7e24c12009-10-30 11:49:00 +0000374bool CodeGenerator::CheckForInlineRuntimeCall(CallRuntime* node) {
375 ZoneList<Expression*>* args = node->arguments();
376 Handle<String> name = node->name();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100377 Runtime::Function* function = node->function();
378 if (function != NULL && function->intrinsic_type == Runtime::INLINE) {
Ben Murdochf87a2032010-10-22 12:50:53 +0100379 int lookup_index = static_cast<int>(function->function_id) -
380 static_cast<int>(Runtime::kFirstInlineFunction);
381 ASSERT(lookup_index >= 0);
382 ASSERT(static_cast<size_t>(lookup_index) <
383 ARRAY_SIZE(kInlineFunctionGenerators));
384 InlineFunctionGenerator generator = kInlineFunctionGenerators[lookup_index];
385 (this->*generator)(args);
386 return true;
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 }
388 return false;
389}
390
391
Steve Block3ce2e202009-11-05 08:53:23 +0000392// Simple condition analysis. ALWAYS_TRUE and ALWAYS_FALSE represent a
393// known result for the test expression, with no side effects.
394CodeGenerator::ConditionAnalysis CodeGenerator::AnalyzeCondition(
395 Expression* cond) {
396 if (cond == NULL) return ALWAYS_TRUE;
397
398 Literal* lit = cond->AsLiteral();
399 if (lit == NULL) return DONT_KNOW;
400
401 if (lit->IsTrue()) {
402 return ALWAYS_TRUE;
403 } else if (lit->IsFalse()) {
404 return ALWAYS_FALSE;
405 }
406
407 return DONT_KNOW;
408}
409
410
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100411bool CodeGenerator::RecordPositions(MacroAssembler* masm,
412 int pos,
413 bool right_here) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000414 if (pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800415 masm->positions_recorder()->RecordStatementPosition(pos);
416 masm->positions_recorder()->RecordPosition(pos);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100417 if (right_here) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800418 return masm->positions_recorder()->WriteRecordedPositions();
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100419 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000420 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100421 return false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000422}
423
424
425void CodeGenerator::CodeForFunctionPosition(FunctionLiteral* fun) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100426 if (FLAG_debug_info) RecordPositions(masm(), fun->start_position(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000427}
428
429
430void CodeGenerator::CodeForReturnPosition(FunctionLiteral* fun) {
Ben Murdochbb769b22010-08-11 14:56:33 +0100431 if (FLAG_debug_info) RecordPositions(masm(), fun->end_position() - 1, false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000432}
433
434
435void CodeGenerator::CodeForStatementPosition(Statement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100436 if (FLAG_debug_info) RecordPositions(masm(), stmt->statement_pos(), false);
Steve Blocka7e24c12009-10-30 11:49:00 +0000437}
438
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100439
Steve Blockd0582a62009-12-15 09:54:21 +0000440void CodeGenerator::CodeForDoWhileConditionPosition(DoWhileStatement* stmt) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100441 if (FLAG_debug_info)
442 RecordPositions(masm(), stmt->condition_position(), false);
Steve Blockd0582a62009-12-15 09:54:21 +0000443}
Steve Blocka7e24c12009-10-30 11:49:00 +0000444
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100445
Steve Blocka7e24c12009-10-30 11:49:00 +0000446void CodeGenerator::CodeForSourcePosition(int pos) {
447 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800448 masm()->positions_recorder()->RecordPosition(pos);
Steve Blocka7e24c12009-10-30 11:49:00 +0000449 }
450}
451
452
Leon Clarkee46be812010-01-19 14:06:41 +0000453const char* GenericUnaryOpStub::GetName() {
454 switch (op_) {
455 case Token::SUB:
Leon Clarkeac952652010-07-15 11:15:24 +0100456 if (negative_zero_ == kStrictNegativeZero) {
457 return overwrite_ == UNARY_OVERWRITE
458 ? "GenericUnaryOpStub_SUB_Overwrite_Strict0"
459 : "GenericUnaryOpStub_SUB_Alloc_Strict0";
460 } else {
461 return overwrite_ == UNARY_OVERWRITE
462 ? "GenericUnaryOpStub_SUB_Overwrite_Ignore0"
463 : "GenericUnaryOpStub_SUB_Alloc_Ignore0";
464 }
Leon Clarkee46be812010-01-19 14:06:41 +0000465 case Token::BIT_NOT:
Leon Clarkeac952652010-07-15 11:15:24 +0100466 return overwrite_ == UNARY_OVERWRITE
Leon Clarkee46be812010-01-19 14:06:41 +0000467 ? "GenericUnaryOpStub_BIT_NOT_Overwrite"
468 : "GenericUnaryOpStub_BIT_NOT_Alloc";
469 default:
470 UNREACHABLE();
471 return "<unknown>";
472 }
473}
474
475
Steve Blocka7e24c12009-10-30 11:49:00 +0000476void ArgumentsAccessStub::Generate(MacroAssembler* masm) {
477 switch (type_) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 case READ_ELEMENT: GenerateReadElement(masm); break;
479 case NEW_OBJECT: GenerateNewObject(masm); break;
480 }
481}
482
483
Leon Clarke4515c472010-02-03 11:58:03 +0000484int CEntryStub::MinorKey() {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100485 ASSERT(result_size_ == 1 || result_size_ == 2);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100486 int result = save_doubles_ ? 1 : 0;
Leon Clarke4515c472010-02-03 11:58:03 +0000487#ifdef _WIN64
Ben Murdochb0fe1622011-05-05 13:52:32 +0100488 return result | ((result_size_ == 1) ? 0 : 2);
Leon Clarke4515c472010-02-03 11:58:03 +0000489#else
Ben Murdochb0fe1622011-05-05 13:52:32 +0100490 return result;
Leon Clarke4515c472010-02-03 11:58:03 +0000491#endif
492}
493
494
Steve Blocka7e24c12009-10-30 11:49:00 +0000495} } // namespace v8::internal