1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package net
.multiphasicapps
.classfile
;
12 import java
.lang
.ref
.Reference
;
13 import java
.lang
.ref
.WeakReference
;
16 * This represents a range of instruction addresses, the start is inclusive
17 * and the end is exclusive.
21 public final class InstructionAddressRange
22 implements Comparable
<InstructionAddressRange
>
24 /** The start address. */
25 protected final int start
;
27 /** The end address. */
28 protected final int end
;
30 /** String representation. */
31 private Reference
<String
> _string
;
34 * Initializes the address range.
36 * @param __s The start address.
37 * @param __e The end address.
40 public InstructionAddressRange(int __s
, int __e
)
51 public final int compareTo(InstructionAddressRange __b
)
53 int rv
= this.start
- __b
.start
;
57 return this.end
- __b
.end
;
65 public final boolean equals(Object __o
)
70 if (!(__o
instanceof InstructionAddressRange
))
73 InstructionAddressRange o
= (InstructionAddressRange
)__o
;
74 return this.start
== o
.start
&&
83 public final int hashCode()
85 return this.start ^
(~
this.end
);
89 * Checks if the given address is in the range of this range.
91 * @param __pc The address to check.
92 * @return If the address is in range.
95 public final boolean inRange(int __pc
)
97 return __pc
>= this.start
&& __pc
< this.end
;
105 public final String
toString()
107 Reference
<String
> ref
= this._string
;
110 if (ref
== null || null == (rv
= ref
.get()))
111 this._string
= new WeakReference
<>((rv
= "@[" + this.start
+
112 "-" + this.end
+ ")"));