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. */
26 struct file_location
{
28 file_location (const char *, int, int);
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. */
40 /* The name as it appeared in the .md file. Names are syntactically
41 limited to the length of this buffer. */
44 /* The name that should actually be used by the generator programs.
45 This is an expansion of NAME, after things like constant substitution. */
49 /* This structure represents a constant defined by define_constant,
50 define_enum, or such-like. */
52 /* The name of the constant. */
55 /* The string to which the constants expands. */
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. */
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. */
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. */
77 /* The C name of the enumeration. */
80 /* True if this is an md-style enum (DEFINE_ENUM) rather than
81 a C-style enum (DEFINE_C_ENUM). */
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 /* Describes one instance of an overloaded_name. */
95 struct overloaded_instance
{
96 /* The next instance in the chain, or null if none. */
97 overloaded_instance
*next
;
99 /* The values that the overloaded_name arguments should have for this
100 instance to be chosen. Each value is a C token. */
101 vec
<const char *> arg_values
;
103 /* The full (non-overloaded) name of the pattern. */
106 /* The corresponding define_expand or define_insn. */
110 /* Describes a define_expand or define_insn whose name was preceded by '@'.
111 Overloads are uniquely determined by their name and the types of their
112 arguments; it's possible to have overloads with the same name but
113 different argument types. */
114 struct overloaded_name
{
115 /* The next overloaded name in the chain. */
116 overloaded_name
*next
;
118 /* The overloaded name (i.e. the name with "@" character and
119 "<...>" placeholders removed). */
122 /* The C types of the iterators that determine the underlying pattern,
123 in the same order as in the pattern name. E.g. "<mode>" in the
124 pattern name would give a "machine_mode" argument here. */
125 vec
<const char *> arg_types
;
127 /* The first instance associated with this overloaded_name. */
128 overloaded_instance
*first_instance
;
130 /* Where to chain new overloaded_instances. */
131 overloaded_instance
**next_instance_ptr
;
136 /* A class for reading .md files and RTL dump files.
138 Implemented in read-md.c.
140 This class has responsibility for reading chars from input files, and
141 for certain common top-level directives including the "include"
144 It does not handle parsing the hierarchically-nested expressions of
145 rtl.def; for that see the rtx_reader subclass below (implemented in
151 md_reader (bool compact
);
152 virtual ~md_reader ();
154 bool read_md_files (int, const char **, bool (*) (const char *));
155 bool read_file (const char *filename
);
156 bool read_file_fragment (const char *filename
,
160 /* A hook that handles a single .md-file directive, up to but not
161 including the closing ')'. It takes two arguments: the file position
162 at which the directive started, and the name of the directive. The next
163 unread character is the optional space after the directive name. */
164 virtual void handle_unknown_directive (file_location
, const char *) = 0;
166 file_location
get_current_location () const;
168 bool is_compact () const { return m_compact
; }
170 /* Defined in read-md.c. */
171 int read_char (void);
172 void unread_char (int ch
);
173 file_location
read_name (struct md_name
*name
);
174 file_location
read_name_or_nil (struct md_name
*);
176 char *read_quoted_string ();
177 char *read_braced_string ();
178 char *read_string (int star_if_braced
);
179 void read_skip_construct (int depth
, file_location loc
);
180 void require_char (char expected
);
181 void require_char_ws (char expected
);
182 void require_word_ws (const char *expected
);
183 int peek_char (void);
185 void set_md_ptr_loc (const void *ptr
, const char *filename
, int lineno
);
186 const struct ptr_loc
*get_md_ptr_loc (const void *ptr
);
187 void copy_md_ptr_loc (const void *new_ptr
, const void *old_ptr
);
188 void fprint_md_ptr_loc (FILE *outf
, const void *ptr
);
189 void print_md_ptr_loc (const void *ptr
);
191 struct enum_type
*lookup_enum_type (const char *name
);
192 void traverse_enum_types (htab_trav callback
, void *info
);
194 void handle_constants ();
195 void traverse_md_constants (htab_trav callback
, void *info
);
196 void handle_enum (file_location loc
, bool md_p
);
198 const char *join_c_conditions (const char *cond1
, const char *cond2
);
199 void fprint_c_condition (FILE *outf
, const char *cond
);
200 void print_c_condition (const char *cond
);
202 /* Defined in read-rtl.c. */
203 const char *apply_iterator_to_string (const char *string
);
204 rtx
copy_rtx_for_iterators (rtx original
);
205 void read_conditions ();
206 void record_potential_iterator_use (struct iterator_group
*group
,
207 rtx x
, unsigned int index
,
209 struct mapping
*read_mapping (struct iterator_group
*group
, htab_t table
);
210 overloaded_name
*handle_overloaded_name (rtx
, vec
<mapping
*> *);
212 const char *get_top_level_filename () const { return m_toplevel_fname
; }
213 const char *get_filename () const { return m_read_md_filename
; }
214 int get_lineno () const { return m_read_md_lineno
; }
215 int get_colno () const { return m_read_md_colno
; }
217 struct obstack
*get_string_obstack () { return &m_string_obstack
; }
218 htab_t
get_md_constants () { return m_md_constants
; }
220 overloaded_name
*get_overloads () const { return m_first_overload
; }
223 /* A singly-linked list of filenames. */
224 struct file_name_list
{
225 struct file_name_list
*next
;
231 void handle_toplevel_file ();
232 void handle_include (file_location loc
);
233 void add_include_path (const char *arg
);
235 bool read_name_1 (struct md_name
*name
, file_location
*out_loc
);
238 /* Are we reading a compact dump? */
241 /* The name of the toplevel file that indirectly included
243 const char *m_toplevel_fname
;
245 /* The directory part of m_toplevel_fname
246 NULL if m_toplevel_fname is a bare filename. */
249 /* The file we are reading. */
250 FILE *m_read_md_file
;
252 /* The filename of m_read_md_file. */
253 const char *m_read_md_filename
;
255 /* The current line number in m_read_md_file. */
256 int m_read_md_lineno
;
258 /* The current column number in m_read_md_file. */
261 /* The column number before the last newline, so that
262 we can handle unread_char ('\n') at least once whilst
263 retaining column information. */
264 int m_last_line_colno
;
266 /* The first directory to search. */
267 file_name_list
*m_first_dir_md_include
;
269 /* A pointer to the null terminator of the md include chain. */
270 file_name_list
**m_last_dir_md_include_ptr
;
272 /* Obstack used for allocating MD strings. */
273 struct obstack m_string_obstack
;
275 /* A table of ptr_locs, hashed on the PTR field. */
278 /* An obstack for the above. Plain xmalloc is a bit heavyweight for a
279 small structure like ptr_loc. */
280 struct obstack m_ptr_loc_obstack
;
282 /* A hash table of triples (A, B, C), where each of A, B and C is a condition
283 and A is equivalent to "B && C". This is used to keep track of the source
284 of conditions that are made up of separate MD strings (such as the split
285 condition of a define_insn_and_split). */
286 htab_t m_joined_conditions
;
288 /* An obstack for allocating joined_conditions entries. */
289 struct obstack m_joined_conditions_obstack
;
291 /* A table of md_constant structures, hashed by name. Null if no
292 constant expansion should occur. */
293 htab_t m_md_constants
;
295 /* A table of enum_type structures, hashed by name. */
298 /* If non-zero, filter the input to just this subset of lines. */
302 /* The first overloaded_name. */
303 overloaded_name
*m_first_overload
;
305 /* Where to chain further overloaded_names, */
306 overloaded_name
**m_next_overload_ptr
;
308 /* A hash table of overloaded_names, keyed off their name and the types of
310 htab_t m_overloads_htab
;
313 /* Global singleton; constrast with rtx_reader_ptr below. */
314 extern md_reader
*md_reader_ptr
;
316 /* An md_reader subclass which skips unknown directives, for
317 the gen* tools that purely use read-md.o. */
319 class noop_reader
: public md_reader
322 noop_reader () : md_reader (false) {}
324 /* A dummy implementation which skips unknown directives. */
325 void handle_unknown_directive (file_location
, const char *);
328 /* An md_reader subclass that actually handles full hierarchical
331 Implemented in read-rtl.c. */
333 class rtx_reader
: public md_reader
336 rtx_reader (bool compact
);
339 bool read_rtx (const char *rtx_name
, vec
<rtx
> *rtxen
);
340 rtx
read_rtx_code (const char *code_name
);
341 virtual rtx
read_rtx_operand (rtx return_rtx
, int idx
);
342 rtx
read_nested_rtx ();
343 rtx
read_rtx_variadic (rtx form
);
344 char *read_until (const char *terminator_chars
, bool consume_terminator
);
346 virtual void handle_any_trailing_information (rtx
) {}
347 virtual rtx
postprocess (rtx x
) { return x
; }
349 /* Hook to allow function_reader subclass to put STRINGBUF into gc-managed
350 memory, rather than within an obstack.
351 This base class implementation is a no-op. */
352 virtual const char *finalize_string (char *stringbuf
) { return stringbuf
; }
355 /* Analogous to rtx_writer's m_in_call_function_usage. */
356 bool m_in_call_function_usage
;
358 /* Support for "reuse_rtx" directives. */
359 auto_vec
<rtx
> m_reuse_rtx_by_id
;
362 /* Global singleton; constrast with md_reader_ptr above. */
363 extern rtx_reader
*rtx_reader_ptr
;
365 extern void (*include_callback
) (const char *);
367 /* Read the next character from the MD file. */
372 return md_reader_ptr
->read_char ();
375 /* Put back CH, which was the last character read from the MD file. */
380 md_reader_ptr
->unread_char (ch
);
383 extern hashval_t
leading_string_hash (const void *);
384 extern int leading_string_eq_p (const void *, const void *);
385 extern const char *join_c_conditions (const char *, const char *);
386 extern void message_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
387 extern void error_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
388 extern void fatal_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
389 extern void fatal_with_file_and_line (const char *, ...)
390 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
391 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN
;
392 extern int read_skip_spaces (void);
393 extern int n_comma_elts (const char *);
394 extern const char *scan_comma_elt (const char **);
395 extern void upcase_string (char *);
396 extern void traverse_enum_types (htab_trav
, void *);
397 extern struct enum_type
*lookup_enum_type (const char *);
399 #endif /* GCC_READ_MD_H */