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
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);
34 inline file_location::file_location (const char *filename_in
, int lineno_in
)
35 : filename (filename_in
), lineno (lineno_in
) {}
37 /* Holds one symbol or number in the .md file. */
39 /* The name as it appeared in the .md file. Names are syntactically
40 limited to the length of this buffer. */
43 /* The name that should actually be used by the generator programs.
44 This is an expansion of NAME, after things like constant substitution. */
48 /* This structure represents a constant defined by define_constant,
49 define_enum, or such-like. */
51 /* The name of the constant. */
54 /* The string to which the constants expands. */
57 /* If the constant is associated with a enumeration, this field
58 points to that enumeration, otherwise it is null. */
59 struct enum_type
*parent_enum
;
62 /* This structure represents one value in an enum_type. */
64 /* The next value in the enum, or null if this is the last. */
65 struct enum_value
*next
;
67 /* The name of the value as it appears in the .md file. */
70 /* The definition of the related C value. */
71 struct md_constant
*def
;
74 /* This structure represents an enum defined by define_enum or the like. */
76 /* The C name of the enumeration. */
79 /* True if this is an md-style enum (DEFINE_ENUM) rather than
80 a C-style enum (DEFINE_C_ENUM). */
83 /* The values of the enumeration. There is always at least one. */
84 struct enum_value
*values
;
86 /* A pointer to the null terminator in VALUES. */
87 struct enum_value
**tail_ptr
;
89 /* The number of enumeration values. */
90 unsigned int num_values
;
97 virtual ~rtx_reader ();
99 bool read_md_files (int, const char **, bool (*) (const char *));
101 /* A hook that handles a single .md-file directive, up to but not
102 including the closing ')'. It takes two arguments: the file position
103 at which the directive started, and the name of the directive. The next
104 unread character is the optional space after the directive name. */
105 virtual void handle_unknown_directive (file_location
, const char *) = 0;
107 file_location
get_current_location () const;
109 int read_char (void);
110 void unread_char (int ch
);
112 const char *get_top_level_filename () const { return m_toplevel_fname
; }
113 const char *get_filename () const { return m_read_md_filename
; }
114 int get_lineno () const { return m_read_md_lineno
; }
117 /* A singly-linked list of filenames. */
118 struct file_name_list
{
119 struct file_name_list
*next
;
125 void handle_toplevel_file ();
126 void handle_include (file_location loc
);
127 void add_include_path (const char *arg
);
130 /* The name of the toplevel file that indirectly included
132 const char *m_toplevel_fname
;
134 /* The directory part of m_toplevel_fname
135 NULL if m_toplevel_fname is a bare filename. */
138 /* The file we are reading. */
139 FILE *m_read_md_file
;
141 /* The filename of m_read_md_file. */
142 const char *m_read_md_filename
;
144 /* The current line number in m_read_md_file. */
145 int m_read_md_lineno
;
147 /* The first directory to search. */
148 file_name_list
*m_first_dir_md_include
;
150 /* A pointer to the null terminator of the md include chain. */
151 file_name_list
**m_last_dir_md_include_ptr
;
154 /* Global singleton. */
155 extern rtx_reader
*rtx_reader_ptr
;
157 /* An rtx_reader subclass which skips unknown directives. */
159 class noop_reader
: public rtx_reader
162 noop_reader () : rtx_reader () {}
164 /* A dummy implementation which skips unknown directives. */
165 void handle_unknown_directive (file_location
, const char *);
168 extern struct obstack string_obstack
;
169 extern void (*include_callback
) (const char *);
171 /* Read the next character from the MD file. */
176 return rtx_reader_ptr
->read_char ();
179 /* Put back CH, which was the last character read from the MD file. */
184 rtx_reader_ptr
->unread_char (ch
);
187 extern hashval_t
leading_string_hash (const void *);
188 extern int leading_string_eq_p (const void *, const void *);
189 extern void copy_md_ptr_loc (const void *, const void *);
190 extern void print_md_ptr_loc (const void *);
191 extern void fprint_md_ptr_loc (FILE *, const void *);
192 extern const char *join_c_conditions (const char *, const char *);
193 extern void print_c_condition (const char *);
194 extern void fprint_c_condition (FILE *, const char *);
195 extern void message_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
196 extern void error_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
197 extern void fatal_at (file_location
, const char *, ...) ATTRIBUTE_PRINTF_2
;
198 extern void fatal_with_file_and_line (const char *, ...)
199 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
200 extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN
;
201 extern int read_skip_spaces (void);
202 extern void require_char_ws (char expected
);
203 extern void read_name (struct md_name
*);
204 extern char *read_quoted_string (void);
205 extern char *read_string (int);
206 extern int n_comma_elts (const char *);
207 extern const char *scan_comma_elt (const char **);
208 extern void upcase_string (char *);
209 extern void traverse_md_constants (htab_trav
, void *);
210 extern void traverse_enum_types (htab_trav
, void *);
211 extern struct enum_type
*lookup_enum_type (const char *);
213 #endif /* GCC_READ_MD_H */