00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /* ==================================================================== 00037 * ==================================================================== 00038 * 00039 * Module: flags.h 00040 * $Revision: 1.1 $ 00041 * $Date: 2005/07/27 02:17:57 $ 00042 * $Author: kevinlo $ 00043 * $Source: /depot/CVSROOT/javi/src/sw/cmplr/common/util/flags.h,v $ 00044 * 00045 * Revision history: 00046 * 08-Sep-89 - Original Version 00047 * 01-Feb-91 - Copied for TP/Muse 00048 * 23-May-93 - Added group support 00049 * 29-Jan-94 - Removed last non-generic info to config.h 00050 * 00051 * Description: 00052 * 00053 * External interface to the command line processing utilities for the 00054 * Ragnarok compiler. 00055 * 00056 * NOTE: This interface should only be visible to modules involved in 00057 * configuration and other initialization. More widely-visible 00058 * configuration options belong in config.h and related files. See 00059 * config.h for a more complete discussion. 00060 * 00061 * 00062 * Exported types: 00063 * 00064 * OPTION_GROUP 00065 * Describes a command-line "option group", a set of related 00066 * options with their own specification namespace. Fields 00067 * are accessed by: 00068 * char *OGROUP_name(grp) Name (e.g., "OPT") of the group. 00069 * These need to be chosen carefully 00070 * so they don't conflict with other 00071 * command-line option names (e.g., 00072 * can't start with L or I without 00073 * restricting directory names that 00074 * can be specified with -L/-I). 00075 * By convention, hierarchical group 00076 * names consist of uppercase names 00077 * separated by underscores. (e.g., 00078 * CG_SWP provides SoftWare Pipelining 00079 * options for Code Generation.) 00080 * OGROUP_DESC *OGROUP_options(grp) 00081 * Array of option descriptors (see 00082 * below), terminated by one with kind 00083 * OVK_COUNT, describing the options 00084 * provided in the group. These exist 00085 * within their own namespace, so names 00086 * do not have to be chosen as carefully 00087 * as the option group name. 00088 * char OGROUP_separator(grp) Character used to separate options 00089 * within the group (usually ':'). 00090 * char OGROUP_valmarker(grp) Character used to separate option 00091 * names from values within the group 00092 * (usually '='). 00093 * char *OGROUP_description(grp) 00094 * One-line description of group. 00095 * 00096 * OPTION_DESC 00097 * Describes an option with an option group. Fields are accessed 00098 * by: 00099 * OPTION_KIND ODESC_kind(od) Kind of option, as given below. 00100 * OPTION_VISIBILITY ODESC_visibility(od) 00101 * Visibility of option, below. 00102 * char *ODESC_name(od) Full verbose name of option. 00103 * char *ODESC_abbrev(od) Shortest acceptable prefix allowed 00104 * for abbreviating option. MUST be 00105 * a prefix of the full name. If prefix 00106 * of more than one opt name in group, 00107 * ambiguity is resolved in favor of 00108 * first appearance in option array. 00109 * NULL means full option name must be 00110 * used. Empty string ("") means any 00111 * non-ambiguous prefix allowed as an 00112 * abbreviation. Abbreviations that 00113 * are not prefixes of the full option 00114 * name should be implemented with their 00115 * own OPTION_DESC (sharing the same 00116 * variable). 00117 * INT64 ODESC_def_val(od) Default value for numeric options. 00118 * INT64 ODESC_min_val(od) Minimum value for numeric options. 00119 * INT64 ODESC_max_val(od) Maximum value for numeric options. 00120 * void *variable Pointer to variable to be set if 00121 * option is given. 00122 * BOOL *specified Pointer to Boolean value to set if 00123 * option is given, or NULL if no such 00124 * notification is necessary. This is 00125 * useful for seeing if options were 00126 * explicitly set on the command line. 00127 * char *ODESC_description(od) 00128 * One-line description of option. 00129 * The "variable" and "specified" are not accessible after the 00130 * initialization of the data structures. 00131 * 00132 * OPTION_KIND 00133 * Enumerated type specifying the various types of options within 00134 * an option group. Valid values are: 00135 * OVK_NONE Option takes no value; its appearance 00136 * will simply set the variable to TRUE 00137 * OVK_BOOL Option takes Boolean value, defaulting 00138 * to TRUE if no value given. Valid values 00139 * are (case-insignificant) "NO", "YES", 00140 * "TRUE", "FALSE", "ON", "OFF", and "0". 00141 * OVK_INT32 Option takes INT32 value, defaulting 00142 * to the specified default if no value 00143 * given or if out of range. 00144 * OVK_INT64 Option takes INT64 value, defaulting 00145 * to the specified default if no value 00146 * given or if out of range. 00147 * OVK_UINT32 Option takes UINT32 value, defaulting 00148 * to the specified default if no value 00149 * given or if out of range. 00150 * OVK_UINT64 Option takes UINT64 value, defaulting 00151 * to the specified default if no value 00152 * given or if out of range. 00153 * OVK_NAME Option takes string value, defaulting to 00154 * the empty string ("") if no value given. 00155 * OVK_SELF Option takes string value, defaulting to 00156 * the option name if no value given. This 00157 * may be useful when you want several 00158 * options to set the same variable. 00159 * OVK_LIST Option takes list value, where the list 00160 * contains the option names and values. 00161 * OVK_OBSOLETE Option is obsolete. 00162 * OVK_UNIMPLEMENTED Option is unimplemented. 00163 * OVK_REPLACED Option is obsolete, replaced by another, 00164 * named by its ODESC_variable field. 00165 * OVK_COUNT Dummy value used to mark end of option 00166 * descriptor array. 00167 * TODO: 64-bit option values not yet implemented. 00168 * 00169 * OPTION_VISIBILITY 00170 * Enumerated type specifying the visibility (to users) of 00171 * options within an option group. Valid values are: 00172 * OVK_VISIBLE Users will see option on full listing. 00173 * Such options should have a valid 00174 * ODESC_description field, and should 00175 * appear in documentation. 00176 * OVK_SHY Users will see option on listing only 00177 * if they've set it or it's been 00178 * implicitly set by one of their options 00179 * (e.g. Ofast). 00180 * OVK_INTERNAL This option does not appear on user 00181 * listings. 00182 * 00183 * 00184 * Exported functions: 00185 * 00186 * void Initialize_Option_Groups ( OPTION_GROUP *og ) 00187 * Initialize auxiliary internal information for the given 00188 * array of option groups. Will be called automatically by 00189 * the a call to Process_Command_Line_Group, but if some 00190 * options have their initial static defaults modified by 00191 * other means before that, calling this explicitly earlier 00192 * will properly identify those as modified on listings. 00193 * 00194 * void Set_Option_Internal ( OPTION_GROUP *ogroup, const char *name ); 00195 * Set the given option in the given group internal, meaning 00196 * that it won't appear on user listings. If the option name 00197 * is NULL, the entire group is set internal. This must be 00198 * called after initialization. 00199 * 00200 * BOOL Process_Command_Line_Group ( char *flag, OPTION_GROUP *og ) 00201 * Attempt to interpret <flag> as a command-line option group. 00202 * <flag> should point just past the initial "-". If <flag> 00203 * does not name an option group (as defined in og or Option_Groups, 00204 * see below), FALSE is returned. Otherwise processes the group, 00205 * setting the appropriate switches as specified in the group 00206 * desciption, possibly signalling errors or warnings for options 00207 * incorrectly specified. Returns TRUE whenever <flags> named 00208 * a valid group. 00209 * 00210 * void Print_Option_Group ( FILE *tf, OPTION_GROUP *og, const char *pfx, 00211 * BOOL internal, BOOL full, BOOL update) 00212 * Print the current settings of the 'og' flags to 'tf'. 00213 * Start lines with pfx (for comments in assembly source file 00214 * output, for example). Identify internal use (tracing) vs. 00215 * customer output (listing files). For internal use, 'full' 00216 * causes all options to be printed, not just set/modified 00217 * ones. If 'update' is TRUE, internal set/modified flags are 00218 * cleared and those options won't be printed next time 00219 * (unless set again). 00220 * 00221 * void Trace_Option_Group ( FILE *tf, OPTION_GROUP *og, BOOL full) 00222 * Trace the current settings of the 'og' flags to 'tf'. 00223 * 00224 * Print_Option_Groups / Trace_Option_Groups 00225 * Same as the singular forms above, but print array of groups. 00226 * 00227 * OPTION_GROUP *Get_Command_Line_Group ( OPTION_GROUP *og, const char *name ) 00228 * Given an option group array and a group name, return a 00229 * pointer to the array element which has the name (or NULL). 00230 * 00231 * INT32 Get_Numeric_Flag ( 00232 * char **cp, 00233 * UINT32 min, 00234 * UINT32 max, 00235 * UINT32 def, 00236 * char *flag) 00237 * Process a numeric flag from the command line. <flag> is a 00238 * pointer to the whole flag as given on the command line. 00239 * <cp> points to a pointer to a position within <flag> at 00240 * which the numeric value is expected. On exit, 00241 * point past the numeric value (if any). <min> and <max> 00242 * give the bounds for the expected value, while <def> gives 00243 * the default value. If either no numeric value is given, 00244 * or the value is outside the required range, the default is 00245 * returned (and a warning issued if outside the range); 00246 * otherwise the number specified by the flag is returned. 00247 * 00248 * 00249 * Exported variables: 00250 * 00251 * OPTION_GROUP Common_Option_Groups[] 00252 * List of option group descriptors common to all phases, terminated 00253 * by a NULL entry. Each phase can have its own list of other groups. 00254 * Statically initialized in config.c. Option groups are modified 00255 * by changing this initial value. After initialization, should 00256 * only be accessed by Process_Command_Line_Group. 00257 * 00258 * char Cmdname[] 00259 * The compiler invocation command. 00260 * 00261 * 00262 * SEE ALSO: 00263 * 00264 * com/config.h General configuration options. 00265 * com/controls.h Flag/pragma-based compiler control options. 00266 * 00267 * ==================================================================== 00268 * ==================================================================== 00269 */ 00270 00271 #ifndef flags_INCLUDED 00272 #define flags_INCLUDED 00273 00274 #ifdef _KEEP_RCS_ID 00275 static char *flags_rcs_id = "$Source: /depot/CVSROOT/javi/src/sw/cmplr/common/util/flags.h,v $ $Revision: 1.1 $"; 00276 #endif /* _KEEP_RCS_ID */ 00277 00278 #ifdef __cplusplus 00279 extern "C" { 00280 #endif 00281 00282 extern char Cmdname[]; 00283 00284 /* Interpret a numeric string such as '356' or '256': */ 00285 extern INT64 Get_Numeric_Flag ( 00286 char **cp, /* String to decode and advance */ 00287 INT64 min, /* Minimum valid value */ 00288 INT64 max, /* Maximum valid value */ 00289 INT64 def, /* Default value if none present */ 00290 char *flag /* Option string (for error messages) */ 00291 ); 00292 00293 /* Interpret a string such as '356K' or '256g' as a numeric value: */ 00294 extern BOOL Atoi_KMG ( /* Returns whether string was valid */ 00295 const char* s, /* String to interpret */ 00296 INT64* val, /* Result of interpretation */ 00297 BOOL suffix_required /* Is a suffix required? (Must be [kKmMgG]) */ 00298 ); 00299 00300 00301 /* Define the option kinds: */ 00302 typedef enum { 00303 OVK_INVALID, 00304 OVK_NONE, /* Option never takes a value */ 00305 OVK_BOOL, /* boolean value */ 00306 OVK_INT32, /* 32-bit integer value */ 00307 OVK_INT64, /* 64-bit integer value */ 00308 OVK_UINT32, /* 32-bit unsigned integer value */ 00309 OVK_UINT64, /* 64-bit unsigned integer value */ 00310 OVK_NAME, /* string value, defaulting to "" */ 00311 OVK_SELF, /* string value, defaulting to option name */ 00312 OVK_LIST, /* list of option name/value pairs */ 00313 OVK_OBSOLETE, /* Option is obsolete */ 00314 OVK_OLD_COUNT,/* Used to be COUNT. Here to avoid a revision mismatch. 00315 * Remove the reference in flags.c at some future time, 00316 * later remove this with another if needed. 00317 */ 00318 OVK_REPLACED, /* Option is obsolete, replaced by another */ 00319 OVK_UNIMPLEMENTED, /* Option is unimplemented */ 00320 00321 OVK_COUNT=63 /* end of list marker */ 00322 } OPTION_KIND; 00323 00324 /* Define the option visibility: */ 00325 typedef enum { 00326 OV_VISIBLE, /* Option freely visible to users */ 00327 OV_SHY, /* Option listed only if user explicitly sets it */ 00328 OV_INTERNAL /* Internal option never listed for users */ 00329 } OPTION_VISIBILITY; 00330 00331 /* Define the list returned for OVK_LIST: */ 00332 typedef struct option_list { 00333 struct option_list *next; 00334 const char *opt; 00335 char *val; 00336 } OPTION_LIST; 00337 00338 #define OLIST_next(o) ((o)->next) 00339 #define OLIST_opt(o) ((o)->opt) 00340 #define OLIST_val(o) ((o)->val) 00341 00342 /* Define an option descriptor: */ 00343 typedef struct option_desc { 00344 mINT8 kind; 00345 mINT8 visibility; 00346 BOOL can_change_by_pragma; /* options pragma */ 00347 const char * name; 00348 const char * abbrev; 00349 INT64 def_val; 00350 INT64 min_val; 00351 INT64 max_val; 00352 void * variable; 00353 void * aux; 00354 const char * description; 00355 } OPTION_DESC; 00356 00357 #define ODESC_kind(o) ((o)->kind) 00358 #define ODESC_visibility(o) ((o)->visibility) 00359 #define ODESC_can_change_by_pragma(o) ((o)->can_change_by_pragma) 00360 #define ODESC_name(o) ((o)->name) 00361 #define ODESC_abbrev(o) ((o)->abbrev) 00362 #define ODESC_def_val(o) ((o)->def_val) 00363 #define ODESC_min_val(o) ((o)->min_val) 00364 #define ODESC_max_val(o) ((o)->max_val) 00365 #define ODESC_variable(o) ((o)->variable) 00366 #define ODESC_description(o) ((o)->description) 00367 00368 /* Define an option group descriptor: */ 00369 typedef struct option_group { 00370 const char * name; /* Group name */ 00371 char separator; /* Separator between sub-options */ 00372 char valmarker; /* ... between option name and value */ 00373 OPTION_DESC * options; /* Array of option descriptors */ 00374 void * aux; /* Auxiliary info for internal use */ 00375 char * description; /* Short description of group */ 00376 } OPTION_GROUP; 00377 00378 #define OGROUP_name(o) ((o)->name) 00379 #define OGROUP_options(o) ((o)->options) 00380 #define OGROUP_separator(o) ((o)->separator) 00381 #define OGROUP_valmarker(o) ((o)->valmarker) 00382 #define OGROUP_description(o) ((o)->description) 00383 00384 /* The option groups common to all compiler components: */ 00385 extern OPTION_GROUP Common_Option_Groups[]; 00386 00387 /* Initialize auxiliary info for an array of OPTION_GROUPs: */ 00388 extern void Initialize_Option_Groups ( OPTION_GROUP *ogroups ); 00389 00390 /* Set the given option in the given group internal, meaning that it 00391 * won't appear on user listings. If the option name is NULL, the 00392 * entire group is set internal. 00393 */ 00394 extern void Set_Option_Internal ( OPTION_GROUP *ogroup, const char *name ); 00395 00396 /* Process the given option group: */ 00397 extern BOOL Process_Command_Line_Group ( 00398 char *flag, 00399 OPTION_GROUP *opt_groups ); 00400 00401 /* Print/trace the settings for the given option group: */ 00402 extern void Print_Option_Group ( 00403 FILE *tf, /* Listing/trace file */ 00404 OPTION_GROUP *opt_group, /* Which group? */ 00405 const char *prefix, /* Prefix for output lines (comment) */ 00406 BOOL internal, /* Internal trace or user listing? */ 00407 BOOL full, /* All options or only set options? */ 00408 BOOL update ); /* Update set/mod flags after list? */ 00409 extern void Trace_Option_Group ( 00410 FILE *tf, /* Trace file */ 00411 OPTION_GROUP *opt_group, /* Which group? */ 00412 BOOL full ); /* All options or only set options? */ 00413 00414 /* Same as the above, but print an array of groups: */ 00415 extern void Print_Option_Groups ( 00416 FILE *tf, /* Listing/trace file */ 00417 OPTION_GROUP *opt_group, /* Group array */ 00418 const char *prefix, /* Prefix for output lines (comment) */ 00419 BOOL internal, /* Internal trace or user listing? */ 00420 BOOL full, /* All options or only set options? */ 00421 BOOL update ); /* Update set/mod flags after list? */ 00422 extern void Trace_Option_Groups ( 00423 FILE *tf, /* Trace file */ 00424 OPTION_GROUP *opt_group, /* Group array */ 00425 BOOL full ); /* All options or only set options? */ 00426 00427 /* Get a group from an array, given its name: */ 00428 extern OPTION_GROUP *Get_Command_Line_Group ( 00429 OPTION_GROUP *og, 00430 const char *name ); 00431 00432 extern void Trace_Command_Line_Group(FILE *, OPTION_GROUP *); 00433 00434 extern void Save_or_restore_options(char *, INT32, BOOL); 00435 00436 #ifdef __cplusplus 00437 } 00438 #endif 00439 #endif /* flags_INCLUDED */
1.5.6