Passo intermediario, ainda falta um longo caminho
[pspdecompiler.git] / main.c
blob52e9e4ecfdbc5b606b0024efffcecf256dd89f1b
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 " -i print prx info\n",
33 prgname
37 int main (int argc, char **argv)
39 char *prxfilename = NULL;
40 char *nidsfilename = NULL;
42 int i, j, verbosity = 0;
43 int printgraph = FALSE;
44 int printcode = FALSE;
45 int printinfo = FALSE;
46 int graphoptions = 0;
48 struct nidstable *nids = NULL;
49 struct prx *p = NULL;
50 struct code *c;
52 for (i = 1; i < argc; i++) {
53 if (strcmp ("--help", argv[i]) == 0) {
54 print_help (argv[0]);
55 return 0;
56 } else if (argv[i][0] == '-') {
57 char *s = argv[i];
58 for (j = 0; s[j]; j++) {
59 switch (s[j]) {
60 case 'v': verbosity++; break;
61 case 'g': printgraph = TRUE; break;
62 case 'c': printcode = TRUE; break;
63 case 'i': printinfo = TRUE; break;
64 case 't': graphoptions |= OUT_PRINT_DFS; break;
65 case 'r': graphoptions |= OUT_PRINT_RDFS; break;
66 case 'd': graphoptions |= OUT_PRINT_DOMINATOR; break;
67 case 'x': graphoptions |= OUT_PRINT_RDOMINATOR; break;
68 case 'f': graphoptions |= OUT_PRINT_FRONTIER; break;
69 case 'z': graphoptions |= OUT_PRINT_RFRONTIER; break;
70 case 'p': graphoptions |= OUT_PRINT_PHIS; break;
71 case 'q': graphoptions |= OUT_PRINT_CODE; break;
72 case 's': graphoptions |= OUT_PRINT_STRUCTURES; break;
73 case 'e': graphoptions |= OUT_PRINT_EDGE_TYPES; break;
74 case 'n':
75 if (i == (argc - 1))
76 fatal (__FILE__ ": missing nids file");
78 nidsfilename = argv[++i];
79 break;
82 } else {
83 prxfilename = argv[i];
87 if (!prxfilename) {
88 print_help (argv[0]);
89 return 0;
92 if (nidsfilename)
93 nids = nids_load (nidsfilename);
95 p = prx_load (prxfilename);
96 if (!p)
97 fatal (__FILE__ ": can't load prx `%s'", prxfilename);
99 if (nids)
100 prx_resolve_nids (p, nids);
102 if (verbosity > 2 && nids && printinfo)
103 nids_print (nids);
105 if (verbosity > 0 && printinfo)
106 prx_print (p, (verbosity > 1));
108 c = code_analyse (p);
109 if (!c)
110 fatal (__FILE__ ": can't analyse code `%s'", prxfilename);
113 if (printgraph)
114 print_graph (c, prxfilename, graphoptions);
116 if (printcode)
117 print_code (c, prxfilename, verbosity);
119 code_free (c);
121 prx_free (p);
123 if (nids)
124 nids_free (nids);
126 return 0;