math: array parameters can be NULL
[smatch.git] / lib.h
blobae54610bd506a5494459c7bcb7f05e5f60304205
1 #ifndef LIB_H
2 #define LIB_H
4 #include <stdbool.h>
5 #include <stdlib.h>
6 #include <stddef.h>
8 /*
9 * Basic helper routine descriptions for 'sparse'.
11 * Copyright (C) 2003 Transmeta Corp.
12 * 2003 Linus Torvalds
13 * 2004 Christopher Li
15 * Permission is hereby granted, free of charge, to any person obtaining a copy
16 * of this software and associated documentation files (the "Software"), to deal
17 * in the Software without restriction, including without limitation the rights
18 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19 * copies of the Software, and to permit persons to whom the Software is
20 * furnished to do so, subject to the following conditions:
22 * The above copyright notice and this permission notice shall be included in
23 * all copies or substantial portions of the Software.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31 * THE SOFTWARE.
34 #include "compat.h"
35 #include "ptrlist.h"
36 #include "utils.h"
37 #include "bits.h"
38 #include "options.h"
40 #define DO_STRINGIFY(x) #x
41 #define STRINGIFY(x) DO_STRINGIFY(x)
43 #ifndef ARRAY_SIZE
44 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
45 #endif
47 extern int parse_error;
49 struct position {
50 unsigned int type:6,
51 stream:14,
52 newline:1,
53 whitespace:1,
54 pos:10;
55 unsigned int line:31,
56 noexpand:1;
59 struct ident;
60 struct token;
61 struct symbol;
62 struct statement;
63 struct asm_operand;
64 struct expression;
65 struct basic_block;
66 struct entrypoint;
67 struct instruction;
68 struct multijmp;
69 struct pseudo;
71 DECLARE_PTR_LIST(symbol_list, struct symbol);
72 DECLARE_PTR_LIST(statement_list, struct statement);
73 DECLARE_PTR_LIST(asm_operand_list, struct asm_operand);
74 DECLARE_PTR_LIST(expression_list, struct expression);
75 DECLARE_PTR_LIST(basic_block_list, struct basic_block);
76 DECLARE_PTR_LIST(instruction_list, struct instruction);
77 DECLARE_PTR_LIST(multijmp_list, struct multijmp);
78 DECLARE_PTR_LIST(pseudo_list, struct pseudo);
79 DECLARE_PTR_LIST(ident_list, struct ident);
80 DECLARE_PTR_LIST(string_list, char);
82 typedef struct pseudo *pseudo_t;
84 #ifdef __GNUC__
85 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
86 #define NORETURN_ATTR __attribute__ ((__noreturn__))
87 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
88 #else
89 #define FORMAT_ATTR(pos)
90 #define NORETURN_ATTR
91 #define SENTINEL_ATTR
92 #endif
94 FORMAT_ATTR(1) NORETURN_ATTR
95 extern void die(const char *, ...);
97 FORMAT_ATTR(2) NORETURN_ATTR
98 extern void error_die(struct position, const char *, ...);
100 extern void info(struct position, const char *, ...) FORMAT_ATTR(2);
101 extern void warning(struct position, const char *, ...) FORMAT_ATTR(2);
102 extern void sparse_error(struct position, const char *, ...) FORMAT_ATTR(2);
103 extern void expression_error(struct expression *, const char *, ...) FORMAT_ATTR(2);
105 #define ERROR_CURR_PHASE (1 << 0)
106 #define ERROR_PREV_PHASE (1 << 1)
107 extern int has_error;
110 enum phase {
111 PASS__PARSE,
112 PASS__LINEARIZE,
113 PASS__MEM2REG,
114 PASS__OPTIM,
115 PASS__FINAL,
118 #define PASS_PARSE (1UL << PASS__PARSE)
119 #define PASS_LINEARIZE (1UL << PASS__LINEARIZE)
120 #define PASS_MEM2REG (1UL << PASS__MEM2REG)
121 #define PASS_OPTIM (1UL << PASS__OPTIM)
122 #define PASS_FINAL (1UL << PASS__FINAL)
125 extern void add_pre_buffer(const char *fmt, ...) FORMAT_ATTR(1);
126 extern void predefine(const char *name, int weak, const char *fmt, ...) FORMAT_ATTR(3);
128 extern void predefine_strong(const char *name, ...) FORMAT_ATTR(1);
129 extern void predefine_weak(const char *name, ...) FORMAT_ATTR(1);
130 extern void predefine_nostd(const char *name);
131 extern void predefined_macros(void);
133 extern void dump_macro_definitions(void);
134 extern struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **files);
135 extern struct symbol_list *__sparse(char *filename);
136 extern struct symbol_list *sparse_keep_tokens(char *filename);
137 extern struct symbol_list *sparse(char *filename);
138 extern void report_stats(void);
140 static inline int symbol_list_size(struct symbol_list *list)
142 return ptr_list_size((struct ptr_list *)(list));
145 static inline int statement_list_size(struct statement_list *list)
147 return ptr_list_size((struct ptr_list *)(list));
150 static inline int expression_list_size(struct expression_list *list)
152 return ptr_list_size((struct ptr_list *)(list));
155 static inline int instruction_list_size(struct instruction_list *list)
157 return ptr_list_size((struct ptr_list *)(list));
160 static inline int pseudo_list_size(struct pseudo_list *list)
162 return ptr_list_size((struct ptr_list *)(list));
165 static inline int bb_list_size(struct basic_block_list *list)
167 return ptr_list_size((struct ptr_list *)(list));
170 static inline void free_instruction_list(struct instruction_list **head)
172 free_ptr_list(head);
175 static inline struct instruction * delete_last_instruction(struct instruction_list **head)
177 return undo_ptr_list_last((struct ptr_list **)head);
180 static inline struct basic_block *first_basic_block(struct basic_block_list *head)
182 return first_ptr_list((struct ptr_list *)head);
184 static inline struct instruction *last_instruction(struct instruction_list *head)
186 return last_ptr_list((struct ptr_list *)head);
189 static inline struct instruction *first_instruction(struct instruction_list *head)
191 return first_ptr_list((struct ptr_list *)head);
194 static inline struct expression *first_expression(struct expression_list *head)
196 return first_ptr_list((struct ptr_list *)head);
199 static inline pseudo_t first_pseudo(struct pseudo_list *head)
201 return first_ptr_list((struct ptr_list *)head);
204 static inline void concat_symbol_list(struct symbol_list *from, struct symbol_list **to)
206 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
209 static inline void concat_basic_block_list(struct basic_block_list *from, struct basic_block_list **to)
211 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
214 static inline void concat_instruction_list(struct instruction_list *from, struct instruction_list **to)
216 concat_ptr_list((struct ptr_list *)from, (struct ptr_list **)to);
219 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
221 add_ptr_list(list, sym);
224 static inline void add_statement(struct statement_list **list, struct statement *stmt)
226 add_ptr_list(list, stmt);
229 static inline void add_expression(struct expression_list **list, struct expression *expr)
231 add_ptr_list(list, expr);
234 static inline void add_ident(struct ident_list **list, struct ident *ident)
236 add_ptr_list(list, ident);
239 #define hashval(x) ((unsigned long)(x))
241 #endif