Mercurial > hg > truffle
comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java @ 12656:9334392ed279
Refactor ConvertNode.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 04 Nov 2013 11:25:10 +0100 |
parents | 035474349265 |
children | e53aa17b8fdf |
comparison
equal
deleted
inserted
replaced
12655:2c4aa758ee18 | 12656:9334392ed279 |
---|---|
302 | 302 |
303 public static Stamp intToLong(IntegerStamp intStamp) { | 303 public static Stamp intToLong(IntegerStamp intStamp) { |
304 return StampFactory.forInteger(Kind.Long, intStamp.lowerBound(), intStamp.upperBound(), signExtend(intStamp.downMask(), Kind.Int), signExtend(intStamp.upMask(), Kind.Int)); | 304 return StampFactory.forInteger(Kind.Long, intStamp.lowerBound(), intStamp.upperBound(), signExtend(intStamp.downMask(), Kind.Int), signExtend(intStamp.upMask(), Kind.Int)); |
305 } | 305 } |
306 | 306 |
307 private static IntegerStamp narrowingKindConvertion(IntegerStamp fromStamp, Kind toKind) { | 307 public static IntegerStamp narrowingKindConversion(IntegerStamp fromStamp, Kind toKind) { |
308 assert toKind == Kind.Byte || toKind == Kind.Char || toKind == Kind.Short || toKind == Kind.Int; | 308 assert toKind == Kind.Byte || toKind == Kind.Char || toKind == Kind.Short || toKind == Kind.Int; |
309 final long upperBound; | 309 final long upperBound; |
310 if (fromStamp.lowerBound() < toKind.getMinValue()) { | 310 if (fromStamp.lowerBound() < toKind.getMinValue()) { |
311 upperBound = toKind.getMaxValue(); | 311 upperBound = toKind.getMaxValue(); |
312 } else { | 312 } else { |
332 } else { | 332 } else { |
333 return value; | 333 return value; |
334 } | 334 } |
335 } | 335 } |
336 | 336 |
337 public static IntegerStamp intToByte(IntegerStamp intStamp) { | |
338 assert intStamp.kind() == Kind.Int; | |
339 return narrowingKindConvertion(intStamp, Kind.Byte); | |
340 } | |
341 | |
342 public static IntegerStamp intToShort(IntegerStamp intStamp) { | |
343 assert intStamp.kind() == Kind.Int; | |
344 return narrowingKindConvertion(intStamp, Kind.Short); | |
345 } | |
346 | |
347 public static IntegerStamp intToChar(IntegerStamp intStamp) { | |
348 assert intStamp.kind() == Kind.Int; | |
349 return narrowingKindConvertion(intStamp, Kind.Char); | |
350 } | |
351 | |
352 public static IntegerStamp longToInt(IntegerStamp longStamp) { | |
353 assert longStamp.kind() == Kind.Long; | |
354 return narrowingKindConvertion(longStamp, Kind.Int); | |
355 } | |
356 | |
357 public static long saturate(long v, Kind kind) { | 337 public static long saturate(long v, Kind kind) { |
358 long max = kind.getMaxValue(); | 338 long max = kind.getMaxValue(); |
359 if (v > max) { | 339 if (v > max) { |
360 return max; | 340 return max; |
361 } | 341 } |