Let void have sizeof 1
[smatch.git] / lib.h
blobb22fa9376154f42f3212664d6b659930342b1c73
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 void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
88 extern int preprocess_only;
90 extern int Waddress_space;
91 extern int Wbitwise;
92 extern int Wcast_to_as;
93 extern int Wcast_truncate;
94 extern int Wcontext;
95 extern int Wdecl;
96 extern int Wdefault_bitfield_sign;
97 extern int Wdo_while;
98 extern int Wenum_mismatch;
99 extern int Wnon_pointer_null;
100 extern int Wold_initializer;
101 extern int Wone_bit_signed_bitfield;
102 extern int Wparen_string;
103 extern int Wptr_subtraction_blows;
104 extern int Wreturn_void;
105 extern int Wshadow;
106 extern int Wtransparent_union;
107 extern int Wtypesign;
108 extern int Wundef;
109 extern int Wuninitialized;
110 extern int Wdeclarationafterstatement;
112 extern int dbg_entry;
113 extern int dbg_dead;
115 extern void declare_builtin_functions(void);
116 extern void create_builtin_stream(void);
117 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
118 extern struct symbol_list *__sparse(char *filename);
119 extern struct symbol_list *sparse_keep_tokens(char *filename);
120 extern struct symbol_list *sparse(char *filename);
122 static inline int symbol_list_size(struct symbol_list *list)
124 return ptr_list_size((struct ptr_list *)(list));
127 static inline int statement_list_size(struct statement_list *list)
129 return ptr_list_size((struct ptr_list *)(list));
132 static inline int expression_list_size(struct expression_list *list)
134 return ptr_list_size((struct ptr_list *)(list));
137 static inline int instruction_list_size(struct instruction_list *list)
139 return ptr_list_size((struct ptr_list *)(list));
142 static inline int pseudo_list_size(struct pseudo_list *list)
144 return ptr_list_size((struct ptr_list *)(list));
147 static inline int bb_list_size(struct basic_block_list *list)
149 return ptr_list_size((struct ptr_list *)(list));
152 static inline void free_instruction_list(struct instruction_list **head)
154 free_ptr_list((struct ptr_list **)head);
157 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
159 return undo_ptr_list_last((struct ptr_list **)head);
162 static inline struct basic_block * delete_last_basic_block(struct basic_block_list **head)
164 return delete_ptr_list_last((struct ptr_list **)head);
167 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
169 return first_ptr_list((struct ptr_list *)head);
171 static inline struct instruction *last_instruction(struct instruction_list *head)
173 return last_ptr_list((struct ptr_list *)head);
176 static inline struct instruction *first_instruction(struct instruction_list *head)
178 return first_ptr_list((struct ptr_list *)head);
181 static inline pseudo_t first_pseudo(struct pseudo_list *head)
183 return first_ptr_list((struct ptr_list *)head);
186 static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to)
188 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
191 static inline void concat_basic_block_list(struct basic_block_list *from, struct basic_block_list **to)
193 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
196 static inline void concat_instruction_list(struct instruction_list *from, struct instruction_list **to)
198 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
201 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
203 add_ptr_list(list, sym);
206 static inline void add_statement(struct statement_list **list, struct statement *stmt)
208 add_ptr_list(list, stmt);
211 static inline void add_expression(struct expression_list **list, struct expression *expr)
213 add_ptr_list(list, expr);
216 #define hashval(x) ((unsigned long)(x))
218 #endif