]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/read-md.h
PR c++/77791
[thirdparty/gcc.git] / gcc / read-md.h
CommitLineData
960ebfe7 1/* MD reader definitions.
f1717362 2 Copyright (C) 1987-2016 Free Software Foundation, Inc.
960ebfe7 3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along 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. */
26struct file_location {
27 file_location () {}
28 file_location (const char *, int);
29
30 const char *filename;
31 int lineno;
32};
33
34inline file_location::file_location (const char *filename_in, int lineno_in)
35 : filename (filename_in), lineno (lineno_in) {}
36
ac0640e5 37/* Holds one symbol or number in the .md file. */
38struct md_name {
39 /* The name as it appeared in the .md file. Names are syntactically
40 limited to the length of this buffer. */
41 char buffer[256];
42
43 /* The name that should actually be used by the generator programs.
44 This is an expansion of NAME, after things like constant substitution. */
45 char *string;
46};
47
5d54fceb 48/* This structure represents a constant defined by define_constant,
49 define_enum, or such-like. */
ac0640e5 50struct md_constant {
5d54fceb 51 /* The name of the constant. */
ac0640e5 52 char *name;
5d54fceb 53
54 /* The string to which the constants expands. */
ac0640e5 55 char *value;
5d54fceb 56
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;
60};
61
62/* This structure represents one value in an enum_type. */
63struct enum_value {
64 /* The next value in the enum, or null if this is the last. */
65 struct enum_value *next;
66
67 /* The name of the value as it appears in the .md file. */
68 char *name;
69
70 /* The definition of the related C value. */
71 struct md_constant *def;
72};
73
74/* This structure represents an enum defined by define_enum or the like. */
75struct enum_type {
76 /* The C name of the enumeration. */
77 char *name;
78
79 /* True if this is an md-style enum (DEFINE_ENUM) rather than
80 a C-style enum (DEFINE_C_ENUM). */
81 bool md_p;
82
83 /* The values of the enumeration. There is always at least one. */
84 struct enum_value *values;
85
86 /* A pointer to the null terminator in VALUES. */
87 struct enum_value **tail_ptr;
88
89 /* The number of enumeration values. */
90 unsigned int num_values;
ac0640e5 91};
960ebfe7 92
ec468049 93class rtx_reader
94{
95 public:
96 rtx_reader ();
97 virtual ~rtx_reader ();
98
99 bool read_md_files (int, const char **, bool (*) (const char *));
100
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;
106
107 file_location get_current_location () const;
108
109 int read_char (void);
110 void unread_char (int ch);
111
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; }
115
116 private:
117 /* A singly-linked list of filenames. */
118 struct file_name_list {
119 struct file_name_list *next;
120 const char *fname;
121 };
122
123 private:
124 void handle_file ();
125 void handle_toplevel_file ();
126 void handle_include (file_location loc);
127 void add_include_path (const char *arg);
128
129 private:
130 /* The name of the toplevel file that indirectly included
131 m_read_md_file. */
132 const char *m_toplevel_fname;
133
134 /* The directory part of m_toplevel_fname
135 NULL if m_toplevel_fname is a bare filename. */
136 char *m_base_dir;
137
138 /* The file we are reading. */
139 FILE *m_read_md_file;
140
141 /* The filename of m_read_md_file. */
142 const char *m_read_md_filename;
143
144 /* The current line number in m_read_md_file. */
145 int m_read_md_lineno;
146
147 /* The first directory to search. */
148 file_name_list *m_first_dir_md_include;
149
150 /* A pointer to the null terminator of the md include chain. */
151 file_name_list **m_last_dir_md_include_ptr;
152};
153
154/* Global singleton. */
155extern rtx_reader *rtx_reader_ptr;
156
157/* An rtx_reader subclass which skips unknown directives. */
158
159class noop_reader : public rtx_reader
160{
161 public:
162 noop_reader () : rtx_reader () {}
163
164 /* A dummy implementation which skips unknown directives. */
165 void handle_unknown_directive (file_location, const char *);
166};
167
960ebfe7 168extern struct obstack string_obstack;
77ba95d0 169extern void (*include_callback) (const char *);
960ebfe7 170
b3453c30 171/* Read the next character from the MD file. */
172
173static inline int
174read_char (void)
175{
ec468049 176 return rtx_reader_ptr->read_char ();
b3453c30 177}
178
179/* Put back CH, which was the last character read from the MD file. */
180
181static inline void
182unread_char (int ch)
183{
ec468049 184 rtx_reader_ptr->unread_char (ch);
b3453c30 185}
186
ac0640e5 187extern hashval_t leading_string_hash (const void *);
188extern int leading_string_eq_p (const void *, const void *);
77c2564f 189extern void copy_md_ptr_loc (const void *, const void *);
190extern void print_md_ptr_loc (const void *);
73ed0c67 191extern void fprint_md_ptr_loc (FILE *, const void *);
960ebfe7 192extern const char *join_c_conditions (const char *, const char *);
193extern void print_c_condition (const char *);
73ed0c67 194extern void fprint_c_condition (FILE *, const char *);
36d192df 195extern void message_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
196extern void error_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
e7ff515f 197extern void fatal_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2;
b3453c30 198extern void fatal_with_file_and_line (const char *, ...)
199 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
200extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
201extern int read_skip_spaces (void);
3604118d 202extern void require_char_ws (char expected);
ac0640e5 203extern void read_name (struct md_name *);
b3453c30 204extern char *read_quoted_string (void);
205extern char *read_string (int);
960ebfe7 206extern int n_comma_elts (const char *);
207extern const char *scan_comma_elt (const char **);
5d54fceb 208extern void upcase_string (char *);
ac0640e5 209extern void traverse_md_constants (htab_trav, void *);
5d54fceb 210extern void traverse_enum_types (htab_trav, void *);
d37b1ac9 211extern struct enum_type *lookup_enum_type (const char *);
ce6bb0f3 212
213#endif /* GCC_READ_MD_H */