00001 /* 00002 * Copyright (C) 1999-2000, The University of Queensland 00003 * Copyright (C) 2001, Sun Microsystems, Inc 00004 * Copyright (C) 2002, Trent Waddington 00005 * 00006 * See the file "LICENSE.TERMS" for information on usage and 00007 * redistribution of this file, and for a DISCLAIMER OF ALL 00008 * WARRANTIES. 00009 * 00010 */ 00011 00012 /*============================================================================== 00013 * File: register.cc 00014 * Desc: Register class descriptions. Holds detailed information about 00015 * a single register. 00016 *============================================================================*/ 00017 00018 /* $Revision: 1.7 $ 00019 * 00020 * 28 Apr 02 - Mike: Mods for boomerang 00021 */ 00022 00023 00024 #if defined(_MSC_VER) && _MSC_VER <= 1200 00025 // For MSVC 5 or 6: warning about debug into truncated to 255 chars 00026 #pragma warning(disable:4786) 00027 #endif 00028 #include <assert.h> 00029 #include "register.h" 00030 #include "type.h" 00031 00032 00033 #if defined(_MSC_VER) && _MSC_VER >= 1400 00034 #pragma warning(disable:4996) // Warnings about e.g. _strdup deprecated in VS 2005 00035 #endif 00036 #ifndef NULL // Don't always include stdio.h 00037 #define NULL 0 00038 #endif 00039 00040 /*============================================================================== 00041 * FUNCTION: Register::Register 00042 * OVERVIEW: Constructor. 00043 * PARAMETERS: <none> 00044 * RETURNS: N/A 00045 *============================================================================*/ 00046 Register::Register() : name(NULL), address(NULL), mappedIndex(-1), 00047 mappedOffset(-1), flt(false) 00048 {} 00049 00050 /*============================================================================== 00051 * FUNCTION: Register::Register 00052 * OVERVIEW: Copy constructor. 00053 * PARAMETERS: Reference to another Register object to construct from 00054 * RETURNS: N/A 00055 *============================================================================*/ 00056 Register::Register(const Register& r) : name(NULL), size(r.size), 00057 address(r.address), mappedIndex(r.mappedIndex), 00058 mappedOffset(r.mappedOffset), flt(r.flt) 00059 { 00060 if (r.name != NULL) 00061 name = strdup(r.name); 00062 } 00063 00064 /*============================================================================== 00065 * FUNCTION: Register::operator= 00066 * OVERVIEW: Copy operator 00067 * PARAMETERS: Reference to another Register object (to be copied) 00068 * RETURNS: This object 00069 *============================================================================*/ 00070 Register Register::operator=(const Register& r2) 00071 { 00072 // copy operator 00073 00074 //if (name != NULL) 00075 //free(name); 00076 name = r2.name; 00077 size = r2.size; 00078 flt = r2.flt; 00079 address = r2.address; 00080 00081 mappedIndex = r2.mappedIndex; 00082 mappedOffset = r2.mappedOffset; 00083 00084 return(*this); 00085 } 00086 00087 /*============================================================================== 00088 * FUNCTION: Register::operator== 00089 * OVERVIEW: Equality operator 00090 * PARAMETERS: Reference to another Register object 00091 * RETURNS: True if the same 00092 *============================================================================*/ 00093 bool Register::operator==(const Register& r2) const { 00094 // compare on name 00095 assert(name != NULL && r2.name != NULL); 00096 if (strcmp(name, r2.name) != 0) 00097 return false; 00098 return true; 00099 } 00100 00101 /*============================================================================== 00102 * FUNCTION: Register::operator< 00103 * OVERVIEW: Comparison operator (to establish an ordering) 00104 * PARAMETERS: Reference to another Register object 00105 * RETURNS: true if this name is less than the given Register's name 00106 *============================================================================*/ 00107 bool Register::operator<(const Register& r2) const 00108 { 00109 assert(name != NULL && r2.name != NULL); 00110 00111 // compare on name 00112 if (strcmp(name, r2.name) < 0) 00113 return true; 00114 return false; 00115 } 00116 00117 /*============================================================================== 00118 * FUNCTION: Register::s_name 00119 * OVERVIEW: Set the name for this register 00120 * PARAMETERS: s: name to set it to 00121 * RETURNS: <nothing> 00122 *============================================================================*/ 00123 void Register::s_name(const char *s) 00124 { 00125 assert(s != NULL); 00126 00127 //if (name != NULL) 00128 //free(name); 00129 name = strdup(s); 00130 } 00131 00132 /*============================================================================== 00133 * FUNCTION: Register::g_name 00134 * OVERVIEW: Get the name for this register 00135 * PARAMETERS: <none> 00136 * RETURNS: The name as a character string 00137 *============================================================================*/ 00138 char *Register::g_name() const { 00139 static char outname[100]; 00140 00141 strncpy(outname, name, 100); 00142 outname[99] = '\0'; 00143 return(outname); 00144 } 00145 00146 /*============================================================================== 00147 * FUNCTION: Register::g_type 00148 * OVERVIEW: Get the type for this register 00149 * PARAMETERS: <none> 00150 * RETURNS: The type as a pointer to a Type object 00151 *============================================================================*/ 00152 Type* Register::g_type() const 00153 { 00154 if (flt) 00155 return new FloatType(size); 00156 return new IntegerType(size); 00157 }