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
00039
00040 #include <malloc.h>
00041 #include "phases.h"
00042 #include "options.h"
00043 #include "string_utils.h"
00044 #include "errors.h"
00045 #include "option_names.h"
00046 #include "option_seen.h"
00047
00048
00049
00050
00051
00052
00053
00054
00055 typedef struct option_list_rec {
00056 int info_index;
00057 char *name;
00058 struct option_list_rec *next;
00059 } option_list_t;
00060
00061 typedef struct index_list_rec {
00062 int info_index;
00063 struct index_list_rec *next;
00064 } index_list_t;
00065
00066 typedef struct option_info_rec {
00067 mask_t valid_langs;
00068 mask_t valid_phases;
00069 #if 0
00070
00071 index_list_t *combo_list;
00072 #endif
00073 option_list_t *implies;
00074 char *name;
00075 char *help_msg;
00076 } option_info_t;
00077
00078
00079 static option_info_t *options;
00080 int max_options = LAST_PREDEFINED_OPTION+100;
00081
00082
00083
00084
00085
00086 static int last_option = LAST_PREDEFINED_OPTION;
00087
00088
00089 char *
00090 get_option_name (int flag)
00091 {
00092
00093 if (options[flag].name == NULL && options[flag].implies != NULL) {
00094 return options[flag].implies->name;
00095 } else {
00096 return options[flag].name;
00097 }
00098 }
00099
00100
00101 char *
00102 get_option_help (int flag)
00103 {
00104 return options[flag].help_msg;
00105 }
00106
00107
00108
00109 boolean
00110 option_has_blank (int flag)
00111 {
00112 return (options[flag].implies != NULL
00113 && has_blank(options[flag].implies->name));
00114 }
00115
00116
00117 void
00118 set_language_for_option (int flag, languages_t l)
00119 {
00120 options[flag].valid_langs = get_language_mask(l);
00121 }
00122
00123 void
00124 add_language_for_option (int flag, languages_t l)
00125 {
00126 options[flag].valid_langs |= get_language_mask(l);
00127 }
00128
00129
00130 boolean
00131 option_matches_language (int flag, languages_t l)
00132 {
00133 return (is_matching_language (options[flag].valid_langs, l));
00134 }
00135
00136
00137 boolean
00138 is_internal_option (int flag)
00139 {
00140 return (is_matching_language (options[flag].valid_langs, L_internal));
00141 }
00142
00143
00144 void
00145 set_internal_option (int flag)
00146 {
00147 add_language_for_option ( flag, L_internal );
00148 }
00149
00150
00151 boolean
00152 option_matches_phase (int flag, phases_t p)
00153 {
00154 return (is_matching_phase (options[flag].valid_phases, p));
00155 }
00156
00157
00158 void
00159 add_phase_for_option(int flag, phases_t p)
00160 {
00161 options[flag].valid_phases |= get_phase_mask(p);
00162 }
00163
00164
00165 void
00166 remove_phase_for_option(int flag, phases_t p)
00167 {
00168 options[flag].valid_phases &= ~(get_phase_mask(p));
00169 }
00170
00171
00172 static void
00173 double_max_options (void)
00174 {
00175 max_options *= 2;
00176 options = (option_info_t *) realloc((char*)options, max_options*sizeof(option_info_t));
00177 double_max_option_seen();
00178 }
00179
00180
00181 int
00182 add_new_option (char *arg)
00183 {
00184 option_list_t *p;
00185 if (last_option >= max_options) {
00186 double_max_options();
00187 }
00188 p = (option_list_t*)malloc(sizeof(option_list_t));
00189 p->name = string_copy(arg);
00190 p->info_index = last_option;
00191 p->next = NULL;
00192 options[last_option].implies = p;
00193 options[last_option].name = NULL;
00194 options[last_option].help_msg = NULL;
00195 options[last_option].valid_langs = get_language_mask(L_ALL);
00196 options[last_option].valid_phases = get_phase_mask(P_NONE);
00197 last_option++;
00198 return last_option-1;
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 int
00208 add_derived_option (int parent, char *arg)
00209 {
00210 option_list_t *pi;
00211 option_list_t *ni;
00212 char* loc;
00213 int new = add_new_option (arg);
00214 if (loc = strstr(arg, "roundoff")) {
00215
00216 roundoff = loc[9];
00217 }
00218
00219 options[new].valid_langs = options[parent].valid_langs;
00220 options[new].valid_phases = options[parent].valid_phases;
00221
00222 pi = options[parent].implies;
00223 ni = options[new].implies;
00224
00225 ni->info_index = parent;
00226 while (pi != NULL) {
00227 ni->info_index = pi->info_index;
00228 ni->name = expand_template_string (pi->name, arg);
00229 pi = pi->next;
00230 if (pi != NULL) {
00231
00232 ni->next = (option_list_t*)malloc(sizeof(option_list_t));
00233 ni = ni->next;
00234 }
00235 }
00236 ni->next = NULL;
00237 return new;
00238 }
00239
00240
00241 boolean
00242 is_derived_option (int flag)
00243 {
00244 return (options[flag].name == NULL);
00245 }
00246
00247
00248 int
00249 get_derived_parent (int flag)
00250 {
00251 return options[flag].implies->info_index;
00252 }
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 static int current_option;
00264
00265 int
00266 first_option (void)
00267 {
00268 current_option = last_option-1;
00269 return current_option;
00270 }
00271
00272 int
00273 next_option (void)
00274 {
00275 current_option--;
00276 return current_option;
00277 }
00278
00279 boolean
00280 no_more_options (void)
00281 {
00282 return (current_option == 0);
00283 }
00284
00285 #if 0
00286
00287
00288
00289
00290
00291
00292 static index_list_t *current_combo;
00293
00294 int
00295 first_combo_item (int combo_flag)
00296 {
00297 current_combo = options[combo_flag].combo_list;
00298 if (current_combo == NULL)
00299 return O_Unrecognized;
00300 else
00301 return current_combo->info_index;
00302 }
00303
00304 int
00305 next_combo_item (int combo_flag)
00306 {
00307 current_combo = current_combo->next;
00308 if (current_combo == NULL)
00309 return O_Unrecognized;
00310 else
00311 return current_combo->info_index;
00312 }
00313
00314 boolean
00315 no_more_combo_items (int combo_flag)
00316 {
00317 return (current_combo == NULL);
00318 }
00319 #endif
00320
00321
00322
00323
00324
00325
00326 static option_list_t *current_implied;
00327
00328 int
00329 first_implied_option (int flag)
00330 {
00331 current_implied = options[flag].implies;
00332 if (current_implied == NULL)
00333 return O_Unrecognized;
00334 else
00335 return current_implied->info_index;
00336 }
00337
00338 int
00339 next_implied_option (int flag)
00340 {
00341 current_implied = current_implied->next;
00342 if (current_implied == NULL)
00343 return O_Unrecognized;
00344 else
00345 return current_implied->info_index;
00346 }
00347
00348 boolean
00349 no_more_implied_options (int flag)
00350 {
00351 return (current_implied == NULL);
00352 }
00353
00354
00355
00356 char *
00357 get_current_implied_name (void)
00358 {
00359 return (current_implied->name);
00360 }
00361
00362 void
00363 dump_option (int flag)
00364 {
00365 option_list_t *pi = options[flag].implies;
00366 #if 0
00367 index_list_t *pc = options[flag].combo_list;
00368 #endif
00369 printf("dump option %d", flag);
00370 if (options[flag].name != NULL) {
00371 printf(" (%s)", options[flag].name);
00372 }
00373 printf("\n");
00374 printf("\tlangs = %llx, phases = %llx\n", options[flag].valid_langs,
00375 options[flag].valid_phases);
00376 if (pi != NULL) {
00377 printf("\timplies:");
00378 while (pi != NULL) {
00379 printf(" %d(%s)", pi->info_index, pi->name);
00380 pi = pi->next;
00381 }
00382 }
00383 printf("\n");
00384 #if 0
00385 if (pc != NULL) {
00386 printf("\tcombos:");
00387 while (pc != NULL) {
00388 printf(" %d", pc->info_index);
00389 pc = pc->next;
00390 }
00391 printf("\n");
00392 }
00393 #endif
00394 }
00395
00396 #include "init_options.i"