| 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'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // if (i == 1) { | 22 // if (i == 1) { |
| 23 // j = 2; | 23 // j = 2; |
| 24 // } else { | 24 // } else { |
| 25 // j = 3; | 25 // j = 3; |
| 26 // } | 26 // } |
| 27 // return j; | 27 // return j; |
| 28 // } | 28 // } |
| 29 | 29 |
| 30 String CP1_IN = """ | 30 String CP1_IN = """ |
| 31 (FunctionDefinition main () return () | 31 (FunctionDefinition main () return () |
| 32 (LetPrim v0 (Constant (Int 1))) | 32 (LetPrim (v0 (Constant (Int 1))) |
| 33 (LetPrim v1 (Constant (Int 1))) | 33 (LetPrim (v1 (Constant (Int 1))) |
| 34 (LetCont (k0 v2) | 34 (LetCont (k0 (v2) |
| 35 (LetCont (k1) (LetPrim v3 (Constant (Int 2))) | 35 (LetCont (k1 () |
| 36 (InvokeContinuation return v3)) | 36 (LetPrim (v3 (Constant (Int 2))) |
| 37 (LetCont (k2) (LetPrim v4 (Constant (Int 3))) | 37 (InvokeContinuation return (v3)))) |
| 38 (InvokeContinuation return v4)) | 38 (LetCont (k2 () |
| 39 (Branch (IsTrue v2) k1 k2)) | 39 (LetPrim (v4 (Constant (Int 3))) |
| 40 (InvokeMethod v0 == v1 k0)) | 40 (InvokeContinuation return (v4)))) |
| 41 (Branch (IsTrue v2) k1 k2)))) |
| 42 (InvokeMethod v0 == (v1) k0))))) |
| 41 """; | 43 """; |
| 42 String CP1_OUT = """ | 44 String CP1_OUT = """ |
| 43 (FunctionDefinition main () return () | 45 (FunctionDefinition main () return () |
| 44 (LetPrim v0 (Constant (Int 1))) | 46 (LetPrim (v0 (Constant (Int 1))) |
| 45 (LetPrim v1 (Constant (Int 1))) | 47 (LetPrim (v1 (Constant (Int 1))) |
| 46 (LetCont (k0 v2) | 48 (LetCont (k0 (v2) |
| 47 (LetCont (k1) | 49 (LetCont (k1 () |
| 48 (LetPrim v3 (Constant (Int 2))) | 50 (LetPrim (v3 (Constant (Int 2))) |
| 49 (InvokeContinuation return v3)) | 51 (InvokeContinuation return (v3)))) |
| 50 (LetCont (k2) | 52 (LetCont (k2 () |
| 51 (LetPrim v4 (Constant (Int 3))) | 53 (LetPrim (v4 (Constant (Int 3))) |
| 52 (InvokeContinuation return v4)) | 54 (InvokeContinuation return (v4)))) |
| 53 (InvokeContinuation k1 )) | 55 (InvokeContinuation k1 ())))) |
| 54 (LetPrim v5 (Constant (Bool true))) | 56 (LetPrim (v5 (Constant (Bool true))) |
| 55 (InvokeContinuation k0 v5)) | 57 (InvokeContinuation k0 (v5))))))) |
| 56 """; | 58 """; |
| 57 | 59 |
| 58 // CP2 represents the following incoming dart code: | 60 // CP2 represents the following incoming dart code: |
| 59 // | 61 // |
| 60 // int main() { | 62 // int main() { |
| 61 // int i = 1; | 63 // int i = 1; |
| 62 // while (true) { | 64 // while (true) { |
| 63 // if (false || false) { | 65 // if (false || false) { |
| 64 // return i; | 66 // return i; |
| 65 // } | 67 // } |
| 66 // if (true && i == 1) { | 68 // if (true && i == 1) { |
| 67 // return i; | 69 // return i; |
| 68 // } | 70 // } |
| 69 // } | 71 // } |
| 70 // return 42; | 72 // return 42; |
| 71 // } | 73 // } |
| 72 | 74 |
| 73 String CP2_IN = """ | 75 String CP2_IN = """ |
| 74 (FunctionDefinition main () return () | 76 (FunctionDefinition main () return () |
| 75 (LetPrim v0 (Constant (Int 1))) | 77 (LetPrim (v0 (Constant (Int 1))) |
| 76 (LetCont* (k0) | 78 (LetCont* (k0 () |
| 77 (LetCont (k1) (LetPrim v1 (Constant (Int 42))) | 79 (LetCont (k1 () |
| 78 (InvokeContinuation return v1)) | 80 (LetPrim (v1 (Constant (Int 42))) |
| 79 (LetCont (k2) (LetPrim v2 (Constant (Bool false))) | 81 (InvokeContinuation return (v1)))) |
| 80 (LetCont (k3 v3) | 82 (LetCont (k2 () |
| 81 (LetCont (k4) (InvokeContinuation return v0)) | 83 (LetPrim (v2 (Constant (Bool false))) |
| 82 (LetCont (k5) (LetPrim v4 (Constant (Bool true))) | 84 (LetCont (k3 (v3) |
| 83 (LetCont (k6 v5) | 85 (LetCont (k4 () |
| 84 (LetCont (k7) (InvokeContinuation return v0)) | 86 (InvokeContinuation return (v0))) |
| 85 (LetCont (k8) (InvokeContinuation* k0)) | 87 (LetCont (k5 () |
| 86 (Branch (IsTrue v5) k7 k8)) | 88 (LetPrim (v4 (Constant (Bool true))) |
| 87 (LetCont (k9) (LetPrim v6 (Constant (Int 1))) | 89 (LetCont (k6 (v5) |
| 88 (LetCont (k10 v7) | 90 (LetCont (k7 () |
| 89 (LetCont (k11) (LetPrim v8 (Constant (Bool true))) | 91 (InvokeContinuation return (v0))) |
| 90 (InvokeContinuation k6 v8)) | 92 (LetCont (k8 () |
| 91 (LetCont (k12) (LetPrim v9 (Constant (Bool false))) | 93 (InvokeContinuation* k0 ())) |
| 92 (InvokeContinuation k6 v9)) | 94 (Branch (IsTrue v5) k7 k8)))) |
| 93 (Branch (IsTrue v7) k11 k12)) | 95 (LetCont (k9 () |
| 94 (InvokeMethod v0 == v6 k10)) | 96 (LetPrim (v6 (Constant (Int 1))) |
| 95 (LetCont (k13) (LetPrim v10 (Constant (Bool false))) | 97 (LetCont (k10 (v7) |
| 96 (InvokeContinuation k6 v10)) | 98 (LetCont (k11 () |
| 97 (Branch (IsTrue v4) k9 k13)) | 99 (LetPrim (v8 (Constant (Bool true))) |
| 98 (Branch (IsTrue v3) k4 k5)) | 100 (InvokeContinuation k6 (v8)))) |
| 99 (LetCont (k14) (LetPrim v11 (Constant (Bool true))) | 101 (LetCont (k12 () |
| 100 (InvokeContinuation k3 v11)) | 102 (LetPrim (v9 (Constant (Bool false
))) |
| 101 (LetCont (k15) (LetPrim v12 (Constant (Bool false))) | 103 (InvokeContinuation k6 (v9)))) |
| 102 (LetCont (k16) (LetPrim v13 (Constant (Bool true))) | 104 (Branch (IsTrue v7) k11 k12)))) |
| 103 (InvokeContinuation k3 v13)) | 105 (InvokeMethod v0 == (v6) k10)))) |
| 104 (LetCont (k17) (LetPrim v14 (Constant (Bool false))) | 106 (LetCont (k13 () |
| 105 (InvokeContinuation k3 v14)) | 107 (LetPrim (v10 (Constant (Bool false))) |
| 106 (Branch (IsTrue v12) k16 k17)) | 108 (InvokeContinuation k6 (v10)))) |
| 107 (Branch (IsTrue v2) k14 k15)) | 109 (Branch (IsTrue v4) k9 k13)))))) |
| 108 (LetPrim v15 (Constant (Bool true))) | 110 (Branch (IsTrue v3) k4 k5)))) |
| 109 (Branch (IsTrue v15) k2 k1)) | 111 (LetCont (k14 () |
| 110 (InvokeContinuation k0)) | 112 (LetPrim (v11 (Constant (Bool true))) |
| 113 (InvokeContinuation k3 (v11)))) |
| 114 (LetCont (k15 () |
| 115 (LetPrim (v12 (Constant (Bool false))) |
| 116 (LetCont (k16 () |
| 117 (LetPrim (v13 (Constant (Bool true))) |
| 118 (InvokeContinuation k3 (v13)))) |
| 119 (LetCont (k17 () |
| 120 (LetPrim (v14 (Constant (Bool false))) |
| 121 (InvokeContinuation k3 (v14)))) |
| 122 (Branch (IsTrue v12) k16 k17))))) |
| 123 (Branch (IsTrue v2) k14 k15)))))) |
| 124 (LetPrim (v15 (Constant (Bool true))) |
| 125 (Branch (IsTrue v15) k2 k1))))) |
| 126 (InvokeContinuation k0 ())))) |
| 111 """; | 127 """; |
| 112 String CP2_OUT = """ | 128 String CP2_OUT = """ |
| 113 (FunctionDefinition main () return () | 129 (FunctionDefinition main () return () |
| 114 (LetPrim v0 (Constant (Int 1))) | 130 (LetPrim (v0 (Constant (Int 1))) |
| 115 (LetCont* (k0) | 131 (LetCont* (k0 () |
| 116 (LetCont (k1) (LetPrim v1 (Constant (Int 42))) | 132 (LetCont (k1 () |
| 117 (InvokeContinuation return v1)) | 133 (LetPrim (v1 (Constant (Int 42))) |
| 118 (LetCont (k2) | 134 (InvokeContinuation return (v1)))) |
| 119 (LetPrim v2 (Constant (Bool false))) | 135 (LetCont (k2 () |
| 120 (LetCont (k3 v3) | 136 (LetPrim (v2 (Constant (Bool false))) |
| 121 (LetCont (k4) (InvokeContinuation return v0)) | 137 (LetCont (k3 (v3) |
| 122 (LetCont (k5) | 138 (LetCont (k4 () |
| 123 (LetPrim v4 (Constant (Bool true))) | 139 (InvokeContinuation return (v0))) |
| 124 (LetCont (k6 v5) | 140 (LetCont (k5 () |
| 125 (LetCont (k7) (InvokeContinuation return v0)) | 141 (LetPrim (v4 (Constant (Bool true))) |
| 126 (LetCont (k8) (InvokeContinuation* k0 )) | 142 (LetCont (k6 (v5) |
| 127 (InvokeContinuation k7 )) | 143 (LetCont (k7 () |
| 128 (LetCont (k9) | 144 (InvokeContinuation return (v0))) |
| 129 (LetPrim v6 (Constant (Int 1))) | 145 (LetCont (k8 () |
| 130 (LetCont (k10 v7) | 146 (InvokeContinuation* k0 ())) |
| 131 (LetCont (k11) | 147 (InvokeContinuation k7 ())))) |
| 132 (LetPrim v8 (Constant (Bool true))) | 148 (LetCont (k9 () |
| 133 (InvokeContinuation k6 v8)) | 149 (LetPrim (v6 (Constant (Int 1))) |
| 134 (LetCont (k12) (LetPrim v9 (Constant (Bool false))) | 150 (LetCont (k10 (v7) |
| 135 (InvokeContinuation k6 v9)) | 151 (LetCont (k11 () |
| 136 (InvokeContinuation k11 )) | 152 (LetPrim (v8 (Constant (Bool true))) |
| 137 (LetPrim v10 (Constant (Bool true))) | 153 (InvokeContinuation k6 (v8)))) |
| 138 (InvokeContinuation k10 v10)) | 154 (LetCont (k12 () |
| 139 (LetCont (k13) (LetPrim v11 (Constant (Bool false))) | 155 (LetPrim (v9 (Constant (Bool false
))) |
| 140 (InvokeContinuation k6 v11)) | 156 (InvokeContinuation k6 (v9)))) |
| 141 (InvokeContinuation k9 )) | 157 (InvokeContinuation k11 ())))) |
| 142 (InvokeContinuation k5 )) | 158 (LetPrim (v10 (Constant (Bool true))) |
| 143 (LetCont (k14) (LetPrim v12 (Constant (Bool true))) | 159 (InvokeContinuation k10 (v10)))))) |
| 144 (InvokeContinuation k3 v12)) | 160 (LetCont (k13 () |
| 145 (LetCont (k15) | 161 (LetPrim (v11 (Constant (Bool false))) |
| 146 (LetPrim v13 (Constant (Bool false))) | 162 (InvokeContinuation k6 (v11)))) |
| 147 (LetCont (k16) (LetPrim v14 (Constant (Bool true))) | 163 (InvokeContinuation k9 ())))))) |
| 148 (InvokeContinuation k3 v14)) | 164 (InvokeContinuation k5 ())))) |
| 149 (LetCont (k17) | 165 (LetCont (k14 () |
| 150 (LetPrim v15 (Constant (Bool false))) | 166 (LetPrim (v12 (Constant (Bool true))) |
| 151 (InvokeContinuation k3 v15)) | 167 (InvokeContinuation k3 (v12)))) |
| 152 (InvokeContinuation k17 )) | 168 (LetCont (k15 () |
| 153 (InvokeContinuation k15 )) | 169 (LetPrim (v13 (Constant (Bool false))) |
| 154 (LetPrim v16 (Constant (Bool true))) | 170 (LetCont (k16 () |
| 155 (InvokeContinuation k2 )) | 171 (LetPrim (v14 (Constant (Bool true))) |
| 156 (InvokeContinuation k0 )) | 172 (InvokeContinuation k3 (v14)))) |
| 173 (LetCont (k17 () |
| 174 (LetPrim (v15 (Constant (Bool false))) |
| 175 (InvokeContinuation k3 (v15)))) |
| 176 (InvokeContinuation k17 ()))))) |
| 177 (InvokeContinuation k15 ())))))) |
| 178 (LetPrim (v16 (Constant (Bool true))) |
| 179 (InvokeContinuation k2 ()))))) |
| 180 (InvokeContinuation k0 ())))) |
| 157 """; | 181 """; |
| 158 | 182 |
| 159 // CP3 represents the following incoming dart code: | 183 // CP3 represents the following incoming dart code: |
| 160 // | 184 // |
| 161 // int main() { | 185 // int main() { |
| 162 // int i = 1; | 186 // int i = 1; |
| 163 // i = f(); | 187 // i = f(); |
| 164 // if (i == 1) { | 188 // if (i == 1) { |
| 165 // return 42; | 189 // return 42; |
| 166 // } | 190 // } |
| 167 // return i; | 191 // return i; |
| 168 // } | 192 // } |
| 169 | 193 |
| 170 String CP3_IN = """ | 194 String CP3_IN = """ |
| 171 (FunctionDefinition main () return () | 195 (FunctionDefinition main () return () |
| 172 (LetPrim v0 (Constant (Int 1))) | 196 (LetPrim (v0 (Constant (Int 1))) |
| 173 (LetCont (k0 v1) (LetPrim v2 (Constant (Int 1))) | 197 (LetCont (k0 (v1) |
| 174 (LetCont (k1 v3) | 198 (LetPrim (v2 (Constant (Int 1))) |
| 175 (LetCont (k2) (LetPrim v4 (Constant (Int 42))) | 199 (LetCont (k1 (v3) |
| 176 (InvokeContinuation return v4)) | 200 (LetCont (k2 () |
| 177 (LetCont (k3) (InvokeContinuation return v1)) | 201 (LetPrim (v4 (Constant (Int 42))) |
| 178 (Branch (IsTrue v3) k2 k3)) | 202 (InvokeContinuation return (v4)))) |
| 179 (InvokeMethod v1 == v2 k1)) | 203 (LetCont (k3 () |
| 180 (InvokeStatic f k0)) | 204 (InvokeContinuation return (v1))) |
| 205 (Branch (IsTrue v3) k2 k3)))) |
| 206 (InvokeMethod v1 == (v2) k1)))) |
| 207 (InvokeStatic f () k0)))) |
| 181 """; | 208 """; |
| 182 String CP3_OUT = CP3_IN; | 209 String CP3_OUT = CP3_IN; |
| 183 | 210 |
| 184 // Addition. | 211 // Addition. |
| 185 | 212 |
| 186 String CP4_IN = """ | 213 String CP4_IN = """ |
| 187 (FunctionDefinition main () return () | 214 (FunctionDefinition main () return () |
| 188 (LetPrim v0 (Constant (Int 1))) | 215 (LetPrim (v0 (Constant (Int 1))) |
| 189 (LetPrim v1 (Constant (Int 2))) | 216 (LetPrim (v1 (Constant (Int 2))) |
| 190 (LetCont (k0 v2) | 217 (LetCont (k0 (v2) |
| 191 (InvokeContinuation return v2)) | 218 (InvokeContinuation return (v2))) |
| 192 (InvokeMethod v0 + v1 k0)) | 219 (InvokeMethod v0 + (v1) k0))))) |
| 193 """; | 220 """; |
| 194 String CP4_OUT = """ | 221 String CP4_OUT = """ |
| 195 (FunctionDefinition main () return () | 222 (FunctionDefinition main () return () |
| 196 (LetPrim v0 (Constant (Int 1))) | 223 (LetPrim (v0 (Constant (Int 1))) |
| 197 (LetPrim v1 (Constant (Int 2))) | 224 (LetPrim (v1 (Constant (Int 2))) |
| 198 (LetCont (k0 v2) | 225 (LetCont (k0 (v2) |
| 199 (InvokeContinuation return v2)) | 226 (InvokeContinuation return (v2))) |
| 200 (LetPrim v3 (Constant (Int 3))) | 227 (LetPrim (v3 (Constant (Int 3))) |
| 201 (InvokeContinuation k0 v3)) | 228 (InvokeContinuation k0 (v3))))))) |
| 202 """; | 229 """; |
| 203 | 230 |
| 204 // Array access operator (no optimization). | 231 // Array access operator (no optimization). |
| 205 | 232 |
| 206 String CP5_IN = """ | 233 String CP5_IN = """ |
| 207 (FunctionDefinition main () return () | 234 (FunctionDefinition main () return () |
| 208 (LetPrim v0 (Constant (Int 1))) | 235 (LetPrim (v0 (Constant (Int 1))) |
| 209 (LetPrim v1 (Constant (Int 2))) | 236 (LetPrim (v1 (Constant (Int 2))) |
| 210 (LetCont (k0 v2) | 237 (LetCont (k0 (v2) |
| 211 (InvokeContinuation return v2)) | 238 (InvokeContinuation return (v2))) |
| 212 (InvokeMethod v0 [] v1 k0)) | 239 (InvokeMethod v0 [] (v1) k0))))) |
| 213 """; | 240 """; |
| 214 String CP5_OUT = CP5_IN; | 241 String CP5_OUT = CP5_IN; |
| 215 | 242 |
| 216 // Division by 0. | 243 // Division by 0. |
| 217 | 244 |
| 218 String CP6_IN = """ | 245 String CP6_IN = """ |
| 219 (FunctionDefinition main () return () | 246 (FunctionDefinition main () return () |
| 220 (LetPrim v0 (Constant (Int 1))) | 247 (LetPrim (v0 (Constant (Int 1))) |
| 221 (LetPrim v1 (Constant (Int 0))) | 248 (LetPrim (v1 (Constant (Int 0))) |
| 222 (LetCont (k0 v2) | 249 (LetCont (k0 (v2) |
| 223 (InvokeContinuation return v2)) | 250 (InvokeContinuation return (v2))) |
| 224 (InvokeMethod v0 / v1 k0)) | 251 (InvokeMethod v0 / (v1) k0))))) |
| 225 """; | 252 """; |
| 226 String CP6_OUT = """ | 253 String CP6_OUT = """ |
| 227 (FunctionDefinition main () return () | 254 (FunctionDefinition main () return () |
| 228 (LetPrim v0 (Constant (Int 1))) | 255 (LetPrim (v0 (Constant (Int 1))) |
| 229 (LetPrim v1 (Constant (Int 0))) | 256 (LetPrim (v1 (Constant (Int 0))) |
| 230 (LetCont (k0 v2) | 257 (LetCont (k0 (v2) |
| 231 (InvokeContinuation return v2)) | 258 (InvokeContinuation return (v2))) |
| 232 (LetPrim v3 (Constant (Double Infinity))) | 259 (LetPrim (v3 (Constant (Double Infinity))) |
| 233 (InvokeContinuation k0 v3)) | 260 (InvokeContinuation k0 (v3))))))) |
| 234 """; | 261 """; |
| 235 | 262 |
| 236 // Concatenate strings. | 263 // Concatenate strings. |
| 237 | 264 |
| 238 String CP7_IN = """ | 265 String CP7_IN = """ |
| 239 (FunctionDefinition main () return () | 266 (FunctionDefinition main () return () |
| 240 (LetPrim v0 (Constant (String "b"))) | 267 (LetPrim (v0 (Constant (String "b"))) |
| 241 (LetPrim v1 (Constant (String "d"))) | 268 (LetPrim (v1 (Constant (String "d"))) |
| 242 (LetPrim v2 (Constant (String "a"))) | 269 (LetPrim (v2 (Constant (String "a"))) |
| 243 (LetPrim v3 (Constant (String "c"))) | 270 (LetPrim (v3 (Constant (String "c"))) |
| 244 (LetPrim v4 (Constant (String ""))) | 271 (LetPrim (v4 (Constant (String ""))) |
| 245 (LetCont (k0 v5) | 272 (LetCont (k0 (v5) |
| 246 (LetCont (k1 v6) | 273 (LetCont (k1 (v6) |
| 247 (InvokeContinuation return v6)) | 274 (InvokeContinuation return (v6))) |
| 248 (InvokeMethod v5 length k1)) | 275 (InvokeMethod v5 length () k1))) |
| 249 (ConcatenateStrings v2 v0 v3 v1 v4 k0)) | 276 (ConcatenateStrings (v2 v0 v3 v1 v4) k0)))))))) |
| 250 """; | 277 """; |
| 251 String CP7_OUT = """ | 278 String CP7_OUT = """ |
| 252 (FunctionDefinition main () return () | 279 (FunctionDefinition main () return () |
| 253 (LetPrim v0 (Constant (String "b"))) | 280 (LetPrim (v0 (Constant (String "b"))) |
| 254 (LetPrim v1 (Constant (String "d"))) | 281 (LetPrim (v1 (Constant (String "d"))) |
| 255 (LetPrim v2 (Constant (String "a"))) | 282 (LetPrim (v2 (Constant (String "a"))) |
| 256 (LetPrim v3 (Constant (String "c"))) | 283 (LetPrim (v3 (Constant (String "c"))) |
| 257 (LetPrim v4 (Constant (String ""))) | 284 (LetPrim (v4 (Constant (String ""))) |
| 258 (LetCont (k0 v5) | 285 (LetCont (k0 (v5) |
| 259 (LetCont (k1 v6) | 286 (LetCont (k1 (v6) |
| 260 (InvokeContinuation return v6)) | 287 (InvokeContinuation return (v6))) |
| 261 (InvokeMethod v5 length k1)) | 288 (InvokeMethod v5 length () k1))) |
| 262 (LetPrim v7 (Constant (String "abcd"))) | 289 (LetPrim (v7 (Constant (String "abcd"))) |
| 263 (InvokeContinuation k0 v7)) | 290 (InvokeContinuation k0 (v7)))))))))) |
| 264 """; | 291 """; |
| 265 | 292 |
| 266 // TODO(jgruber): We can't test is-check optimization because the unstringifier | 293 // TODO(jgruber): We can't test is-check optimization because the unstringifier |
| 267 // does not recreate accurate types for the TypeOperator node. | 294 // does not recreate accurate types for the TypeOperator node. |
| 268 | 295 |
| 269 // Simple branch removal. | 296 // Simple branch removal. |
| 270 | 297 |
| 271 String CP8_IN = """ | 298 String CP8_IN = """ |
| 272 (FunctionDefinition main () return () | 299 (FunctionDefinition main () return () |
| 273 (LetPrim v0 (Constant (Int 1))) | 300 (LetPrim (v0 (Constant (Int 1))) |
| 274 (LetPrim v1 (Constant (Int 1))) | 301 (LetPrim (v1 (Constant (Int 1))) |
| 275 (LetCont (k0 v2) | 302 (LetCont (k0 (v2) |
| 276 (LetCont (k1) | 303 (LetCont (k1 () |
| 277 (LetPrim v3 (Constant (Int 42))) | 304 (LetPrim (v3 (Constant (Int 42))) |
| 278 (InvokeContinuation return v3)) | 305 (InvokeContinuation return (v3)))) |
| 279 (LetCont (k2) | 306 (LetCont (k2 () |
| 280 (InvokeContinuation return v0)) | 307 (InvokeContinuation return (v0))) |
| 281 (Branch (IsTrue v2) k1 k2)) | 308 (Branch (IsTrue v2) k1 k2)))) |
| 282 (InvokeMethod v0 == v1 k0)) | 309 (InvokeMethod v0 == (v1) k0))))) |
| 283 """; | 310 """; |
| 284 String CP8_OUT = """ | 311 String CP8_OUT = """ |
| 285 (FunctionDefinition main () return () | 312 (FunctionDefinition main () return () |
| 286 (LetPrim v0 (Constant (Int 1))) | 313 (LetPrim (v0 (Constant (Int 1))) |
| 287 (LetPrim v1 (Constant (Int 1))) | 314 (LetPrim (v1 (Constant (Int 1))) |
| 288 (LetCont (k0 v2) | 315 (LetCont (k0 (v2) |
| 289 (LetCont (k1) (LetPrim v3 (Constant (Int 42))) | 316 (LetCont (k1 () |
| 290 (InvokeContinuation return v3)) | 317 (LetPrim (v3 (Constant (Int 42))) |
| 291 (LetCont (k2) (InvokeContinuation return v0)) | 318 (InvokeContinuation return (v3)))) |
| 292 (InvokeContinuation k1 )) | 319 (LetCont (k2 () |
| 293 (LetPrim v4 (Constant (Bool true))) | 320 (InvokeContinuation return (v0))) |
| 294 (InvokeContinuation k0 v4)) | 321 (InvokeContinuation k1 ())))) |
| 322 (LetPrim (v4 (Constant (Bool true))) |
| 323 (InvokeContinuation k0 (v4))))))) |
| 295 """; | 324 """; |
| 296 | 325 |
| 297 // While loop. | 326 // While loop. |
| 298 | 327 |
| 299 String CP9_IN = """ | 328 String CP9_IN = """ |
| 300 (FunctionDefinition main () return () | 329 (FunctionDefinition main () return () |
| 301 (LetPrim v0 (Constant (Int 1))) | 330 (LetPrim (v0 (Constant (Int 1))) |
| 302 (LetCont* (k0 v1) | 331 (LetCont* (k0 (v1) |
| 303 (LetCont (k1) | 332 (LetCont (k1 () |
| 304 (InvokeContinuation return v1)) | 333 (InvokeContinuation return (v1))) |
| 305 (LetCont (k2) | 334 (LetCont (k2 () |
| 306 (LetPrim v2 (Constant (Int 1))) | 335 (LetPrim (v2 (Constant (Int 1))) |
| 307 (LetCont (k3 v3) | 336 (LetCont (k3 (v3) |
| 308 (LetCont (k4 v4) | 337 (LetCont (k4 (v4) |
| 309 (LetCont (k5) | 338 (LetCont (k5 () |
| 310 (LetPrim v5 (Constant (Int 42))) | 339 (LetPrim (v5 (Constant (Int 42))) |
| 311 (InvokeContinuation return v5)) | 340 (InvokeContinuation return (v5)))) |
| 312 (LetCont (k6) | 341 (LetCont (k6 () |
| 313 (LetPrim v6 (Constant (Int 1))) | 342 (LetPrim (v6 (Constant (Int 1))) |
| 314 (LetCont (k7 v7) | 343 (LetCont (k7 (v7) |
| 315 (InvokeContinuation* k0 v7)) | 344 (InvokeContinuation* k0 (v7))) |
| 316 (InvokeMethod v1 + v6 k7)) | 345 (InvokeMethod v1 + (v6) k7)))) |
| 317 (Branch (IsTrue v4) k5 k6)) | 346 (Branch (IsTrue v4) k5 k6)))) |
| 318 (LetCont (k8) | 347 (LetCont (k8 () |
| 319 (LetPrim v8 (Constant (Bool false))) | 348 (LetPrim (v8 (Constant (Bool false))) |
| 320 (InvokeContinuation k4 v8)) | 349 (InvokeContinuation k4 (v8)))) |
| 321 (LetCont (k9) | 350 (LetCont (k9 () |
| 322 (LetPrim v9 (Constant (Bool true))) | 351 (LetPrim (v9 (Constant (Bool true))) |
| 323 (InvokeContinuation k4 v9)) | 352 (InvokeContinuation k4 (v9)))) |
| 324 (Branch (IsTrue v3) k8 k9)) | 353 (Branch (IsTrue v3) k8 k9))))) |
| 325 (InvokeMethod v1 == v2 k3)) | 354 (InvokeMethod v1 == (v2) k3)))) |
| 326 (LetPrim v10 (Constant (Bool true))) | 355 (LetPrim (v10 (Constant (Bool true))) |
| 327 (Branch (IsTrue v10) k2 k1)) | 356 (Branch (IsTrue v10) k2 k1))))) |
| 328 (InvokeContinuation k0 v0)) | 357 (InvokeContinuation k0 (v0))))) |
| 329 """; | 358 """; |
| 330 String CP9_OUT = """ | 359 String CP9_OUT = """ |
| 331 (FunctionDefinition main () return () | 360 (FunctionDefinition main () return () |
| 332 (LetPrim v0 (Constant (Int 1))) | 361 (LetPrim (v0 (Constant (Int 1))) |
| 333 (LetCont* (k0 v1) | 362 (LetCont* (k0 (v1) |
| 334 (LetCont (k1) | 363 (LetCont (k1 () |
| 335 (InvokeContinuation return v1)) | 364 (InvokeContinuation return (v1))) |
| 336 (LetCont (k2) | 365 (LetCont (k2 () |
| 337 (LetPrim v2 (Constant (Int 1))) | 366 (LetPrim (v2 (Constant (Int 1))) |
| 338 (LetCont (k3 v3) | 367 (LetCont (k3 (v3) |
| 339 (LetCont (k4 v4) | 368 (LetCont (k4 (v4) |
| 340 (LetCont (k5) | 369 (LetCont (k5 () |
| 341 (LetPrim v5 (Constant (Int 42))) | 370 (LetPrim (v5 (Constant (Int 42))) |
| 342 (InvokeContinuation return v5)) | 371 (InvokeContinuation return (v5)))) |
| 343 (LetCont (k6) | 372 (LetCont (k6 () |
| 344 (LetPrim v6 (Constant (Int 1))) | 373 (LetPrim (v6 (Constant (Int 1))) |
| 345 (LetCont (k7 v7) | 374 (LetCont (k7 (v7) |
| 346 (InvokeContinuation* k0 v7)) | 375 (InvokeContinuation* k0 (v7))) |
| 347 (InvokeMethod v1 + v6 k7)) | 376 (InvokeMethod v1 + (v6) k7)))) |
| 348 (Branch (IsTrue v4) k5 k6)) | 377 (Branch (IsTrue v4) k5 k6)))) |
| 349 (LetCont (k8) | 378 (LetCont (k8 () |
| 350 (LetPrim v8 (Constant (Bool false))) | 379 (LetPrim (v8 (Constant (Bool false))) |
| 351 (InvokeContinuation k4 v8)) | 380 (InvokeContinuation k4 (v8)))) |
| 352 (LetCont (k9) | 381 (LetCont (k9 () |
| 353 (LetPrim v9 (Constant (Bool true))) | 382 (LetPrim (v9 (Constant (Bool true))) |
| 354 (InvokeContinuation k4 v9)) | 383 (InvokeContinuation k4 (v9)))) |
| 355 (Branch (IsTrue v3) k8 k9)) | 384 (Branch (IsTrue v3) k8 k9))))) |
| 356 (InvokeMethod v1 == v2 k3)) | 385 (InvokeMethod v1 == (v2) k3)))) |
| 357 (LetPrim v10 (Constant (Bool true))) | 386 (LetPrim (v10 (Constant (Bool true))) |
| 358 (InvokeContinuation k2 )) | 387 (InvokeContinuation k2 ()))))) |
| 359 (InvokeContinuation k0 v0)) | 388 (InvokeContinuation k0 (v0))))) |
| 360 """; | 389 """; |
| 361 | 390 |
| 362 // While loop, from: | 391 // While loop, from: |
| 363 // | 392 // |
| 364 // int main() { | 393 // int main() { |
| 365 // for (int i = 0; i < 2; i++) { | 394 // for (int i = 0; i < 2; i++) { |
| 366 // print(42 + i); | 395 // print(42 + i); |
| 367 // } | 396 // } |
| 368 // } | 397 // } |
| 369 | 398 |
| 370 String CP10_IN = """ | 399 String CP10_IN = """ |
| 371 (FunctionDefinition main () return () | 400 (FunctionDefinition main () return () |
| 372 (LetPrim v0 (Constant (Int 0))) | 401 (LetPrim (v0 (Constant (Int 0))) |
| 373 (LetCont* (k0 v1) | 402 (LetCont* (k0 (v1) |
| 374 (LetCont (k1) | 403 (LetCont (k1 () |
| 375 (LetPrim v2 (Constant (Null))) | 404 (LetPrim (v2 (Constant (Null))) |
| 376 (InvokeContinuation return v2)) | 405 (InvokeContinuation return (v2)))) |
| 377 (LetCont (k2) | 406 (LetCont (k2 () |
| 378 (LetPrim v3 (Constant (Int 42))) | 407 (LetPrim (v3 (Constant (Int 42))) |
| 379 (LetCont (k3 v4) | 408 (LetCont (k3 (v4) |
| 380 (LetCont (k4 v5) | 409 (LetCont (k4 (v5) |
| 381 (LetPrim v6 (Constant (Int 1))) | 410 (LetPrim (v6 (Constant (Int 1))) |
| 382 (LetCont (k5 v7) | 411 (LetCont (k5 (v7) |
| 383 (InvokeContinuation* k0 v7)) | 412 (InvokeContinuation* k0 (v7))) |
| 384 (InvokeMethod v1 + v6 k5)) | 413 (InvokeMethod v1 + (v6) k5)))) |
| 385 (InvokeStatic print v4 k4)) | 414 (InvokeStatic print (v4) k4))) |
| 386 (InvokeMethod v3 + v1 k3)) | 415 (InvokeMethod v3 + (v1) k3)))) |
| 387 (LetPrim v8 (Constant (Int 2))) | 416 (LetPrim (v8 (Constant (Int 2))) |
| 388 (LetCont (k6 v9) | 417 (LetCont (k6 (v9) |
| 389 (Branch (IsTrue v9) k2 k1)) | 418 (Branch (IsTrue v9) k2 k1)) |
| 390 (InvokeMethod v1 < v8 k6)) | 419 (InvokeMethod v1 < (v8) k6)))))) |
| 391 (InvokeContinuation k0 v0)) | 420 (InvokeContinuation k0 (v0))))) |
| 392 """; | 421 """; |
| 393 String CP10_OUT = CP10_IN; | 422 String CP10_OUT = CP10_IN; |
| 394 | 423 |
| 395 /// Normalizes whitespace by replacing all whitespace sequences by a single | 424 /// Normalizes whitespace by replacing all whitespace sequences by a single |
| 396 /// space and trimming leading and trailing whitespace. | 425 /// space and trimming leading and trailing whitespace. |
| 397 String normalizeSExpr(String input) { | 426 String normalizeSExpr(String input) { |
| 398 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); | 427 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); |
| 399 } | 428 } |
| 400 | 429 |
| 401 /// Parses the given input IR, runs an optimization pass over it, and compares | 430 /// Parses the given input IR, runs an optimization pass over it, and compares |
| (...skipping 26 matching lines...) Expand all Loading... |
| 428 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); | 457 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); |
| 429 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); | 458 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); |
| 430 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); | 459 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); |
| 431 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); | 460 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); |
| 432 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); | 461 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); |
| 433 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); | 462 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); |
| 434 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); | 463 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); |
| 435 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); | 464 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); |
| 436 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); | 465 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); |
| 437 } | 466 } |
| OLD | NEW |