00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "c_breeze.h"
00039 #include "register.h"
00040
00041 void
00042 Register::setType (typeNode * the_type)
00043 {
00044 if ( the_type->is_char()
00045 || the_type->is_int()
00046 || the_type->is_pointer() )
00047 makeGPR();
00048 else if ( the_type->is_float() )
00049 makeFPR();
00050 else
00051 CBZFAIL(("don't know how to put low-level type %d into a register.",
00052 the_type->typ()));
00053 }
00054
00055 string
00056 Register::to_string (bool wantPrefixAdd, bool wantPrefixRemove) const
00057 {
00058
00059 string name;
00060 if (CBZ::ArchInfo.
00061 get_reg_name (*this, name, wantPrefixAdd, wantPrefixRemove))
00062 return name;
00063
00064
00065 char *pBuf = new char[20];
00066 switch (_type)
00067 {
00068 case reg_gpr:
00069 return cbz_util::string_format ("gpr_%d", _num);
00070 case reg_fpr:
00071 return cbz_util::string_format ("fpr_%d", _num);
00072 case reg_stack_ptr:
00073 return cbz_util::string_format ("sp");
00074 case reg_frame_ptr:
00075 return cbz_util::string_format ("fp");
00076 default:
00077 return cbz_util::string_format ("R_%d", _num);
00078 }
00079 }
00080
00081 string
00082 reg_or_const::to_string (bool quote_strings, bool addAsmConstPrefix) const
00083 {
00084
00085
00086 if (_is_const && _const.is_str () && !quote_strings)
00087 return _const.Str ();
00088
00089
00090 if (!_is_const)
00091 return _reg.to_string ();
00092
00093
00094 string str = _const.to_string (false);
00095 cbz_util::string_replace (str, "UL", "");
00096 cbz_util::string_replace (str, "U", "");
00097 if (addAsmConstPrefix && !_const.is_str ())
00098 str = CBZ::ArchInfo.get_asm_const_prefix () + str;
00099 return str;
00100 }
00101
00102
00103 ostream & operator << (ostream & os, const reg_or_const & rc)
00104 {
00105
00106 os << rc.to_string (true);
00107 return os;
00108 }
00109
00110 Register
00111 Register::getRegSp ()
00112 {
00113 assert (CBZ::ArchInfo.is_valid ());
00114 return *(CBZ::ArchInfo.get_reg_sp ());
00115 }
00116
00117 Register
00118 Register::getRegFp ()
00119 {
00120 assert (CBZ::ArchInfo.is_valid ());
00121 return *(CBZ::ArchInfo.get_reg_fp ());
00122 }
00123
00124 Register
00125 Register::getRegRetValFixed ()
00126 {
00127 assert (CBZ::ArchInfo.is_valid ());
00128 const arch_info::register_info * info =
00129 CBZ::ArchInfo.get_reg_retval_fixed ();
00130 Register reg;
00131 if (info)
00132 reg = *info;
00133 return reg;
00134 }
00135
00136 Register
00137 Register::getRegRetValFloat ()
00138 {
00139 assert (CBZ::ArchInfo.is_valid ());
00140 const arch_info::register_info * info =
00141 CBZ::ArchInfo.get_reg_retval_float ();
00142 Register reg;
00143 if (info)
00144 reg = *info;
00145 return reg;
00146 }
00147
00148 bool
00149 Register::getRegRetVal (typeNode * the_type, Register & reg)
00150 {
00151 if ( the_type->is_void() )
00152 return false;
00153 else if ( the_type->is_integer()
00154 || the_type->is_pointer() )
00155 reg = Register::getRegRetValFixed();
00156 else if ( the_type->is_float() )
00157 reg = Register::getRegRetValFloat();
00158 else
00159 CBZFAIL(("low-level type %d can't be returned in a register.",
00160 the_type->typ()));
00161 return true;
00162 }
00163
00164