9 * Basic helper routine descriptions for 'sparse'.
11 * Copyright (C) 2003 Transmeta Corp.
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
40 #define DO_STRINGIFY(x) #x
41 #define STRINGIFY(x) DO_STRINGIFY(x)
44 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
48 #define PATH_MAX 4096 // Hurd doesn't define this
51 extern const char *sparse_version
;
75 DECLARE_PTR_LIST(symbol_list
, struct symbol
);
76 DECLARE_PTR_LIST(statement_list
, struct statement
);
77 DECLARE_PTR_LIST(asm_operand_list
, struct asm_operand
);
78 DECLARE_PTR_LIST(expression_list
, struct expression
);
79 DECLARE_PTR_LIST(basic_block_list
, struct basic_block
);
80 DECLARE_PTR_LIST(instruction_list
, struct instruction
);
81 DECLARE_PTR_LIST(multijmp_list
, struct multijmp
);
82 DECLARE_PTR_LIST(pseudo_list
, struct pseudo
);
83 DECLARE_PTR_LIST(ident_list
, struct ident
);
84 DECLARE_PTR_LIST(string_list
, char);
86 typedef struct pseudo
*pseudo_t
;
89 #define FORMAT_ATTR(pos) __attribute__ ((__format__ (__printf__, pos, pos+1)))
90 #define NORETURN_ATTR __attribute__ ((__noreturn__))
91 #define SENTINEL_ATTR __attribute__ ((__sentinel__))
93 #define FORMAT_ATTR(pos)
98 FORMAT_ATTR(1) NORETURN_ATTR
99 extern void die(const char *, ...);
101 FORMAT_ATTR(2) NORETURN_ATTR
102 extern void error_die(struct position
, const char *, ...);
104 extern void info(struct position
, const char *, ...) FORMAT_ATTR(2);
105 extern void warning(struct position
, const char *, ...) FORMAT_ATTR(2);
106 extern void sparse_error(struct position
, const char *, ...) FORMAT_ATTR(2);
107 extern void expression_error(struct expression
*, const char *, ...) FORMAT_ATTR(2);
109 #define ERROR_CURR_PHASE (1 << 0)
110 #define ERROR_PREV_PHASE (1 << 1)
111 extern int has_error
;
122 #define PASS_PARSE (1UL << PASS__PARSE)
123 #define PASS_LINEARIZE (1UL << PASS__LINEARIZE)
124 #define PASS_MEM2REG (1UL << PASS__MEM2REG)
125 #define PASS_OPTIM (1UL << PASS__OPTIM)
126 #define PASS_FINAL (1UL << PASS__FINAL)
129 extern void add_pre_buffer(const char *fmt
, ...) FORMAT_ATTR(1);
130 extern void predefine(const char *name
, int weak
, const char *fmt
, ...) FORMAT_ATTR(3);
131 extern void predefine_strong(const char *name
, ...) FORMAT_ATTR(1);
132 extern void predefine_weak(const char *name
, ...) FORMAT_ATTR(1);
133 extern void predefine_nostd(const char *name
);
134 extern void predefined_macros(void);
137 extern void dump_macro_definitions(void);
138 extern struct symbol_list
*sparse_initialize(int argc
, char **argv
, struct string_list
**files
);
139 extern struct symbol_list
*__sparse(char *filename
);
140 extern struct symbol_list
*sparse_keep_tokens(char *filename
);
141 extern struct symbol_list
*sparse(char *filename
);
142 extern void report_stats(void);
144 static inline int symbol_list_size(struct symbol_list
*list
)
146 return ptr_list_size((struct ptr_list
*)(list
));
149 static inline int statement_list_size(struct statement_list
*list
)
151 return ptr_list_size((struct ptr_list
*)(list
));
154 static inline int expression_list_size(struct expression_list
*list
)
156 return ptr_list_size((struct ptr_list
*)(list
));
159 static inline int instruction_list_size(struct instruction_list
*list
)
161 return ptr_list_size((struct ptr_list
*)(list
));
164 static inline int pseudo_list_size(struct pseudo_list
*list
)
166 return ptr_list_size((struct ptr_list
*)(list
));
169 static inline int bb_list_size(struct basic_block_list
*list
)
171 return ptr_list_size((struct ptr_list
*)(list
));
174 static inline void free_instruction_list(struct instruction_list
**head
)
179 static inline struct instruction
* delete_last_instruction(struct instruction_list
**head
)
181 return undo_ptr_list_last((struct ptr_list
**)head
);
184 static inline struct basic_block
*first_basic_block(struct basic_block_list
*head
)
186 return first_ptr_list((struct ptr_list
*)head
);
188 static inline struct instruction
*last_instruction(struct instruction_list
*head
)
190 return last_ptr_list((struct ptr_list
*)head
);
193 static inline struct instruction
*first_instruction(struct instruction_list
*head
)
195 return first_ptr_list((struct ptr_list
*)head
);
198 static inline struct expression
*first_expression(struct expression_list
*head
)
200 return first_ptr_list((struct ptr_list
*)head
);
203 static inline pseudo_t
first_pseudo(struct pseudo_list
*head
)
205 return first_ptr_list((struct ptr_list
*)head
);
208 static inline struct symbol
*first_symbol(struct symbol_list
*head
)
210 return first_ptr_list((struct ptr_list
*)head
);
213 static inline void concat_symbol_list(struct symbol_list
*from
, struct symbol_list
**to
)
215 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
218 static inline void concat_basic_block_list(struct basic_block_list
*from
, struct basic_block_list
**to
)
220 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
223 static inline void concat_instruction_list(struct instruction_list
*from
, struct instruction_list
**to
)
225 concat_ptr_list((struct ptr_list
*)from
, (struct ptr_list
**)to
);
228 static inline void add_symbol(struct symbol_list
**list
, struct symbol
*sym
)
230 add_ptr_list(list
, sym
);
233 static inline void add_statement(struct statement_list
**list
, struct statement
*stmt
)
235 add_ptr_list(list
, stmt
);
238 static inline void add_expression(struct expression_list
**list
, struct expression
*expr
)
240 add_ptr_list(list
, expr
);
243 static inline void add_ident(struct ident_list
**list
, struct ident
*ident
)
245 add_ptr_list(list
, ident
);
248 #define hashval(x) ((unsigned long)(x))