00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #if ! defined(BUILD_OS_DARWIN)
00041 #include <elf.h>
00042 #endif
00043 #include <errno.h>
00044 #include <sys/stat.h>
00045 #include <sys/elf_whirl.h>
00046 #ifndef __MINGW32__
00047 #include <libgen.h>
00048 #endif
00049 #include <algorithm>
00050
00051 #include "defs.h"
00052 #include "pu_info.h"
00053 #include "opcode.h"
00054 #include "wn.h"
00055 #include "ir_bread.h"
00056 #include "err_host.tab"
00057
00058
00059 static void *handle;
00060
00061 extern BOOL
00062 file_exists (char *path)
00063 {
00064 INT st;
00065 struct stat sbuf;
00066 st = stat(path, &sbuf);
00067 if (st == -1 && (errno == ENOENT || errno == ENOTDIR))
00068 return FALSE;
00069 else
00070 return TRUE;
00071 }
00072
00073 static INT sym_size = 0;
00074 static INT wn_size = 0;
00075 static INT dg_size = 0;
00076 static INT pref_size = 0;
00077 static INT fb_size = 0;
00078
00079 static void
00080 size_of_each_pu (PU_Info *pu_tree, BOOL verbose)
00081 {
00082 PU_Info *pu;
00083 INT i = 0;
00084
00085 for (pu = pu_tree; pu != NULL; pu = PU_Info_next(pu)) {
00086 if (verbose)
00087 printf("%d\t%d\t%d\t%d\t%d\t%d\n",
00088 i,
00089
00090 (INT)PU_Info_subsect_size(pu,WT_SYMTAB),
00091 (INT)PU_Info_subsect_size(pu,WT_TREE),
00092 (INT)PU_Info_subsect_size(pu,WT_DEPGRAPH),
00093 (INT)PU_Info_subsect_size(pu,WT_PREFETCH),
00094 (INT)PU_Info_subsect_size(pu,WT_FEEDBACK)
00095 );
00096 sym_size += PU_Info_subsect_size(pu,WT_SYMTAB);
00097 wn_size += PU_Info_subsect_size(pu,WT_TREE);
00098 dg_size += PU_Info_subsect_size(pu,WT_DEPGRAPH);
00099 pref_size += PU_Info_subsect_size(pu,WT_PREFETCH);
00100 fb_size += PU_Info_subsect_size(pu,WT_FEEDBACK);
00101 if (PU_Info_child(pu)) {
00102 size_of_each_pu (PU_Info_child(pu), verbose);
00103 }
00104 i++;
00105 }
00106 }
00107
00108 static void
00109 print_size (const char *name, INT size)
00110 {
00111 if (size == 0) return;
00112 printf("%7s:\t%7d\n", name, size);
00113 }
00114
00115 static void
00116 ir_size (char *input_file, BOOL verbose)
00117 {
00118 PU_Info *pu_tree;
00119 INT gsym_size = 0;
00120 INT const_size = 0;
00121 INT dst_size = 0;
00122 INT str_size = 0;
00123 INT ipa_size = 0;
00124 INT info_size = 0;
00125 handle = Open_Input_Info (input_file);
00126
00127 gsym_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_GLOBALS);
00128 const_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_CONSTAB);
00129 dst_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_DST);
00130 str_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_STRTAB);
00131 ipa_size = Get_Elf_Section_Size (handle, SHT_MIPS_WHIRL, WT_IPA_SUMMARY);
00132
00133 pu_tree = WN_get_PU_Infos (handle, NULL);
00134 if (pu_tree == (PU_Info *)-1) {
00135 ErrMsg ( EC_IR_Scn_Read, "PU headers", input_file);
00136 }
00137 info_size = Sizeof_PU_Infos(pu_tree);
00138
00139 print_size("GLOBALS", gsym_size);
00140 print_size("CONSTS", const_size);
00141 print_size("DST", dst_size);
00142 print_size("STRTAB", str_size);
00143 print_size("IPA", ipa_size);
00144 print_size("PU_INFO", info_size);
00145 if (verbose) {
00146 printf("--------------------------------------------------------\n");
00147 printf("PU#\tSYMTAB\tTREE\tDEPGRF\tPREF\tFEEDBACK\n");
00148 }
00149 size_of_each_pu (pu_tree, verbose);
00150 if (verbose)
00151 printf("--------------------------------------------------------\n");
00152 print_size("PU_SYMS", sym_size);
00153 print_size("WHIRL", wn_size);
00154 print_size("DEPGRF", dg_size);
00155 print_size("PREF", pref_size);
00156 print_size("FEEDBACK", fb_size);
00157
00158 Free_Input_Info ();
00159 }
00160
00161 static void
00162 usage (char *progname)
00163 {
00164 fprintf (stderr, "Usage: %s [-v] <Binary IR>\n", progname);
00165 fprintf (stderr, "\t-v option will print out verbose info\n");
00166 fprintf (stderr, "\tall sizes are in bytes\n");
00167 exit (1);
00168 }
00169
00170 main (INT argc, char *argv[])
00171 {
00172 register char *progname;
00173 INT binarg = 1;
00174 BOOL verbose = FALSE;
00175
00176 MEM_Initialize();
00177 Set_Error_Tables (Phases, host_errlist);
00178 Init_Error_Handler (10);
00179 Set_Error_File(NULL);
00180 Set_Error_Line(ERROR_LINE_UNKNOWN);
00181
00182 #ifdef __MINGW32__
00183 progname = strrchr(argv[0], '\\');
00184 if (progname == NULL) {
00185 progname = strrchr(argv[0], '/');
00186 }
00187 if (progname == NULL) {
00188 progname = argv[0];
00189 }
00190 else {
00191 progname++;
00192 }
00193 #else
00194 progname = basename (argv[0]);
00195 #endif
00196
00197 if (argc < 2)
00198 usage(progname);
00199 while (*argv[binarg] == '-') {
00200 if (strcmp(argv[binarg], "-v") == 0) {
00201 verbose = TRUE;
00202 } else {
00203 usage(progname);
00204 }
00205 ++binarg;
00206 }
00207
00208 if (argc < binarg+1)
00209 usage(progname);
00210 if (!file_exists(argv[binarg]))
00211 usage(progname);
00212
00213 ir_size (argv[binarg], verbose);
00214
00215 exit (0);
00216 }
00217
00218
00219
00220
00221
00222 void Signal_Cleanup (INT sig) { }
00223
00224 const char * Host_Format_Parm (INT kind, MEM_PTR parm) { return NULL; }
00225
00226 INT8 Debug_Level = 0;