new api: add_conditional_hook(), set_cond_states();
[smatch.git] / smatch.c
blob5082fb638cf66cea34d66ba146899f3abd782378
1 /*
2 * sparse/smatch.c
4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include <stdio.h>
11 #include "smatch.h"
13 typedef void (*reg_func) (int id);
14 void register_smatch_extra(int id);
15 void register_smatch_ignore(int id);
16 void register_implications(int id);
17 void register_function_hooks(int id);
18 void register_conditional_function_hooks(int id);
19 void check_null_deref(int id);
20 void check_overflow(int id);
21 void check_locking(int id);
22 void check_memory(int id);
23 void check_frees_argument(int id);
24 /* <- your test goes here */
25 /* void register_template(int id); */
27 static const reg_func reg_funcs[] = {
28 &register_smatch_extra, /* smatch_extra always has to be first */
29 &register_smatch_ignore,
30 &check_null_deref,
31 &check_overflow,
32 &check_locking,
33 &check_memory,
34 // &check_frees_argument,
36 /* <- your test goes here */
37 /* &register_template, */
39 &register_implications, /* implications always has to be last */
40 NULL
43 static void help(void)
45 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
46 printf("--debug: print lots of debug output.\n");
47 printf("--debug-implied: print debug output about implications.\n");
48 printf("--assume-loops: assume loops always go through at least once.\n");
49 printf("--known-conditions: don't branch for known conditions.");
50 exit(1);
53 int main(int argc, char **argv)
55 int i;
56 reg_func func;
58 register_function_hooks(-1);
59 register_conditional_function_hooks(-1);
60 /* The script IDs start at 1.
61 0 is used for internal stuff. */
62 for(i = 0; (func = reg_funcs[i]); i++){
63 func(i + 1);
66 while(argc >= 2) {
67 if (!strcmp(argv[1], "--debug")) {
68 debug_states = 1;
69 } else if (!strcmp(argv[1], "--debug-implied")) {
70 debug_implied_states = 1;
71 } else if (!strcmp(argv[1], "--no-implied")) {
72 option_no_implied = 1;
73 } else if (!strcmp(argv[1], "--assume-loops")) {
74 option_assume_loops = 1;
75 } else if (!strcmp(argv[1], "--known-conditions")) {
76 option_known_conditions = 1;
77 } else if (!strcmp(argv[1], "--help")) {
78 help();
79 } else {
80 break;
82 argc--;
83 argv++;
86 smatch(argc, argv);
87 return 0;