hotspot/src/share/vm/ci/ciConstant.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2003 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// ciConstant
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// This class represents a constant value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class ciConstant VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  friend class ciEnv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  friend class ciField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  BasicType _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    jint      _int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    jlong     _long;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    jint      _long_half[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    jfloat    _float;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    jdouble   _double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    ciObject* _object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  } _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  void print_impl(outputStream* st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  ciConstant() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _type = T_ILLEGAL; _value._long = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ciConstant(BasicType type, jint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    assert(type != T_LONG && type != T_DOUBLE && type != T_FLOAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
           "using the wrong ciConstant constructor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _type = type; _value._int = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  ciConstant(jlong value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    _type = T_LONG; _value._long = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  ciConstant(jfloat value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _type = T_FLOAT; _value._float = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ciConstant(jdouble value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _type = T_DOUBLE; _value._double = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  ciConstant(BasicType type, ciObject* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _type = type; _value._object = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  BasicType basic_type() const { return _type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  jboolean  as_boolean() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    assert(basic_type() == T_BOOLEAN, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return (jboolean)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  jchar     as_char() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    assert(basic_type() == T_CHAR, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    return (jchar)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  jbyte     as_byte() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    assert(basic_type() == T_BYTE, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    return (jbyte)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  jshort    as_short() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    assert(basic_type() == T_SHORT, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return (jshort)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  jint      as_int() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    assert(basic_type() == T_BOOLEAN || basic_type() == T_CHAR  ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
           basic_type() == T_BYTE    || basic_type() == T_SHORT ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
           basic_type() == T_INT, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return _value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  jlong     as_long() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    assert(basic_type() == T_LONG, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    return _value._long;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  jfloat    as_float() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    assert(basic_type() == T_FLOAT, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    return _value._float;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  jdouble   as_double() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    assert(basic_type() == T_DOUBLE, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return _value._double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  ciObject* as_object() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(basic_type() == T_OBJECT || basic_type() == T_ARRAY, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return _value._object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // Debugging output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
};