location.cpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.20 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
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 // Constructors
00036 
00037 void Location::overflow(Mode mode, int f1, int f2, int f3) {
00038   // should handle field overflow somehow - for now: fatal error
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 // predicates
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 // Implementation of IntFreeList
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); // for debugging only
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

Generated on Mon Oct 9 13:37:13 2006 for Strongtalk VM by  doxygen 1.4.7