Mercurial > hg > graal-jvmci-8
comparison graal/Compiler/src/com/sun/c1x/alloc/Range.java @ 2507:9ec15d6914ca
Pull over of compiler from maxine repository.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:43:22 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2506:4a3bf8a5bf41 | 2507:9ec15d6914ca |
---|---|
1 /* | |
2 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.sun.c1x.alloc; | |
24 | |
25 | |
26 /** | |
27 * Represents a range of integers from a start (inclusive) to an end (exclusive. | |
28 * | |
29 * @author Thomas Wuerthinger | |
30 */ | |
31 public final class Range { | |
32 | |
33 public static final Range EndMarker = new Range(Integer.MAX_VALUE, Integer.MAX_VALUE, null); | |
34 | |
35 /** | |
36 * The start of the range, inclusive. | |
37 */ | |
38 public int from; | |
39 | |
40 /** | |
41 * The end of the range, exclusive. | |
42 */ | |
43 public int to; | |
44 | |
45 /** | |
46 * A link to allow the range to be put into a singly linked list. | |
47 */ | |
48 public Range next; | |
49 | |
50 boolean intersects(Range r) { | |
51 return intersectsAt(r) != -1; | |
52 } | |
53 | |
54 | |
55 /** | |
56 * Creates a new range. | |
57 * | |
58 * @param from the start of the range, inclusive | |
59 * @param to the end of the range, exclusive | |
60 * @param next link to the next range in a linked list | |
61 */ | |
62 Range(int from, int to, Range next) { | |
63 this.from = from; | |
64 this.to = to; | |
65 this.next = next; | |
66 } | |
67 | |
68 int intersectsAt(Range r2) { | |
69 Range r1 = this; | |
70 | |
71 assert r2 != null : "null ranges not allowed"; | |
72 assert r1 != EndMarker && r2 != EndMarker : "empty ranges not allowed"; | |
73 | |
74 do { | |
75 if (r1.from < r2.from) { | |
76 if (r1.to <= r2.from) { | |
77 r1 = r1.next; | |
78 if (r1 == EndMarker) { | |
79 return -1; | |
80 } | |
81 } else { | |
82 return r2.from; | |
83 } | |
84 } else { | |
85 if (r2.from < r1.from) { | |
86 if (r2.to <= r1.from) { | |
87 r2 = r2.next; | |
88 if (r2 == EndMarker) { | |
89 return -1; | |
90 } | |
91 } else { | |
92 return r1.from; | |
93 } | |
94 } else { // r1.from() == r2.from() | |
95 if (r1.from == r1.to) { | |
96 r1 = r1.next; | |
97 if (r1 == EndMarker) { | |
98 return -1; | |
99 } | |
100 } else { | |
101 if (r2.from == r2.to) { | |
102 r2 = r2.next; | |
103 if (r2 == EndMarker) { | |
104 return -1; | |
105 } | |
106 } else { | |
107 return r1.from; | |
108 } | |
109 } | |
110 } | |
111 } | |
112 } while (true); | |
113 } | |
114 | |
115 @Override | |
116 public String toString() { | |
117 return "[" + from + ", " + to + "]"; | |
118 } | |
119 } |