00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 # include "incls/_precompiled.incl"
00025
00026 # ifdef DELTA_COMPILER
00027
00028 # include "incls/_location.cpp.incl"
00029
00030 static char* specialLocNames[nofSpecialLocations] = {
00031 "illegalLocation", "unAllocated", "noRegister", "topOfStack", "resultOfNLR", "topOfFloatStack"
00032 };
00033
00034
00035
00036
00037 void Location::overflow(Mode mode, int f1, int f2, int f3) {
00038
00039 fatal("Location field overflow - please notify the compiler folks");
00040 }
00041
00042
00043 Location::Location(Mode mode, int f) {
00044 _loc = (int)mode + (f<<_fPos);
00045 }
00046
00047
00048 Location::Location(Mode mode, int f1, int f2, int f3) {
00049 if ((f1 & _f1Mask) != f1 || (f2 & _f2Mask) != f2 || (f3 & _f3Mask) != f3) overflow(mode, f1, f2, f3);
00050 _loc = int(mode) + (f1 << _f1Pos) + (f2 << _f2Pos) + (f3 << _f3Pos);
00051 }
00052
00053
00054 char* Location::name() const {
00055 char* s;
00056 switch (mode()) {
00057 case specialLoc : s = specialLocNames[id()]; break;
00058 case registerLoc: s = Mapping::asRegister(*this).name(); break;
00059 case stackLoc : {
00060 s = NEW_RESOURCE_ARRAY(char, 8);
00061 sprintf(s, "S%d", offset());
00062 break;
00063 }
00064 break;
00065 case contextLoc1: {
00066 s = NEW_RESOURCE_ARRAY(char, 24);
00067 sprintf(s, "C%d,%d(%d)", contextNo(), tempNo(), scopeID());
00068 }
00069 break;
00070 case contextLoc2: {
00071 s = NEW_RESOURCE_ARRAY(char, 24);
00072 sprintf(s, "C%d,%d[%d]", contextNo(), tempNo(), scopeOffs());
00073 }
00074 break;
00075 case floatLoc: {
00076 s = NEW_RESOURCE_ARRAY(char, 16);
00077 sprintf(s, "F%d(%d)", floatNo(), scopeNo());
00078 }
00079 break;
00080 default: ShouldNotReachHere(); break;
00081 }
00082 return s;
00083 }
00084
00085
00086
00087
00088 bool Location::isTopOfStack() const {
00089 return *this == topOfStack || *this == topOfFloatStack;
00090 }
00091
00092
00093 bool Location::isTemporaryRegister() const {
00094 return isRegisterLocation() && Mapping::isTemporaryRegister(*this);
00095 }
00096
00097
00098 bool Location::isTrashedRegister() const {
00099 return isRegisterLocation() && Mapping::isTrashedRegister(*this);
00100 }
00101
00102
00103 bool Location::isLocalRegister() const {
00104 return isRegisterLocation() && Mapping::isLocalRegister(*this);
00105 }
00106
00107
00108
00109
00110 void IntFreeList::grow() {
00111 _list->append(_first);
00112 _first = _list->length() - 1;
00113 }
00114
00115
00116 IntFreeList::IntFreeList(int size) {
00117 _first = -1;
00118 _list = new GrowableArray<int>(2);
00119 assert(_list->length() == 0, "should be zero");
00120 }
00121
00122
00123 int IntFreeList::allocate() {
00124 if (_first < 0) grow();
00125 int i = _first;
00126 _first = _list->at(i);
00127 _list->at_put(i, -1);
00128 return i;
00129 }
00130
00131
00132 int IntFreeList::allocated() {
00133 int n = length();
00134 int i = _first;
00135 while (i >= 0) {
00136 i = _list->at(i);
00137 n--;
00138 };
00139 assert(n >= 0, "should be >= 0");
00140 return n;
00141 }
00142
00143
00144 void IntFreeList::release(int i) {
00145 assert(_list->at(i) == -1, "should have been allocated before");
00146 _list->at_put(i, _first);
00147 _first = i;
00148 }
00149
00150
00151 int IntFreeList::length() {
00152 return _list->length();
00153 }
00154
00155
00156 void IntFreeList::print() {
00157 std->print("FreeList 0x%x:", this); _list->print();
00158 }
00159
00160
00161 # endif