c1_ValueType.cpp revision 1472:c18cbe5936b8
1238384Sjkim/*
2238384Sjkim * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
3238384Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4238384Sjkim *
5238384Sjkim * This code is free software; you can redistribute it and/or modify it
6238384Sjkim * under the terms of the GNU General Public License version 2 only, as
7238384Sjkim * published by the Free Software Foundation.
8238384Sjkim *
9238384Sjkim * This code is distributed in the hope that it will be useful, but WITHOUT
10238384Sjkim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11238384Sjkim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12238384Sjkim * version 2 for more details (a copy is included in the LICENSE file that
13238384Sjkim * accompanied this code).
14238384Sjkim *
15238384Sjkim * You should have received a copy of the GNU General Public License version
16238384Sjkim * 2 along with this work; if not, write to the Free Software Foundation,
17238384Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18238384Sjkim *
19238384Sjkim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20238384Sjkim * or visit www.oracle.com if you need additional information or have any
21238384Sjkim * questions.
22238384Sjkim *
23238384Sjkim */
24238384Sjkim
25238384Sjkim# include "incls/_precompiled.incl"
26238384Sjkim# include "incls/_c1_ValueType.cpp.incl"
27238384Sjkim
28238384Sjkim
29238384Sjkim// predefined types
30238384SjkimVoidType*       voidType     = NULL;
31238384SjkimIntType*        intType      = NULL;
32238384SjkimLongType*       longType     = NULL;
33238384SjkimFloatType*      floatType    = NULL;
34238384SjkimDoubleType*     doubleType   = NULL;
35238384SjkimObjectType*     objectType   = NULL;
36238384SjkimArrayType*      arrayType    = NULL;
37238384SjkimInstanceType*   instanceType = NULL;
38238384SjkimClassType*      classType    = NULL;
39238384SjkimAddressType*    addressType  = NULL;
40238384SjkimIllegalType*    illegalType  = NULL;
41238384Sjkim
42238384Sjkim
43238384Sjkim// predefined constants
44238384SjkimIntConstant*    intZero      = NULL;
45238384SjkimIntConstant*    intOne       = NULL;
46238384SjkimObjectConstant* objectNull   = NULL;
47238384Sjkim
48238384Sjkim
49238384Sjkimvoid ValueType::initialize() {
50238384Sjkim  // Note: Must initialize all types for each compilation
51238384Sjkim  //       as they are allocated within a ResourceMark!
52238384Sjkim
53238384Sjkim  // types
54238384Sjkim  voidType     = new VoidType();
55238384Sjkim  intType      = new IntType();
56238384Sjkim  longType     = new LongType();
57238384Sjkim  floatType    = new FloatType();
58238384Sjkim  doubleType   = new DoubleType();
59238384Sjkim  objectType   = new ObjectType();
60238384Sjkim  arrayType    = new ArrayType();
61238384Sjkim  instanceType = new InstanceType();
62238384Sjkim  classType    = new ClassType();
63238384Sjkim  addressType  = new AddressType();
64238384Sjkim  illegalType  = new IllegalType();
65238384Sjkim
66238384Sjkim  // constants
67238384Sjkim  intZero     = new IntConstant(0);
68238384Sjkim  intOne      = new IntConstant(1);
69238384Sjkim  objectNull  = new ObjectConstant(ciNullObject::make());
70238384Sjkim};
71238384Sjkim
72238384Sjkim
73238384SjkimValueType* ValueType::meet(ValueType* y) const {
74238384Sjkim  // incomplete & conservative solution for now - fix this!
75238384Sjkim  assert(tag() == y->tag(), "types must match");
76238384Sjkim  return base();
77238384Sjkim}
78238384Sjkim
79238384Sjkim
80238384SjkimValueType* ValueType::join(ValueType* y) const {
81238384Sjkim  Unimplemented();
82238384Sjkim  return NULL;
83238384Sjkim}
84238384Sjkim
85238384Sjkim
86238384Sjkim
87238384Sjkimjobject ObjectType::encoding() const {
88238384Sjkim  assert(is_constant(), "must be");
89238384Sjkim  return constant_value()->constant_encoding();
90238384Sjkim}
91238384Sjkim
92238384Sjkimbool ObjectType::is_loaded() const {
93238384Sjkim  assert(is_constant(), "must be");
94238384Sjkim  return constant_value()->is_loaded();
95238384Sjkim}
96238384Sjkim
97238384SjkimciObject* ObjectConstant::constant_value() const                   { return _value; }
98238384SjkimciObject* ArrayConstant::constant_value() const                    { return _value; }
99238384SjkimciObject* InstanceConstant::constant_value() const                 { return _value; }
100238384SjkimciObject* ClassConstant::constant_value() const                    { return _value; }
101238384Sjkim
102238384Sjkim
103238384SjkimValueType* as_ValueType(BasicType type) {
104238384Sjkim  switch (type) {
105238384Sjkim    case T_VOID   : return voidType;
106238384Sjkim    case T_BYTE   : // fall through
107238384Sjkim    case T_CHAR   : // fall through
108238384Sjkim    case T_SHORT  : // fall through
109238384Sjkim    case T_BOOLEAN: // fall through
110238384Sjkim    case T_INT    : return intType;
111238384Sjkim    case T_LONG   : return longType;
112238384Sjkim    case T_FLOAT  : return floatType;
113238384Sjkim    case T_DOUBLE : return doubleType;
114238384Sjkim    case T_ARRAY  : return arrayType;
115238384Sjkim    case T_OBJECT : return objectType;
116238384Sjkim    case T_ADDRESS: return addressType;
117238384Sjkim    case T_ILLEGAL: return illegalType;
118238384Sjkim  }
119238384Sjkim  ShouldNotReachHere();
120238384Sjkim  return illegalType;
121238384Sjkim}
122238384Sjkim
123238384Sjkim
124238384SjkimValueType* as_ValueType(ciConstant value) {
125238384Sjkim  switch (value.basic_type()) {
126238384Sjkim    case T_BYTE   : // fall through
127238384Sjkim    case T_CHAR   : // fall through
128238384Sjkim    case T_SHORT  : // fall through
129238384Sjkim    case T_BOOLEAN: // fall through
130238384Sjkim    case T_INT    : return new IntConstant   (value.as_int   ());
131238384Sjkim    case T_LONG   : return new LongConstant  (value.as_long  ());
132238384Sjkim    case T_FLOAT  : return new FloatConstant (value.as_float ());
133238384Sjkim    case T_DOUBLE : return new DoubleConstant(value.as_double());
134238384Sjkim    case T_ARRAY  : // fall through (ciConstant doesn't have an array accessor)
135238384Sjkim    case T_OBJECT : return new ObjectConstant(value.as_object());
136238384Sjkim  }
137238384Sjkim  ShouldNotReachHere();
138238384Sjkim  return illegalType;
139238384Sjkim}
140238384Sjkim
141238384Sjkim
142238384SjkimBasicType as_BasicType(ValueType* type) {
143238384Sjkim  switch (type->tag()) {
144238384Sjkim    case voidTag:    return T_VOID;
145238384Sjkim    case intTag:     return T_INT;
146238384Sjkim    case longTag:    return T_LONG;
147238384Sjkim    case floatTag:   return T_FLOAT;
148238384Sjkim    case doubleTag:  return T_DOUBLE;
149238384Sjkim    case objectTag:  return T_OBJECT;
150238384Sjkim    case addressTag: return T_ADDRESS;
151238384Sjkim    case illegalTag: return T_ILLEGAL;
152238384Sjkim  }
153238384Sjkim  ShouldNotReachHere();
154238384Sjkim  return T_ILLEGAL;
155238384Sjkim}
156238384Sjkim