OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 199 } |
200 #endif // ENABLE_DISASSEMBLER | 200 #endif // ENABLE_DISASSEMBLER |
201 | 201 |
202 if (!code.is_null()) { | 202 if (!code.is_null()) { |
203 Counters::total_compiled_code_size.Increment(code->instruction_size()); | 203 Counters::total_compiled_code_size.Increment(code->instruction_size()); |
204 } | 204 } |
205 return code; | 205 return code; |
206 } | 206 } |
207 | 207 |
208 | 208 |
209 // Generate the code. Takes a function literal, generates code for it, assemble | 209 // Generate the code. Compile the AST and assemble all the pieces into a |
210 // all the pieces into a Code object. This function is only to be called by | 210 // Code object. |
211 // the compiler.cc code. | 211 bool CodeGenerator::MakeCode(CompilationInfo* info) { |
212 Handle<Code> CodeGenerator::MakeCode(CompilationInfo* info) { | |
213 Handle<Script> script = info->script(); | 212 Handle<Script> script = info->script(); |
214 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 213 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
215 int len = String::cast(script->source())->length(); | 214 int len = String::cast(script->source())->length(); |
216 Counters::total_old_codegen_source_size.Increment(len); | 215 Counters::total_old_codegen_source_size.Increment(len); |
217 } | 216 } |
218 MakeCodePrologue(info); | 217 MakeCodePrologue(info); |
219 // Generate code. | 218 // Generate code. |
220 const int kInitialBufferSize = 4 * KB; | 219 const int kInitialBufferSize = 4 * KB; |
221 MacroAssembler masm(NULL, kInitialBufferSize); | 220 MacroAssembler masm(NULL, kInitialBufferSize); |
222 CodeGenerator cgen(&masm); | 221 CodeGenerator cgen(&masm); |
223 CodeGeneratorScope scope(&cgen); | 222 CodeGeneratorScope scope(&cgen); |
224 cgen.Generate(info); | 223 cgen.Generate(info); |
225 if (cgen.HasStackOverflow()) { | 224 if (cgen.HasStackOverflow()) { |
226 ASSERT(!Top::has_pending_exception()); | 225 ASSERT(!Top::has_pending_exception()); |
227 return Handle<Code>::null(); | 226 return false; |
228 } | 227 } |
229 | 228 |
230 InLoopFlag in_loop = (cgen.loop_nesting() != 0) ? IN_LOOP : NOT_IN_LOOP; | 229 InLoopFlag in_loop = info->is_in_loop() ? IN_LOOP : NOT_IN_LOOP; |
231 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop); | 230 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, in_loop); |
232 return MakeCodeEpilogue(cgen.masm(), flags, info); | 231 Handle<Code> code = MakeCodeEpilogue(cgen.masm(), flags, info); |
| 232 info->SetCode(code); // May be an empty handle. |
| 233 return !code.is_null(); |
233 } | 234 } |
234 | 235 |
235 | 236 |
236 #ifdef ENABLE_LOGGING_AND_PROFILING | 237 #ifdef ENABLE_LOGGING_AND_PROFILING |
237 | 238 |
238 bool CodeGenerator::ShouldGenerateLog(Expression* type) { | 239 bool CodeGenerator::ShouldGenerateLog(Expression* type) { |
239 ASSERT(type != NULL); | 240 ASSERT(type != NULL); |
240 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false; | 241 if (!Logger::is_logging() && !CpuProfiler::is_profiling()) return false; |
241 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle()); | 242 Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle()); |
242 if (FLAG_log_regexp) { | 243 if (FLAG_log_regexp) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 array->set(j++, *(var->name())); | 319 array->set(j++, *(var->name())); |
319 if (node->fun() == NULL) { | 320 if (node->fun() == NULL) { |
320 if (var->mode() == Variable::CONST) { | 321 if (var->mode() == Variable::CONST) { |
321 // In case this is const property use the hole. | 322 // In case this is const property use the hole. |
322 array->set_the_hole(j++); | 323 array->set_the_hole(j++); |
323 } else { | 324 } else { |
324 array->set_undefined(j++); | 325 array->set_undefined(j++); |
325 } | 326 } |
326 } else { | 327 } else { |
327 Handle<SharedFunctionInfo> function = | 328 Handle<SharedFunctionInfo> function = |
328 Compiler::BuildFunctionInfo(node->fun(), script(), this); | 329 Compiler::BuildFunctionInfo(node->fun(), script()); |
329 // Check for stack-overflow exception. | 330 // Check for stack-overflow exception. |
330 if (HasStackOverflow()) return; | 331 if (function.is_null()) { |
| 332 SetStackOverflow(); |
| 333 return; |
| 334 } |
331 array->set(j++, *function); | 335 array->set(j++, *function); |
332 } | 336 } |
333 } | 337 } |
334 } | 338 } |
335 | 339 |
336 // Invoke the platform-dependent code generator to do the actual | 340 // Invoke the platform-dependent code generator to do the actual |
337 // declaration the global variables and functions. | 341 // declaration the global variables and functions. |
338 DeclareGlobals(array); | 342 DeclareGlobals(array); |
339 } | 343 } |
340 | 344 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 496 } |
493 } | 497 } |
494 | 498 |
495 | 499 |
496 void ApiGetterEntryStub::SetCustomCache(Code* value) { | 500 void ApiGetterEntryStub::SetCustomCache(Code* value) { |
497 info()->set_load_stub_cache(value); | 501 info()->set_load_stub_cache(value); |
498 } | 502 } |
499 | 503 |
500 | 504 |
501 } } // namespace v8::internal | 505 } } // namespace v8::internal |
OLD | NEW |