Fix typo in symbol.h: s/keywrods/keywords/
[smatch.git] / lib.h
blob49ef9bb2a76f360fd4bbb6eea653e201b658dc75
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 repeat_phase, merge_phi_sources;
22 extern int gcc_major, gcc_minor;
24 extern unsigned int hexval(unsigned int c);
26 struct position {
27 unsigned int type:6,
28 stream:14,
29 newline:1,
30 whitespace:1,
31 pos:10;
32 unsigned int line:31,
33 noexpand:1;
36 struct cmdline_include {
37 char *filename;
38 int fd;
41 extern struct cmdline_include cmdline_include[];
42 extern int cmdline_include_nr;
45 struct ident;
46 struct token;
47 struct symbol;
48 struct statement;
49 struct expression;
50 struct basic_block;
51 struct entrypoint;
52 struct instruction;
53 struct multijmp;
54 struct pseudo;
56 DECLARE_PTR_LIST(symbol_list, struct symbol);
57 DECLARE_PTR_LIST(statement_list, struct statement);
58 DECLARE_PTR_LIST(expression_list, struct expression);
59 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
60 DECLARE_PTR_LIST(instruction_list, struct instruction);
61 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
62 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
63 DECLARE_PTR_LIST(string_list, char);
65 typedef struct pseudo *pseudo_t;
67 struct token *skip_to(struct token *, int);
68 struct token *expect(struct token *, int, const char *);
69 #ifdef __GNUC__
70 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
71 #else
72 #define FORMAT_ATTR(pos)
73 #endif
74 extern void die(const char *, ...) FORMAT_ATTR(1);
75 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
76 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
77 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
78 extern void error_die(struct position, const char *, ...) FORMAT_ATTR(2);
79 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
80 #undef FORMAT_ATTR
82 extern char **handle_switch(char *arg, char **next);
83 extern void add_pre_buffer(const char *fmt, ...);
85 extern int preprocess_only;
86 extern int Wptr_subtraction_blows;
87 extern int Wdefault_bitfield_sign;
88 extern int Wundefined_preprocessor;
89 extern int Wbitwise, Wtypesign, Wcontext;
90 extern int Wtransparent_union;
91 extern int Waddress_space;
92 extern int Wcast_to_address_space;
93 extern int Wenum_mismatch;
94 extern int Wdecl;
95 extern int Wone_bit_signed_bitfield;
96 extern int Wshadow;
97 extern int Wcast_truncate;
98 extern int Wdo_while;
99 extern int Wuninitialized;
101 extern int dbg_entry;
102 extern int dbg_dead;
104 extern void declare_builtin_functions(void);
105 extern void create_builtin_stream(void);
106 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
107 extern struct symbol_list *__sparse(char *filename);
108 extern struct symbol_list *sparse(char *filename);
110 static inline int symbol_list_size(struct symbol_list *list)
112 return ptr_list_size((struct ptr_list *)(list));
115 static inline int statement_list_size(struct statement_list *list)
117 return ptr_list_size((struct ptr_list *)(list));
120 static inline int expression_list_size(struct expression_list *list)
122 return ptr_list_size((struct ptr_list *)(list));
125 static inline int instruction_list_size(struct instruction_list *list)
127 return ptr_list_size((struct ptr_list *)(list));
130 static inline int pseudo_list_size(struct pseudo_list *list)
132 return ptr_list_size((struct ptr_list *)(list));
135 static inline int bb_list_size(struct basic_block_list *list)
137 return ptr_list_size((struct ptr_list *)(list));
140 static inline void free_instruction_list(struct instruction_list **head)
142 free_ptr_list((struct ptr_list **)head);
145 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
147 return undo_ptr_list_last((struct ptr_list **)head);
150 static inline struct basic_block * delete_last_basic_block(struct basic_block_list **head)
152 return delete_ptr_list_last((struct ptr_list **)head);
155 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
157 return first_ptr_list((struct ptr_list *)head);
159 static inline struct instruction *last_instruction(struct instruction_list *head)
161 return last_ptr_list((struct ptr_list *)head);
164 static inline struct instruction *first_instruction(struct instruction_list *head)
166 return first_ptr_list((struct ptr_list *)head);
169 static inline pseudo_t first_pseudo(struct pseudo_list *head)
171 return first_ptr_list((struct ptr_list *)head);
174 static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to)
176 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
179 static inline void concat_basic_block_list(struct basic_block_list *from, struct basic_block_list **to)
181 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
184 static inline void concat_instruction_list(struct instruction_list *from, struct instruction_list **to)
186 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
189 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
191 add_ptr_list(list, sym);
194 static inline void add_statement(struct statement_list **list, struct statement *stmt)
196 add_ptr_list(list, stmt);
199 static inline void add_expression(struct expression_list **list, struct expression *expr)
201 add_ptr_list(list, expr);
204 #define hashval(x) ((unsigned long)(x))
206 #endif