| 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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 for (LabelElement element in target.labels) { | 799 for (LabelElement element in target.labels) { |
| 800 if (result === null) result = <LabelElement>[]; | 800 if (result === null) result = <LabelElement>[]; |
| 801 result.add(element); | 801 result.add(element); |
| 802 } | 802 } |
| 803 return (result === null) ? const <LabelElement>[] : result; | 803 return (result === null) ? const <LabelElement>[] : result; |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 | 806 |
| 807 class SsaBuilder extends ResolvedVisitor implements Visitor { | 807 class SsaBuilder extends ResolvedVisitor implements Visitor { |
| 808 final SsaBuilderTask builder; | 808 final SsaBuilderTask builder; |
| 809 final JavaScriptBackend backend; |
| 809 final Interceptors interceptors; | 810 final Interceptors interceptors; |
| 810 final WorkItem work; | 811 final WorkItem work; |
| 811 final ConstantSystem constantSystem; | 812 final ConstantSystem constantSystem; |
| 812 bool methodInterceptionEnabled; | 813 bool methodInterceptionEnabled; |
| 813 HGraph graph; | 814 HGraph graph; |
| 814 LocalsHandler localsHandler; | 815 LocalsHandler localsHandler; |
| 815 HInstruction rethrowableException; | 816 HInstruction rethrowableException; |
| 816 Map<Element, HParameterValue> parameters; | 817 Map<Element, HParameterValue> parameters; |
| 817 | 818 |
| 818 Map<TargetElement, JumpHandler> jumpTargets; | 819 Map<TargetElement, JumpHandler> jumpTargets; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 835 // block is closed. | 836 // block is closed. |
| 836 HBasicBlock lastOpenedBlock; | 837 HBasicBlock lastOpenedBlock; |
| 837 | 838 |
| 838 LibraryElement get currentLibrary => work.element.getLibrary(); | 839 LibraryElement get currentLibrary => work.element.getLibrary(); |
| 839 Element get currentElement => work.element; | 840 Element get currentElement => work.element; |
| 840 Compiler get compiler => builder.compiler; | 841 Compiler get compiler => builder.compiler; |
| 841 CodeEmitterTask get emitter => builder.emitter; | 842 CodeEmitterTask get emitter => builder.emitter; |
| 842 | 843 |
| 843 SsaBuilder(this.constantSystem, SsaBuilderTask builder, WorkItem work) | 844 SsaBuilder(this.constantSystem, SsaBuilderTask builder, WorkItem work) |
| 844 : this.builder = builder, | 845 : this.builder = builder, |
| 846 this.backend = builder.backend, |
| 845 this.work = work, | 847 this.work = work, |
| 846 interceptors = builder.interceptors, | 848 interceptors = builder.interceptors, |
| 847 methodInterceptionEnabled = true, | 849 methodInterceptionEnabled = true, |
| 848 graph = new HGraph(), | 850 graph = new HGraph(), |
| 849 stack = new List<HInstruction>(), | 851 stack = new List<HInstruction>(), |
| 850 activationVariables = new Map<Element, HLocalValue>(), | 852 activationVariables = new Map<Element, HLocalValue>(), |
| 851 jumpTargets = new Map<TargetElement, JumpHandler>(), | 853 jumpTargets = new Map<TargetElement, JumpHandler>(), |
| 852 parameters = new Map<Element, HParameterValue>(), | 854 parameters = new Map<Element, HParameterValue>(), |
| 853 inliningStack = <InliningState>[], | 855 inliningStack = <InliningState>[], |
| 854 super(work.resolutionTree) { | 856 super(work.resolutionTree) { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 if (body === null) continue; | 1237 if (body === null) continue; |
| 1236 List bodyCallInputs = <HInstruction>[]; | 1238 List bodyCallInputs = <HInstruction>[]; |
| 1237 bodyCallInputs.add(newObject); | 1239 bodyCallInputs.add(newObject); |
| 1238 int arity = body.functionSignature.parameterCount; | 1240 int arity = body.functionSignature.parameterCount; |
| 1239 body.functionSignature.forEachParameter((parameter) { | 1241 body.functionSignature.forEachParameter((parameter) { |
| 1240 bodyCallInputs.add(localsHandler.readLocal(parameter)); | 1242 bodyCallInputs.add(localsHandler.readLocal(parameter)); |
| 1241 }); | 1243 }); |
| 1242 // TODO(ahe): The constructor name is statically resolved. See | 1244 // TODO(ahe): The constructor name is statically resolved. See |
| 1243 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner | 1245 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner |
| 1244 // way to do this? | 1246 // way to do this? |
| 1245 SourceString name = new SourceString(compiler.namer.getName(body)); | 1247 SourceString name = new SourceString(backend.namer.getName(body)); |
| 1246 // TODO(kasperl): This seems fishy. We shouldn't be inventing all | 1248 // TODO(kasperl): This seems fishy. We shouldn't be inventing all |
| 1247 // these selectors. Maybe the resolver can do more of the work | 1249 // these selectors. Maybe the resolver can do more of the work |
| 1248 // for us here? | 1250 // for us here? |
| 1249 LibraryElement library = body.getLibrary(); | 1251 LibraryElement library = body.getLibrary(); |
| 1250 Selector selector = new Selector.call(name, library, arity); | 1252 Selector selector = new Selector.call(name, library, arity); |
| 1251 add(new HInvokeDynamicMethod(selector, bodyCallInputs)); | 1253 add(new HInvokeDynamicMethod(selector, bodyCallInputs)); |
| 1252 } | 1254 } |
| 1253 close(new HReturn(newObject)).addSuccessor(graph.exit); | 1255 close(new HReturn(newObject)).addSuccessor(graph.exit); |
| 1254 return closeFunction(); | 1256 return closeFunction(); |
| 1255 } | 1257 } |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2391 enableMethodInterception(); | 2393 enableMethodInterception(); |
| 2392 } | 2394 } |
| 2393 | 2395 |
| 2394 void handleForeignJsHasEquals(Send node) { | 2396 void handleForeignJsHasEquals(Send node) { |
| 2395 List<HInstruction> inputs = <HInstruction>[]; | 2397 List<HInstruction> inputs = <HInstruction>[]; |
| 2396 if (!node.arguments.tail.isEmpty()) { | 2398 if (!node.arguments.tail.isEmpty()) { |
| 2397 compiler.cancel( | 2399 compiler.cancel( |
| 2398 'More than one expression in JS_HAS_EQUALS()', node: node); | 2400 'More than one expression in JS_HAS_EQUALS()', node: node); |
| 2399 } | 2401 } |
| 2400 addGenericSendArgumentsToList(node.arguments, inputs); | 2402 addGenericSendArgumentsToList(node.arguments, inputs); |
| 2401 String name = compiler.namer.instanceMethodName( | 2403 String name = backend.namer.instanceMethodName( |
| 2402 currentLibrary, Elements.OPERATOR_EQUALS, 1); | 2404 currentLibrary, Elements.OPERATOR_EQUALS, 1); |
| 2403 push(new HForeign(new DartString.literal('!!#.$name'), | 2405 push(new HForeign(new DartString.literal('!!#.$name'), |
| 2404 const LiteralDartString('bool'), | 2406 const LiteralDartString('bool'), |
| 2405 inputs)); | 2407 inputs)); |
| 2406 } | 2408 } |
| 2407 | 2409 |
| 2408 void handleForeignJsCurrentIsolate(Send node) { | 2410 void handleForeignJsCurrentIsolate(Send node) { |
| 2409 if (!node.arguments.isEmpty()) { | 2411 if (!node.arguments.isEmpty()) { |
| 2410 compiler.cancel( | 2412 compiler.cancel( |
| 2411 'Too many arguments to JS_CURRENT_ISOLATE', node: node); | 2413 'Too many arguments to JS_CURRENT_ISOLATE', node: node); |
| 2412 } | 2414 } |
| 2413 | 2415 |
| 2414 if (!compiler.hasIsolateSupport()) { | 2416 if (!compiler.hasIsolateSupport()) { |
| 2415 // If the isolate library is not used, we just generate code | 2417 // If the isolate library is not used, we just generate code |
| 2416 // to fetch the Leg's current isolate. | 2418 // to fetch the Leg's current isolate. |
| 2417 String name = compiler.namer.CURRENT_ISOLATE; | 2419 String name = backend.namer.CURRENT_ISOLATE; |
| 2418 push(new HForeign(new DartString.literal(name), | 2420 push(new HForeign(new DartString.literal(name), |
| 2419 const LiteralDartString('var'), | 2421 const LiteralDartString('var'), |
| 2420 <HInstruction>[])); | 2422 <HInstruction>[])); |
| 2421 } else { | 2423 } else { |
| 2422 // Call a helper method from the isolate library. The isolate | 2424 // Call a helper method from the isolate library. The isolate |
| 2423 // library uses its own isolate structure, that encapsulates | 2425 // library uses its own isolate structure, that encapsulates |
| 2424 // Leg's isolate. | 2426 // Leg's isolate. |
| 2425 Element element = compiler.isolateLibrary.find( | 2427 Element element = compiler.isolateLibrary.find( |
| 2426 const SourceString('_currentIsolate')); | 2428 const SourceString('_currentIsolate')); |
| 2427 if (element === null) { | 2429 if (element === null) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2470 } | 2472 } |
| 2471 FunctionElement function = element; | 2473 FunctionElement function = element; |
| 2472 FunctionSignature params = function.computeSignature(compiler); | 2474 FunctionSignature params = function.computeSignature(compiler); |
| 2473 if (params.optionalParameterCount !== 0) { | 2475 if (params.optionalParameterCount !== 0) { |
| 2474 compiler.cancel( | 2476 compiler.cancel( |
| 2475 'JS_TO_CLOSURE does not handle closure with optional parameters', | 2477 'JS_TO_CLOSURE does not handle closure with optional parameters', |
| 2476 node: closure); | 2478 node: closure); |
| 2477 } | 2479 } |
| 2478 visit(closure); | 2480 visit(closure); |
| 2479 List<HInstruction> inputs = <HInstruction>[pop()]; | 2481 List<HInstruction> inputs = <HInstruction>[pop()]; |
| 2480 String invocationName = compiler.namer.closureInvocationName( | 2482 String invocationName = backend.namer.closureInvocationName( |
| 2481 new Selector.callClosure(params.requiredParameterCount)); | 2483 new Selector.callClosure(params.requiredParameterCount)); |
| 2482 push(new HForeign(new DartString.literal('#.$invocationName'), | 2484 push(new HForeign(new DartString.literal('#.$invocationName'), |
| 2483 const LiteralDartString('var'), | 2485 const LiteralDartString('var'), |
| 2484 inputs)); | 2486 inputs)); |
| 2485 } | 2487 } |
| 2486 | 2488 |
| 2487 visitForeignSend(Send node) { | 2489 visitForeignSend(Send node) { |
| 2488 Selector selector = elements.getSelector(node); | 2490 Selector selector = elements.getSelector(node); |
| 2489 SourceString name = selector.name; | 2491 SourceString name = selector.name; |
| 2490 if (name == const SourceString('JS')) { | 2492 if (name == const SourceString('JS')) { |
| (...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4040 new HSubGraphBlockInformation(elseBranch.graph)); | 4042 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4041 | 4043 |
| 4042 HBasicBlock conditionStartBlock = conditionBranch.block; | 4044 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4043 conditionStartBlock.setBlockFlow(info, joinBlock); | 4045 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4044 SubGraph conditionGraph = conditionBranch.graph; | 4046 SubGraph conditionGraph = conditionBranch.graph; |
| 4045 HIf branch = conditionGraph.end.last; | 4047 HIf branch = conditionGraph.end.last; |
| 4046 assert(branch is HIf); | 4048 assert(branch is HIf); |
| 4047 branch.blockInformation = conditionStartBlock.blockFlow; | 4049 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4048 } | 4050 } |
| 4049 } | 4051 } |
| OLD | NEW |