OLD | NEW |
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 '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
9 import '../common/tasks.dart' show CompilerTask; | 9 import '../common/tasks.dart' show CompilerTask; |
10 import '../compiler.dart'; | 10 import '../compiler.dart'; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 this.registry, | 63 this.registry, |
64 SourceInformationStrategy sourceInformationFactory, | 64 SourceInformationStrategy sourceInformationFactory, |
65 Kernel kernel) { | 65 Kernel kernel) { |
66 graph.element = targetElement; | 66 graph.element = targetElement; |
67 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? | 67 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? |
68 this.sourceInformationBuilder = | 68 this.sourceInformationBuilder = |
69 sourceInformationFactory.createBuilderForContext(resolvedAst); | 69 sourceInformationFactory.createBuilderForContext(resolvedAst); |
70 graph.sourceInformation = | 70 graph.sourceInformation = |
71 sourceInformationBuilder.buildVariableDeclaration(); | 71 sourceInformationBuilder.buildVariableDeclaration(); |
72 this.localsHandler = new LocalsHandler(this, targetElement, null, compiler); | 72 this.localsHandler = new LocalsHandler(this, targetElement, null, compiler); |
73 this.astAdapter = new KernelAstAdapter( | 73 this.astAdapter = new KernelAstAdapter(kernel, compiler.backend, |
74 compiler.backend, | 74 resolvedAst, kernel.nodeToAst, kernel.nodeToElement); |
75 resolvedAst, | |
76 kernel.nodeToAst, | |
77 kernel.nodeToElement, | |
78 kernel.fields, | |
79 kernel.functions, | |
80 kernel.classes, | |
81 kernel.libraries); | |
82 Element originTarget = targetElement; | 75 Element originTarget = targetElement; |
83 if (originTarget.isPatch) { | 76 if (originTarget.isPatch) { |
84 originTarget = originTarget.origin; | 77 originTarget = originTarget.origin; |
85 } | 78 } |
86 if (originTarget is FunctionElement) { | 79 if (originTarget is FunctionElement) { |
87 target = kernel.functions[originTarget]; | 80 target = kernel.functions[originTarget]; |
88 } else if (originTarget is FieldElement) { | 81 } else if (originTarget is FieldElement) { |
89 target = kernel.fields[originTarget]; | 82 target = kernel.fields[originTarget]; |
90 } | 83 } |
91 } | 84 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 listInstruction = new HLiteralList(elements, backend.extendableArrayType); | 286 listInstruction = new HLiteralList(elements, backend.extendableArrayType); |
294 add(listInstruction); | 287 add(listInstruction); |
295 // TODO(het): set runtime type info | 288 // TODO(het): set runtime type info |
296 } | 289 } |
297 | 290 |
298 // TODO(het): Set the instruction type to the list type given by inference | 291 // TODO(het): Set the instruction type to the list type given by inference |
299 stack.add(listInstruction); | 292 stack.add(listInstruction); |
300 } | 293 } |
301 | 294 |
302 @override | 295 @override |
| 296 void visitMapLiteral(ir.MapLiteral mapLiteral) { |
| 297 if (mapLiteral.isConst) { |
| 298 stack.add( |
| 299 graph.addConstant(astAdapter.getConstantFor(mapLiteral), compiler)); |
| 300 return; |
| 301 } |
| 302 |
| 303 // The map literal constructors take the key-value pairs as a List |
| 304 List<HInstruction> constructorArgs = <HInstruction>[]; |
| 305 for (ir.MapEntry mapEntry in mapLiteral.entries) { |
| 306 mapEntry.accept(this); |
| 307 constructorArgs.add(pop()); |
| 308 constructorArgs.add(pop()); |
| 309 } |
| 310 |
| 311 // The constructor is a procedure because it's a factory. |
| 312 ir.Procedure constructor; |
| 313 List<HInstruction> inputs = <HInstruction>[]; |
| 314 if (constructorArgs.isEmpty) { |
| 315 constructor = astAdapter.mapLiteralConstructorEmpty; |
| 316 } else { |
| 317 constructor = astAdapter.mapLiteralConstructor; |
| 318 HLiteralList argList = |
| 319 new HLiteralList(constructorArgs, backend.extendableArrayType); |
| 320 add(argList); |
| 321 inputs.add(argList); |
| 322 } |
| 323 |
| 324 // TODO(het): Add type information |
| 325 _pushStaticInvocation(constructor, inputs, backend.dynamicType); |
| 326 } |
| 327 |
| 328 @override |
| 329 void visitMapEntry(ir.MapEntry mapEntry) { |
| 330 // Visit value before the key because each will push an expression to the |
| 331 // stack, so when we pop them off, the key is popped first, then the value. |
| 332 mapEntry.value.accept(this); |
| 333 mapEntry.key.accept(this); |
| 334 } |
| 335 |
| 336 @override |
303 void visitStaticGet(ir.StaticGet staticGet) { | 337 void visitStaticGet(ir.StaticGet staticGet) { |
304 var staticTarget = staticGet.target; | 338 var staticTarget = staticGet.target; |
305 Element element = astAdapter.getElement(staticTarget).declaration; | 339 Element element = astAdapter.getElement(staticTarget).declaration; |
306 if (staticTarget is ir.Procedure && | 340 if (staticTarget is ir.Procedure && |
307 staticTarget.kind == ir.ProcedureKind.Getter) { | 341 staticTarget.kind == ir.ProcedureKind.Getter) { |
308 // Invoke the getter | 342 // Invoke the getter |
309 _pushStaticInvocation( | 343 _pushStaticInvocation( |
310 target, const <HInstruction>[], astAdapter.returnTypeOf(target)); | 344 target, const <HInstruction>[], astAdapter.returnTypeOf(target)); |
311 } else { | 345 } else { |
312 push(new HStatic(element, astAdapter.inferredTypeOf(staticTarget))); | 346 push(new HStatic(element, astAdapter.inferredTypeOf(staticTarget))); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 ir.Procedure target = invocation.target; | 442 ir.Procedure target = invocation.target; |
409 TypeMask typeMask = astAdapter.returnTypeOf(target); | 443 TypeMask typeMask = astAdapter.returnTypeOf(target); |
410 | 444 |
411 List<HInstruction> arguments = _visitArguments(invocation.arguments); | 445 List<HInstruction> arguments = _visitArguments(invocation.arguments); |
412 | 446 |
413 _pushStaticInvocation(target, arguments, typeMask); | 447 _pushStaticInvocation(target, arguments, typeMask); |
414 } | 448 } |
415 | 449 |
416 void _pushStaticInvocation( | 450 void _pushStaticInvocation( |
417 ir.Node target, List<HInstruction> arguments, TypeMask typeMask) { | 451 ir.Node target, List<HInstruction> arguments, TypeMask typeMask) { |
418 bool targetCanThrow = astAdapter.getCanThrow(target); | |
419 | |
420 HInstruction instruction = new HInvokeStatic( | 452 HInstruction instruction = new HInvokeStatic( |
421 astAdapter.getElement(target).declaration, arguments, typeMask, | 453 astAdapter.getElement(target).declaration, arguments, typeMask, |
422 targetCanThrow: targetCanThrow); | 454 targetCanThrow: astAdapter.getCanThrow(target)); |
423 instruction.sideEffects = astAdapter.getSideEffects(target); | 455 instruction.sideEffects = astAdapter.getSideEffects(target); |
424 | 456 |
425 push(instruction); | 457 push(instruction); |
426 } | 458 } |
427 | 459 |
428 // TODO(het): Decide when to inline | 460 // TODO(het): Decide when to inline |
429 @override | 461 @override |
430 void visitMethodInvocation(ir.MethodInvocation invocation) { | 462 void visitMethodInvocation(ir.MethodInvocation invocation) { |
431 invocation.receiver.accept(this); | 463 invocation.receiver.accept(this); |
432 HInstruction receiver = pop(); | 464 HInstruction receiver = pop(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 void visitThisExpression(ir.ThisExpression thisExpression) { | 564 void visitThisExpression(ir.ThisExpression thisExpression) { |
533 stack.add(localsHandler.readThis()); | 565 stack.add(localsHandler.readThis()); |
534 } | 566 } |
535 | 567 |
536 @override | 568 @override |
537 void visitNot(ir.Not not) { | 569 void visitNot(ir.Not not) { |
538 not.operand.accept(this); | 570 not.operand.accept(this); |
539 push(new HNot(popBoolified(), backend.boolType)); | 571 push(new HNot(popBoolified(), backend.boolType)); |
540 } | 572 } |
541 } | 573 } |
OLD | NEW |