1 /* MD reader definitions.
2 Copyright (C) 1987-2017 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 /* A class for reading .md files and RTL dump files.
96 Implemented in read-md.c.
98 This class has responsibility for reading chars from input files, and
99 for certain common top-level directives including the "include"
102 It does not handle parsing the hierarchically-nested expressions of
103 rtl.def; for that see the rtx_reader subclass below (implemented in
109 md_reader (bool compact
);
110 virtual ~md_reader ();
112 bool read_md_files (int, const char **, bool (*) (const char *));
113 bool read_file (const char *filename
);
115 /* A hook that handles a single .md-file directive, up to but not
116 including the closing ')'. It takes two arguments: the file position
117 at which the directive started, and the name of the directive. The next
118 unread character is the optional space after the directive name. */
119 virtual void handle_unknown_directive (file_location
, const char *) = 0;
121 file_location
get_current_location () const;
123 bool is_compact () const { return m_compact
; }
125 /* Defined in read-md.c. */
126 int read_char (void);
127 void unread_char (int ch
);
128 file_location
read_name (struct md_name
*name
);
129 file_location
read_name_or_nil (struct md_name
*);
131 char *read_quoted_string ();
132 char *read_braced_string ();
133 char *read_string (int star_if_braced
);
134 void read_skip_construct (int depth
, file_location loc
);
135 void require_char (char expected
);
136 void require_char_ws (char expected
);
137 void require_word_ws (const char *expected
);
138 int peek_char (void);
140 void set_md_ptr_loc (const void *ptr
, const char *filename
, int lineno
);
141 const struct ptr_loc
*get_md_ptr_loc (const void *ptr
);
142 void copy_md_ptr_loc (const void *new_ptr
, const void *old_ptr
);
143 void fprint_md_ptr_loc (FILE *outf
, const void *ptr
);
144 void print_md_ptr_loc (const void *ptr
);
146 struct enum_type
*lookup_enum_type (const char *name
);
147 void traverse_enum_types (htab_trav callback
, void *info
);
149 void handle_constants ();
150 void traverse_md_constants (htab_trav callback
, void *info
);
151 void handle_enum (file_location loc
, bool md_p
);
153 const char *join_c_conditions (const char *cond1
, const char *cond2
);
154 void fprint_c_condition (FILE *outf
, const char *cond
);
155 void print_c_condition (const char *cond
);
157 /* Defined in read-rtl.c. */
158 const char *apply_iterator_to_string (const char *string
);
159 rtx
copy_rtx_for_iterators (rtx original
);
160 void read_conditions ();
161 void record_potential_iterator_use (struct iterator_group
*group
,
162 void *ptr
, const char *name
);
163 struct mapping
*read_mapping (struct iterator_group
*group
, htab_t table
);
165 const char *get_top_level_filename () const { return m_toplevel_fname
; }
166 const char *get_filename () const { return m_read_md_filename
; }
167 int get_lineno () const { return m_read_md_lineno
; }
168 int get_colno () const { return m_read_md_colno
; }
170 struct obstack
*get_string_obstack () { return &m_string_obstack
; }
171 htab_t
get_md_constants () { return m_md_constants
; }
174 /* A singly-linked list of filenames. */
175 struct file_name_list
{
176 struct file_name_list
*next
;
182 void handle_toplevel_file ();
183 void handle_include (file_location loc
);
184 void add_include_path (const char *arg
);
186 bool read_name_1 (struct md_name
*name
, file_location
*out_loc
);
189 /* Are we reading a compact dump? */
192 /* The name of the toplevel file that indirectly included
194 const char *m_toplevel_fname
;
196 /* The directory part of m_toplevel_fname
197 NULL if m_toplevel_fname is a bare filename. */
200 /* The file we are reading. */
201 FILE *m_read_md_file
;
203 /* The filename of m_read_md_file. */
204 const char *m_read_md_filename
;
206 /* The current line number in m_read_md_file. */
207 int m_read_md_lineno
;
209 /* The current column number in m_read_md_file. */
212 /* The column number before the last newline, so that
213 we can handle unread_char ('\n') at least once whilst
214 retaining column information. */
215 int m_last_line_colno
;
217 /* The first directory to search. */
218 file_name_list
*m_first_dir_md_include
;
220 /* A pointer to the null terminator of the md include chain. */
221 file_name_list
**m_last_dir_md_include_ptr
;
223 /* Obstack used for allocating MD strings. */
224 struct obstack m_string_obstack
;
226 /* A table of ptr_locs, hashed on the PTR field. */
229 /* An obstack for the above. Plain xmalloc is a bit heavyweight for a
230 small structure like ptr_loc. */
231 struct obstack m_ptr_loc_obstack
;
233 /* A hash table of triples (A, B, C), where each of A, B and C is a condition
234 and A is equivalent to "B && C". This is used to keep track of the source
235 of conditions that are made up of separate MD strings (such as the split
236 condition of a define_insn_and_split). */
237 htab_t m_joined_conditions
;
239 /* An obstack for allocating joined_conditions entries. */
240 struct obstack m_joined_conditions_obstack
;
242 /* A table of md_constant structures, hashed by name. Null if no
243 constant expansion should occur. */
244 htab_t m_md_constants
;
246 /* A table of enum_type structures, hashed by name. */
250 /* Global singleton; constrast with rtx_reader_ptr below. */
251 extern md_reader
*md_reader_ptr
;
253 /* An md_reader subclass which skips unknown directives, for
254 the gen* tools that purely use read-md.o. */
256 class noop_reader
: public md_reader
259 noop_reader () : md_reader (false) {}
261 /* A dummy implementation which skips unknown directives. */
262 void handle_unknown_directive (file_location
, const char *);
265 /* An md_reader subclass that actually handles full hierarchical
268 Implemented in read-rtl.c. */
270 class rtx_reader
: public md_reader
273 rtx_reader (bool compact
);
276 bool read_rtx (const char *rtx_name
, vec
<rtx
> *rtxen
);
277 rtx
read_rtx_code (const char *code_name
);
278 virtual rtx
read_rtx_operand (rtx return_rtx
, int idx
);
279 rtx
read_nested_rtx ();
280 rtx
read_rtx_variadic (rtx form
);
281 char *read_until (const char *terminator_chars
, bool consume_terminator
);
283 virtual void handle_any_trailing_information (rtx
) {}
284 virtual rtx
postprocess (rtx x
) { return x
; }
286 /* Hook to allow function_reader subclass to put STRINGBUF into gc-managed
287 memory, rather than within an obstack.
288 This base class implementation is a no-op. */
289 virtual const char *finalize_string (char *stringbuf
) { return stringbuf
; }
292 /* Analogous to rtx_writer's m_in_call_function_usage. */
293 bool m_in_call_function_usage
;
295 /* Support for "reuse_rtx" directives. */
296 auto_vec
<rtx
> m_reuse_rtx_by_id
;
299 /* Global singleton; constrast with md_reader_ptr above. */
300 extern rtx_reader
*rtx_reader_ptr
;
302 extern void (*include_callback
) (const char *);
304 /* Read the next character from the MD file. */
309 return md_reader_ptr
->read_char ();
312 /* Put back CH, which was the last character read from the MD file. */
317 md_reader_ptr
->unread_char (ch
);
320 extern hashval_t
leading_string_hash (const void *);
321 extern int leading_string_eq_p (const void *, const void *);
322 extern const char *join_c_conditions (const char *, const char *);
323 extern void message_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
324 extern void error_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
325 extern void fatal_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
326 extern void fatal_with_file_and_line (const char *, ...)
327 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
328 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN
;
329 extern int read_skip_spaces (void);
330 extern int n_comma_elts (const char *);
331 extern const char *scan_comma_elt (const char **);
332 extern void upcase_string (char *);
333 extern void traverse_enum_types (htab_trav
, void *);
334 extern struct enum_type
*lookup_enum_type (const char *);
336 #endif /* GCC_READ_MD_H */