Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
| 10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 function.SetCode(code); | 236 function.SetCode(code); |
| 237 ASSERT(CodePatcher::CodeIsPatchable(code)); | 237 ASSERT(CodePatcher::CodeIsPatchable(code)); |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 | 242 |
| 243 static RawError* CompileFunctionHelper(const Function& function, | 243 static RawError* CompileFunctionHelper(const Function& function, |
| 244 bool optimized) { | 244 bool optimized) { |
| 245 Isolate* isolate = Isolate::Current(); | 245 Isolate* isolate = Isolate::Current(); |
| 246 Error& error = Error::Handle(); | |
| 247 LongJump* base = isolate->long_jump_base(); | 246 LongJump* base = isolate->long_jump_base(); |
| 248 LongJump jump; | 247 LongJump jump; |
| 249 isolate->set_long_jump_base(&jump); | 248 isolate->set_long_jump_base(&jump); |
| 250 // Skips parsing if we need to only install unoptimized code. | 249 // Skips parsing if we need to only install unoptimized code. |
| 251 if (!optimized && !Code::Handle(function.unoptimized_code()).IsNull()) { | 250 if (!optimized && !Code::Handle(function.unoptimized_code()).IsNull()) { |
| 252 InstallUnoptimizedCode(function); | 251 InstallUnoptimizedCode(function); |
| 253 isolate->set_long_jump_base(base); | 252 isolate->set_long_jump_base(base); |
| 254 return Error::null(); | 253 return Error::null(); |
| 255 } | 254 } |
| 256 if (setjmp(*jump.Set()) == 0) { | 255 if (setjmp(*jump.Set()) == 0) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 OS::Print(" var %s scope %ld (valid %d-%d) offset %ld\n", | 315 OS::Print(" var %s scope %ld (valid %d-%d) offset %ld\n", |
| 317 var_name.ToCString(), scope_id, begin_pos, end_pos, slot); | 316 var_name.ToCString(), scope_id, begin_pos, end_pos, slot); |
| 318 } | 317 } |
| 319 OS::Print("}\n"); | 318 OS::Print("}\n"); |
| 320 OS::Print("Exception Handlers for function '%s' {\n", function_fullname); | 319 OS::Print("Exception Handlers for function '%s' {\n", function_fullname); |
| 321 const ExceptionHandlers& handlers = | 320 const ExceptionHandlers& handlers = |
| 322 ExceptionHandlers::Handle(code.exception_handlers()); | 321 ExceptionHandlers::Handle(code.exception_handlers()); |
| 323 OS::Print("%s", handlers.ToCString()); | 322 OS::Print("%s", handlers.ToCString()); |
| 324 OS::Print("}\n"); | 323 OS::Print("}\n"); |
| 325 } | 324 } |
| 325 isolate->set_long_jump_base(base); | |
| 326 return Error::null(); | |
| 326 } else { | 327 } else { |
| 328 Error& error = Error::Handle(); | |
| 327 // We got an error during compilation. | 329 // We got an error during compilation. |
| 328 error = isolate->object_store()->sticky_error(); | 330 error = isolate->object_store()->sticky_error(); |
| 329 isolate->object_store()->clear_sticky_error(); | 331 isolate->object_store()->clear_sticky_error(); |
| 332 isolate->set_long_jump_base(base); | |
| 333 return error.raw(); | |
| 330 } | 334 } |
| 331 isolate->set_long_jump_base(base); | 335 UNREACHABLE(); |
| 332 return error.raw(); | 336 return Error::null(); |
| 333 } | 337 } |
| 334 | 338 |
| 335 | 339 |
| 336 RawError* Compiler::CompileFunction(const Function& function) { | 340 RawError* Compiler::CompileFunction(const Function& function) { |
| 337 return CompileFunctionHelper(function, false); // Non-optimized. | 341 return CompileFunctionHelper(function, false); // Non-optimized. |
| 338 } | 342 } |
| 339 | 343 |
| 340 | 344 |
| 341 RawError* Compiler::CompileOptimizedFunction(const Function& function) { | 345 RawError* Compiler::CompileOptimizedFunction(const Function& function) { |
| 342 return CompileFunctionHelper(function, true); // Optimized. | 346 return CompileFunctionHelper(function, true); // Optimized. |
| 343 } | 347 } |
| 344 | 348 |
| 345 | 349 |
| 346 RawError* Compiler::CompileParsedFunction( | 350 RawError* Compiler::CompileParsedFunction( |
| 347 const ParsedFunction& parsed_function) { | 351 const ParsedFunction& parsed_function) { |
| 348 Isolate* isolate = Isolate::Current(); | 352 Isolate* isolate = Isolate::Current(); |
| 349 Error& error = Error::Handle(); | |
| 350 LongJump* base = isolate->long_jump_base(); | 353 LongJump* base = isolate->long_jump_base(); |
| 351 LongJump jump; | 354 LongJump jump; |
| 352 isolate->set_long_jump_base(&jump); | 355 isolate->set_long_jump_base(&jump); |
| 353 if (setjmp(*jump.Set()) == 0) { | 356 if (setjmp(*jump.Set()) == 0) { |
| 354 CompileParsedFunctionHelper(parsed_function, false); // Non-optimized. | 357 CompileParsedFunctionHelper(parsed_function, false); // Non-optimized. |
| 358 isolate->set_long_jump_base(base); | |
| 359 return Error::null(); | |
| 355 } else { | 360 } else { |
| 361 Error& error = Error::Handle(); | |
| 356 // We got an error during compilation. | 362 // We got an error during compilation. |
| 357 error = isolate->object_store()->sticky_error(); | 363 error = isolate->object_store()->sticky_error(); |
| 358 isolate->object_store()->clear_sticky_error(); | 364 isolate->object_store()->clear_sticky_error(); |
| 365 isolate->set_long_jump_base(base); | |
| 366 return error.raw(); | |
| 359 } | 367 } |
| 360 isolate->set_long_jump_base(base); | 368 UNREACHABLE(); |
| 361 return error.raw(); | 369 return Error::null(); |
| 362 } | 370 } |
| 363 | 371 |
| 364 | 372 |
| 365 RawError* Compiler::CompileAllFunctions(const Class& cls) { | 373 RawError* Compiler::CompileAllFunctions(const Class& cls) { |
| 366 Error& error = Error::Handle(); | 374 Error& error = Error::Handle(); |
| 367 Array& functions = Array::Handle(cls.functions()); | 375 Array& functions = Array::Handle(cls.functions()); |
| 368 Function& func = Function::Handle(); | 376 Function& func = Function::Handle(); |
| 369 for (int i = 0; i < functions.Length(); i++) { | 377 for (int i = 0; i < functions.Length(); i++) { |
| 370 func ^= functions.At(i); | 378 func ^= functions.At(i); |
| 371 ASSERT(!func.IsNull()); | 379 ASSERT(!func.IsNull()); |
| 372 if (!func.HasCode() && !func.IsAbstract()) { | 380 if (!func.HasCode() && !func.IsAbstract()) { |
| 373 error = CompileFunction(func); | 381 error = CompileFunction(func); |
| 374 if (!error.IsNull()) { | 382 if (!error.IsNull()) { |
| 375 return error.raw(); | 383 return error.raw(); |
| 376 } | 384 } |
| 377 } | 385 } |
| 378 } | 386 } |
| 379 return error.raw(); | 387 return error.raw(); |
| 380 } | 388 } |
| 381 | 389 |
| 382 | 390 |
| 383 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { | 391 RawObject* Compiler::ExecuteOnce(SequenceNode* fragment) { |
| 384 Isolate* isolate = Isolate::Current(); | 392 Isolate* isolate = Isolate::Current(); |
| 385 Object& result = Object::Handle(); | |
| 386 LongJump* base = isolate->long_jump_base(); | 393 LongJump* base = isolate->long_jump_base(); |
| 387 LongJump jump; | 394 LongJump jump; |
| 388 isolate->set_long_jump_base(&jump); | 395 isolate->set_long_jump_base(&jump); |
| 389 if (setjmp(*jump.Set()) == 0) { | 396 if (setjmp(*jump.Set()) == 0) { |
| 390 if (FLAG_trace_compiler) { | 397 if (FLAG_trace_compiler) { |
| 391 OS::Print("compiling expression: "); | 398 OS::Print("compiling expression: "); |
| 392 AstPrinter::PrintNode(fragment); | 399 AstPrinter::PrintNode(fragment); |
| 393 } | 400 } |
| 394 | 401 |
| 395 // Create a dummy function object for the code generator. | 402 // Create a dummy function object for the code generator. |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 414 // would compile func automatically. We are checking fewer invariants | 421 // would compile func automatically. We are checking fewer invariants |
| 415 // here. | 422 // here. |
| 416 ParsedFunction parsed_function(func); | 423 ParsedFunction parsed_function(func); |
| 417 parsed_function.SetNodeSequence(fragment); | 424 parsed_function.SetNodeSequence(fragment); |
| 418 parsed_function.set_default_parameter_values(Array::Handle()); | 425 parsed_function.set_default_parameter_values(Array::Handle()); |
| 419 | 426 |
| 420 CompileParsedFunctionHelper(parsed_function, false); // Non-optimized. | 427 CompileParsedFunctionHelper(parsed_function, false); // Non-optimized. |
| 421 | 428 |
| 422 GrowableArray<const Object*> arguments; // no arguments. | 429 GrowableArray<const Object*> arguments; // no arguments. |
| 423 const Array& kNoArgumentNames = Array::Handle(); | 430 const Array& kNoArgumentNames = Array::Handle(); |
| 431 Object& result = Object::Handle(); | |
| 424 result = DartEntry::InvokeStatic(func, | 432 result = DartEntry::InvokeStatic(func, |
| 425 arguments, | 433 arguments, |
| 426 kNoArgumentNames); | 434 kNoArgumentNames); |
| 435 isolate->set_long_jump_base(base); | |
| 436 return result.raw(); | |
| 427 } else { | 437 } else { |
| 438 Object& result = Object::Handle(); | |
| 428 result = isolate->object_store()->sticky_error(); | 439 result = isolate->object_store()->sticky_error(); |
| 429 isolate->object_store()->clear_sticky_error(); | 440 isolate->object_store()->clear_sticky_error(); |
| 441 isolate->set_long_jump_base(base); | |
| 442 return result.raw(); | |
| 430 } | 443 } |
| 431 isolate->set_long_jump_base(base); | 444 UNREACHABLE(); |
| 432 return result.raw(); | 445 return Error::null(); |
|
siva
2012/05/05 00:11:15
Object::null()
regis
2012/05/05 00:24:09
Good point. I'll change it in my next cl.
| |
| 433 } | 446 } |
| 434 | 447 |
| 435 | 448 |
| 436 } // namespace dart | 449 } // namespace dart |
| OLD | NEW |