[PR 70965] Schedule extra rebuild_cgraph_edges
[official-gcc.git] / gcc / read-md.h
blob996b514976f190f604e93340c96c5e3f20881968
1 /* MD reader definitions.
2 Copyright (C) 1987-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_READ_MD_H
21 #define GCC_READ_MD_H
23 #include "obstack.h"
25 /* Records a position in the file. */
26 struct file_location {
27 file_location () {}
28 file_location (const char *, int, int);
30 const char *filename;
31 int lineno;
32 int colno;
35 inline file_location::file_location (const char *filename_in, int lineno_in, int colno_in)
36 : filename (filename_in), lineno (lineno_in), colno (colno_in) {}
38 /* Holds one symbol or number in the .md file. */
39 struct md_name {
40 /* The name as it appeared in the .md file. Names are syntactically
41 limited to the length of this buffer. */
42 char buffer[256];
44 /* The name that should actually be used by the generator programs.
45 This is an expansion of NAME, after things like constant substitution. */
46 char *string;
49 /* This structure represents a constant defined by define_constant,
50 define_enum, or such-like. */
51 struct md_constant {
52 /* The name of the constant. */
53 char *name;
55 /* The string to which the constants expands. */
56 char *value;
58 /* If the constant is associated with a enumeration, this field
59 points to that enumeration, otherwise it is null. */
60 struct enum_type *parent_enum;
63 /* This structure represents one value in an enum_type. */
64 struct enum_value {
65 /* The next value in the enum, or null if this is the last. */
66 struct enum_value *next;
68 /* The name of the value as it appears in the .md file. */
69 char *name;
71 /* The definition of the related C value. */
72 struct md_constant *def;
75 /* This structure represents an enum defined by define_enum or the like. */
76 struct enum_type {
77 /* The C name of the enumeration. */
78 char *name;
80 /* True if this is an md-style enum (DEFINE_ENUM) rather than
81 a C-style enum (DEFINE_C_ENUM). */
82 bool md_p;
84 /* The values of the enumeration. There is always at least one. */
85 struct enum_value *values;
87 /* A pointer to the null terminator in VALUES. */
88 struct enum_value **tail_ptr;
90 /* The number of enumeration values. */
91 unsigned int num_values;
94 class rtx_reader
96 public:
97 rtx_reader ();
98 virtual ~rtx_reader ();
100 bool read_md_files (int, const char **, bool (*) (const char *));
102 /* A hook that handles a single .md-file directive, up to but not
103 including the closing ')'. It takes two arguments: the file position
104 at which the directive started, and the name of the directive. The next
105 unread character is the optional space after the directive name. */
106 virtual void handle_unknown_directive (file_location, const char *) = 0;
108 file_location get_current_location () const;
110 /* Defined in read-md.c. */
111 int read_char (void);
112 void unread_char (int ch);
113 void read_name (struct md_name *name);
114 void read_escape ();
115 char *read_quoted_string ();
116 char *read_braced_string ();
117 char *read_string (int star_if_braced);
118 void read_skip_construct (int depth, file_location loc);
120 void set_md_ptr_loc (const void *ptr, const char *filename, int lineno);
121 const struct ptr_loc *get_md_ptr_loc (const void *ptr);
122 void copy_md_ptr_loc (const void *new_ptr, const void *old_ptr);
123 void fprint_md_ptr_loc (FILE *outf, const void *ptr);
124 void print_md_ptr_loc (const void *ptr);
126 struct enum_type *lookup_enum_type (const char *name);
127 void traverse_enum_types (htab_trav callback, void *info);
129 void handle_constants ();
130 void traverse_md_constants (htab_trav callback, void *info);
131 void handle_enum (file_location loc, bool md_p);
133 const char *join_c_conditions (const char *cond1, const char *cond2);
134 void fprint_c_condition (FILE *outf, const char *cond);
135 void print_c_condition (const char *cond);
137 /* Defined in read-rtl.c. */
138 const char *apply_iterator_to_string (const char *string);
139 rtx copy_rtx_for_iterators (rtx original);
140 void read_conditions ();
141 void record_potential_iterator_use (struct iterator_group *group,
142 void *ptr, const char *name);
143 struct mapping *read_mapping (struct iterator_group *group, htab_t table);
144 bool read_rtx (const char *rtx_name, vec<rtx> *rtxen);
145 rtx read_rtx_code (const char *code_name);
146 void read_rtx_operand (rtx return_rtx, int idx);
147 rtx read_nested_rtx ();
148 rtx read_rtx_variadic (rtx form);
150 const char *get_top_level_filename () const { return m_toplevel_fname; }
151 const char *get_filename () const { return m_read_md_filename; }
152 int get_lineno () const { return m_read_md_lineno; }
153 int get_colno () const { return m_read_md_colno; }
155 struct obstack *get_string_obstack () { return &m_string_obstack; }
156 htab_t get_md_constants () { return m_md_constants; }
158 private:
159 /* A singly-linked list of filenames. */
160 struct file_name_list {
161 struct file_name_list *next;
162 const char *fname;
165 private:
166 void handle_file ();
167 void handle_toplevel_file ();
168 void handle_include (file_location loc);
169 void add_include_path (const char *arg);
171 private:
172 /* The name of the toplevel file that indirectly included
173 m_read_md_file. */
174 const char *m_toplevel_fname;
176 /* The directory part of m_toplevel_fname
177 NULL if m_toplevel_fname is a bare filename. */
178 char *m_base_dir;
180 /* The file we are reading. */
181 FILE *m_read_md_file;
183 /* The filename of m_read_md_file. */
184 const char *m_read_md_filename;
186 /* The current line number in m_read_md_file. */
187 int m_read_md_lineno;
189 /* The current column number in m_read_md_file. */
190 int m_read_md_colno;
192 /* The column number before the last newline, so that
193 we can handle unread_char ('\n') at least once whilst
194 retaining column information. */
195 int m_last_line_colno;
197 /* The first directory to search. */
198 file_name_list *m_first_dir_md_include;
200 /* A pointer to the null terminator of the md include chain. */
201 file_name_list **m_last_dir_md_include_ptr;
203 /* Obstack used for allocating MD strings. */
204 struct obstack m_string_obstack;
206 /* A table of ptr_locs, hashed on the PTR field. */
207 htab_t m_ptr_locs;
209 /* An obstack for the above. Plain xmalloc is a bit heavyweight for a
210 small structure like ptr_loc. */
211 struct obstack m_ptr_loc_obstack;
213 /* A hash table of triples (A, B, C), where each of A, B and C is a condition
214 and A is equivalent to "B && C". This is used to keep track of the source
215 of conditions that are made up of separate MD strings (such as the split
216 condition of a define_insn_and_split). */
217 htab_t m_joined_conditions;
219 /* An obstack for allocating joined_conditions entries. */
220 struct obstack m_joined_conditions_obstack;
222 /* A table of md_constant structures, hashed by name. Null if no
223 constant expansion should occur. */
224 htab_t m_md_constants;
226 /* A table of enum_type structures, hashed by name. */
227 htab_t m_enum_types;
230 /* Global singleton. */
231 extern rtx_reader *rtx_reader_ptr;
233 /* An rtx_reader subclass which skips unknown directives. */
235 class noop_reader : public rtx_reader
237 public:
238 noop_reader () : rtx_reader () {}
240 /* A dummy implementation which skips unknown directives. */
241 void handle_unknown_directive (file_location, const char *);
244 extern void (*include_callback) (const char *);
246 /* Read the next character from the MD file. */
248 static inline int
249 read_char (void)
251 return rtx_reader_ptr->read_char ();
254 /* Put back CH, which was the last character read from the MD file. */
256 static inline void
257 unread_char (int ch)
259 rtx_reader_ptr->unread_char (ch);
262 extern hashval_t leading_string_hash (const void *);
263 extern int leading_string_eq_p (const void *, const void *);
264 extern const char *join_c_conditions (const char *, const char *);
265 extern void message_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
266 extern void error_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
267 extern void fatal_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
268 extern void fatal_with_file_and_line (const char *, ...)
269 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
270 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
271 extern int read_skip_spaces (void);
272 extern void require_char_ws (char expected);
273 extern int n_comma_elts (const char *);
274 extern const char *scan_comma_elt (const char **);
275 extern void upcase_string (char *);
276 extern void traverse_enum_types (htab_trav, void *);
277 extern struct enum_type *lookup_enum_type (const char *);
279 #endif /* GCC_READ_MD_H */