Com o autor
[pspdecompiler.git] / main.c
blob87a39bd8b9ad274354f49ea451f7bd276cd69e09
1 /**
2 * Author: Humberto Naves (hsnaves@gmail.com)
3 */
5 #include <stdio.h>
6 #include <string.h>
8 #include "code.h"
9 #include "prx.h"
10 #include "output.h"
11 #include "nids.h"
12 #include "hash.h"
13 #include "utils.h"
15 static
16 void print_help (char *prgname)
18 report (
19 "Usage:\n"
20 " %s [-g] [-n nidsfile] [-v] prxfile\n"
21 "Where:\n"
22 " -g output graphviz dot\n"
23 " -t print depth first search number\n"
24 " -r print the reverse depth first search number\n"
25 " -d print the dominator\n"
26 " -x print the reverse dominator\n"
27 " -f print the frontier\n"
28 " -z print the reverse frontier\n"
29 " -p print phi functions\n"
30 " -q print code into nodes\n"
31 " -s print structures\n"
32 " -e print edge types\n"
33 " -c output code\n"
34 " -v increase verbosity\n"
35 " -n specify nids xml file\n"
36 " -i print prx info\n",
37 prgname
41 int main (int argc, char **argv)
43 char *prxfilename = NULL;
44 char *nidsfilename = NULL;
46 int i, j, verbosity = 0;
47 int printgraph = FALSE;
48 int printcode = FALSE;
49 int printinfo = FALSE;
50 int graphoptions = 0;
52 struct nidstable *nids = NULL;
53 struct prx *p = NULL;
54 struct code *c;
56 for (i = 1; i < argc; i++) {
57 if (strcmp ("--help", argv[i]) == 0) {
58 print_help (argv[0]);
59 return 0;
60 } else if (argv[i][0] == '-') {
61 char *s = argv[i];
62 for (j = 0; s[j]; j++) {
63 switch (s[j]) {
64 case 'v': verbosity++; break;
65 case 'g': printgraph = TRUE; break;
66 case 'c': printcode = TRUE; break;
67 case 'i': printinfo = TRUE; break;
68 case 't': graphoptions |= OUT_PRINT_DFS; break;
69 case 'r': graphoptions |= OUT_PRINT_RDFS; break;
70 case 'd': graphoptions |= OUT_PRINT_DOMINATOR; break;
71 case 'x': graphoptions |= OUT_PRINT_RDOMINATOR; break;
72 case 'f': graphoptions |= OUT_PRINT_FRONTIER; break;
73 case 'z': graphoptions |= OUT_PRINT_RFRONTIER; break;
74 case 'p': graphoptions |= OUT_PRINT_PHIS; break;
75 case 'q': graphoptions |= OUT_PRINT_CODE; break;
76 case 's': graphoptions |= OUT_PRINT_STRUCTURES; break;
77 case 'e': graphoptions |= OUT_PRINT_EDGE_TYPES; break;
78 case 'n':
79 if (i == (argc - 1))
80 fatal (__FILE__ ": missing nids file");
82 nidsfilename = argv[++i];
83 break;
86 } else {
87 prxfilename = argv[i];
91 if (!prxfilename) {
92 print_help (argv[0]);
93 return 0;
96 if (nidsfilename)
97 nids = nids_load (nidsfilename);
99 p = prx_load (prxfilename);
100 if (!p)
101 fatal (__FILE__ ": can't load prx `%s'", prxfilename);
103 if (nids)
104 prx_resolve_nids (p, nids);
106 if (verbosity > 2 && nids && printinfo)
107 nids_print (nids);
109 if (verbosity > 0 && printinfo)
110 prx_print (p, (verbosity > 1));
112 c = code_analyse (p);
113 if (!c)
114 fatal (__FILE__ ": can't analyse code `%s'", prxfilename);
117 if (printgraph)
118 print_graph (c, prxfilename, graphoptions);
120 if (printcode)
121 print_code (c, prxfilename);
123 code_free (c);
125 prx_free (p);
127 if (nids)
128 nids_free (nids);
130 return 0;