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 class Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 return compiler.findHelper(const SourceString('indexSet')); | 86 return compiler.findHelper(const SourceString('indexSet')); |
| 87 } | 87 } |
| 88 | 88 |
| 89 Element getEqualsNullInterceptor() { | 89 Element getEqualsNullInterceptor() { |
| 90 return compiler.findHelper(const SourceString('eqNull')); | 90 return compiler.findHelper(const SourceString('eqNull')); |
| 91 } | 91 } |
| 92 | 92 |
| 93 Element getExceptionUnwrapper() { | 93 Element getExceptionUnwrapper() { |
| 94 return compiler.findHelper(const SourceString('unwrapException')); | 94 return compiler.findHelper(const SourceString('unwrapException')); |
| 95 } | 95 } |
| 96 | |
| 97 Element getTraceFromException() { | |
| 98 return compiler.findHelper(const SourceString('getTraceFromException')); | |
| 99 } | |
| 96 } | 100 } |
| 97 | 101 |
| 98 class SsaBuilderTask extends CompilerTask { | 102 class SsaBuilderTask extends CompilerTask { |
| 99 SsaBuilderTask(Compiler compiler) | 103 SsaBuilderTask(Compiler compiler) |
| 100 : super(compiler), interceptors = new Interceptors(compiler); | 104 : super(compiler), interceptors = new Interceptors(compiler); |
| 101 String get name() => 'SSA builder'; | 105 String get name() => 'SSA builder'; |
| 102 Interceptors interceptors; | 106 Interceptors interceptors; |
| 103 | 107 |
| 104 HGraph build(WorkItem work) { | 108 HGraph build(WorkItem work) { |
| 105 return measure(() { | 109 return measure(() { |
| (...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 // Note that the name of this element is irrelevant. | 2311 // Note that the name of this element is irrelevant. |
| 2308 Element element = new Element( | 2312 Element element = new Element( |
| 2309 const SourceString('exception'), ElementKind.PARAMETER, work.element); | 2313 const SourceString('exception'), ElementKind.PARAMETER, work.element); |
| 2310 HParameterValue exception = new HParameterValue(element); | 2314 HParameterValue exception = new HParameterValue(element); |
| 2311 add(exception); | 2315 add(exception); |
| 2312 HInstruction oldRethrowableException = rethrowableException; | 2316 HInstruction oldRethrowableException = rethrowableException; |
| 2313 rethrowableException = exception; | 2317 rethrowableException = exception; |
| 2314 push(new HStatic(interceptors.getExceptionUnwrapper())); | 2318 push(new HStatic(interceptors.getExceptionUnwrapper())); |
| 2315 List<HInstruction> inputs = <HInstruction>[pop(), exception]; | 2319 List<HInstruction> inputs = <HInstruction>[pop(), exception]; |
| 2316 HInvokeStatic unwrappedException = | 2320 HInvokeStatic unwrappedException = |
| 2317 new HInvokeStatic(Selector.INVOCATION_1, inputs); | 2321 new HInvokeStatic(Selector.INVOCATION_1, inputs); |
| 2318 add(unwrappedException); | 2322 add(unwrappedException); |
| 2319 | 2323 |
| 2320 tryInstruction.exception = exception; | 2324 tryInstruction.exception = exception; |
| 2325 | |
| 2326 bool requiresTrace = false; | |
| 2327 for (CatchBlock block in node.catchBlocks) { | |
| 2328 if (block.trace != null) { | |
| 2329 requiresTrace = true; | |
| 2330 break; | |
| 2331 } | |
| 2332 } | |
| 2333 | |
| 2334 HInstruction traceInstruction = null; | |
|
floitsch
2012/03/06 10:22:32
Did you consider to fetch the trace lazily (in the
ngeoffray
2012/03/06 12:12:50
Yes. But the last implementation I ended up with d
| |
| 2335 if (requiresTrace) { | |
| 2336 push(new HStatic(interceptors.getTraceFromException())); | |
| 2337 traceInstruction = new HInvokeStatic(Selector.INVOCATION_1, | |
| 2338 <HInstruction>[pop(), exception]); | |
| 2339 add(traceInstruction); | |
| 2340 } | |
| 2341 | |
| 2321 Link<Node> link = node.catchBlocks.nodes; | 2342 Link<Node> link = node.catchBlocks.nodes; |
| 2322 | 2343 |
| 2323 void pushCondition(CatchBlock catchBlock) { | 2344 void pushCondition(CatchBlock catchBlock) { |
| 2324 VariableDefinitions declaration = catchBlock.formals.nodes.head; | 2345 VariableDefinitions declaration = catchBlock.formals.nodes.head; |
| 2325 HInstruction condition = null; | 2346 HInstruction condition = null; |
| 2326 if (declaration.type == null) { | 2347 if (declaration.type == null) { |
| 2327 condition = graph.addNewLiteralTrue(); | 2348 condition = graph.addNewLiteralTrue(); |
| 2328 stack.add(condition); | 2349 stack.add(condition); |
| 2329 } else { | 2350 } else { |
| 2330 Element typeElement = elements[declaration.type]; | 2351 Element typeElement = elements[declaration.type]; |
| 2331 if (typeElement == null) { | 2352 if (typeElement == null) { |
| 2332 compiler.cancel('Catch with unresolved type', node: catchBlock); | 2353 compiler.cancel('Catch with unresolved type', node: catchBlock); |
| 2333 } | 2354 } |
| 2334 condition = new HIs(typeElement, unwrappedException); | 2355 condition = new HIs(typeElement, unwrappedException); |
| 2335 push(condition); | 2356 push(condition); |
| 2336 } | 2357 } |
| 2337 } | 2358 } |
| 2338 | 2359 |
| 2339 void visitThen() { | 2360 void visitThen() { |
| 2340 CatchBlock catchBlock = link.head; | 2361 CatchBlock catchBlock = link.head; |
| 2341 link = link.tail; | 2362 link = link.tail; |
| 2342 VariableDefinitions declaration = catchBlock.formals.nodes.head; | 2363 localsHandler.updateLocal(elements[catchBlock.exception], |
| 2343 localsHandler.updateLocal(elements[declaration.definitions.nodes.head], | |
| 2344 unwrappedException); | 2364 unwrappedException); |
| 2365 Node trace = catchBlock.trace; | |
| 2366 if (trace != null) { | |
| 2367 localsHandler.updateLocal(elements[trace], traceInstruction); | |
| 2368 } | |
| 2345 visit(catchBlock); | 2369 visit(catchBlock); |
| 2346 } | 2370 } |
| 2347 | 2371 |
| 2348 void visitElse() { | 2372 void visitElse() { |
| 2349 if (link.isEmpty()) { | 2373 if (link.isEmpty()) { |
| 2350 close(new HThrow(exception, isRethrow: true)); | 2374 close(new HThrow(exception, isRethrow: true)); |
| 2351 } else { | 2375 } else { |
| 2352 CatchBlock newBlock = link.head; | 2376 CatchBlock newBlock = link.head; |
| 2353 pushCondition(newBlock); | 2377 pushCondition(newBlock); |
| 2354 handleIf(visitThen, visitElse); | 2378 handleIf(visitThen, visitElse); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2399 // Normally, we would call [close] here. However, then we hit | 2423 // Normally, we would call [close] here. However, then we hit |
| 2400 // another unimplemented feature: aborting loop body. Simply | 2424 // another unimplemented feature: aborting loop body. Simply |
| 2401 // calling [add] does not work as it asserts that the instruction | 2425 // calling [add] does not work as it asserts that the instruction |
| 2402 // isn't a control flow instruction. So we inline parts of [add]. | 2426 // isn't a control flow instruction. So we inline parts of [add]. |
| 2403 current.addAfter(current.last, new HThrow(message)); | 2427 current.addAfter(current.last, new HThrow(message)); |
| 2404 if (isExpression) { | 2428 if (isExpression) { |
| 2405 stack.add(graph.addNewLiteralNull()); | 2429 stack.add(graph.addNewLiteralNull()); |
| 2406 } | 2430 } |
| 2407 } | 2431 } |
| 2408 } | 2432 } |
| OLD | NEW |