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 #ifdef USE_PCH 00037 #include "be_com_pch.h" 00038 #endif /* USE_PCH */ 00039 #pragma hdrstop 00040 00041 #include "whirl2src.h" 00042 00043 #include "dso.h" // load_so 00044 00045 #include "w2c_weak.h" // W2C_ 00046 #include "w2f_weak.h" // W2F_ 00047 00048 extern BOOL Show_Progress; 00049 00050 static BOOL init_whirl2c = FALSE; /* Has whirl2c been initialized already? */ 00051 static BOOL init_whirl2f = FALSE; /* Has whirl2f been initialized already? */ 00052 static WN* w2src_func_nd = NULL; /* The current PU being processed */ 00053 00054 /*********************************************************************** 00055 * 00056 * Initialize whirl2c for processing: 00057 * - load the DSO if it hasn't been loaded yet 00058 * - store the supplied PU -- it is used by the _Emit routines. 00059 * - store the fact that the DSO has been loaded, so that 00060 * subsequent calls do not try to load it again. 00061 * 00062 ***********************************************************************/ 00063 extern void 00064 Whirl2C_Init (WN* func_nd) 00065 { 00066 w2src_func_nd = func_nd; 00067 if (!init_whirl2c) { 00068 if (W2C_Process_Command_Line == NULL) { 00069 /* load and initialize whirl2c */ 00070 extern char *W2C_Path; 00071 char* str; 00072 load_so("whirl2c.so", W2C_Path, Show_Progress); 00073 str = ""; 00074 W2C_Process_Command_Line(0, &str, 0, &str); 00075 W2C_Init (); 00076 } 00077 init_whirl2c = TRUE; 00078 } 00079 } 00080 00081 /*********************************************************************** 00082 * 00083 * Initialize whirl2f for processing: 00084 * - load the DSO if it hasn't been loaded yet 00085 * - store the supplied PU -- it is used by the _Emit routines. 00086 * - store the fact that the DSO has been loaded, so that 00087 * subsequent calls do not try to load it again. 00088 * 00089 ***********************************************************************/ 00090 extern void 00091 Whirl2F_Init (WN* func_nd) 00092 { 00093 w2src_func_nd = func_nd; 00094 if (!init_whirl2f) { 00095 if (W2F_Process_Command_Line == NULL) { 00096 /* load and initialize whirl2f */ 00097 extern char *W2F_Path; 00098 char* str; 00099 str = ""; 00100 load_so("whirl2f.so", W2F_Path, Show_Progress); 00101 W2F_Process_Command_Line(0, &str, 0, &str); 00102 W2F_Init (); 00103 } 00104 init_whirl2f = TRUE; 00105 } 00106 } 00107 00108 /*********************************************************************** 00109 * 00110 * Based on the source language of the current PU, 00111 * initialize either whirl2c or whirl2f. 00112 * 00113 ***********************************************************************/ 00114 extern void 00115 Whirl2Src_Init (WN* func_nd) 00116 { 00117 switch (PU_src_lang(Get_Current_PU())) { 00118 case PU_C_LANG: 00119 case PU_CXX_LANG: 00120 Whirl2C_Init (func_nd); 00121 break; 00122 case PU_F90_LANG: 00123 case PU_F77_LANG: 00124 Whirl2F_Init (func_nd); 00125 break; 00126 default: 00127 FmtAssert (FALSE, ("Unknown source language type")); 00128 break; 00129 } 00130 } 00131 00132 /*********************************************************************** 00133 * 00134 * Emit the supplied wn in C using whirl2c into the supplied FILE*. 00135 * 00136 ***********************************************************************/ 00137 extern void 00138 Whirl2C_Emit (FILE* fp, WN* wn) 00139 { 00140 if (!init_whirl2c) { 00141 Is_True (FALSE, ("Whirl2C_Emit: whirl2c not initialized\n")); 00142 return; 00143 } 00144 W2C_Push_PU (w2src_func_nd, wn); 00145 W2C_Translate_Wn(fp, wn); 00146 W2C_Pop_PU(); 00147 return; 00148 } 00149 00150 /*********************************************************************** 00151 * 00152 * Emit the supplied wn in Fortran using whirl2f into the supplied FILE*. 00153 * 00154 ***********************************************************************/ 00155 extern void 00156 Whirl2F_Emit (FILE* fp, WN* wn) 00157 { 00158 if (!init_whirl2f) { 00159 Is_True (FALSE, ("Whirl2F_Emit: whirl2f not initialized\n")); 00160 return; 00161 } 00162 W2F_Push_PU (w2src_func_nd, wn); 00163 W2F_Translate_Wn(fp, wn); 00164 W2F_Pop_PU(); 00165 return; 00166 } 00167 00168 /*********************************************************************** 00169 * 00170 * Emit the supplied wn in source form into the supplied FILE*. 00171 * 00172 ***********************************************************************/ 00173 extern void 00174 Whirl2Src_Emit (FILE* fp, WN* wn) 00175 { 00176 switch (PU_src_lang(Get_Current_PU())) { 00177 case PU_C_LANG: 00178 case PU_CXX_LANG: 00179 Whirl2C_Emit (fp, wn); 00180 break; 00181 case PU_F90_LANG: 00182 case PU_F77_LANG: 00183 Whirl2F_Emit (fp, wn); 00184 break; 00185 default: 00186 FmtAssert (FALSE, ("Unknown source language type")); 00187 break; 00188 } 00189 } 00190 00191 #ifndef __linux__ 00192 00193 // These functions are needed only for prompf_anl.so 00194 00195 /*********************************************************************** 00196 * 00197 * This is a dummy routine that calls the following two routines: 00198 * W2C_Translate_Istore_Lhs 00199 * W2F_Translate_Istore_Lhs 00200 * thereby forcing them to actually get "weak"ly defined in the .o 00201 * 00202 ***********************************************************************/ 00203 static void 00204 dummy () 00205 { 00206 W2C_Translate_Istore_Lhs ((char*) NULL, (UINT) 0, (WN*) NULL, (WN_OFFSET) 0, 00207 (TY_IDX) NULL, (TYPE_ID) 0); 00208 W2F_Translate_Istore_Lhs ((char*) NULL, (UINT) 0, (WN*) NULL, (WN_OFFSET) 0, 00209 (TY_IDX) NULL, (TYPE_ID) 0); 00210 W2C_Translate_Wn_Str ((char*) NULL, (UINT) 0, (WN*) NULL); 00211 W2F_Translate_Wn_Str ((char*) NULL, (UINT) 0, (WN*) NULL); 00212 } 00213 00214 extern void 00215 Whirl2Src_Translate_Iload_Str(char *str_buf, 00216 UINT buf_size, 00217 WN* iload) 00218 { 00219 INT i; 00220 for (i=0; i<buf_size; i++) str_buf[i]='\0'; 00221 switch (PU_src_lang(Get_Current_PU())) { 00222 case PU_C_LANG: 00223 case PU_CXX_LANG: 00224 W2C_Push_PU (w2src_func_nd, iload); 00225 W2C_Translate_Wn_Str(str_buf, buf_size, iload); 00226 W2C_Pop_PU (); 00227 break; 00228 case PU_F90_LANG: 00229 case PU_F77_LANG: 00230 W2F_Push_PU (w2src_func_nd, iload); 00231 W2F_Translate_Wn_Str(str_buf, buf_size, iload); 00232 W2F_Pop_PU (); 00233 break; 00234 default: 00235 FmtAssert (FALSE, ("Unknown source language type")); 00236 } 00237 } 00238 00239 extern void 00240 Whirl2Src_Translate_Istore_Str(char *str_buf, 00241 UINT buf_size, 00242 WN* istore) 00243 { 00244 INT i; 00245 for (i=0; i<buf_size; i++) str_buf[i]='\0'; 00246 switch (PU_src_lang(Get_Current_PU())) { 00247 case PU_C_LANG: 00248 case PU_CXX_LANG: 00249 W2C_Push_PU (w2src_func_nd, istore); 00250 W2C_Translate_Istore_Lhs(str_buf, buf_size, WN_kid1(istore), 00251 WN_offset(istore), WN_ty(istore), 00252 WN_desc(istore)); 00253 W2C_Pop_PU (); 00254 break; 00255 case PU_F90_LANG: 00256 case PU_F77_LANG: 00257 W2F_Push_PU (w2src_func_nd, istore); 00258 W2F_Translate_Istore_Lhs(str_buf, buf_size, WN_kid1(istore), 00259 WN_offset(istore), WN_ty(istore), 00260 WN_desc(istore)); 00261 W2F_Pop_PU (); 00262 break; 00263 default: 00264 FmtAssert (FALSE, ("Unknown source language type")); 00265 } 00266 } 00267 00268 #endif // __linux__