]>
Commit | Line | Data |
---|---|---|
960ebfe7 | 1 | /* MD reader definitions. |
f1717362 | 2 | Copyright (C) 1987-2016 Free Software Foundation, Inc. |
960ebfe7 | 3 | |
4 | This file is part of GCC. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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/>. */ | |
19 | ||
ce6bb0f3 | 20 | #ifndef GCC_READ_MD_H |
21 | #define GCC_READ_MD_H | |
22 | ||
960ebfe7 | 23 | #include "obstack.h" |
ac0640e5 | 24 | |
36d192df | 25 | /* Records a position in the file. */ |
26 | struct file_location { | |
27 | file_location () {} | |
2a340d63 | 28 | file_location (const char *, int, int); |
36d192df | 29 | |
30 | const char *filename; | |
31 | int lineno; | |
2a340d63 | 32 | int colno; |
36d192df | 33 | }; |
34 | ||
2a340d63 | 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) {} | |
36d192df | 37 | |
ac0640e5 | 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]; | |
43 | ||
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; | |
47 | }; | |
48 | ||
5d54fceb | 49 | /* This structure represents a constant defined by define_constant, |
50 | define_enum, or such-like. */ | |
ac0640e5 | 51 | struct md_constant { |
5d54fceb | 52 | /* The name of the constant. */ |
ac0640e5 | 53 | char *name; |
5d54fceb | 54 | |
55 | /* The string to which the constants expands. */ | |
ac0640e5 | 56 | char *value; |
5d54fceb | 57 | |
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; | |
61 | }; | |
62 | ||
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; | |
67 | ||
68 | /* The name of the value as it appears in the .md file. */ | |
69 | char *name; | |
70 | ||
71 | /* The definition of the related C value. */ | |
72 | struct md_constant *def; | |
73 | }; | |
74 | ||
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; | |
79 | ||
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; | |
83 | ||
84 | /* The values of the enumeration. There is always at least one. */ | |
85 | struct enum_value *values; | |
86 | ||
87 | /* A pointer to the null terminator in VALUES. */ | |
88 | struct enum_value **tail_ptr; | |
89 | ||
90 | /* The number of enumeration values. */ | |
91 | unsigned int num_values; | |
ac0640e5 | 92 | }; |
960ebfe7 | 93 | |
ec468049 | 94 | class rtx_reader |
95 | { | |
96 | public: | |
97 | rtx_reader (); | |
98 | virtual ~rtx_reader (); | |
99 | ||
100 | bool read_md_files (int, const char **, bool (*) (const char *)); | |
101 | ||
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; | |
107 | ||
108 | file_location get_current_location () const; | |
109 | ||
110 | int read_char (void); | |
111 | void unread_char (int ch); | |
112 | ||
113 | const char *get_top_level_filename () const { return m_toplevel_fname; } | |
114 | const char *get_filename () const { return m_read_md_filename; } | |
115 | int get_lineno () const { return m_read_md_lineno; } | |
2a340d63 | 116 | int get_colno () const { return m_read_md_colno; } |
ec468049 | 117 | |
118 | private: | |
119 | /* A singly-linked list of filenames. */ | |
120 | struct file_name_list { | |
121 | struct file_name_list *next; | |
122 | const char *fname; | |
123 | }; | |
124 | ||
125 | private: | |
126 | void handle_file (); | |
127 | void handle_toplevel_file (); | |
128 | void handle_include (file_location loc); | |
129 | void add_include_path (const char *arg); | |
130 | ||
131 | private: | |
132 | /* The name of the toplevel file that indirectly included | |
133 | m_read_md_file. */ | |
134 | const char *m_toplevel_fname; | |
135 | ||
136 | /* The directory part of m_toplevel_fname | |
137 | NULL if m_toplevel_fname is a bare filename. */ | |
138 | char *m_base_dir; | |
139 | ||
140 | /* The file we are reading. */ | |
141 | FILE *m_read_md_file; | |
142 | ||
143 | /* The filename of m_read_md_file. */ | |
144 | const char *m_read_md_filename; | |
145 | ||
146 | /* The current line number in m_read_md_file. */ | |
147 | int m_read_md_lineno; | |
148 | ||
2a340d63 | 149 | /* The current column number in m_read_md_file. */ |
150 | int m_read_md_colno; | |
151 | ||
152 | /* The column number before the last newline, so that | |
153 | we can handle unread_char ('\n') at least once whilst | |
154 | retaining column information. */ | |
155 | int m_last_line_colno; | |
156 | ||
ec468049 | 157 | /* The first directory to search. */ |
158 | file_name_list *m_first_dir_md_include; | |
159 | ||
160 | /* A pointer to the null terminator of the md include chain. */ | |
161 | file_name_list **m_last_dir_md_include_ptr; | |
162 | }; | |
163 | ||
164 | /* Global singleton. */ | |
165 | extern rtx_reader *rtx_reader_ptr; | |
166 | ||
167 | /* An rtx_reader subclass which skips unknown directives. */ | |
168 | ||
169 | class noop_reader : public rtx_reader | |
170 | { | |
171 | public: | |
172 | noop_reader () : rtx_reader () {} | |
173 | ||
174 | /* A dummy implementation which skips unknown directives. */ | |
175 | void handle_unknown_directive (file_location, const char *); | |
176 | }; | |
177 | ||
960ebfe7 | 178 | extern struct obstack string_obstack; |
77ba95d0 | 179 | extern void (*include_callback) (const char *); |
960ebfe7 | 180 | |
b3453c30 | 181 | /* Read the next character from the MD file. */ |
182 | ||
183 | static inline int | |
184 | read_char (void) | |
185 | { | |
ec468049 | 186 | return rtx_reader_ptr->read_char (); |
b3453c30 | 187 | } |
188 | ||
189 | /* Put back CH, which was the last character read from the MD file. */ | |
190 | ||
191 | static inline void | |
192 | unread_char (int ch) | |
193 | { | |
ec468049 | 194 | rtx_reader_ptr->unread_char (ch); |
b3453c30 | 195 | } |
196 | ||
ac0640e5 | 197 | extern hashval_t leading_string_hash (const void *); |
198 | extern int leading_string_eq_p (const void *, const void *); | |
77c2564f | 199 | extern void copy_md_ptr_loc (const void *, const void *); |
200 | extern void print_md_ptr_loc (const void *); | |
73ed0c67 | 201 | extern void fprint_md_ptr_loc (FILE *, const void *); |
960ebfe7 | 202 | extern const char *join_c_conditions (const char *, const char *); |
203 | extern void print_c_condition (const char *); | |
73ed0c67 | 204 | extern void fprint_c_condition (FILE *, const char *); |
36d192df | 205 | extern void message_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2; |
206 | extern void error_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2; | |
e7ff515f | 207 | extern void fatal_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2; |
b3453c30 | 208 | extern void fatal_with_file_and_line (const char *, ...) |
209 | ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; | |
210 | extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN; | |
211 | extern int read_skip_spaces (void); | |
3604118d | 212 | extern void require_char_ws (char expected); |
ac0640e5 | 213 | extern void read_name (struct md_name *); |
b3453c30 | 214 | extern char *read_quoted_string (void); |
215 | extern char *read_string (int); | |
960ebfe7 | 216 | extern int n_comma_elts (const char *); |
217 | extern const char *scan_comma_elt (const char **); | |
5d54fceb | 218 | extern void upcase_string (char *); |
ac0640e5 | 219 | extern void traverse_md_constants (htab_trav, void *); |
5d54fceb | 220 | extern void traverse_enum_types (htab_trav, void *); |
d37b1ac9 | 221 | extern struct enum_type *lookup_enum_type (const char *); |
ce6bb0f3 | 222 | |
223 | #endif /* GCC_READ_MD_H */ |