Make get_all_states() not segfault every time.
[smatch.git] / lib.h
blob42a33968340d3452e00c6a2b2b7ec27e3351316d
1 #ifndef LIB_H
2 #define LIB_H
4 #include <stdlib.h>
5 #include <stddef.h>
7 /*
8 * Basic helper routine descriptions for 'sparse'.
10 * Copyright (C) 2003 Transmeta Corp.
11 * 2003 Linus Torvalds
12 * 2004 Christopher Li
14 * Licensed under the Open Software License version 1.1
17 #include "compat.h"
18 #include "ptrlist.h"
20 extern int verbose, optimize, optimize_size, preprocessing;
21 extern int die_if_error;
22 extern int repeat_phase, merge_phi_sources;
23 extern int gcc_major, gcc_minor, gcc_patchlevel;
25 extern unsigned int hexval(unsigned int c);
27 struct position {
28 unsigned int type:6,
29 stream:14,
30 newline:1,
31 whitespace:1,
32 pos:10;
33 unsigned int line:31,
34 noexpand:1;
37 struct cmdline_include {
38 char *filename;
39 int fd;
42 extern struct cmdline_include cmdline_include[];
43 extern int cmdline_include_nr;
46 struct ident;
47 struct token;
48 struct symbol;
49 struct statement;
50 struct expression;
51 struct basic_block;
52 struct entrypoint;
53 struct instruction;
54 struct multijmp;
55 struct pseudo;
57 DECLARE_PTR_LIST(symbol_list, struct symbol);
58 DECLARE_PTR_LIST(statement_list, struct statement);
59 DECLARE_PTR_LIST(expression_list, struct expression);
60 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
61 DECLARE_PTR_LIST(instruction_list, struct instruction);
62 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
63 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
64 DECLARE_PTR_LIST(string_list, char);
66 typedef struct pseudo *pseudo_t;
68 struct token *skip_to(struct token *, int);
69 struct token *expect(struct token *, int, const char *);
70 #ifdef __GNUC__
71 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
72 #define NORETURN_ATTR __attribute__ ((__noreturn__))
73 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
74 #else
75 #define FORMAT_ATTR(pos)
76 #define NORETURN_ATTR
77 #define SENTINEL_ATTR
78 #endif
79 extern void die(const char *, ...) FORMAT_ATTR(1) NORETURN_ATTR;
80 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
81 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
82 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
83 extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2) NORETURN_ATTR;
84 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
86 extern char **handle_switch(char *arg, char **next);
87 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
89 extern int preprocess_only;
91 extern int Waddress_space;
92 extern int Wbitwise;
93 extern int Wcast_to_as;
94 extern int Wcast_truncate;
95 extern int Wcontext;
96 extern int Wdecl;
97 extern int Wdefault_bitfield_sign;
98 extern int Wdo_while;
99 extern int Wenum_mismatch;
100 extern int Wnon_pointer_null;
101 extern int Wold_initializer;
102 extern int Wone_bit_signed_bitfield;
103 extern int Wparen_string;
104 extern int Wptr_subtraction_blows;
105 extern int Wreturn_void;
106 extern int Wshadow;
107 extern int Wtransparent_union;
108 extern int Wtypesign;
109 extern int Wundef;
110 extern int Wuninitialized;
111 extern int Wdeclarationafterstatement;
113 extern int dbg_entry;
114 extern int dbg_dead;
116 extern void declare_builtin_functions(void);
117 extern void create_builtin_stream(void);
118 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
119 extern struct symbol_list *__sparse(char *filename);
120 extern struct symbol_list *sparse_keep_tokens(char *filename);
121 extern struct symbol_list *sparse(char *filename);
123 static inline int symbol_list_size(struct symbol_list *list)
125 return ptr_list_size((struct ptr_list *)(list));
128 static inline int statement_list_size(struct statement_list *list)
130 return ptr_list_size((struct ptr_list *)(list));
133 static inline int expression_list_size(struct expression_list *list)
135 return ptr_list_size((struct ptr_list *)(list));
138 static inline int instruction_list_size(struct instruction_list *list)
140 return ptr_list_size((struct ptr_list *)(list));
143 static inline int pseudo_list_size(struct pseudo_list *list)
145 return ptr_list_size((struct ptr_list *)(list));
148 static inline int bb_list_size(struct basic_block_list *list)
150 return ptr_list_size((struct ptr_list *)(list));
153 static inline void free_instruction_list(struct instruction_list **head)
155 free_ptr_list((struct ptr_list **)head);
158 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
160 return undo_ptr_list_last((struct ptr_list **)head);
163 static inline struct basic_block * delete_last_basic_block(struct basic_block_list **head)
165 return delete_ptr_list_last((struct ptr_list **)head);
168 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
170 return first_ptr_list((struct ptr_list *)head);
172 static inline struct instruction *last_instruction(struct instruction_list *head)
174 return last_ptr_list((struct ptr_list *)head);
177 static inline struct instruction *first_instruction(struct instruction_list *head)
179 return first_ptr_list((struct ptr_list *)head);
182 static inline pseudo_t first_pseudo(struct pseudo_list *head)
184 return first_ptr_list((struct ptr_list *)head);
187 static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to)
189 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
192 static inline void concat_basic_block_list(struct basic_block_list *from, struct basic_block_list **to)
194 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
197 static inline void concat_instruction_list(struct instruction_list *from, struct instruction_list **to)
199 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
202 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
204 add_ptr_list(list, sym);
207 static inline void add_statement(struct statement_list **list, struct statement *stmt)
209 add_ptr_list(list, stmt);
212 static inline void add_expression(struct expression_list **list, struct expression *expr)
214 add_ptr_list(list, expr);
217 #define hashval(x) ((unsigned long)(x))
219 #endif