Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2808683003: Remove most direct uses of 'backend' and 'compiler' in GraphBuilder. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 9 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 this.compiler = compiler; 143 this.compiler = compiler;
144 this.loopHandler = new KernelLoopHandler(this); 144 this.loopHandler = new KernelLoopHandler(this);
145 typeBuilder = new TypeBuilder(this); 145 typeBuilder = new TypeBuilder(this);
146 graph.element = targetElement; 146 graph.element = targetElement;
147 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? 147 // TODO(het): Should sourceInformationBuilder be in GraphBuilder?
148 this.sourceInformationBuilder = 148 this.sourceInformationBuilder =
149 sourceInformationFactory.createBuilderForContext(resolvedAst); 149 sourceInformationFactory.createBuilderForContext(resolvedAst);
150 graph.sourceInformation = 150 graph.sourceInformation =
151 sourceInformationBuilder.buildVariableDeclaration(); 151 sourceInformationBuilder.buildVariableDeclaration();
152 this.localsHandler = new LocalsHandler( 152 this.localsHandler = new LocalsHandler(
153 this, targetElement, null, backend.nativeData, backend.interceptorData); 153 this, targetElement, null, nativeData, interceptorData);
154 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, 154 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend,
155 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); 155 resolvedAst, kernel.nodeToAst, kernel.nodeToElement);
156 target = astAdapter.getInitialKernelNode(targetElement); 156 target = astAdapter.getInitialKernelNode(targetElement);
157 if (targetElement is ConstructorBodyElement) { 157 if (targetElement is ConstructorBodyElement) {
158 _targetIsConstructorBody = true; 158 _targetIsConstructorBody = true;
159 } 159 }
160 } 160 }
161 161
162 HGraph build() { 162 HGraph build() {
163 // TODO(het): no reason to do this here... 163 // TODO(het): no reason to do this here...
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 return typeBuilder.potentiallyCheckOrTrustType(value, type, 213 return typeBuilder.potentiallyCheckOrTrustType(value, type,
214 kind: HTypeConversion.BOOLEAN_CONVERSION_CHECK); 214 kind: HTypeConversion.BOOLEAN_CONVERSION_CHECK);
215 } 215 }
216 HInstruction result = new HBoolify(value, commonMasks.boolType); 216 HInstruction result = new HBoolify(value, commonMasks.boolType);
217 add(result); 217 add(result);
218 return result; 218 return result;
219 } 219 }
220 220
221 void _addClassTypeVariablesIfNeeded(ir.Member constructor) { 221 void _addClassTypeVariablesIfNeeded(ir.Member constructor) {
222 var enclosing = constructor.enclosingClass; 222 var enclosing = constructor.enclosingClass;
223 if (backend.rtiNeed.classNeedsRti(astAdapter.getElement(enclosing))) { 223 if (rtiNeed.classNeedsRti(astAdapter.getElement(enclosing))) {
224 enclosing.typeParameters.forEach((ir.TypeParameter typeParameter) { 224 enclosing.typeParameters.forEach((ir.TypeParameter typeParameter) {
225 var typeParamElement = astAdapter.getElement(typeParameter); 225 var typeParamElement = astAdapter.getElement(typeParameter);
226 HParameterValue param = 226 HParameterValue param =
227 addParameter(typeParamElement, commonMasks.nonNullType); 227 addParameter(typeParamElement, commonMasks.nonNullType);
228 // This is a little bit wacky (and n^2) until we make the localsHandler 228 // This is a little bit wacky (and n^2) until we make the localsHandler
229 // take Kernel DartTypes instead of just the AST DartTypes. 229 // take Kernel DartTypes instead of just the AST DartTypes.
230 var typeVariableType = astAdapter 230 var typeVariableType = astAdapter
231 .getClass(enclosing) 231 .getClass(enclosing)
232 .typeVariables 232 .typeVariables
233 .firstWhere( 233 .firstWhere(
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 signature.forEachRequiredParameter((_) { 398 signature.forEachRequiredParameter((_) {
399 arguments.positional[positionalIndex++].accept(this); 399 arguments.positional[positionalIndex++].accept(this);
400 builtArguments.add(pop()); 400 builtArguments.add(pop());
401 }); 401 });
402 if (!signature.optionalParametersAreNamed) { 402 if (!signature.optionalParametersAreNamed) {
403 signature.forEachOptionalParameter((ParameterElement element) { 403 signature.forEachOptionalParameter((ParameterElement element) {
404 if (positionalIndex < arguments.positional.length) { 404 if (positionalIndex < arguments.positional.length) {
405 arguments.positional[positionalIndex++].accept(this); 405 arguments.positional[positionalIndex++].accept(this);
406 builtArguments.add(pop()); 406 builtArguments.add(pop());
407 } else { 407 } else {
408 var constantValue = 408 var constantValue = constants.getConstantValue(element.constant);
409 backend.constants.getConstantValue(element.constant);
410 assert(invariant(element, constantValue != null, 409 assert(invariant(element, constantValue != null,
411 message: 'No constant computed for $element')); 410 message: 'No constant computed for $element'));
412 builtArguments.add(graph.addConstant(constantValue, closedWorld)); 411 builtArguments.add(graph.addConstant(constantValue, closedWorld));
413 } 412 }
414 }); 413 });
415 } else { 414 } else {
416 signature.orderedOptionalParameters.forEach((ParameterElement element) { 415 signature.orderedOptionalParameters.forEach((ParameterElement element) {
417 var correspondingNamed = arguments.named.firstWhere( 416 var correspondingNamed = arguments.named.firstWhere(
418 (named) => named.name == element.name, 417 (named) => named.name == element.name,
419 orElse: () => null); 418 orElse: () => null);
420 if (correspondingNamed != null) { 419 if (correspondingNamed != null) {
421 correspondingNamed.value.accept(this); 420 correspondingNamed.value.accept(this);
422 builtArguments.add(pop()); 421 builtArguments.add(pop());
423 } else { 422 } else {
424 var constantValue = 423 var constantValue = constants.getConstantValue(element.constant);
425 backend.constants.getConstantValue(element.constant);
426 assert(invariant(element, constantValue != null, 424 assert(invariant(element, constantValue != null,
427 message: 'No constant computed for $element')); 425 message: 'No constant computed for $element'));
428 builtArguments.add(graph.addConstant(constantValue, closedWorld)); 426 builtArguments.add(graph.addConstant(constantValue, closedWorld));
429 } 427 }
430 }); 428 });
431 } 429 }
432 430
433 return builtArguments; 431 return builtArguments;
434 } 432 }
435 433
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 new DartString.literal(prefixElement.deferredImport.uri.toString()), 576 new DartString.literal(prefixElement.deferredImport.uri.toString()),
579 closedWorld); 577 closedWorld);
580 _pushStaticInvocation(astAdapter.checkDeferredIsLoaded, 578 _pushStaticInvocation(astAdapter.checkDeferredIsLoaded,
581 [prefixConstant, uriConstant], astAdapter.checkDeferredIsLoadedType); 579 [prefixConstant, uriConstant], astAdapter.checkDeferredIsLoadedType);
582 } 580 }
583 581
584 @override 582 @override
585 void visitLoadLibrary(ir.LoadLibrary loadLibrary) { 583 void visitLoadLibrary(ir.LoadLibrary loadLibrary) {
586 // TODO(efortuna): Source information! 584 // TODO(efortuna): Source information!
587 push(new HInvokeStatic( 585 push(new HInvokeStatic(
588 backend.helpers.loadLibraryWrapper, 586 helpers.loadLibraryWrapper,
589 [ 587 [
590 graph.addConstantString( 588 graph.addConstantString(
591 new DartString.literal(loadLibrary.import.name), closedWorld) 589 new DartString.literal(loadLibrary.import.name), closedWorld)
592 ], 590 ],
593 commonMasks.nonNullType, 591 commonMasks.nonNullType,
594 targetCanThrow: false)); 592 targetCanThrow: false));
595 } 593 }
596 594
597 @override 595 @override
598 void visitBlock(ir.Block block) { 596 void visitBlock(ir.Block block) {
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 1451
1454 HInstruction buildCondition() => graph.addConstantBool(true, closedWorld); 1452 HInstruction buildCondition() => graph.addConstantBool(true, closedWorld);
1455 1453
1456 void buildSwitch() { 1454 void buildSwitch() {
1457 HInstruction buildExpression(ir.SwitchStatement notUsed) { 1455 HInstruction buildExpression(ir.SwitchStatement notUsed) {
1458 return localsHandler.readLocal(switchTarget); 1456 return localsHandler.readLocal(switchTarget);
1459 } 1457 }
1460 1458
1461 List<ConstantValue> getConstants( 1459 List<ConstantValue> getConstants(
1462 ir.SwitchStatement parentSwitch, ir.SwitchCase switchCase) { 1460 ir.SwitchStatement parentSwitch, ir.SwitchCase switchCase) {
1463 return <ConstantValue>[ 1461 return <ConstantValue>[constantSystem.createInt(caseIndex[switchCase])];
1464 backend.constantSystem.createInt(caseIndex[switchCase])
1465 ];
1466 } 1462 }
1467 1463
1468 void buildSwitchCase(ir.SwitchCase switchCase) { 1464 void buildSwitchCase(ir.SwitchCase switchCase) {
1469 switchCase.body.accept(this); 1465 switchCase.body.accept(this);
1470 if (!isAborted()) { 1466 if (!isAborted()) {
1471 // Ensure that we break the loop if the case falls through. (This 1467 // Ensure that we break the loop if the case falls through. (This
1472 // is only possible for the last case.) 1468 // is only possible for the last case.)
1473 jumpTargets[switchTarget].generateBreak(); 1469 jumpTargets[switchTarget].generateBreak();
1474 } 1470 }
1475 } 1471 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 @override 1666 @override
1671 void visitNullLiteral(ir.NullLiteral nullLiteral) { 1667 void visitNullLiteral(ir.NullLiteral nullLiteral) {
1672 stack.add(graph.addConstantNull(closedWorld)); 1668 stack.add(graph.addConstantNull(closedWorld));
1673 } 1669 }
1674 1670
1675 /// Set the runtime type information if necessary. 1671 /// Set the runtime type information if necessary.
1676 HInstruction setListRuntimeTypeInfoIfNeeded( 1672 HInstruction setListRuntimeTypeInfoIfNeeded(
1677 HInstruction object, ir.ListLiteral listLiteral) { 1673 HInstruction object, ir.ListLiteral listLiteral) {
1678 ResolutionInterfaceType type = localsHandler 1674 ResolutionInterfaceType type = localsHandler
1679 .substInContext(astAdapter.getDartTypeOfListLiteral(listLiteral)); 1675 .substInContext(astAdapter.getDartTypeOfListLiteral(listLiteral));
1680 if (!backend.rtiNeed.classNeedsRti(type.element) || type.treatAsRaw) { 1676 if (!rtiNeed.classNeedsRti(type.element) || type.treatAsRaw) {
1681 return object; 1677 return object;
1682 } 1678 }
1683 List<HInstruction> arguments = <HInstruction>[]; 1679 List<HInstruction> arguments = <HInstruction>[];
1684 for (ResolutionDartType argument in type.typeArguments) { 1680 for (ResolutionDartType argument in type.typeArguments) {
1685 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); 1681 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement));
1686 } 1682 }
1687 // TODO(15489): Register at codegen. 1683 // TODO(15489): Register at codegen.
1688 registry?.registerInstantiation(type); 1684 registry?.registerInstantiation(type);
1689 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object); 1685 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object);
1690 } 1686 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 inputs.add(argList); 1741 inputs.add(argList);
1746 } 1742 }
1747 1743
1748 assert(constructor.kind == ir.ProcedureKind.Factory); 1744 assert(constructor.kind == ir.ProcedureKind.Factory);
1749 1745
1750 ResolutionInterfaceType type = localsHandler 1746 ResolutionInterfaceType type = localsHandler
1751 .substInContext(astAdapter.getDartTypeOfMapLiteral(mapLiteral)); 1747 .substInContext(astAdapter.getDartTypeOfMapLiteral(mapLiteral));
1752 1748
1753 ir.Class cls = constructor.enclosingClass; 1749 ir.Class cls = constructor.enclosingClass;
1754 1750
1755 if (backend.rtiNeed.classNeedsRti(astAdapter.getClass(cls))) { 1751 if (rtiNeed.classNeedsRti(astAdapter.getClass(cls))) {
1756 List<HInstruction> typeInputs = <HInstruction>[]; 1752 List<HInstruction> typeInputs = <HInstruction>[];
1757 type.typeArguments.forEach((ResolutionDartType argument) { 1753 type.typeArguments.forEach((ResolutionDartType argument) {
1758 typeInputs 1754 typeInputs
1759 .add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); 1755 .add(typeBuilder.analyzeTypeArgument(argument, sourceElement));
1760 }); 1756 });
1761 1757
1762 // We lift this common call pattern into a helper function to save space 1758 // We lift this common call pattern into a helper function to save space
1763 // in the output. 1759 // in the output.
1764 if (typeInputs.every((HInstruction input) => input.isNull())) { 1760 if (typeInputs.every((HInstruction input) => input.isNull())) {
1765 if (constructorArgs.isEmpty) { 1761 if (constructorArgs.isEmpty) {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 return stringConstant.primitiveValue.slowToString(); 2186 return stringConstant.primitiveValue.slowToString();
2191 } 2187 }
2192 2188
2193 void handleForeignJsCurrentIsolateContext(ir.StaticInvocation invocation) { 2189 void handleForeignJsCurrentIsolateContext(ir.StaticInvocation invocation) {
2194 if (_unexpectedForeignArguments(invocation, 0, 0)) { 2190 if (_unexpectedForeignArguments(invocation, 0, 0)) {
2195 // Result expected on stack. 2191 // Result expected on stack.
2196 stack.add(graph.addConstantNull(closedWorld)); 2192 stack.add(graph.addConstantNull(closedWorld));
2197 return; 2193 return;
2198 } 2194 }
2199 2195
2200 if (!backend.backendUsage.isIsolateInUse) { 2196 if (!backendUsage.isIsolateInUse) {
2201 // If the isolate library is not used, we just generate code 2197 // If the isolate library is not used, we just generate code
2202 // to fetch the static state. 2198 // to fetch the static state.
2203 String name = backend.namer.staticStateHolder; 2199 String name = namer.staticStateHolder;
2204 push(new HForeignCode( 2200 push(new HForeignCode(
2205 js.js.parseForeignJS(name), commonMasks.dynamicType, <HInstruction>[], 2201 js.js.parseForeignJS(name), commonMasks.dynamicType, <HInstruction>[],
2206 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER)); 2202 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER));
2207 } else { 2203 } else {
2208 // Call a helper method from the isolate library. The isolate library uses 2204 // Call a helper method from the isolate library. The isolate library uses
2209 // its own isolate structure that encapsulates the isolate structure used 2205 // its own isolate structure that encapsulates the isolate structure used
2210 // for binding to methods. 2206 // for binding to methods.
2211 ir.Procedure target = astAdapter.currentIsolate; 2207 ir.Procedure target = astAdapter.currentIsolate;
2212 if (target == null) { 2208 if (target == null) {
2213 reporter.internalError(astAdapter.getNode(invocation), 2209 reporter.internalError(astAdapter.getNode(invocation),
2214 'Isolate library and compiler mismatch.'); 2210 'Isolate library and compiler mismatch.');
2215 } 2211 }
2216 _pushStaticInvocation(target, <HInstruction>[], commonMasks.dynamicType); 2212 _pushStaticInvocation(target, <HInstruction>[], commonMasks.dynamicType);
2217 } 2213 }
2218 } 2214 }
2219 2215
2220 void handleForeignJsCallInIsolate(ir.StaticInvocation invocation) { 2216 void handleForeignJsCallInIsolate(ir.StaticInvocation invocation) {
2221 if (_unexpectedForeignArguments(invocation, 2, 2)) { 2217 if (_unexpectedForeignArguments(invocation, 2, 2)) {
2222 // Result expected on stack. 2218 // Result expected on stack.
2223 stack.add(graph.addConstantNull(closedWorld)); 2219 stack.add(graph.addConstantNull(closedWorld));
2224 return; 2220 return;
2225 } 2221 }
2226 2222
2227 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); 2223 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments);
2228 2224
2229 if (!backend.backendUsage.isIsolateInUse) { 2225 if (!backendUsage.isIsolateInUse) {
2230 // If the isolate library is not used, we ignore the isolate argument and 2226 // If the isolate library is not used, we ignore the isolate argument and
2231 // just invoke the closure. 2227 // just invoke the closure.
2232 push(new HInvokeClosure(new Selector.callClosure(0), 2228 push(new HInvokeClosure(new Selector.callClosure(0),
2233 <HInstruction>[inputs[1]], commonMasks.dynamicType)); 2229 <HInstruction>[inputs[1]], commonMasks.dynamicType));
2234 } else { 2230 } else {
2235 // Call a helper method from the isolate library. 2231 // Call a helper method from the isolate library.
2236 ir.Procedure callInIsolate = astAdapter.callInIsolate; 2232 ir.Procedure callInIsolate = astAdapter.callInIsolate;
2237 if (callInIsolate == null) { 2233 if (callInIsolate == null) {
2238 reporter.internalError(astAdapter.getNode(invocation), 2234 reporter.internalError(astAdapter.getNode(invocation),
2239 'Isolate library and compiler mismatch.'); 2235 'Isolate library and compiler mismatch.');
(...skipping 22 matching lines...) Expand all
2262 if (closure is ir.StaticGet) { 2258 if (closure is ir.StaticGet) {
2263 ir.Member staticTarget = closure.target; 2259 ir.Member staticTarget = closure.target;
2264 if (staticTarget is ir.Procedure) { 2260 if (staticTarget is ir.Procedure) {
2265 if (staticTarget.kind == ir.ProcedureKind.Method) { 2261 if (staticTarget.kind == ir.ProcedureKind.Method) {
2266 ir.FunctionNode function = staticTarget.function; 2262 ir.FunctionNode function = staticTarget.function;
2267 if (function != null && 2263 if (function != null &&
2268 function.requiredParameterCount == 2264 function.requiredParameterCount ==
2269 function.positionalParameters.length && 2265 function.positionalParameters.length &&
2270 function.namedParameters.isEmpty) { 2266 function.namedParameters.isEmpty) {
2271 push(new HForeignCode( 2267 push(new HForeignCode(
2272 js.js.expressionTemplateYielding(backend.emitter 2268 js.js.expressionTemplateYielding(emitter
2273 .staticFunctionAccess(astAdapter.getMethod(staticTarget))), 2269 .staticFunctionAccess(astAdapter.getMethod(staticTarget))),
2274 commonMasks.dynamicType, 2270 commonMasks.dynamicType,
2275 <HInstruction>[], 2271 <HInstruction>[],
2276 nativeBehavior: native.NativeBehavior.PURE, 2272 nativeBehavior: native.NativeBehavior.PURE,
2277 foreignFunction: astAdapter.getMethod(staticTarget))); 2273 foreignFunction: astAdapter.getMethod(staticTarget)));
2278 return; 2274 return;
2279 } 2275 }
2280 problem = 'does not handle a closure with optional parameters'; 2276 problem = 'does not handle a closure with optional parameters';
2281 } 2277 }
2282 } 2278 }
2283 } 2279 }
2284 2280
2285 reporter.reportErrorMessage(astAdapter.getNode(invocation), 2281 reporter.reportErrorMessage(astAdapter.getNode(invocation),
2286 MessageKind.GENERIC, {'text': "'$name' $problem."}); 2282 MessageKind.GENERIC, {'text': "'$name' $problem."});
2287 stack.add(graph.addConstantNull(closedWorld)); // Result expected on stack. 2283 stack.add(graph.addConstantNull(closedWorld)); // Result expected on stack.
2288 return; 2284 return;
2289 } 2285 }
2290 2286
2291 void handleForeignJsSetStaticState(ir.StaticInvocation invocation) { 2287 void handleForeignJsSetStaticState(ir.StaticInvocation invocation) {
2292 if (_unexpectedForeignArguments(invocation, 1, 1)) { 2288 if (_unexpectedForeignArguments(invocation, 1, 1)) {
2293 // Result expected on stack. 2289 // Result expected on stack.
2294 stack.add(graph.addConstantNull(closedWorld)); 2290 stack.add(graph.addConstantNull(closedWorld));
2295 return; 2291 return;
2296 } 2292 }
2297 2293
2298 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments); 2294 List<HInstruction> inputs = _visitPositionalArguments(invocation.arguments);
2299 2295
2300 String isolateName = backend.namer.staticStateHolder; 2296 String isolateName = namer.staticStateHolder;
2301 SideEffects sideEffects = new SideEffects.empty(); 2297 SideEffects sideEffects = new SideEffects.empty();
2302 sideEffects.setAllSideEffects(); 2298 sideEffects.setAllSideEffects();
2303 push(new HForeignCode(js.js.parseForeignJS("$isolateName = #"), 2299 push(new HForeignCode(js.js.parseForeignJS("$isolateName = #"),
2304 commonMasks.dynamicType, inputs, 2300 commonMasks.dynamicType, inputs,
2305 nativeBehavior: native.NativeBehavior.CHANGES_OTHER, 2301 nativeBehavior: native.NativeBehavior.CHANGES_OTHER,
2306 effects: sideEffects)); 2302 effects: sideEffects));
2307 } 2303 }
2308 2304
2309 void handleForeignJsGetStaticState(ir.StaticInvocation invocation) { 2305 void handleForeignJsGetStaticState(ir.StaticInvocation invocation) {
2310 if (_unexpectedForeignArguments(invocation, 0, 0)) { 2306 if (_unexpectedForeignArguments(invocation, 0, 0)) {
2311 // Result expected on stack. 2307 // Result expected on stack.
2312 stack.add(graph.addConstantNull(closedWorld)); 2308 stack.add(graph.addConstantNull(closedWorld));
2313 return; 2309 return;
2314 } 2310 }
2315 2311
2316 push(new HForeignCode(js.js.parseForeignJS(backend.namer.staticStateHolder), 2312 push(new HForeignCode(js.js.parseForeignJS(namer.staticStateHolder),
2317 commonMasks.dynamicType, <HInstruction>[], 2313 commonMasks.dynamicType, <HInstruction>[],
2318 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER)); 2314 nativeBehavior: native.NativeBehavior.DEPENDS_OTHER));
2319 } 2315 }
2320 2316
2321 void handleForeignJsGetName(ir.StaticInvocation invocation) { 2317 void handleForeignJsGetName(ir.StaticInvocation invocation) {
2322 if (_unexpectedForeignArguments(invocation, 1, 1)) { 2318 if (_unexpectedForeignArguments(invocation, 1, 1)) {
2323 // Result expected on stack. 2319 // Result expected on stack.
2324 stack.add(graph.addConstantNull(closedWorld)); 2320 stack.add(graph.addConstantNull(closedWorld));
2325 return; 2321 return;
2326 } 2322 }
(...skipping 19 matching lines...) Expand all
2346 2342
2347 void handleForeignJsEmbeddedGlobal(ir.StaticInvocation invocation) { 2343 void handleForeignJsEmbeddedGlobal(ir.StaticInvocation invocation) {
2348 if (_unexpectedForeignArguments(invocation, 2, 2)) { 2344 if (_unexpectedForeignArguments(invocation, 2, 2)) {
2349 // Result expected on stack. 2345 // Result expected on stack.
2350 stack.add(graph.addConstantNull(closedWorld)); 2346 stack.add(graph.addConstantNull(closedWorld));
2351 return; 2347 return;
2352 } 2348 }
2353 String globalName = _foreignConstantStringArgument( 2349 String globalName = _foreignConstantStringArgument(
2354 invocation, 1, 'JS_EMBEDDED_GLOBAL', 'second '); 2350 invocation, 1, 'JS_EMBEDDED_GLOBAL', 'second ');
2355 js.Template expr = js.js.expressionTemplateYielding( 2351 js.Template expr = js.js.expressionTemplateYielding(
2356 backend.emitter.generateEmbeddedGlobalAccess(globalName)); 2352 emitter.generateEmbeddedGlobalAccess(globalName));
2357 2353
2358 native.NativeBehavior nativeBehavior = 2354 native.NativeBehavior nativeBehavior =
2359 astAdapter.getNativeBehavior(invocation); 2355 astAdapter.getNativeBehavior(invocation);
2360 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null, 2356 assert(invariant(astAdapter.getNode(invocation), nativeBehavior != null,
2361 message: "No NativeBehavior for $invocation")); 2357 message: "No NativeBehavior for $invocation"));
2362 2358
2363 TypeMask ssaType = 2359 TypeMask ssaType =
2364 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld); 2360 astAdapter.typeFromNativeBehavior(nativeBehavior, closedWorld);
2365 push(new HForeignCode(expr, ssaType, const <HInstruction>[], 2361 push(new HForeignCode(expr, ssaType, const <HInstruction>[],
2366 nativeBehavior: nativeBehavior)); 2362 nativeBehavior: nativeBehavior));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 if (_unexpectedForeignArguments(invocation, 1, 1)) { 2410 if (_unexpectedForeignArguments(invocation, 1, 1)) {
2415 stack.add( 2411 stack.add(
2416 // Result expected on stack. 2412 // Result expected on stack.
2417 graph.addConstantBool(false, closedWorld)); 2413 graph.addConstantBool(false, closedWorld));
2418 return; 2414 return;
2419 } 2415 }
2420 String name = _foreignConstantStringArgument(invocation, 0, 'JS_GET_FLAG'); 2416 String name = _foreignConstantStringArgument(invocation, 0, 'JS_GET_FLAG');
2421 bool value = false; 2417 bool value = false;
2422 switch (name) { 2418 switch (name) {
2423 case 'MUST_RETAIN_METADATA': 2419 case 'MUST_RETAIN_METADATA':
2424 value = backend.mirrorsData.mustRetainMetadata; 2420 value = mirrorsData.mustRetainMetadata;
2425 break; 2421 break;
2426 case 'USE_CONTENT_SECURITY_POLICY': 2422 case 'USE_CONTENT_SECURITY_POLICY':
2427 value = options.useContentSecurityPolicy; 2423 value = options.useContentSecurityPolicy;
2428 break; 2424 break;
2429 default: 2425 default:
2430 reporter.reportErrorMessage( 2426 reporter.reportErrorMessage(
2431 astAdapter.getNode(invocation), 2427 astAdapter.getNode(invocation),
2432 MessageKind.GENERIC, 2428 MessageKind.GENERIC,
2433 {'text': 'Error: Unknown internal flag "$name".'}); 2429 {'text': 'Error: Unknown internal flag "$name".'});
2434 } 2430 }
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2681 assert(noSuchMethod != null); 2677 assert(noSuchMethod != null);
2682 return noSuchMethod; 2678 return noSuchMethod;
2683 } 2679 }
2684 2680
2685 void _generateSuperNoSuchMethod(ir.Expression invocation, String publicName, 2681 void _generateSuperNoSuchMethod(ir.Expression invocation, String publicName,
2686 List<HInstruction> arguments) { 2682 List<HInstruction> arguments) {
2687 Selector selector = astAdapter.getSelector(invocation); 2683 Selector selector = astAdapter.getSelector(invocation);
2688 ir.Class cls = _containingClass(invocation).superclass; 2684 ir.Class cls = _containingClass(invocation).superclass;
2689 assert(cls != null); 2685 assert(cls != null);
2690 ir.Procedure noSuchMethod = _findNoSuchMethodInClass(cls); 2686 ir.Procedure noSuchMethod = _findNoSuchMethodInClass(cls);
2691 if (backend.backendUsage.isInvokeOnUsed && 2687 if (backendUsage.isInvokeOnUsed &&
2692 _containingClass(noSuchMethod) != astAdapter.objectClass) { 2688 _containingClass(noSuchMethod) != astAdapter.objectClass) {
2693 // Register the call as dynamic if [noSuchMethod] on the super 2689 // Register the call as dynamic if [noSuchMethod] on the super
2694 // class is _not_ the default implementation from [Object] (it might be 2690 // class is _not_ the default implementation from [Object] (it might be
2695 // overridden in the super class, but it might have a different number of 2691 // overridden in the super class, but it might have a different number of
2696 // arguments), in case the [noSuchMethod] implementation calls 2692 // arguments), in case the [noSuchMethod] implementation calls
2697 // [JSInvocationMirror._invokeOn]. 2693 // [JSInvocationMirror._invokeOn].
2698 // TODO(johnniwinther): Register this more precisely. 2694 // TODO(johnniwinther): Register this more precisely.
2699 registry?.registerDynamicUse(new DynamicUse(selector, null)); 2695 registry?.registerDynamicUse(new DynamicUse(selector, null));
2700 } 2696 }
2701 2697
2702 ConstantValue nameConstant = 2698 ConstantValue nameConstant =
2703 backend.constantSystem.createString(new DartString.literal(publicName)); 2699 constantSystem.createString(new DartString.literal(publicName));
2704 2700
2705 js.Name internalName = backend.namer.invocationName(selector); 2701 js.Name internalName = namer.invocationName(selector);
2706 2702
2707 var argumentsInstruction = 2703 var argumentsInstruction =
2708 new HLiteralList(arguments, commonMasks.extendableArrayType); 2704 new HLiteralList(arguments, commonMasks.extendableArrayType);
2709 add(argumentsInstruction); 2705 add(argumentsInstruction);
2710 2706
2711 var argumentNames = new List<HInstruction>(); 2707 var argumentNames = new List<HInstruction>();
2712 for (String argumentName in selector.namedArguments) { 2708 for (String argumentName in selector.namedArguments) {
2713 ConstantValue argumentNameConstant = backend.constantSystem 2709 ConstantValue argumentNameConstant =
2714 .createString(new DartString.literal(argumentName)); 2710 constantSystem.createString(new DartString.literal(argumentName));
2715 argumentNames.add(graph.addConstant(argumentNameConstant, closedWorld)); 2711 argumentNames.add(graph.addConstant(argumentNameConstant, closedWorld));
2716 } 2712 }
2717 var argumentNamesInstruction = 2713 var argumentNamesInstruction =
2718 new HLiteralList(argumentNames, commonMasks.extendableArrayType); 2714 new HLiteralList(argumentNames, commonMasks.extendableArrayType);
2719 add(argumentNamesInstruction); 2715 add(argumentNamesInstruction);
2720 2716
2721 ConstantValue kindConstant = 2717 ConstantValue kindConstant =
2722 backend.constantSystem.createInt(selector.invocationMirrorKind); 2718 constantSystem.createInt(selector.invocationMirrorKind);
2723 2719
2724 _pushStaticInvocation( 2720 _pushStaticInvocation(
2725 astAdapter.createInvocationMirror, 2721 astAdapter.createInvocationMirror,
2726 [ 2722 [
2727 graph.addConstant(nameConstant, closedWorld), 2723 graph.addConstant(nameConstant, closedWorld),
2728 graph.addConstantStringFromName(internalName, closedWorld), 2724 graph.addConstantStringFromName(internalName, closedWorld),
2729 graph.addConstant(kindConstant, closedWorld), 2725 graph.addConstant(kindConstant, closedWorld),
2730 argumentsInstruction, 2726 argumentsInstruction,
2731 argumentNamesInstruction 2727 argumentNamesInstruction
2732 ], 2728 ],
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2850 push( 2846 push(
2851 new HIs.variable(typeValue, expression, pop(), commonMasks.boolType)); 2847 new HIs.variable(typeValue, expression, pop(), commonMasks.boolType));
2852 return; 2848 return;
2853 } 2849 }
2854 2850
2855 if (_isInterfaceWithNoDynamicTypes(type)) { 2851 if (_isInterfaceWithNoDynamicTypes(type)) {
2856 HInstruction representations = typeBuilder 2852 HInstruction representations = typeBuilder
2857 .buildTypeArgumentRepresentations(typeValue, sourceElement); 2853 .buildTypeArgumentRepresentations(typeValue, sourceElement);
2858 add(representations); 2854 add(representations);
2859 ClassElement element = typeValue.element; 2855 ClassElement element = typeValue.element;
2860 js.Name operator = backend.namer.operatorIs(element); 2856 js.Name operator = namer.operatorIs(element);
2861 HInstruction isFieldName = 2857 HInstruction isFieldName =
2862 graph.addConstantStringFromName(operator, closedWorld); 2858 graph.addConstantStringFromName(operator, closedWorld);
2863 HInstruction asFieldName = closedWorld.hasAnyStrictSubtype(element) 2859 HInstruction asFieldName = closedWorld.hasAnyStrictSubtype(element)
2864 ? graph.addConstantStringFromName( 2860 ? graph.addConstantStringFromName(
2865 backend.namer.substitutionName(element), closedWorld) 2861 namer.substitutionName(element), closedWorld)
2866 : graph.addConstantNull(closedWorld); 2862 : graph.addConstantNull(closedWorld);
2867 List<HInstruction> inputs = <HInstruction>[ 2863 List<HInstruction> inputs = <HInstruction>[
2868 expression, 2864 expression,
2869 isFieldName, 2865 isFieldName,
2870 representations, 2866 representations,
2871 asFieldName 2867 asFieldName
2872 ]; 2868 ];
2873 _pushStaticInvocation( 2869 _pushStaticInvocation(
2874 astAdapter.checkSubtype, inputs, commonMasks.boolType); 2870 astAdapter.checkSubtype, inputs, commonMasks.boolType);
2875 push( 2871 push(
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
3227 enterBlock.setBlockFlow( 3223 enterBlock.setBlockFlow(
3228 new HTryBlockInformation( 3224 new HTryBlockInformation(
3229 kernelBuilder.wrapStatementGraph(bodyGraph), 3225 kernelBuilder.wrapStatementGraph(bodyGraph),
3230 exception, 3226 exception,
3231 kernelBuilder.wrapStatementGraph(catchGraph), 3227 kernelBuilder.wrapStatementGraph(catchGraph),
3232 kernelBuilder.wrapStatementGraph(finallyGraph)), 3228 kernelBuilder.wrapStatementGraph(finallyGraph)),
3233 exitBlock); 3229 exitBlock);
3234 kernelBuilder.inTryStatement = previouslyInTryStatement; 3230 kernelBuilder.inTryStatement = previouslyInTryStatement;
3235 } 3231 }
3236 } 3232 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698