Go to the documentation of this file.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 #ifdef USE_PCH
00037 #include "be_com_pch.h"
00038 #endif
00039 #pragma hdrstop
00040 #include "be_symtab.h"
00041 #include "pu_info.h"
00042 #include "cxx_memory.h"
00043
00044 BE_SCOPE *Be_scope_tab;
00045
00046 BE_SYMBOL_TABLE Be_symbol_table;
00047
00048 BE_PREG_TAB Be_preg_tab;
00049
00050 static SYMTAB_IDX next_level = 0;
00051
00052 static MEM_POOL Be_symtab_pool;
00053
00054 void
00055 BE_symtab_initialize_be_scopes(void)
00056 {
00057 MEM_POOL_Initialize(&Be_symtab_pool, "back end symbol table", FALSE);
00058 MEM_POOL_Push(&Be_symtab_pool);
00059 }
00060
00061 void
00062 BE_symtab_free_be_scopes(void)
00063 {
00064 MEM_POOL_Pop(&Be_symtab_pool);
00065 MEM_POOL_Delete(&Be_symtab_pool);
00066 }
00067
00068 void
00069 BE_symtab_alloc_scope_level(const SYMTAB_IDX level)
00070 {
00071 while (level >= next_level) {
00072 BE_SCOPE *temp = CXX_NEW_ARRAY(BE_SCOPE, 1 + next_level * 2,
00073 &Be_symtab_pool);
00074 SYMTAB_IDX i;
00075 for (i = 0; i < next_level; i++) {
00076 temp[i] = Be_scope_tab[i];
00077 }
00078 next_level = 1 + next_level * 2;
00079 for (; i < next_level; i++) {
00080 temp[i].be_st_tab = NULL;
00081 }
00082 CXX_DELETE_ARRAY(Be_scope_tab, &Be_symtab_pool);
00083 Be_scope_tab = temp;
00084 }
00085 SYMTAB_IDX i = level;
00086 while (Be_scope_tab[i].be_st_tab == NULL && i > 0) {
00087 Be_scope_tab[i].be_st_tab = CXX_NEW(BE_ST_TAB, &Be_symtab_pool);
00088 --i;
00089 }
00090 }
00091
00092
00093 BOOL
00094 ST_is_const_initialized (const ST* st)
00095 {
00096
00097 if ( ST_class(st) != CLASS_VAR )
00098 return FALSE;
00099
00100
00101 if (!ST_is_const_var(st))
00102 return FALSE;
00103
00104
00105 if (BE_ST_unknown_const(st))
00106 return FALSE;
00107
00108
00109
00110
00111
00112 TY_IDX ty = ST_type(st);
00113
00114
00115
00116
00117 if (TY_is_volatile(ty)) {
00118 return FALSE;
00119 }
00120
00121 return TRUE;
00122 }
00123
00124
00125
00126 struct match_inito_by_st {
00127 private:
00128 const ST_IDX st_idx;
00129
00130 public:
00131 match_inito_by_st(const ST *const st) : st_idx(ST_st_idx(st)) { }
00132 match_inito_by_st(const ST_IDX esstee_idx) : st_idx(esstee_idx) { }
00133
00134 BOOL operator()(INITO_IDX, const INITO *inito) const
00135 { return INITO_st_idx(*inito) == st_idx; }
00136 };
00137
00138
00139
00140
00141
00142
00143 BOOL
00144 ST_is_const_initialized_scalar(const ST *st, TCON &tcon_copy)
00145 {
00146
00147 if (BE_ST_unknown_const(st) != 0) {
00148 Is_True (FALSE, ("Asking for value of unknown const"));
00149 return FALSE;
00150 }
00151
00152 if (!ST_is_const_initialized(st))
00153 return FALSE;
00154
00155 TY_IDX ty = ST_type(st);
00156 TYPE_ID mtype = TY_mtype(ty);
00157
00158
00159 if (!Is_Simple_Type(ty)) {
00160 return FALSE;
00161 }
00162
00163
00164
00165
00166 const ST *base;
00167 for (base = st;
00168 (!ST_is_initialized(base) && ST_base_idx(base) != ST_st_idx(base));
00169 base = ST_base(base));
00170
00171 BOOL initialized = ST_is_initialized(base);
00172
00173
00174
00175
00176 if (!initialized || ST_init_value_zero(st)) {
00177 if (MTYPE_is_integral(mtype)) {
00178 tcon_copy = Host_To_Targ(mtype, 0L);
00179 }
00180 else {
00181 tcon_copy = Host_To_Targ_Float(mtype, 0.0);
00182 }
00183 return TRUE;
00184 }
00185
00186
00187
00188 INITO_IDX inito_idx = For_all_until(Inito_Table,
00189 ST_IDX_level(ST_st_idx(st)),
00190 match_inito_by_st(st));
00191
00192
00193 if (inito_idx == (INITO_IDX) 0)
00194 return FALSE;
00195
00196
00197 INITV &inov = Initv_Table[INITO_val(inito_idx)];
00198
00199 switch (INITV_kind(inov)) {
00200 case INITVKIND_ZERO:
00201 tcon_copy = Host_To_Targ(mtype, 0L);
00202 return TRUE;
00203 case INITVKIND_ONE:
00204 tcon_copy = Host_To_Targ(mtype, 1L);
00205 return TRUE;
00206 case INITVKIND_VAL:
00207 tcon_copy = Tcon_Table[INITV_tc(inov)];
00208 return TRUE;
00209 }
00210 return FALSE;
00211 }
00212
00213
00214 extern INITV_IDX
00215 ST_has_initv(const ST *st)
00216 {
00217 if (!ST_is_initialized (st))
00218 return (INITV_IDX) 0;
00219
00220 TY_IDX ty = ST_type(st);
00221
00222
00223
00224 INITO_IDX inito_idx;
00225 inito_idx = For_all_until(Inito_Table, ST_IDX_level(ST_st_idx(st)),
00226 match_inito_by_st(st));
00227
00228 if (inito_idx == (INITO_IDX) 0) {
00229 return (INITV_IDX) 0;
00230 }
00231 else {
00232 return INITO_val(inito_idx);
00233 }
00234 }
00235
00236
00237
00238
00239
00240 extern INITV_IDX
00241 ST_is_const_and_has_initv(const ST *st)
00242 {
00243
00244 if (BE_ST_unknown_const(st) != 0) {
00245 Is_True (FALSE, ("Asking for value/initv of unknown const"));
00246 return (INITV_IDX) 0;
00247 }
00248
00249 if (!ST_is_const_initialized(st))
00250 return (INITV_IDX) 0;
00251
00252 return ST_has_initv(st);
00253 }