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 #include <elf.h> 00036 #include <errno.h> /* for sys_errlist */ 00037 #include <sys/stat.h> 00038 #include <sys/elf_whirl.h> 00039 #include <algorithm> 00040 using namespace std; 00041 00042 #include "defs.h" 00043 #include "x_libgen.h" /* for basename() */ 00044 #include "pu_info.h" 00045 #include "opcode.h" 00046 #include "wn.h" 00047 #include "ir_bread.h" /* for WN_open_input(), etc. */ 00048 #include "err_host.tab" 00049 00050 00051 static void *handle; /* file handle */ 00052 00053 extern BOOL 00054 file_exists (char *path) 00055 { 00056 INT st; 00057 struct stat sbuf; 00058 st = stat(path, &sbuf); 00059 if (st == -1 && (errno == ENOENT || errno == ENOTDIR)) 00060 return FALSE; 00061 else 00062 return TRUE; 00063 } 00064 00065 static INT sym_size = 0; 00066 static INT wn_size = 0; 00067 static INT dg_size = 0; 00068 static INT pref_size = 0; 00069 static INT fb_size = 0; 00070 00071 static void 00072 size_of_each_pu (PU_Info *pu_tree, BOOL verbose) 00073 { 00074 PU_Info *pu; 00075 INT i = 0; 00076 00077 for (pu = pu_tree; pu != NULL; pu = PU_Info_next(pu)) { 00078 if (verbose) 00079 printf("%d\t%d\t%d\t%d\t%d\t%d\n", 00080 i, 00081 PU_Info_subsect_size(pu,WT_SYMTAB), 00082 PU_Info_subsect_size(pu,WT_TREE), 00083 PU_Info_subsect_size(pu,WT_DEPGRAPH), 00084 PU_Info_subsect_size(pu,WT_PREFETCH), 00085 PU_Info_subsect_size(pu,WT_FEEDBACK) 00086 ); 00087 sym_size += PU_Info_subsect_size(pu,WT_SYMTAB); 00088 wn_size += PU_Info_subsect_size(pu,WT_TREE); 00089 dg_size += PU_Info_subsect_size(pu,WT_DEPGRAPH); 00090 pref_size += PU_Info_subsect_size(pu,WT_PREFETCH); 00091 fb_size += PU_Info_subsect_size(pu,WT_FEEDBACK); 00092 if (PU_Info_child(pu)) { 00093 size_of_each_pu (PU_Info_child(pu), verbose); 00094 } 00095 i++; 00096 } 00097 } 00098 00099 static void 00100 print_size (char *name, INT size) 00101 { 00102 if (size == 0) return; 00103 printf("%7s:\t%7d\n", name, size); 00104 } 00105 00106 static void 00107 ir_size (char *input_file, BOOL verbose) 00108 { 00109 PU_Info *pu_tree; 00110 INT gsym_size = 0; 00111 INT const_size = 0; 00112 INT dst_size = 0; 00113 INT str_size = 0; 00114 INT ipa_size = 0; 00115 INT info_size = 0; 00116 handle = Open_Input_Info (input_file); 00117 00118 gsym_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_GLOBALS); 00119 const_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_CONSTAB); 00120 dst_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_DST); 00121 str_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_STRTAB); 00122 ipa_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_IPA_SUMMARY); 00123 00124 pu_tree = WN_get_PU_Infos (handle, NULL); 00125 if (pu_tree == (PU_Info *)-1) { 00126 ErrMsg ( EC_IR_Scn_Read, "PU headers", input_file); 00127 } 00128 info_size = Sizeof_PU_Infos(pu_tree); 00129 00130 print_size("GLOBALS", gsym_size); 00131 print_size("CONSTS", const_size); 00132 print_size("DST", dst_size); 00133 print_size("STRTAB", str_size); 00134 print_size("IPA", ipa_size); 00135 print_size("PU_INFO", info_size); 00136 if (verbose) { 00137 printf("--------------------------------------------------------\n"); 00138 printf("PU#\tSYMTAB\tTREE\tDEPGRF\tPREF\tFEEDBACK\n"); 00139 } 00140 size_of_each_pu (pu_tree, verbose); 00141 if (verbose) 00142 printf("--------------------------------------------------------\n"); 00143 print_size("PU_SYMS", sym_size); 00144 print_size("WHIRL", wn_size); 00145 print_size("DEPGRF", dg_size); 00146 print_size("PREF", pref_size); 00147 print_size("FEEDBACK", fb_size); 00148 00149 Free_Input_Info (); 00150 } 00151 00152 static void 00153 usage (char *progname) 00154 { 00155 fprintf (stderr, "Usage: %s [-v] <Binary IR>\n", progname); 00156 fprintf (stderr, "\t-v option will print out verbose info\n"); 00157 fprintf (stderr, "\tall sizes are in bytes\n"); 00158 exit (1); 00159 } 00160 00161 main (INT argc, char *argv[]) 00162 { 00163 register char *progname; 00164 INT binarg = 1; 00165 BOOL verbose = FALSE; 00166 00167 MEM_Initialize(); 00168 Set_Error_Tables (Phases, host_errlist); 00169 Init_Error_Handler (10); 00170 Set_Error_File(NULL); 00171 Set_Error_Line(ERROR_LINE_UNKNOWN); 00172 00173 progname = ux_basename (argv[0]); 00174 00175 if (argc < 2) 00176 usage(progname); 00177 while (*argv[binarg] == '-') { 00178 if (strcmp(argv[binarg], "-v") == 0) { 00179 verbose = TRUE; 00180 } else { 00181 usage(progname); 00182 } 00183 ++binarg; 00184 } 00185 00186 if (argc < binarg+1) 00187 usage(progname); 00188 if (!file_exists(argv[binarg])) 00189 usage(progname); 00190 00191 ir_size (argv[binarg], verbose); 00192 00193 exit (0); 00194 } /* main */ 00195 00196 00197 /* Dummy definitions to satisify references from routines that got pulled 00198 * in by the header files but are never called 00199 */ 00200 void Signal_Cleanup (INT sig) { } 00201 00202 char * Host_Format_Parm (INT kind, MEM_PTR parm) { return NULL; } 00203 00204 INT8 Debug_Level = 0;