Chromium Code Reviews| 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 #import("../../../lib/compiler/implementation/ssa/ssa.dart"); | 5 #import("../../../lib/compiler/implementation/ssa/ssa.dart"); |
| 6 #import("../../../lib/compiler/implementation/leg.dart"); | 6 #import("../../../lib/compiler/implementation/leg.dart"); |
| 7 | 7 |
| 8 Value instructionValue = new InstructionValue(new HReturn(null)); | 8 Value instructionValue = new InstructionValue(new HReturn(null)); |
| 9 Value lengthValue = new LengthValue(new HReturn(null)); | 9 Value lengthValue = new LengthValue(new HReturn(null)); |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 Range _0_instruction = createInstructionRange(0); | 35 Range _0_instruction = createInstructionRange(0); |
| 36 | 36 |
| 37 checkAndRange(Range one, Range two, lower, upper) { | 37 checkAndRange(Range one, Range two, lower, upper) { |
| 38 if (lower is num) lower = new IntValue(lower); | 38 if (lower is num) lower = new IntValue(lower); |
| 39 if (upper is num) upper = new IntValue(upper); | 39 if (upper is num) upper = new IntValue(upper); |
| 40 Range range = new Range(lower, upper); | 40 Range range = new Range(lower, upper); |
| 41 Expect.equals(range, one & two); | 41 Expect.equals(range, one & two); |
| 42 } | 42 } |
| 43 | 43 |
| 44 checkSubRange(Range one, Range two, [lower, upper]) { | 44 checkSubRange(Range one, Range two, [lower, upper]) { |
| 45 | |
| 46 buildBound(one, two) { | |
| 47 // Create a bound just like the algorithm does. | |
|
Søren Gjesse
2012/10/08 14:00:42
Which algorithm? (add more context to the referenc
ngeoffray
2012/10/08 14:16:39
Done.
| |
| 48 if (two is IntValue) { | |
| 49 if (two.isNegative()) { | |
| 50 return new AddValue(one, -two); | |
| 51 } else if (two.isZero()) { | |
| 52 return one; | |
| 53 } | |
| 54 } | |
| 55 if (one is IntValue) { | |
| 56 if (one.isNegative()) { | |
| 57 return new SubtractValue(-two, -one); | |
| 58 } else if (one.isZero()) { | |
| 59 return -two; | |
| 60 } | |
| 61 } | |
| 62 return new SubtractValue(one, two); | |
| 63 } | |
| 64 | |
| 45 if (lower == null) { | 65 if (lower == null) { |
| 46 lower = new OperationValue(one.lower, two.upper, const SubtractOperation()); | 66 lower = buildBound(one.lower, two.upper); |
| 47 } else if (lower is num) { | 67 } else if (lower is num) { |
| 48 lower = new IntValue(lower); | 68 lower = new IntValue(lower); |
| 49 } | 69 } |
| 50 if (upper == null) { | 70 if (upper == null) { |
| 51 upper = new OperationValue(one.upper, two.lower, const SubtractOperation()); | 71 upper = buildBound(one.upper, two.lower); |
| 52 } else if (upper is num) { | 72 } else if (upper is num) { |
| 53 upper = new IntValue(upper); | 73 upper = new IntValue(upper); |
| 54 } | 74 } |
| 55 | 75 |
| 56 Expect.equals(new Range(lower, upper), one - two); | 76 Expect.equals(new Range(lower, upper), one - two); |
| 57 } | 77 } |
| 58 | 78 |
| 79 checkNegateRange(Range range, [arg1, arg2]) { | |
| 80 if (arg1 is Range) { | |
| 81 Expect.equals(arg1, -range); | |
| 82 } else { | |
| 83 Value low, up; | |
| 84 if (arg1 is num) { | |
| 85 low = new IntValue(arg1); | |
| 86 } else if (arg1 == null) { | |
| 87 low = new NegateValue(range.upper); | |
| 88 } else { | |
| 89 low = arg1; | |
| 90 } | |
| 91 if (arg2 is num) { | |
| 92 up = new IntValue(arg2); | |
| 93 } else if (arg2 == null) { | |
| 94 up = new NegateValue(range.lower); | |
| 95 } else { | |
| 96 up = arg2; | |
| 97 } | |
| 98 Expect.equals(new Range(low, up), -range); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 testNegate() { | |
| 103 checkNegateRange(instruction); | |
| 104 checkNegateRange(FF, nFF); | |
| 105 checkNegateRange(nFF, FF); | |
| 106 checkNegateRange(FA, -0xFA, -0xFA); | |
| 107 checkNegateRange(length); | |
| 108 checkNegateRange(_FA_FF, -0xFF, -0xFA); | |
| 109 checkNegateRange(_0_FF, _nFF_0); | |
| 110 checkNegateRange(_nFF_FF, _nFF_FF); | |
| 111 checkNegateRange(_nFF_0, _0_FF); | |
| 112 checkNegateRange(_0_length, -lengthValue, 0); | |
| 113 checkNegateRange(_0_instruction, -instructionValue, 0); | |
| 114 } | |
| 115 | |
| 59 testAnd() { | 116 testAnd() { |
| 60 checkAndRange( | 117 checkAndRange( |
| 61 instruction, instruction, const MinIntValue(), const MaxIntValue()); | 118 instruction, instruction, const MinIntValue(), const MaxIntValue()); |
| 62 checkAndRange(instruction, FF, 0, 0xFF); | 119 checkAndRange(instruction, FF, 0, 0xFF); |
| 63 checkAndRange(instruction, FA, 0, 0xFA); | 120 checkAndRange(instruction, FA, 0, 0xFA); |
| 64 checkAndRange(instruction, nFF, const MinIntValue(), const MaxIntValue()); | 121 checkAndRange(instruction, nFF, const MinIntValue(), const MaxIntValue()); |
| 65 checkAndRange(instruction, length, 0, length.upper); | 122 checkAndRange(instruction, length, 0, length.upper); |
| 66 checkAndRange(instruction, _FA_FF, 0, 0xFF); | 123 checkAndRange(instruction, _FA_FF, 0, 0xFF); |
| 67 checkAndRange(instruction, _0_FF, 0, 0xFF); | 124 checkAndRange(instruction, _0_FF, 0, 0xFF); |
| 68 checkAndRange(instruction, _nFF_FF, const MinIntValue(), const MaxIntValue()); | 125 checkAndRange(instruction, _nFF_FF, const MinIntValue(), const MaxIntValue()); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 checkSubRange(_0_instruction, _nFF_FF, -0xFF, null); | 359 checkSubRange(_0_instruction, _nFF_FF, -0xFF, null); |
| 303 checkSubRange(_0_instruction, _nFF_0, 0, null); | 360 checkSubRange(_0_instruction, _nFF_0, 0, null); |
| 304 checkSubRange(_0_instruction, _0_length, null, _0_instruction.upper); | 361 checkSubRange(_0_instruction, _0_length, null, _0_instruction.upper); |
| 305 checkSubRange(_0_instruction, _0_instruction, null, _0_instruction.upper); | 362 checkSubRange(_0_instruction, _0_instruction, null, _0_instruction.upper); |
| 306 } | 363 } |
| 307 | 364 |
| 308 main() { | 365 main() { |
| 309 HInstruction.idCounter = 0; | 366 HInstruction.idCounter = 0; |
| 310 testAnd(); | 367 testAnd(); |
| 311 testSub(); | 368 testSub(); |
| 369 testNegate(); | |
| 312 } | 370 } |
| OLD | NEW |