| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); | 205 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); |
| 206 defaultValueTypes.update(index, parameter.name, type); | 206 defaultValueTypes.update(index, parameter.name, type); |
| 207 index++; | 207 index++; |
| 208 }); | 208 }); |
| 209 } | 209 } |
| 210 HTypeList parameterTypes = | 210 HTypeList parameterTypes = |
| 211 backend.optimisticParameterTypes(element.declaration, | 211 backend.optimisticParameterTypes(element.declaration, |
| 212 defaultValueTypes); | 212 defaultValueTypes); |
| 213 if (!parameterTypes.allUnknown) { | 213 if (!parameterTypes.allUnknown) { |
| 214 int i = 0; | 214 int i = 0; |
| 215 signature.forEachParameter((Element param) { | 215 signature.orderedForEachParameter((Element param) { |
| 216 builder.parameters[param].guaranteedType = parameterTypes[i++]; | 216 builder.parameters[param].guaranteedType = parameterTypes[i++]; |
| 217 }); | 217 }); |
| 218 } | 218 } |
| 219 backend.registerParameterTypesOptimization( | 219 backend.registerParameterTypesOptimization( |
| 220 element, parameterTypes, defaultValueTypes); | 220 element, parameterTypes, defaultValueTypes); |
| 221 } | 221 } |
| 222 | 222 |
| 223 if (compiler.tracer.enabled) { | 223 if (compiler.tracer.enabled) { |
| 224 String name; | 224 String name; |
| 225 if (element.isMember()) { | 225 if (element.isMember()) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 * | 358 * |
| 359 * Invariant: [function] must be an implementation element. | 359 * Invariant: [function] must be an implementation element. |
| 360 */ | 360 */ |
| 361 void startFunction(FunctionElement function, | 361 void startFunction(FunctionElement function, |
| 362 FunctionExpression node) { | 362 FunctionExpression node) { |
| 363 assert(invariant(node, function.isImplementation)); | 363 assert(invariant(node, function.isImplementation)); |
| 364 Compiler compiler = builder.compiler; | 364 Compiler compiler = builder.compiler; |
| 365 closureData = compiler.closureToClassMapper.computeClosureToClassMapping( | 365 closureData = compiler.closureToClassMapper.computeClosureToClassMapping( |
| 366 node, builder.elements); | 366 node, builder.elements); |
| 367 FunctionSignature signature = function.computeSignature(compiler); | 367 FunctionSignature signature = function.computeSignature(compiler); |
| 368 signature.forEachParameter((Element element) { | 368 signature.orderedForEachParameter((Element element) { |
| 369 HInstruction parameter = new HParameterValue(element); | 369 HInstruction parameter = new HParameterValue(element); |
| 370 builder.add(parameter); | 370 builder.add(parameter); |
| 371 builder.parameters[element] = parameter; | 371 builder.parameters[element] = parameter; |
| 372 directLocals[element] = parameter; | 372 directLocals[element] = parameter; |
| 373 parameter.guaranteedType = | 373 parameter.guaranteedType = |
| 374 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element)); | 374 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element)); |
| 375 }); | 375 }); |
| 376 | 376 |
| 377 enterScope(node); | 377 enterScope(node); |
| 378 | 378 |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 stack = <HInstruction>[]; | 1007 stack = <HInstruction>[]; |
| 1008 returnElement = new Element(const SourceString("result"), | 1008 returnElement = new Element(const SourceString("result"), |
| 1009 ElementKind.VARIABLE, | 1009 ElementKind.VARIABLE, |
| 1010 function); | 1010 function); |
| 1011 localsHandler.updateLocal(returnElement, | 1011 localsHandler.updateLocal(returnElement, |
| 1012 graph.addConstantNull(constantSystem)); | 1012 graph.addConstantNull(constantSystem)); |
| 1013 elements = compiler.enqueuer.resolution.getCachedElements(function); | 1013 elements = compiler.enqueuer.resolution.getCachedElements(function); |
| 1014 assert(elements !== null); | 1014 assert(elements !== null); |
| 1015 FunctionSignature signature = function.computeSignature(compiler); | 1015 FunctionSignature signature = function.computeSignature(compiler); |
| 1016 int index = 0; | 1016 int index = 0; |
| 1017 signature.forEachParameter((Element parameter) { | 1017 signature.orderedForEachParameter((Element parameter) { |
| 1018 HInstruction argument = compiledArguments[index++]; | 1018 HInstruction argument = compiledArguments[index++]; |
| 1019 localsHandler.updateLocal(parameter, argument); | 1019 localsHandler.updateLocal(parameter, argument); |
| 1020 potentiallyCheckType(argument, parameter); | 1020 potentiallyCheckType(argument, parameter); |
| 1021 }); | 1021 }); |
| 1022 return state; | 1022 return state; |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 void leaveInlinedMethod(InliningState state) { | 1025 void leaveInlinedMethod(InliningState state) { |
| 1026 InliningState poppedState = inliningStack.removeLast(); | 1026 InliningState poppedState = inliningStack.removeLast(); |
| 1027 assert(state == poppedState); | 1027 assert(state == poppedState); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 "Parameters and arguments didn't match for super/redirect call", | 1112 "Parameters and arguments didn't match for super/redirect call", |
| 1113 element: constructor); | 1113 element: constructor); |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 sourceElementStack.add(constructor.enclosingElement); | 1116 sourceElementStack.add(constructor.enclosingElement); |
| 1117 buildFieldInitializers(constructor.enclosingElement, fieldValues); | 1117 buildFieldInitializers(constructor.enclosingElement, fieldValues); |
| 1118 sourceElementStack.removeLast(); | 1118 sourceElementStack.removeLast(); |
| 1119 | 1119 |
| 1120 int index = 0; | 1120 int index = 0; |
| 1121 FunctionSignature params = constructor.computeSignature(compiler); | 1121 FunctionSignature params = constructor.computeSignature(compiler); |
| 1122 params.forEachParameter((Element parameter) { | 1122 params.orderedForEachParameter((Element parameter) { |
| 1123 HInstruction argument = compiledArguments[index++]; | 1123 HInstruction argument = compiledArguments[index++]; |
| 1124 localsHandler.updateLocal(parameter, argument); | 1124 localsHandler.updateLocal(parameter, argument); |
| 1125 // Don't forget to update the field, if the parameter is of the | 1125 // Don't forget to update the field, if the parameter is of the |
| 1126 // form [:this.x:]. | 1126 // form [:this.x:]. |
| 1127 if (parameter.kind == ElementKind.FIELD_PARAMETER) { | 1127 if (parameter.kind == ElementKind.FIELD_PARAMETER) { |
| 1128 FieldParameterElement fieldParameterElement = parameter; | 1128 FieldParameterElement fieldParameterElement = parameter; |
| 1129 fieldValues[fieldParameterElement.fieldElement] = argument; | 1129 fieldValues[fieldParameterElement.fieldElement] = argument; |
| 1130 } | 1130 } |
| 1131 }); | 1131 }); |
| 1132 | 1132 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 openFunction(functionElement, function); | 1264 openFunction(functionElement, function); |
| 1265 | 1265 |
| 1266 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); | 1266 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); |
| 1267 | 1267 |
| 1268 // Compile the possible initialization code for local fields and | 1268 // Compile the possible initialization code for local fields and |
| 1269 // super fields. | 1269 // super fields. |
| 1270 buildFieldInitializers(classElement, fieldValues); | 1270 buildFieldInitializers(classElement, fieldValues); |
| 1271 | 1271 |
| 1272 // Compile field-parameters such as [:this.x:]. | 1272 // Compile field-parameters such as [:this.x:]. |
| 1273 FunctionSignature params = functionElement.computeSignature(compiler); | 1273 FunctionSignature params = functionElement.computeSignature(compiler); |
| 1274 params.forEachParameter((Element element) { | 1274 params.orderedForEachParameter((Element element) { |
| 1275 if (element.kind == ElementKind.FIELD_PARAMETER) { | 1275 if (element.kind == ElementKind.FIELD_PARAMETER) { |
| 1276 // If the [element] is a field-parameter then | 1276 // If the [element] is a field-parameter then |
| 1277 // initialize the field element with its value. | 1277 // initialize the field element with its value. |
| 1278 FieldParameterElement fieldParameterElement = element; | 1278 FieldParameterElement fieldParameterElement = element; |
| 1279 HInstruction parameterValue = localsHandler.readLocal(element); | 1279 HInstruction parameterValue = localsHandler.readLocal(element); |
| 1280 fieldValues[fieldParameterElement.fieldElement] = parameterValue; | 1280 fieldValues[fieldParameterElement.fieldElement] = parameterValue; |
| 1281 } | 1281 } |
| 1282 }); | 1282 }); |
| 1283 | 1283 |
| 1284 // Analyze the constructor and all referenced constructors and collect | 1284 // Analyze the constructor and all referenced constructors and collect |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1312 // Generate calls to the constructor bodies. | 1312 // Generate calls to the constructor bodies. |
| 1313 for (int index = constructors.length - 1; index >= 0; index--) { | 1313 for (int index = constructors.length - 1; index >= 0; index--) { |
| 1314 FunctionElement constructor = constructors[index]; | 1314 FunctionElement constructor = constructors[index]; |
| 1315 assert(invariant(functionElement, constructor.isImplementation)); | 1315 assert(invariant(functionElement, constructor.isImplementation)); |
| 1316 ConstructorBodyElement body = getConstructorBody(constructor); | 1316 ConstructorBodyElement body = getConstructorBody(constructor); |
| 1317 if (body === null) continue; | 1317 if (body === null) continue; |
| 1318 List bodyCallInputs = <HInstruction>[]; | 1318 List bodyCallInputs = <HInstruction>[]; |
| 1319 bodyCallInputs.add(newObject); | 1319 bodyCallInputs.add(newObject); |
| 1320 FunctionSignature functionSignature = body.computeSignature(compiler); | 1320 FunctionSignature functionSignature = body.computeSignature(compiler); |
| 1321 int arity = functionSignature.parameterCount; | 1321 int arity = functionSignature.parameterCount; |
| 1322 functionSignature.forEachParameter((parameter) { | 1322 functionSignature.orderedForEachParameter((parameter) { |
| 1323 bodyCallInputs.add(localsHandler.readLocal(parameter)); | 1323 bodyCallInputs.add(localsHandler.readLocal(parameter)); |
| 1324 }); | 1324 }); |
| 1325 // TODO(ahe): The constructor name is statically resolved. See | 1325 // TODO(ahe): The constructor name is statically resolved. See |
| 1326 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner | 1326 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner |
| 1327 // way to do this? | 1327 // way to do this? |
| 1328 SourceString name = | 1328 SourceString name = |
| 1329 new SourceString(backend.namer.getName(body.declaration)); | 1329 new SourceString(backend.namer.getName(body.declaration)); |
| 1330 // TODO(kasperl): This seems fishy. We shouldn't be inventing all | 1330 // TODO(kasperl): This seems fishy. We shouldn't be inventing all |
| 1331 // these selectors. Maybe the resolver can do more of the work | 1331 // these selectors. Maybe the resolver can do more of the work |
| 1332 // for us here? | 1332 // for us here? |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 assert(invariant(functionElement, functionElement.isImplementation)); | 1394 assert(invariant(functionElement, functionElement.isImplementation)); |
| 1395 HBasicBlock block = graph.addNewBlock(); | 1395 HBasicBlock block = graph.addNewBlock(); |
| 1396 open(graph.entry); | 1396 open(graph.entry); |
| 1397 | 1397 |
| 1398 localsHandler.startFunction(functionElement, node); | 1398 localsHandler.startFunction(functionElement, node); |
| 1399 close(new HGoto()).addSuccessor(block); | 1399 close(new HGoto()).addSuccessor(block); |
| 1400 | 1400 |
| 1401 open(block); | 1401 open(block); |
| 1402 | 1402 |
| 1403 FunctionSignature params = functionElement.computeSignature(compiler); | 1403 FunctionSignature params = functionElement.computeSignature(compiler); |
| 1404 params.forEachParameter((Element element) { | 1404 params.orderedForEachParameter((Element element) { |
| 1405 if (elements.isParameterChecked(element)) { | 1405 if (elements.isParameterChecked(element)) { |
| 1406 addParameterCheckInstruction(element); | 1406 addParameterCheckInstruction(element); |
| 1407 } | 1407 } |
| 1408 }); | 1408 }); |
| 1409 | 1409 |
| 1410 // Put the type checks in the first successor of the entry, | 1410 // Put the type checks in the first successor of the entry, |
| 1411 // because that is where the type guards will also be inserted. | 1411 // because that is where the type guards will also be inserted. |
| 1412 // This way we ensure that a type guard will dominate the type | 1412 // This way we ensure that a type guard will dominate the type |
| 1413 // check. | 1413 // check. |
| 1414 params.forEachParameter((Element element) { | 1414 params.orderedForEachParameter((Element element) { |
| 1415 HInstruction newParameter = potentiallyCheckType( | 1415 HInstruction newParameter = potentiallyCheckType( |
| 1416 localsHandler.directLocals[element], element); | 1416 localsHandler.directLocals[element], element); |
| 1417 localsHandler.directLocals[element] = newParameter; | 1417 localsHandler.directLocals[element] = newParameter; |
| 1418 }); | 1418 }); |
| 1419 | 1419 |
| 1420 // Add the type parameters of the class as parameters of this | 1420 // Add the type parameters of the class as parameters of this |
| 1421 // method. | 1421 // method. |
| 1422 var enclosing = functionElement.enclosingElement; | 1422 var enclosing = functionElement.enclosingElement; |
| 1423 if (functionElement.isConstructor() && compiler.world.needsRti(enclosing)) { | 1423 if (functionElement.isConstructor() && compiler.world.needsRti(enclosing)) { |
| 1424 enclosing.typeVariables.forEach((TypeVariableType typeVariable) { | 1424 enclosing.typeVariables.forEach((TypeVariableType typeVariable) { |
| (...skipping 2920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4345 new HSubGraphBlockInformation(elseBranch.graph)); | 4345 new HSubGraphBlockInformation(elseBranch.graph)); |
| 4346 | 4346 |
| 4347 HBasicBlock conditionStartBlock = conditionBranch.block; | 4347 HBasicBlock conditionStartBlock = conditionBranch.block; |
| 4348 conditionStartBlock.setBlockFlow(info, joinBlock); | 4348 conditionStartBlock.setBlockFlow(info, joinBlock); |
| 4349 SubGraph conditionGraph = conditionBranch.graph; | 4349 SubGraph conditionGraph = conditionBranch.graph; |
| 4350 HIf branch = conditionGraph.end.last; | 4350 HIf branch = conditionGraph.end.last; |
| 4351 assert(branch is HIf); | 4351 assert(branch is HIf); |
| 4352 branch.blockInformation = conditionStartBlock.blockFlow; | 4352 branch.blockInformation = conditionStartBlock.blockFlow; |
| 4353 } | 4353 } |
| 4354 } | 4354 } |
| OLD | NEW |