OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'dart:async'; | 5 import 'dart:async'; |
6 import '../mock_compiler.dart'; | 6 import '../mock_compiler.dart'; |
7 import 'sexpr_unstringifier.dart'; | 7 import 'sexpr_unstringifier.dart'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
10 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; | 10 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; |
11 import 'package:compiler/src/cps_ir/optimizers.dart'; | 11 import 'package:compiler/src/cps_ir/optimizers.dart'; |
12 import 'package:compiler/src/dart2jslib.dart' as dart2js; | 12 import 'package:compiler/src/constant_system_dart.dart'; |
13 | 13 |
14 // The tests in this file that ensure that sparse constant propagation on the | 14 // The tests in this file that ensure that sparse constant propagation on the |
15 // CPS IR works as expected. | 15 // CPS IR works as expected. |
16 | 16 |
17 // CP1 represents the following incoming dart code: | 17 // CP1 represents the following incoming dart code: |
18 // | 18 // |
19 // int main() { | 19 // int main() { |
20 // int i = 1; | 20 // int i = 1; |
21 // int j; | 21 // int j; |
22 // if (i == 1) { | 22 // if (i == 1) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 /// the stringification of the result against the expected output. | 493 /// the stringification of the result against the expected output. |
494 Future testConstantPropagator(String input, String expectedOutput) { | 494 Future testConstantPropagator(String input, String expectedOutput) { |
495 final compiler = new MockCompiler.internal( | 495 final compiler = new MockCompiler.internal( |
496 emitJavaScript: false, | 496 emitJavaScript: false, |
497 enableMinification: false); | 497 enableMinification: false); |
498 return compiler.init().then((_) { | 498 return compiler.init().then((_) { |
499 final unstringifier = new SExpressionUnstringifier(); | 499 final unstringifier = new SExpressionUnstringifier(); |
500 final stringifier = new SExpressionStringifier(); | 500 final stringifier = new SExpressionStringifier(); |
501 final optimizer = new TypePropagator( | 501 final optimizer = new TypePropagator( |
502 compiler.types, | 502 compiler.types, |
503 dart2js.DART_CONSTANT_SYSTEM, | 503 DART_CONSTANT_SYSTEM, |
504 new UnitTypeSystem(), | 504 new UnitTypeSystem(), |
505 compiler.internalError); | 505 compiler.internalError); |
506 | 506 |
507 final f = unstringifier.unstringify(input); | 507 final f = unstringifier.unstringify(input); |
508 optimizer.rewrite(f); | 508 optimizer.rewrite(f); |
509 | 509 |
510 String expected = normalizeSExpr(expectedOutput); | 510 String expected = normalizeSExpr(expectedOutput); |
511 String actual = normalizeSExpr(stringifier.visit(f)); | 511 String actual = normalizeSExpr(stringifier.visit(f)); |
512 | 512 |
513 Expect.equals(expected, actual); | 513 Expect.equals(expected, actual); |
514 }); | 514 }); |
515 } | 515 } |
516 | 516 |
517 void main() { | 517 void main() { |
518 asyncTest(() => testConstantPropagator(CP1_IN, CP1_OUT)); | 518 asyncTest(() => testConstantPropagator(CP1_IN, CP1_OUT)); |
519 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); | 519 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); |
520 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); | 520 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); |
521 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); | 521 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); |
522 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); | 522 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); |
523 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); | 523 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); |
524 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); | 524 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); |
525 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); | 525 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); |
526 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); | 526 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); |
527 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); | 527 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); |
528 } | 528 } |
OLD | NEW |