Save memory. Don't copy the state name so much.
[smatch.git] / smatch.c
blobd06666800379c554d8a1b6ed812df4aac2814f9d
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 <libgen.h>
12 #include "smatch.h"
14 char *bin_dir;
16 typedef void (*reg_func) (int id);
17 void register_smatch_extra(int id);
18 void register_smatch_ignore(int id);
19 void register_implications(int id);
20 void register_function_hooks(int id);
21 void check_null_deref(int id);
22 void check_overflow(int id);
23 void check_locking(int id);
24 void check_memory(int id);
25 void check_frees_argument(int id);
26 void check_leaks(int id);
27 void check_type(int id);
28 void check_allocation_funcs(int id);
29 /* <- your test goes here */
30 /* void register_template(int id); */
32 static const reg_func reg_funcs[] = {
33 &register_smatch_extra, /* smatch_extra always has to be first */
34 &register_smatch_ignore,
35 &check_null_deref,
36 &check_overflow,
37 &check_locking,
38 &check_memory,
39 // &check_type,
40 // &check_allocation_funcs,
41 // &check_leaks,
42 // &check_frees_argument,
44 /* <- your test goes here */
45 /* &register_template, */
47 &register_implications, /* implications always has to be last */
48 NULL
51 static void help(void)
53 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
54 printf("--debug: print lots of debug output.\n");
55 printf("--debug-implied: print debug output about implications.\n");
56 printf("--assume-loops: assume loops always go through at least once.\n");
57 printf("--known-conditions: don't branch for known conditions.");
58 exit(1);
61 int main(int argc, char **argv)
63 int i;
64 reg_func func;
66 bin_dir = dirname(alloc_string(argv[0]));
68 /* The script IDs start at 1.
69 0 is used for internal stuff. */
70 create_function_hash();
71 for(i = 0; (func = reg_funcs[i]); i++){
72 func(i + 1);
74 register_function_hooks(-1);
76 while(argc >= 2) {
77 if (!strcmp(argv[1], "--debug")) {
78 debug_states = 1;
79 } else if (!strcmp(argv[1], "--debug-implied")) {
80 debug_implied_states = 1;
81 } else if (!strcmp(argv[1], "--no-implied")) {
82 option_no_implied = 1;
83 } else if (!strcmp(argv[1], "--assume-loops")) {
84 option_assume_loops = 1;
85 } else if (!strcmp(argv[1], "--known-conditions")) {
86 option_known_conditions = 1;
87 } else if (!strcmp(argv[1], "--help")) {
88 help();
89 } else {
90 break;
92 argc--;
93 argv++;
96 smatch(argc, argv);
97 return 0;