1 /* MD reader definitions.
2 Copyright (C) 1987-2019 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
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
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/>. */
25 /* Records a position in the file. */
29 file_location (const char *, int, int);
36 inline file_location::file_location (const char *filename_in
, int lineno_in
, int colno_in
)
37 : filename (filename_in
), lineno (lineno_in
), colno (colno_in
) {}
39 /* Holds one symbol or number in the .md file. */
41 /* The name as it appeared in the .md file. Names are syntactically
42 limited to the length of this buffer. */
45 /* The name that should actually be used by the generator programs.
46 This is an expansion of NAME, after things like constant substitution. */
50 /* This structure represents a constant defined by define_constant,
51 define_enum, or such-like. */
53 /* The name of the constant. */
56 /* The string to which the constants expands. */
59 /* If the constant is associated with a enumeration, this field
60 points to that enumeration, otherwise it is null. */
61 struct enum_type
*parent_enum
;
64 /* This structure represents one value in an enum_type. */
66 /* The next value in the enum, or null if this is the last. */
67 struct enum_value
*next
;
69 /* The name of the value as it appears in the .md file. */
72 /* The definition of the related C value. */
73 struct md_constant
*def
;
76 /* This structure represents an enum defined by define_enum or the like. */
78 /* The C name of the enumeration. */
81 /* True if this is an md-style enum (DEFINE_ENUM) rather than
82 a C-style enum (DEFINE_C_ENUM). */
85 /* The values of the enumeration. There is always at least one. */
86 struct enum_value
*values
;
88 /* A pointer to the null terminator in VALUES. */
89 struct enum_value
**tail_ptr
;
91 /* The number of enumeration values. */
92 unsigned int num_values
;
95 /* Describes one instance of an overloaded_name. */
96 struct overloaded_instance
{
97 /* The next instance in the chain, or null if none. */
98 overloaded_instance
*next
;
100 /* The values that the overloaded_name arguments should have for this
101 instance to be chosen. Each value is a C token. */
102 vec
<const char *> arg_values
;
104 /* The full (non-overloaded) name of the pattern. */
107 /* The corresponding define_expand or define_insn. */
111 /* Describes a define_expand or define_insn whose name was preceded by '@'.
112 Overloads are uniquely determined by their name and the types of their
113 arguments; it's possible to have overloads with the same name but
114 different argument types. */
115 struct overloaded_name
{
116 /* The next overloaded name in the chain. */
117 overloaded_name
*next
;
119 /* The overloaded name (i.e. the name with "@" character and
120 "<...>" placeholders removed). */
123 /* The C types of the iterators that determine the underlying pattern,
124 in the same order as in the pattern name. E.g. "<mode>" in the
125 pattern name would give a "machine_mode" argument here. */
126 vec
<const char *> arg_types
;
128 /* The first instance associated with this overloaded_name. */
129 overloaded_instance
*first_instance
;
131 /* Where to chain new overloaded_instances. */
132 overloaded_instance
**next_instance_ptr
;
137 /* A class for reading .md files and RTL dump files.
139 Implemented in read-md.c.
141 This class has responsibility for reading chars from input files, and
142 for certain common top-level directives including the "include"
145 It does not handle parsing the hierarchically-nested expressions of
146 rtl.def; for that see the rtx_reader subclass below (implemented in
152 md_reader (bool compact
);
153 virtual ~md_reader ();
155 bool read_md_files (int, const char **, bool (*) (const char *));
156 bool read_file (const char *filename
);
157 bool read_file_fragment (const char *filename
,
161 /* A hook that handles a single .md-file directive, up to but not
162 including the closing ')'. It takes two arguments: the file position
163 at which the directive started, and the name of the directive. The next
164 unread character is the optional space after the directive name. */
165 virtual void handle_unknown_directive (file_location
, const char *) = 0;
167 file_location
get_current_location () const;
169 bool is_compact () const { return m_compact
; }
171 /* Defined in read-md.c. */
172 int read_char (void);
173 void unread_char (int ch
);
174 file_location
read_name (struct md_name
*name
);
175 file_location
read_name_or_nil (struct md_name
*);
177 char *read_quoted_string ();
178 char *read_braced_string ();
179 char *read_string (int star_if_braced
);
180 void read_skip_construct (int depth
, file_location loc
);
181 void require_char (char expected
);
182 void require_char_ws (char expected
);
183 void require_word_ws (const char *expected
);
184 int peek_char (void);
186 void set_md_ptr_loc (const void *ptr
, const char *filename
, int lineno
);
187 const struct ptr_loc
*get_md_ptr_loc (const void *ptr
);
188 void copy_md_ptr_loc (const void *new_ptr
, const void *old_ptr
);
189 void fprint_md_ptr_loc (FILE *outf
, const void *ptr
);
190 void print_md_ptr_loc (const void *ptr
);
192 struct enum_type
*lookup_enum_type (const char *name
);
193 void traverse_enum_types (htab_trav callback
, void *info
);
195 void handle_constants ();
196 void traverse_md_constants (htab_trav callback
, void *info
);
197 void handle_enum (file_location loc
, bool md_p
);
199 const char *join_c_conditions (const char *cond1
, const char *cond2
);
200 void fprint_c_condition (FILE *outf
, const char *cond
);
201 void print_c_condition (const char *cond
);
203 /* Defined in read-rtl.c. */
204 const char *apply_iterator_to_string (const char *string
);
205 rtx
copy_rtx_for_iterators (rtx original
);
206 void read_conditions ();
207 void record_potential_iterator_use (struct iterator_group
*group
,
208 rtx x
, unsigned int index
,
210 struct mapping
*read_mapping (struct iterator_group
*group
, htab_t table
);
211 overloaded_name
*handle_overloaded_name (rtx
, vec
<mapping
*> *);
213 const char *get_top_level_filename () const { return m_toplevel_fname
; }
214 const char *get_filename () const { return m_read_md_filename
; }
215 int get_lineno () const { return m_read_md_lineno
; }
216 int get_colno () const { return m_read_md_colno
; }
218 struct obstack
*get_string_obstack () { return &m_string_obstack
; }
219 htab_t
get_md_constants () { return m_md_constants
; }
221 overloaded_name
*get_overloads () const { return m_first_overload
; }
224 /* A singly-linked list of filenames. */
225 struct file_name_list
{
226 struct file_name_list
*next
;
232 void handle_toplevel_file ();
233 void handle_include (file_location loc
);
234 void add_include_path (const char *arg
);
236 bool read_name_1 (struct md_name
*name
, file_location
*out_loc
);
239 /* Are we reading a compact dump? */
242 /* The name of the toplevel file that indirectly included
244 const char *m_toplevel_fname
;
246 /* The directory part of m_toplevel_fname
247 NULL if m_toplevel_fname is a bare filename. */
250 /* The file we are reading. */
251 FILE *m_read_md_file
;
253 /* The filename of m_read_md_file. */
254 const char *m_read_md_filename
;
256 /* The current line number in m_read_md_file. */
257 int m_read_md_lineno
;
259 /* The current column number in m_read_md_file. */
262 /* The column number before the last newline, so that
263 we can handle unread_char ('\n') at least once whilst
264 retaining column information. */
265 int m_last_line_colno
;
267 /* The first directory to search. */
268 file_name_list
*m_first_dir_md_include
;
270 /* A pointer to the null terminator of the md include chain. */
271 file_name_list
**m_last_dir_md_include_ptr
;
273 /* Obstack used for allocating MD strings. */
274 struct obstack m_string_obstack
;
276 /* A table of ptr_locs, hashed on the PTR field. */
279 /* An obstack for the above. Plain xmalloc is a bit heavyweight for a
280 small structure like ptr_loc. */
281 struct obstack m_ptr_loc_obstack
;
283 /* A hash table of triples (A, B, C), where each of A, B and C is a condition
284 and A is equivalent to "B && C". This is used to keep track of the source
285 of conditions that are made up of separate MD strings (such as the split
286 condition of a define_insn_and_split). */
287 htab_t m_joined_conditions
;
289 /* An obstack for allocating joined_conditions entries. */
290 struct obstack m_joined_conditions_obstack
;
292 /* A table of md_constant structures, hashed by name. Null if no
293 constant expansion should occur. */
294 htab_t m_md_constants
;
296 /* A table of enum_type structures, hashed by name. */
299 /* If non-zero, filter the input to just this subset of lines. */
303 /* The first overloaded_name. */
304 overloaded_name
*m_first_overload
;
306 /* Where to chain further overloaded_names, */
307 overloaded_name
**m_next_overload_ptr
;
309 /* A hash table of overloaded_names, keyed off their name and the types of
311 htab_t m_overloads_htab
;
314 /* Global singleton; constrast with rtx_reader_ptr below. */
315 extern md_reader
*md_reader_ptr
;
317 /* An md_reader subclass which skips unknown directives, for
318 the gen* tools that purely use read-md.o. */
320 class noop_reader
: public md_reader
323 noop_reader () : md_reader (false) {}
325 /* A dummy implementation which skips unknown directives. */
326 void handle_unknown_directive (file_location
, const char *);
329 /* An md_reader subclass that actually handles full hierarchical
332 Implemented in read-rtl.c. */
334 class rtx_reader
: public md_reader
337 rtx_reader (bool compact
);
340 bool read_rtx (const char *rtx_name
, vec
<rtx
> *rtxen
);
341 rtx
rtx_alloc_for_name (const char *);
342 rtx
read_rtx_code (const char *code_name
);
343 virtual rtx
read_rtx_operand (rtx return_rtx
, int idx
);
344 rtx
read_nested_rtx ();
345 rtx
read_rtx_variadic (rtx form
);
346 char *read_until (const char *terminator_chars
, bool consume_terminator
);
348 virtual void handle_any_trailing_information (rtx
) {}
349 virtual rtx
postprocess (rtx x
) { return x
; }
351 /* Hook to allow function_reader subclass to put STRINGBUF into gc-managed
352 memory, rather than within an obstack.
353 This base class implementation is a no-op. */
354 virtual const char *finalize_string (char *stringbuf
) { return stringbuf
; }
357 /* Analogous to rtx_writer's m_in_call_function_usage. */
358 bool m_in_call_function_usage
;
360 /* Support for "reuse_rtx" directives. */
361 auto_vec
<rtx
> m_reuse_rtx_by_id
;
364 /* Global singleton; constrast with md_reader_ptr above. */
365 extern rtx_reader
*rtx_reader_ptr
;
367 extern void (*include_callback
) (const char *);
369 /* Read the next character from the MD file. */
374 return md_reader_ptr
->read_char ();
377 /* Put back CH, which was the last character read from the MD file. */
382 md_reader_ptr
->unread_char (ch
);
385 extern hashval_t
leading_string_hash (const void *);
386 extern int leading_string_eq_p (const void *, const void *);
387 extern const char *join_c_conditions (const char *, const char *);
388 extern void message_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
389 extern void error_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
390 extern void fatal_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
391 extern void fatal_with_file_and_line (const char *, ...)
392 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
393 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN
;
394 extern int read_skip_spaces (void);
395 extern int n_comma_elts (const char *);
396 extern const char *scan_comma_elt (const char **);
397 extern void upcase_string (char *);
398 extern void traverse_enum_types (htab_trav
, void *);
399 extern struct enum_type
*lookup_enum_type (const char *);
401 #endif /* GCC_READ_MD_H */