src/share/vm/ci/ciConstant.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciConstant.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,112 @@
     1.4 +/*
     1.5 + * Copyright 1999-2003 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// ciConstant
    1.29 +//
    1.30 +// This class represents a constant value.
    1.31 +class ciConstant VALUE_OBJ_CLASS_SPEC {
    1.32 +private:
    1.33 +  friend class ciEnv;
    1.34 +  friend class ciField;
    1.35 +
    1.36 +  BasicType _type;
    1.37 +  union {
    1.38 +    jint      _int;
    1.39 +    jlong     _long;
    1.40 +    jint      _long_half[2];
    1.41 +    jfloat    _float;
    1.42 +    jdouble   _double;
    1.43 +    ciObject* _object;
    1.44 +  } _value;
    1.45 +
    1.46 +  // Implementation of the print method.
    1.47 +  void print_impl(outputStream* st);
    1.48 +
    1.49 +public:
    1.50 +
    1.51 +  ciConstant() {
    1.52 +    _type = T_ILLEGAL; _value._long = -1;
    1.53 +  }
    1.54 +  ciConstant(BasicType type, jint value) {
    1.55 +    assert(type != T_LONG && type != T_DOUBLE && type != T_FLOAT,
    1.56 +           "using the wrong ciConstant constructor");
    1.57 +    _type = type; _value._int = value;
    1.58 +  }
    1.59 +  ciConstant(jlong value) {
    1.60 +    _type = T_LONG; _value._long = value;
    1.61 +  }
    1.62 +  ciConstant(jfloat value) {
    1.63 +    _type = T_FLOAT; _value._float = value;
    1.64 +  }
    1.65 +  ciConstant(jdouble value) {
    1.66 +    _type = T_DOUBLE; _value._double = value;
    1.67 +  }
    1.68 +  ciConstant(BasicType type, ciObject* p) {
    1.69 +    _type = type; _value._object = p;
    1.70 +  }
    1.71 +
    1.72 +  BasicType basic_type() const { return _type; }
    1.73 +
    1.74 +  jboolean  as_boolean() {
    1.75 +    assert(basic_type() == T_BOOLEAN, "wrong type");
    1.76 +    return (jboolean)_value._int;
    1.77 +  }
    1.78 +  jchar     as_char() {
    1.79 +    assert(basic_type() == T_CHAR, "wrong type");
    1.80 +    return (jchar)_value._int;
    1.81 +  }
    1.82 +  jbyte     as_byte() {
    1.83 +    assert(basic_type() == T_BYTE, "wrong type");
    1.84 +    return (jbyte)_value._int;
    1.85 +  }
    1.86 +  jshort    as_short() {
    1.87 +    assert(basic_type() == T_SHORT, "wrong type");
    1.88 +    return (jshort)_value._int;
    1.89 +  }
    1.90 +  jint      as_int() {
    1.91 +    assert(basic_type() == T_BOOLEAN || basic_type() == T_CHAR  ||
    1.92 +           basic_type() == T_BYTE    || basic_type() == T_SHORT ||
    1.93 +           basic_type() == T_INT, "wrong type");
    1.94 +    return _value._int;
    1.95 +  }
    1.96 +  jlong     as_long() {
    1.97 +    assert(basic_type() == T_LONG, "wrong type");
    1.98 +    return _value._long;
    1.99 +  }
   1.100 +  jfloat    as_float() {
   1.101 +    assert(basic_type() == T_FLOAT, "wrong type");
   1.102 +    return _value._float;
   1.103 +  }
   1.104 +  jdouble   as_double() {
   1.105 +    assert(basic_type() == T_DOUBLE, "wrong type");
   1.106 +    return _value._double;
   1.107 +  }
   1.108 +  ciObject* as_object() const {
   1.109 +    assert(basic_type() == T_OBJECT || basic_type() == T_ARRAY, "wrong type");
   1.110 +    return _value._object;
   1.111 +  }
   1.112 +
   1.113 +  // Debugging output
   1.114 +  void print();
   1.115 +};

mercurial