8 * Basic helper routine descriptions for 'sparse'.
10 * Copyright (C) 2003 Transmeta Corp.
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this software and associated documentation files (the "Software"), to deal
16 * in the Software without restriction, including without limitation the rights
17 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 * copies of the Software, and to permit persons to whom the Software is
19 * furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36 #define DO_STRINGIFY(x) #x
37 #define STRINGIFY(x) DO_STRINGIFY(x)
40 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
43 extern int verbose
, optimize
, optimize_size
, preprocessing
;
44 extern int die_if_error
;
45 extern int parse_error
;
46 extern int repeat_phase
, merge_phi_sources
;
47 extern int gcc_major
, gcc_minor
, gcc_patchlevel
;
49 extern unsigned int hexval(unsigned int c
);
72 DECLARE_PTR_LIST(symbol_list
, struct symbol
);
73 DECLARE_PTR_LIST(statement_list
, struct statement
);
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(context_list
, struct context
);
78 DECLARE_PTR_LIST(multijmp_list
, struct multijmp
);
79 DECLARE_PTR_LIST(pseudo_list
, struct pseudo
);
80 DECLARE_PTR_LIST(string_list
, char);
82 typedef struct pseudo
*pseudo_t
;
84 struct token
*skip_to(struct token
*, int);
85 struct token
*expect(struct token
*, int, const char *);
87 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
88 #define NORETURN_ATTR __attribute__ ((__noreturn__))
89 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
91 #define FORMAT_ATTR(pos)
95 extern void die(const char *, ...) FORMAT_ATTR(1) NORETURN_ATTR
;
96 extern void info(struct position
, const char *, ...) FORMAT_ATTR(2);
97 extern void warning(struct position
, const char *, ...) FORMAT_ATTR(2);
98 extern void sparse_error(struct position
, const char *, ...) FORMAT_ATTR(2);
99 extern void error_die(struct position
, const char *, ...) FORMAT_ATTR(2) NORETURN_ATTR
;
100 extern void expression_error(struct expression
*, const char *, ...) FORMAT_ATTR(2);
102 extern void add_pre_buffer(const char *fmt
, ...) FORMAT_ATTR(1);
104 extern int preprocess_only
;
106 extern int Waddress_space
;
108 extern int Wcast_to_as
;
109 extern int Wcast_truncate
;
112 extern int Wdeclarationafterstatement
;
113 extern int Wdefault_bitfield_sign
;
114 extern int Wdesignated_init
;
115 extern int Wdo_while
;
116 extern int Wenum_mismatch
;
118 extern int Winit_cstring
;
119 extern int Wnon_pointer_null
;
120 extern int Wold_initializer
;
121 extern int Wone_bit_signed_bitfield
;
122 extern int Wparen_string
;
123 extern int Wptr_subtraction_blows
;
124 extern int Wreturn_void
;
126 extern int Wsizeof_bool
;
127 extern int Wtransparent_union
;
128 extern int Wtypesign
;
130 extern int Wuninitialized
;
131 extern int Wunknown_attribute
;
134 extern int dbg_entry
;
139 extern void declare_builtin_functions(void);
140 extern void create_builtin_stream(void);
141 extern struct symbol_list
*sparse_initialize(int argc
, char **argv
, struct string_list
**files
);
142 extern struct symbol_list
*__sparse(char *filename
);
143 extern struct symbol_list
*sparse_keep_tokens(char *filename
);
144 extern struct symbol_list
*sparse(char *filename
);
146 static inline int symbol_list_size(struct symbol_list
*list
)
148 return ptr_list_size((struct ptr_list
*)(list
));
151 static inline int statement_list_size(struct statement_list
*list
)
153 return ptr_list_size((struct ptr_list
*)(list
));
156 static inline int context_list_size(struct context_list
*list
)
158 return ptr_list_size((struct ptr_list
*)(list
));
161 static inline int expression_list_size(struct expression_list
*list
)
163 return ptr_list_size((struct ptr_list
*)(list
));
166 static inline int instruction_list_size(struct instruction_list
*list
)
168 return ptr_list_size((struct ptr_list
*)(list
));
171 static inline int pseudo_list_size(struct pseudo_list
*list
)
173 return ptr_list_size((struct ptr_list
*)(list
));
176 static inline int bb_list_size(struct basic_block_list
*list
)
178 return ptr_list_size((struct ptr_list
*)(list
));
181 static inline void free_instruction_list(struct instruction_list
**head
)
183 free_ptr_list((struct ptr_list
**)head
);
186 static inline struct instruction
* delete_last_instruction(struct instruction_list
**head
)
188 return undo_ptr_list_last((struct ptr_list
**)head
);
191 static inline struct basic_block
* delete_last_basic_block(struct basic_block_list
**head
)
193 return delete_ptr_list_last((struct ptr_list
**)head
);
196 static inline struct basic_block
*first_basic_block(struct basic_block_list
*head
)
198 return first_ptr_list((struct ptr_list
*)head
);
200 static inline struct instruction
*last_instruction(struct instruction_list
*head
)
202 return last_ptr_list((struct ptr_list
*)head
);
205 static inline struct instruction
*first_instruction(struct instruction_list
*head
)
207 return first_ptr_list((struct ptr_list
*)head
);
210 static inline pseudo_t
first_pseudo(struct pseudo_list
*head
)
212 return first_ptr_list((struct ptr_list
*)head
);
215 static inline void concat_symbol_list(struct symbol_list
*from
, struct symbol_list
**to
)
217 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
220 static inline void concat_basic_block_list(struct basic_block_list
*from
, struct basic_block_list
**to
)
222 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
225 static inline void concat_instruction_list(struct instruction_list
*from
, struct instruction_list
**to
)
227 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
230 static inline void add_symbol(struct symbol_list
**list
, struct symbol
*sym
)
232 add_ptr_list(list
, sym
);
235 static inline void add_statement(struct statement_list
**list
, struct statement
*stmt
)
237 add_ptr_list(list
, stmt
);
240 static inline void add_expression(struct expression_list
**list
, struct expression
*expr
)
242 add_ptr_list(list
, expr
);
245 #define hashval(x) ((unsigned long)(x))