001 // This file is part of the program FRYSK. 002 // 003 // Copyright 2007, Red Hat Inc. 004 // 005 // FRYSK is free software; you can redistribute it and/or modify it 006 // under the terms of the GNU General Public License as published by 007 // the Free Software Foundation; version 2 of the License. 008 // 009 // FRYSK is distributed in the hope that it will be useful, but 010 // WITHOUT ANY WARRANTY; without even the implied warranty of 011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 // General Public License for more details. 013 // 014 // You should have received a copy of the GNU General Public License 015 // along with FRYSK; if not, write to the Free Software Foundation, 016 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 017 // 018 // In addition, as a special exception, Red Hat, Inc. gives You the 019 // additional right to link the code of FRYSK with code not covered 020 // under the GNU General Public License ("Non-GPL Code") and to 021 // distribute linked combinations including the two, subject to the 022 // limitations in this paragraph. Non-GPL Code permitted under this 023 // exception must only link to the code of FRYSK through those well 024 // defined interfaces identified in the file named EXCEPTION found in 025 // the source code files (the "Approved Interfaces"). The files of 026 // Non-GPL Code may instantiate templates or use macros or inline 027 // functions from the Approved Interfaces without causing the 028 // resulting work to be covered by the GNU General Public 029 // License. Only Red Hat, Inc. may make changes or additions to the 030 // list of Approved Interfaces. You must obey the GNU General Public 031 // License in all respects for all of the FRYSK code and other code 032 // used in conjunction with FRYSK except the Non-GPL Code covered by 033 // this exception. If you modify this file, you may extend this 034 // exception to your version of the file, but you are not obligated to 035 // do so. If you do not wish to provide this exception without 036 // modification, you must delete this exception statement from your 037 // version and license this file solely under the GPL without 038 // exception. 039 040 package frysk.value; 041 042 import inua.eio.ByteOrder; 043 import java.util.HashMap; 044 045 public class StandardTypes { 046 public static final CharType byteLittleEndianType 047 = new CharType("byte", ByteOrder.LITTLE_ENDIAN, 1, true); 048 public static final CharType byteBigEndianType 049 = new CharType("byte", ByteOrder.BIG_ENDIAN, 1, true); 050 051 public static CharType getByteType(ByteOrder order) { 052 if (order == ByteOrder.LITTLE_ENDIAN) 053 return byteLittleEndianType; 054 else 055 return byteBigEndianType; 056 } 057 058 public static final SignedType shortLittleEndianType 059 = new SignedType("short", ByteOrder.LITTLE_ENDIAN, 2); 060 public static final SignedType shortBigEndianType 061 = new SignedType("short", ByteOrder.BIG_ENDIAN, 2); 062 063 public static SignedType getShortType(ByteOrder order) { 064 if (order == ByteOrder.LITTLE_ENDIAN) 065 return shortLittleEndianType; 066 else 067 return shortBigEndianType; 068 } 069 070 public static final SignedType intLittleEndianType 071 = new SignedType("int", ByteOrder.LITTLE_ENDIAN, 4); 072 public static final SignedType intBigEndianType 073 = new SignedType("int", ByteOrder.BIG_ENDIAN, 4); 074 075 public static SignedType getIntType(ByteOrder order) { 076 if (order == ByteOrder.LITTLE_ENDIAN) 077 return intLittleEndianType; 078 else 079 return intBigEndianType; 080 } 081 082 public static final SignedType longLittleEndianType 083 = new SignedType("long", ByteOrder.LITTLE_ENDIAN, 8); 084 public static final SignedType longBigEndianType 085 = new SignedType("long", ByteOrder.BIG_ENDIAN, 8); 086 087 public static SignedType getLongType(ByteOrder order) { 088 if (order == ByteOrder.LITTLE_ENDIAN) 089 return longLittleEndianType; 090 else 091 return longBigEndianType; 092 } 093 094 public static final FloatingPointType floatLittleEndianType 095 = new FloatingPointType("float", ByteOrder.LITTLE_ENDIAN, 4); 096 public static final FloatingPointType floatBigEndianType 097 = new FloatingPointType("float", ByteOrder.BIG_ENDIAN, 4); 098 099 public static FloatingPointType getFloatType(ByteOrder order) { 100 if (order == ByteOrder.LITTLE_ENDIAN) 101 return floatLittleEndianType; 102 else 103 return floatBigEndianType; 104 } 105 106 public static final FloatingPointType doubleLittleEndianType 107 = new FloatingPointType("double", ByteOrder.LITTLE_ENDIAN, 8); 108 public static final FloatingPointType doubleBigEndianType 109 = new FloatingPointType("double", ByteOrder.BIG_ENDIAN, 8); 110 111 public static FloatingPointType getDoubleType(ByteOrder order) { 112 if (order == ByteOrder.LITTLE_ENDIAN) 113 return doubleLittleEndianType; 114 else 115 return doubleBigEndianType; 116 } 117 118 119 private static class OrderMap extends HashMap { 120 static final long serialVersionUID = 0; 121 OrderMap put(ArithmeticType type) { 122 super.put(type.order(), type); 123 return this; 124 } 125 ArithmeticType get(ByteOrder order) { 126 return (ArithmeticType)super.get(order); 127 } 128 } 129 130 public static final ArithmeticType INT8B_T 131 = new SignedType("int8b_t", ByteOrder.BIG_ENDIAN, 1); 132 public static final ArithmeticType INT8L_T 133 = new SignedType("int8l_t", ByteOrder.LITTLE_ENDIAN, 1); 134 private static final OrderMap int8_t = new OrderMap() 135 .put(INT8B_T).put(INT8L_T); 136 public static ArithmeticType int8_t(ByteOrder order) { 137 return int8_t.get(order); 138 } 139 140 public static final ArithmeticType INT16B_T 141 = new SignedType("int16b_t", ByteOrder.BIG_ENDIAN, 2); 142 public static final ArithmeticType INT16L_T 143 = new SignedType("int16l_t", ByteOrder.LITTLE_ENDIAN, 2); 144 private static final OrderMap int16_t = new OrderMap() 145 .put(INT16B_T).put(INT16L_T); 146 public static ArithmeticType int16_t(ByteOrder order) { 147 return int16_t.get(order); 148 } 149 150 public static final ArithmeticType INT32B_T 151 = new SignedType("int32b_t", ByteOrder.BIG_ENDIAN, 4); 152 public static final ArithmeticType INT32L_T 153 = new SignedType("int32l_t", ByteOrder.LITTLE_ENDIAN, 4); 154 private static final OrderMap int32_t = new OrderMap() 155 .put(INT32B_T).put(INT32L_T); 156 public static ArithmeticType int32_t(ByteOrder order) { 157 return int32_t.get(order); 158 } 159 160 public static final ArithmeticType INT64B_T 161 = new SignedType("int64b_t", ByteOrder.BIG_ENDIAN, 8); 162 public static final ArithmeticType INT64L_T 163 = new SignedType("int64l_t", ByteOrder.LITTLE_ENDIAN, 8); 164 private static final OrderMap int64_t = new OrderMap() 165 .put(INT64B_T).put(INT64L_T); 166 public static ArithmeticType int64_t(ByteOrder order) { 167 return int64_t.get(order); 168 } 169 170 public static final ArithmeticType INT128B_T 171 = new SignedType("int128b_t", ByteOrder.BIG_ENDIAN, 16); 172 public static final ArithmeticType INT128L_T 173 = new SignedType("int128l_t", ByteOrder.LITTLE_ENDIAN, 16); 174 private static final OrderMap int128_t = new OrderMap() 175 .put(INT128B_T).put(INT128L_T); 176 public static ArithmeticType int128_t(ByteOrder order) { 177 return int128_t.get(order); 178 } 179 180 public static final ArithmeticType UINT8B_T 181 = new UnsignedType("uint8b_t", ByteOrder.BIG_ENDIAN, 1); 182 public static final ArithmeticType UINT8L_T 183 = new UnsignedType("uint8l_t", ByteOrder.LITTLE_ENDIAN, 1); 184 private static final OrderMap uint8_t = new OrderMap() 185 .put(UINT8B_T).put(UINT8L_T); 186 public static ArithmeticType uint8_t(ByteOrder order) { 187 return uint8_t.get(order); 188 } 189 190 public static final ArithmeticType UINT16B_T 191 = new UnsignedType("uint16b_t", ByteOrder.BIG_ENDIAN, 2); 192 public static final ArithmeticType UINT16L_T 193 = new UnsignedType("uint16l_t", ByteOrder.LITTLE_ENDIAN, 2); 194 private static final OrderMap uint16_t = new OrderMap() 195 .put(UINT16B_T).put(UINT16L_T); 196 public static ArithmeticType uint16_t(ByteOrder order) { 197 return uint16_t.get(order); 198 } 199 200 public static final ArithmeticType UINT32B_T 201 = new UnsignedType("uint32b_t", ByteOrder.BIG_ENDIAN, 4); 202 public static final ArithmeticType UINT32L_T 203 = new UnsignedType("uint32l_t", ByteOrder.LITTLE_ENDIAN, 4); 204 private static final OrderMap uint32_t = new OrderMap() 205 .put(UINT32B_T).put(UINT32L_T); 206 public static ArithmeticType uint32_t(ByteOrder order) { 207 return uint32_t.get(order); 208 } 209 210 public static final ArithmeticType UINT64B_T 211 = new UnsignedType("uint64b_t", ByteOrder.BIG_ENDIAN, 8); 212 public static final ArithmeticType UINT64L_T 213 = new UnsignedType("uint64l_t", ByteOrder.LITTLE_ENDIAN, 8); 214 private static final OrderMap uint64_t = new OrderMap() 215 .put(UINT64B_T).put(UINT64L_T); 216 public static ArithmeticType uint64_t(ByteOrder order) { 217 return uint64_t.get(order); 218 } 219 220 public static final ArithmeticType UINT128B_T 221 = new UnsignedType("uint128b_t", ByteOrder.BIG_ENDIAN, 16); 222 public static final ArithmeticType UINT128L_T 223 = new UnsignedType("uint128l_t", ByteOrder.LITTLE_ENDIAN, 16); 224 private static final OrderMap uint128_t = new OrderMap() 225 .put(UINT128B_T).put(UINT128L_T); 226 public static ArithmeticType uint128_t(ByteOrder order) { 227 return uint128_t.get(order); 228 } 229 230 public static final ArithmeticType FLOAT32B_T 231 = new FloatingPointType("float32b_t", ByteOrder.BIG_ENDIAN, 4); 232 public static final ArithmeticType FLOAT32L_T 233 = new FloatingPointType("float32l_t", ByteOrder.LITTLE_ENDIAN, 4); 234 private static final OrderMap float32_t = new OrderMap() 235 .put(FLOAT32B_T).put(FLOAT32L_T); 236 public static ArithmeticType float32_t(ByteOrder order) { 237 return float32_t.get(order); 238 } 239 240 public static final ArithmeticType FLOAT64B_T 241 = new FloatingPointType("float64b_t", ByteOrder.BIG_ENDIAN, 8); 242 public static final ArithmeticType FLOAT64L_T 243 = new FloatingPointType("float64l_t", ByteOrder.LITTLE_ENDIAN, 8); 244 private static final OrderMap float64_t = new OrderMap() 245 .put(FLOAT64B_T).put(FLOAT64L_T); 246 public static ArithmeticType float64_t(ByteOrder order) { 247 return float64_t.get(order); 248 } 249 250 public static final ArithmeticType FLOAT80B_T 251 = new FloatingPointType("float80b_t", ByteOrder.BIG_ENDIAN, 10); 252 public static final ArithmeticType FLOAT80L_T 253 = new FloatingPointType("float80l_t", ByteOrder.LITTLE_ENDIAN, 10); 254 private static final OrderMap float80_t = new OrderMap() 255 .put(FLOAT80B_T).put(FLOAT80L_T); 256 public static ArithmeticType float80_t(ByteOrder order) { 257 return float80_t.get(order); 258 } 259 260 public static final ArithmeticType VOIDPTR32B_T 261 = new PointerType("voidptr32b_t", ByteOrder.BIG_ENDIAN, 4, 262 new VoidType()); 263 public static final ArithmeticType VOIDPTR32L_T 264 = new PointerType("voidptr32l_t", ByteOrder.LITTLE_ENDIAN, 4, 265 new VoidType()); 266 public static final OrderMap voidptr32_t = new OrderMap() 267 .put(VOIDPTR32B_T).put(VOIDPTR32L_T); 268 public static ArithmeticType voidptr32_t(ByteOrder order) { 269 return voidptr32_t.get(order); 270 } 271 272 public static final ArithmeticType VOIDPTR64B_T 273 = new PointerType("VOIDPTR64B_T", ByteOrder.BIG_ENDIAN, 8, 274 new VoidType()); 275 public static final ArithmeticType VOIDPTR64L_T 276 = new PointerType("VOIDPTR64L_T", ByteOrder.LITTLE_ENDIAN, 8, 277 new VoidType()); 278 public static final OrderMap voidptr64_t = new OrderMap() 279 .put(VOIDPTR64B_T).put(VOIDPTR64L_T); 280 public static ArithmeticType voidptr64_t(ByteOrder order) { 281 return voidptr64_t.get(order); 282 } 283 284 }