Bug in var->Def
[pspdecompiler.git] / main.c
blob2f56cef6410d948a1996cf64b73dc8a92936383f
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"
16 int g_verbosity;
17 int g_printoptions;
19 static
20 void print_help (char *prgname)
22 report (
23 "Usage:\n"
24 " %s [-g] [-n nidsfile] [-v] prxfile\n"
25 "Where:\n"
26 " -c output code\n"
27 " -d print the dominator\n"
28 " -e print edge types\n"
29 " -f print the frontier\n"
30 " -g output graphviz dot\n"
31 " -i print prx info\n"
32 " -n specify nids xml file\n"
33 " -q print code into nodes\n"
34 " -r print the reverse depth first search number\n"
35 " -s print structures\n"
36 " -t print depth first search number\n"
37 " -v increase verbosity\n"
38 " -x print the reverse dominator\n"
39 " -z print the reverse frontier\n",
40 prgname
44 int main (int argc, char **argv)
46 char *prxfilename = NULL;
47 char *nidsfilename = NULL;
49 int i, j;
50 int printgraph = FALSE;
51 int printcode = FALSE;
52 int printinfo = FALSE;
54 struct nidstable *nids = NULL;
55 struct prx *p = NULL;
56 struct code *c;
58 g_verbosity = 0;
60 for (i = 1; i < argc; i++) {
61 if (strcmp ("--help", argv[i]) == 0) {
62 print_help (argv[0]);
63 return 0;
64 } else if (argv[i][0] == '-') {
65 char *s = argv[i];
66 for (j = 0; s[j]; j++) {
67 switch (s[j]) {
68 case 'v': g_verbosity++; break;
69 case 'g': printgraph = TRUE; break;
70 case 'c': printcode = TRUE; break;
71 case 'i': printinfo = TRUE; break;
72 case 't': g_printoptions |= OUT_PRINT_DFS; break;
73 case 'r': g_printoptions |= OUT_PRINT_RDFS; break;
74 case 'd': g_printoptions |= OUT_PRINT_DOMINATOR; break;
75 case 'x': g_printoptions |= OUT_PRINT_RDOMINATOR; break;
76 case 'f': g_printoptions |= OUT_PRINT_FRONTIER; break;
77 case 'z': g_printoptions |= OUT_PRINT_RFRONTIER; break;
78 case 'q': g_printoptions |= OUT_PRINT_CODE; break;
79 case 's': g_printoptions |= OUT_PRINT_STRUCTURES; break;
80 case 'e': g_printoptions |= OUT_PRINT_EDGE_TYPES; break;
81 case 'n':
82 if (i == (argc - 1))
83 fatal (__FILE__ ": missing nids file");
85 nidsfilename = argv[++i];
86 break;
89 } else {
90 prxfilename = argv[i];
94 if (!prxfilename) {
95 print_help (argv[0]);
96 return 0;
99 if (nidsfilename)
100 nids = nids_load (nidsfilename);
102 p = prx_load (prxfilename);
103 if (!p)
104 fatal (__FILE__ ": can't load prx `%s'", prxfilename);
106 if (nids)
107 prx_resolve_nids (p, nids);
109 if (g_verbosity > 2 && nids && printinfo)
110 nids_print (nids);
112 if (g_verbosity > 0 && printinfo)
113 prx_print (p, (g_verbosity > 1));
115 c = code_analyse (p);
116 if (!c)
117 fatal (__FILE__ ": can't analyse code `%s'", prxfilename);
120 if (printgraph)
121 print_graph (c, prxfilename);
123 if (printcode)
124 print_code (c, prxfilename);
126 code_free (c);
128 prx_free (p);
130 if (nids)
131 nids_free (nids);
133 return 0;