1 /*
   2  * Copyright (c) 2014, 2014, 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 org.graalvm.compiler.core.common.calc;
  24 
  25 import org.graalvm.compiler.debug.GraalError;
  26 
  27 public enum FloatConvert {
  28     F2I(FloatConvertCategory.FloatingPointToInteger),
  29     D2I(FloatConvertCategory.FloatingPointToInteger),
  30     F2L(FloatConvertCategory.FloatingPointToInteger),
  31     D2L(FloatConvertCategory.FloatingPointToInteger),
  32     I2F(FloatConvertCategory.IntegerToFloatingPoint),
  33     L2F(FloatConvertCategory.IntegerToFloatingPoint),
  34     D2F(FloatConvertCategory.FloatingPointToFloatingPoint),
  35     I2D(FloatConvertCategory.IntegerToFloatingPoint),
  36     L2D(FloatConvertCategory.IntegerToFloatingPoint),
  37     F2D(FloatConvertCategory.FloatingPointToFloatingPoint);
  38 
  39     private FloatConvertCategory category;
  40 
  41     FloatConvert(FloatConvertCategory category) {
  42         this.category = category;
  43     }
  44 
  45     public FloatConvertCategory getCategory() {
  46         return category;
  47     }
  48 
  49     public FloatConvert reverse() {
  50         switch (this) {
  51             case D2F:
  52                 return F2D;
  53             case D2I:
  54                 return I2D;
  55             case D2L:
  56                 return L2D;
  57             case F2D:
  58                 return D2F;
  59             case F2I:
  60                 return I2F;
  61             case F2L:
  62                 return L2F;
  63             case I2D:
  64                 return D2I;
  65             case I2F:
  66                 return F2I;
  67             case L2D:
  68                 return D2L;
  69             case L2F:
  70                 return F2L;
  71             default:
  72                 throw GraalError.shouldNotReachHere();
  73         }
  74     }
  75 }