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 /* ==================================================================== 00037 * ==================================================================== 00038 * 00039 * 00040 * Revision history: 00041 * 21-Feb-95 - Original Version 00042 * 00043 * Description: 00044 * Clean up functions for the be driver. 00045 * 00046 * ==================================================================== 00047 * ==================================================================== 00048 */ 00049 00050 #include <elf.h> /* for wn.h */ 00051 #ifndef _SYS_TYPES_H 00052 #include <sys/types.h> /* for off_t */ 00053 #endif /* _SYS_TYPES_H */ 00054 00055 00056 #include "defs.h" 00057 #include "glob.h" /* for Src_File_Name, etc. */ 00058 #include "erglob.h" /* for EC_Src_Close, etc. */ 00059 #include "erlib.h" /* for EC_Obj_Close, etc. */ 00060 #include "errors.h" /* Set_Error_Line(), etc. */ 00061 #include "file_util.h" /* for unlink() */ 00062 #include "tracing.h" /* Set_Trace_File() */ 00063 #include "symtab.h" /* for wn.h */ 00064 #include "wn.h" /* for ir_bread.h */ 00065 #include "pu_info.h" /* for ir_bread.h */ 00066 #include "ir_bread.h" /* Free_Input_Info () */ 00067 #include "anl_driver.h" /* Prompf related */ 00068 #include "w2c_driver.h" /* Whirl2c related */ 00069 #include "w2f_driver.h" /* Whirl2f related */ 00070 #include "instr_reader.h" 00071 #include "be_symtab.h" 00072 00073 00074 BOOL Prompf_anl_loaded = FALSE; 00075 BOOL Purple_loaded = FALSE; 00076 BOOL Whirl2f_loaded = FALSE; 00077 BOOL Whirl2c_loaded = FALSE; 00078 00079 /* The subroutines we use from Prompf, Whirl2c, and Whirl2f 00080 */ 00081 00082 #include "w2c_weak.h" 00083 #include "w2f_weak.h" 00084 00085 #if !(defined(__linux__) || defined(__CYGWIN__)) 00086 #pragma weak Anl_Cleanup 00087 #endif 00088 00089 00090 /* ==================================================================== 00091 * 00092 * Cleanup_Files 00093 * 00094 * Close all per-source files involved in a compilation and prepare the 00095 * global variables for the next source. This routine is externalized 00096 * for signal cleanup; the report parameter allows suppressing of error 00097 * reporting during such cleanup. 00098 * 00099 * ==================================================================== 00100 */ 00101 00102 void 00103 Cleanup_Files (BOOL report, /* Report errors during cleanup? */ 00104 BOOL delete_dotofile /* remove .o file ? */) 00105 { 00106 /* No current line number for errors: */ 00107 Set_Error_Line (ERROR_LINE_UNKNOWN); 00108 00109 /* Close source file: */ 00110 if ( Src_File != NULL && Src_File != stdin && fclose (Src_File) ) { 00111 if ( report ) 00112 ErrMsg ( EC_Src_Close, Src_File_Name, errno ); 00113 } 00114 Src_File = NULL; 00115 00116 /* Release all memory used for reading the WHIRL file. */ 00117 Free_Input_Info (); 00118 00119 /* Close object file -- should generally be unnecessary: */ 00120 if ( Obj_File != NULL ) { 00121 if (delete_dotofile) { 00122 if (unlink ( Obj_File_Name) ) { 00123 if ( report ) 00124 ErrMsg ( EC_Obj_Close, Obj_File_Name, errno ); 00125 } 00126 } else if (Obj_File != (FILE *) MMAPPED_FILE) { 00127 if ( fclose (Obj_File) ) { 00128 if ( report ) 00129 ErrMsg ( EC_Obj_Close, Obj_File_Name, errno ); 00130 } 00131 } 00132 } 00133 Obj_File = NULL; 00134 00135 /* Close listing file: */ 00136 if ( Lst_File != NULL && Lst_File != stdout && fclose (Lst_File) ) { 00137 if ( report ) 00138 ErrMsg ( EC_Lst_Close, Lst_File_Name, errno ); 00139 } 00140 Lst_File = NULL; 00141 00142 /* Close transformation log file: */ 00143 if ( Tlog_File != NULL && Tlog_File != stdout && fclose (Tlog_File) ) { 00144 if ( report ) 00145 ErrMsg ( EC_Tlog_Close, Tlog_File_Name, errno ); 00146 } 00147 Lst_File = NULL; 00148 00149 if (Whirl2c_loaded) 00150 W2C_Cleanup(); 00151 if (Whirl2f_loaded) 00152 W2F_Cleanup(); 00153 #if !(defined(__linux__) || defined(__alpha) || defined(__CYGWIN__)) 00154 if (Prompf_anl_loaded) 00155 Anl_Cleanup(); 00156 #endif 00157 00158 /* Close trace file: */ 00159 Set_Trace_File ( NULL ); 00160 00161 /* Disable timing file: */ 00162 Tim_File = NULL; 00163 00164 /* Finally close error file: */ 00165 Set_Error_File ( NULL ); 00166 Set_Error_Source ( NULL ); 00167 } /* Cleanup_Files */ 00168 00169 00170 /* ==================================================================== 00171 * 00172 * Terminate 00173 * 00174 * Do any necessary cleanup and terminate the program with the given 00175 * status. 00176 * 00177 * ==================================================================== 00178 */ 00179 00180 void 00181 Terminate (INT status) 00182 { 00183 /* Close and delete files as necessary: */ 00184 Cleanup_Files ( FALSE, TRUE); 00185 00186 exit (status); 00187 } /* Terminate */ 00188 00189 // do early termination, not a normal clean ending. 00190 void 00191 Early_Terminate (INT status) 00192 { 00193 // In case are doing early exit, cleanup related-symtab tables. 00194 // ??? Is apparently some ordering problem with the global destructors 00195 // ??? that can cause segfaults if we don't first manually clear these. 00196 if (CURRENT_SYMTAB > GLOBAL_SYMTAB && Scope_tab[CURRENT_SYMTAB].preg_tab != NULL) { 00197 Scope_tab[CURRENT_SYMTAB].preg_tab->Un_register(Be_preg_tab); 00198 Be_preg_tab.Clear(); 00199 } 00200 for (SYMTAB_IDX scope_level = CURRENT_SYMTAB; 00201 scope_level >= GLOBAL_SYMTAB; 00202 --scope_level) 00203 { 00204 if (Scope_tab[scope_level].st_tab != NULL 00205 && Be_scope_tab[scope_level].be_st_tab != NULL) 00206 { 00207 Scope_tab[scope_level].st_tab-> 00208 Un_register(*Be_scope_tab[scope_level].be_st_tab); 00209 Be_scope_tab[scope_level].be_st_tab->Clear(); 00210 } 00211 } 00212 00213 Terminate(status); 00214 }