]>
Commit | Line | Data |
---|---|---|
10692477 | 1 | /* MD reader definitions. |
818ab71a | 2 | Copyright (C) 1987-2016 Free Software Foundation, Inc. |
10692477 RS |
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 | ||
f1717f8d KC |
20 | #ifndef GCC_READ_MD_H |
21 | #define GCC_READ_MD_H | |
22 | ||
10692477 | 23 | #include "obstack.h" |
9f418533 | 24 | |
cc472607 RS |
25 | /* Records a position in the file. */ |
26 | struct file_location { | |
27 | file_location () {} | |
28 | file_location (const char *, int); | |
29 | ||
30 | const char *filename; | |
31 | int lineno; | |
32 | }; | |
33 | ||
34 | inline file_location::file_location (const char *filename_in, int lineno_in) | |
35 | : filename (filename_in), lineno (lineno_in) {} | |
36 | ||
9f418533 RS |
37 | /* Holds one symbol or number in the .md file. */ |
38 | struct 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 | ||
24609606 RS |
48 | /* This structure represents a constant defined by define_constant, |
49 | define_enum, or such-like. */ | |
9f418533 | 50 | struct md_constant { |
24609606 | 51 | /* The name of the constant. */ |
9f418533 | 52 | char *name; |
24609606 RS |
53 | |
54 | /* The string to which the constants expands. */ | |
9f418533 | 55 | char *value; |
24609606 RS |
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. */ | |
63 | struct 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. */ | |
75 | struct 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; | |
9f418533 | 91 | }; |
10692477 | 92 | |
600ab3fc | 93 | /* A callback that handles a single .md-file directive, up to but not |
cc472607 RS |
94 | including the closing ')'. It takes two arguments: the file position |
95 | at which the directive started, and the name of the directive. The next | |
600ab3fc | 96 | unread character is the optional space after the directive name. */ |
cc472607 | 97 | typedef void (*directive_handler_t) (file_location, const char *); |
600ab3fc RS |
98 | |
99 | extern const char *in_fname; | |
c5e88b39 | 100 | extern FILE *read_md_file; |
d2a3ce4e RS |
101 | extern int read_md_lineno; |
102 | extern const char *read_md_filename; | |
10692477 | 103 | extern struct obstack string_obstack; |
600ab3fc | 104 | extern void (*include_callback) (const char *); |
10692477 | 105 | |
c5e88b39 RS |
106 | /* Read the next character from the MD file. */ |
107 | ||
108 | static inline int | |
109 | read_char (void) | |
110 | { | |
7f7c467f RS |
111 | int ch; |
112 | ||
113 | ch = getc (read_md_file); | |
114 | if (ch == '\n') | |
115 | read_md_lineno++; | |
116 | return ch; | |
c5e88b39 RS |
117 | } |
118 | ||
119 | /* Put back CH, which was the last character read from the MD file. */ | |
120 | ||
121 | static inline void | |
122 | unread_char (int ch) | |
123 | { | |
7f7c467f RS |
124 | if (ch == '\n') |
125 | read_md_lineno--; | |
c5e88b39 RS |
126 | ungetc (ch, read_md_file); |
127 | } | |
128 | ||
9f418533 RS |
129 | extern hashval_t leading_string_hash (const void *); |
130 | extern int leading_string_eq_p (const void *, const void *); | |
d2a3ce4e RS |
131 | extern void copy_md_ptr_loc (const void *, const void *); |
132 | extern void print_md_ptr_loc (const void *); | |
41723253 | 133 | extern void fprint_md_ptr_loc (FILE *, const void *); |
10692477 RS |
134 | extern const char *join_c_conditions (const char *, const char *); |
135 | extern void print_c_condition (const char *); | |
41723253 | 136 | extern void fprint_c_condition (FILE *, const char *); |
cc472607 RS |
137 | extern void message_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2; |
138 | extern void error_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2; | |
8f246310 | 139 | extern void fatal_at (file_location, const char *, ...) ATTRIBUTE_PRINTF_2; |
c5e88b39 RS |
140 | extern void fatal_with_file_and_line (const char *, ...) |
141 | ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; | |
142 | extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN; | |
143 | extern int read_skip_spaces (void); | |
9f418533 | 144 | extern void read_name (struct md_name *); |
c5e88b39 RS |
145 | extern char *read_quoted_string (void); |
146 | extern char *read_string (int); | |
10692477 RS |
147 | extern int n_comma_elts (const char *); |
148 | extern const char *scan_comma_elt (const char **); | |
24609606 | 149 | extern void upcase_string (char *); |
9f418533 | 150 | extern void traverse_md_constants (htab_trav, void *); |
24609606 | 151 | extern void traverse_enum_types (htab_trav, void *); |
8f4fe86c | 152 | extern struct enum_type *lookup_enum_type (const char *); |
600ab3fc RS |
153 | extern bool read_md_files (int, char **, bool (*) (const char *), |
154 | directive_handler_t); | |
f1717f8d KC |
155 | |
156 | #endif /* GCC_READ_MD_H */ |