Liveness funcionando
[pspdecompiler.git] / main.c
blob6d86376e8fc95d2d2a69de0afd24f3f9d27b073b
1 #include <stdio.h>
2 #include <string.h>
4 #include "code.h"
5 #include "prx.h"
6 #include "output.h"
7 #include "nids.h"
8 #include "hash.h"
9 #include "utils.h"
11 static
12 void print_help (char *prgname)
14 report (
15 "Usage:\n"
16 " %s [-g] [-n nidsfile] [-v] prxfile\n"
17 "Where:\n"
18 " -g output graphviz dot\n"
19 " -t print depth first search number\n"
20 " -r print the reverse depth first search number\n"
21 " -d print the dominator\n"
22 " -x print the reverse dominator\n"
23 " -f print the frontier\n"
24 " -z print the reverse frontier\n"
25 " -p print phi functions\n"
26 " -q print code into nodes\n"
27 " -s print structures\n"
28 " -e print edge types\n"
29 " -c output code\n"
30 " -v increase verbosity\n"
31 " -n specify nids xml file\n",
32 prgname
36 int main (int argc, char **argv)
38 char *prxfilename = NULL;
39 char *nidsfilename = NULL;
41 int i, j, verbosity = 0;
42 int printgraph = FALSE;
43 int graphoptions = 0;
44 int printcode = FALSE;
46 struct nidstable *nids = NULL;
47 struct prx *p = NULL;
48 struct code *c;
50 for (i = 1; i < argc; i++) {
51 if (strcmp ("--help", argv[i]) == 0) {
52 print_help (argv[0]);
53 return 0;
54 } else if (argv[i][0] == '-') {
55 char *s = argv[i];
56 for (j = 0; s[j]; j++) {
57 switch (s[j]) {
58 case 'v': verbosity++; break;
59 case 'g': printgraph = TRUE; break;
60 case 'c': printcode = TRUE; break;
61 case 't': graphoptions |= OUT_PRINT_DFS; break;
62 case 'r': graphoptions |= OUT_PRINT_RDFS; break;
63 case 'd': graphoptions |= OUT_PRINT_DOMINATOR; break;
64 case 'x': graphoptions |= OUT_PRINT_RDOMINATOR; break;
65 case 'f': graphoptions |= OUT_PRINT_FRONTIER; break;
66 case 'z': graphoptions |= OUT_PRINT_RFRONTIER; break;
67 case 'p': graphoptions |= OUT_PRINT_PHIS; break;
68 case 'q': graphoptions |= OUT_PRINT_CODE; break;
69 case 's': graphoptions |= OUT_PRINT_STRUCTURES; break;
70 case 'e': graphoptions |= OUT_PRINT_EDGE_TYPES; break;
71 case 'n':
72 if (i == (argc - 1))
73 fatal (__FILE__ ": missing nids file");
75 nidsfilename = argv[++i];
76 break;
79 } else {
80 prxfilename = argv[i];
84 if (!prxfilename) {
85 print_help (argv[0]);
86 return 0;
89 if (nidsfilename)
90 nids = nids_load (nidsfilename);
92 p = prx_load (prxfilename);
93 if (!p)
94 fatal (__FILE__ ": can't load prx `%s'", prxfilename);
96 if (nids)
97 prx_resolve_nids (p, nids);
99 if (verbosity > 2 && nids)
100 nids_print (nids);
102 if (verbosity > 0) prx_print (p, (verbosity > 1));
104 c = code_analyse (p);
105 if (!c)
106 fatal (__FILE__ ": can't analyse code `%s'", prxfilename);
109 if (printgraph)
110 print_graph (c, prxfilename, graphoptions);
112 if (printcode)
113 print_code (c, prxfilename, verbosity);
115 code_free (c);
117 prx_free (p);
119 if (nids)
120 nids_free (nids);
122 return 0;