Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
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 //-*-c++-*- 00037 //============================================================================ 00038 // 00039 // 00040 // Revision history: 00041 // 23-SEP-97 dahl - Original Version 00042 // 00043 // Description: 00044 // Allow the user to set command line options via pragmas in the source. 00045 // 00046 //============================================================================ 00047 00048 #include "defs.h" // INT32 00049 #include "region_util.h" // debug flags 00050 #include "tracing.h" // Get_Trace 00051 #include "config.h" // Opt_Level 00052 #include "phase.h" // BE_PHASES 00053 #include "driver_util.h" // Process_Command_Line 00054 #include "cxx_memory.h" // CXX_NEW_ARRAY 00055 #include "config_wopt.h" // WOPT_Enable_LFTR2 00056 #include "flags.h" // Common_Option_Group 00057 #include "options_stack.h" // options stack 00058 00059 00060 #if defined(_GCC_NO_PRAGMAWEAK) || defined(__CYGWIN__) 00061 extern "C" void Process_Command_Line (INT, char **) { } 00062 #else 00063 # pragma weak Process_Command_Line 00064 #endif 00065 00066 //============================================================================ 00067 // Push_Current_Options 00068 // allocates stack slot and then copies global's values into that space 00069 //============================================================================ 00070 void 00071 OPTIONS_STACK::Push_Current_Options(void) 00072 { 00073 // allocate memory_pool, need guess on size 00074 char *tmp = CXX_NEW_ARRAY(char, OPTIONS_SIZE, &MEM_pu_nz_pool); 00075 00076 // save all options to temp location 00077 Save_or_restore_options(tmp, OPTIONS_SIZE, TRUE); 00078 00079 // push current options onto stack 00080 _options_stack.Push(tmp); 00081 00082 Is_Trace(Trace(), (TFile,"OPTIONS_STACK::Push_Current_Options, size=%d\n", 00083 _options_stack.Elements())); 00084 } 00085 00086 //============================================================================ 00087 // Pop_Current_Options 00088 // copies stack contents into global values, deallocates stack slot 00089 //============================================================================ 00090 void 00091 OPTIONS_STACK::Pop_Current_Options(void) 00092 { 00093 // delete old options memory 00094 char *tmp = _options_stack.Top(); 00095 _options_stack.Pop(); 00096 CXX_DELETE_ARRAY(tmp, &MEM_pu_nz_pool); 00097 00098 // pointer to space where old options are 00099 tmp = _options_stack.Top(); 00100 00101 // copy options back from stack 00102 Save_or_restore_options(tmp, OPTIONS_SIZE, FALSE); 00103 00104 Is_Trace(Trace(), (TFile,"OPTIONS_STACK::Pop_Current_Options, size=%d\n", 00105 _options_stack.Elements())); 00106 } 00107 00108 // ==================================================================== 00109 // str2argv (private) 00110 // convert options string to argv format, returns argc 00111 // ==================================================================== 00112 INT32 00113 OPTIONS_STACK::str2argv(char *str, char ***argv, MEM_POOL *pool) 00114 { 00115 // first count number of options, add 2 for command and filename 00116 INT32 argc = 2; 00117 INT32 i; 00118 for (i=0; i<strlen(str); i++) 00119 if (str[i] == '-') 00120 argc++; 00121 00122 // allocate array and fill in command and filename 00123 *argv = CXX_NEW_ARRAY(char *, argc, pool); 00124 (*argv)[0] = ""; // command 00125 (*argv)[argc-1] = ""; // filename 00126 00127 // fill in options 00128 INT32 pos = 0; 00129 for (i=1; i<argc-1; i++) { 00130 // eat up white space 00131 while (str[pos] == ' ') 00132 pos++; 00133 // first find length of option 00134 INT32 len; 00135 for (len=0; str[pos+len] != ' ' && str[pos+len] != '\0'; len++) 00136 ; // empty body 00137 // allocate 00138 (*argv)[i] = CXX_NEW_ARRAY(char, len+1, pool); // the 1 is for the '\0' 00139 // copy and NULL terminate 00140 strncpy((*argv)[i], &str[pos], len); 00141 (*argv)[i][len] = '\0'; 00142 // point to beginning of next option 00143 pos += len + 1; // the 1 is to skip the required space 00144 } 00145 00146 #ifdef Is_True_On 00147 if (Trace()) { 00148 fprintf(TFile, "OPTIONS_STACK::str2argv, argc=%d\n", argc); 00149 for (i=0; i<argc; i++) 00150 fprintf(TFile, " %d: %s\n", i, (*argv)[i]); 00151 } 00152 #endif 00153 00154 return argc; 00155 } 00156 00157 // ==================================================================== 00158 // Process_Pragma_Options 00159 // process any region or PU level options pragmas 00160 // ==================================================================== 00161 void 00162 OPTIONS_STACK::Process_Pragma_Options(char *options_string) 00163 { 00164 if (options_string == NULL) // no options pragma in this PU or region 00165 return; 00166 00167 Is_Trace(Trace(), 00168 (TFile,"OPTIONS_STACK::Process_Pragma_Options, options = %s\n", 00169 options_string)); 00170 00171 // malloc memory and save old options on stack 00172 Push_Current_Options(); 00173 00174 // set variables based on options_string 00175 MEM_POOL Options_pool; 00176 MEM_POOL_Initialize(&Options_pool, "Options_pool", FALSE); 00177 MEM_POOL_Push(&Options_pool); 00178 char **argv; 00179 // create an argv from the options string 00180 INT32 argc = str2argv(options_string, &argv, &Options_pool); 00181 // set the various options based on options string 00182 Process_Command_Line(argc, argv); 00183 MEM_POOL_Pop(&Options_pool); 00184 00185 #ifdef Is_True_On 00186 if (Trace()) { 00187 OPTION_GROUP *og = Get_Command_Line_Group(Common_Option_Groups, "WOPT"); 00188 Is_True(og != NULL, ("OPTIONS_STACK::Process_Pragma_Options, " 00189 "could not find WOPT group")); 00190 Trace_Command_Line_Group(TFile, og); // only prints differences 00191 } 00192 #endif 00193 }