-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
134 lines (109 loc) · 3.03 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Author: Humberto Naves (hsnaves@gmail.com)
*/
#include <stdio.h>
#include <string.h>
#include "code.h"
#include "prx.h"
#include "output.h"
#include "nids.h"
#include "hash.h"
#include "utils.h"
int g_verbosity;
int g_printoptions;
static
void print_help (char *prgname)
{
report (
"Usage:\n"
" %s [-g] [-n nidsfile] [-v] prxfile\n"
"Where:\n"
" -c output code\n"
" -d print the dominator\n"
" -e print edge types\n"
" -f print the frontier\n"
" -g output graphviz dot\n"
" -i print prx info\n"
" -n specify nids xml file\n"
" -q print code into nodes\n"
" -r print the reverse depth first search number\n"
" -s print structures\n"
" -t print depth first search number\n"
" -v increase verbosity\n"
" -x print the reverse dominator\n"
" -z print the reverse frontier\n",
prgname
);
}
int main (int argc, char **argv)
{
char *prxfilename = NULL;
char *nidsfilename = NULL;
int i, j;
int printgraph = FALSE;
int printcode = FALSE;
int printinfo = FALSE;
struct nidstable *nids = NULL;
struct prx *p = NULL;
struct code *c;
g_verbosity = 0;
for (i = 1; i < argc; i++) {
if (strcmp ("--help", argv[i]) == 0) {
print_help (argv[0]);
return 0;
} else if (argv[i][0] == '-') {
char *s = argv[i];
for (j = 0; s[j]; j++) {
switch (s[j]) {
case 'v': g_verbosity++; break;
case 'g': printgraph = TRUE; break;
case 'c': printcode = TRUE; break;
case 'i': printinfo = TRUE; break;
case 't': g_printoptions |= OUT_PRINT_DFS; break;
case 'r': g_printoptions |= OUT_PRINT_RDFS; break;
case 'd': g_printoptions |= OUT_PRINT_DOMINATOR; break;
case 'x': g_printoptions |= OUT_PRINT_RDOMINATOR; break;
case 'f': g_printoptions |= OUT_PRINT_FRONTIER; break;
case 'z': g_printoptions |= OUT_PRINT_RFRONTIER; break;
case 'q': g_printoptions |= OUT_PRINT_CODE; break;
case 's': g_printoptions |= OUT_PRINT_STRUCTURES; break;
case 'e': g_printoptions |= OUT_PRINT_EDGE_TYPES; break;
case 'n':
if (i == (argc - 1))
fatal (__FILE__ ": missing nids file");
nidsfilename = argv[++i];
break;
}
}
} else {
prxfilename = argv[i];
}
}
if (!prxfilename) {
print_help (argv[0]);
return 0;
}
if (nidsfilename)
nids = nids_load (nidsfilename);
p = prx_load (prxfilename);
if (!p)
fatal (__FILE__ ": can't load prx `%s'", prxfilename);
if (nids)
prx_resolve_nids (p, nids);
if (g_verbosity > 2 && nids && printinfo)
nids_print (nids);
if (g_verbosity > 0 && printinfo)
prx_print (p, (g_verbosity > 1));
c = code_analyse (p);
if (!c)
fatal (__FILE__ ": can't analyse code `%s'", prxfilename);
if (printgraph)
print_graph (c, prxfilename);
if (printcode)
print_code (c, prxfilename);
code_free (c);
prx_free (p);
if (nids)
nids_free (nids);
return 0;
}