Debian Codegraph @

src/main/java/com/kenai/jnr/x86asm/Immediate.java

raw
1 //
2 // Copyright (C) 2010 Wayne Meissner
3 // Copyright (c) 2008-2009, Petr Kobalicek <[email protected]>
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 // OTHER DEALINGS IN THE SOFTWARE.
25
26 package com.kenai.jnr.x86asm;
27
28 /**
29 *
30 */
31 @Deprecated
32 public final class Immediate extends Operand {
33 private final long value;
34 private final boolean isUnsigned;
35 private final RELOC_MODE relocMode;
36
37 public Immediate(long value, boolean isUnsigned) {
38 super(OP.OP_IMM, 0);
39 this.value = value;
40 this.isUnsigned = isUnsigned;
41 this.relocMode = RELOC_MODE.RELOC_NONE;
42 }
43
44 public long value() {
45 return value;
46 }
47
48 public final byte byteValue() {
49 return (byte) value;
50 }
51
52 public final short shortValue() {
53 return (short) value;
54 }
55
56 public final int intValue() {
57 return (int) value;
58 }
59
60 public final long longValue() {
61 return value;
62 }
63
64 /** Return true if immediate is unsigned value. */
65 public final boolean isUnsigned() {
66 return isUnsigned;
67 }
68
69 /** Return relocation mode. */
70 RELOC_MODE relocMode() {
71 return relocMode;
72 }
73
74 /**
75 * Internal cache of common native long values
76 */
77 private static final class Cache {
78 private Cache() {}
79
80 static final Immediate[] cache = new Immediate[256];
81
82 static {
83 for (int i = 0; i < cache.length; ++i) {
84 cache[i] = new Immediate(i - 128, false);
85 }
86 }
87
88 }
89
90 public static final Immediate imm(long value) {
91 return value >= -128 && value <= 127
92 ? Cache.cache[128 + (int) value] : new Immediate(value, false);
93 }
94
95 public static final Immediate uimm(long value) {
96 return new Immediate(value, true);
97 }
98 }