]>
Commit | Line | Data |
---|---|---|
10692477 RS |
1 | /* MD reader definitions. |
2 | Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, | |
3 | 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 | |
4 | Free Software Foundation, Inc. | |
5 | ||
6 | This file is part of GCC. | |
7 | ||
8 | GCC is free software; you can redistribute it and/or modify it under | |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 3, or (at your option) any later | |
11 | version. | |
12 | ||
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GCC; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #include "obstack.h" | |
9f418533 RS |
23 | #include "hashtab.h" |
24 | ||
25 | /* Holds one symbol or number in the .md file. */ | |
26 | struct md_name { | |
27 | /* The name as it appeared in the .md file. Names are syntactically | |
28 | limited to the length of this buffer. */ | |
29 | char buffer[256]; | |
30 | ||
31 | /* The name that should actually be used by the generator programs. | |
32 | This is an expansion of NAME, after things like constant substitution. */ | |
33 | char *string; | |
34 | }; | |
35 | ||
24609606 RS |
36 | /* This structure represents a constant defined by define_constant, |
37 | define_enum, or such-like. */ | |
9f418533 | 38 | struct md_constant { |
24609606 | 39 | /* The name of the constant. */ |
9f418533 | 40 | char *name; |
24609606 RS |
41 | |
42 | /* The string to which the constants expands. */ | |
9f418533 | 43 | char *value; |
24609606 RS |
44 | |
45 | /* If the constant is associated with a enumeration, this field | |
46 | points to that enumeration, otherwise it is null. */ | |
47 | struct enum_type *parent_enum; | |
48 | }; | |
49 | ||
50 | /* This structure represents one value in an enum_type. */ | |
51 | struct enum_value { | |
52 | /* The next value in the enum, or null if this is the last. */ | |
53 | struct enum_value *next; | |
54 | ||
55 | /* The name of the value as it appears in the .md file. */ | |
56 | char *name; | |
57 | ||
58 | /* The definition of the related C value. */ | |
59 | struct md_constant *def; | |
60 | }; | |
61 | ||
62 | /* This structure represents an enum defined by define_enum or the like. */ | |
63 | struct enum_type { | |
64 | /* The C name of the enumeration. */ | |
65 | char *name; | |
66 | ||
67 | /* True if this is an md-style enum (DEFINE_ENUM) rather than | |
68 | a C-style enum (DEFINE_C_ENUM). */ | |
69 | bool md_p; | |
70 | ||
71 | /* The values of the enumeration. There is always at least one. */ | |
72 | struct enum_value *values; | |
73 | ||
74 | /* A pointer to the null terminator in VALUES. */ | |
75 | struct enum_value **tail_ptr; | |
76 | ||
77 | /* The number of enumeration values. */ | |
78 | unsigned int num_values; | |
9f418533 | 79 | }; |
10692477 | 80 | |
600ab3fc RS |
81 | /* A callback that handles a single .md-file directive, up to but not |
82 | including the closing ')'. It takes two arguments: the line number on | |
83 | which the directive started, and the name of the directive. The next | |
84 | unread character is the optional space after the directive name. */ | |
85 | typedef void (*directive_handler_t) (int, const char *); | |
86 | ||
87 | extern const char *in_fname; | |
c5e88b39 | 88 | extern FILE *read_md_file; |
d2a3ce4e RS |
89 | extern int read_md_lineno; |
90 | extern const char *read_md_filename; | |
10692477 | 91 | extern struct obstack string_obstack; |
600ab3fc | 92 | extern void (*include_callback) (const char *); |
10692477 | 93 | |
c5e88b39 RS |
94 | /* Read the next character from the MD file. */ |
95 | ||
96 | static inline int | |
97 | read_char (void) | |
98 | { | |
7f7c467f RS |
99 | int ch; |
100 | ||
101 | ch = getc (read_md_file); | |
102 | if (ch == '\n') | |
103 | read_md_lineno++; | |
104 | return ch; | |
c5e88b39 RS |
105 | } |
106 | ||
107 | /* Put back CH, which was the last character read from the MD file. */ | |
108 | ||
109 | static inline void | |
110 | unread_char (int ch) | |
111 | { | |
7f7c467f RS |
112 | if (ch == '\n') |
113 | read_md_lineno--; | |
c5e88b39 RS |
114 | ungetc (ch, read_md_file); |
115 | } | |
116 | ||
9f418533 RS |
117 | extern hashval_t leading_string_hash (const void *); |
118 | extern int leading_string_eq_p (const void *, const void *); | |
d2a3ce4e RS |
119 | extern void copy_md_ptr_loc (const void *, const void *); |
120 | extern void print_md_ptr_loc (const void *); | |
10692477 RS |
121 | extern const char *join_c_conditions (const char *, const char *); |
122 | extern void print_c_condition (const char *); | |
123 | extern void message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2; | |
bb933490 | 124 | extern void error_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2; |
c5e88b39 RS |
125 | extern void fatal_with_file_and_line (const char *, ...) |
126 | ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; | |
127 | extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN; | |
128 | extern int read_skip_spaces (void); | |
9f418533 | 129 | extern void read_name (struct md_name *); |
c5e88b39 RS |
130 | extern char *read_quoted_string (void); |
131 | extern char *read_string (int); | |
9b68b6ea | 132 | extern void read_skip_construct (int, int); |
10692477 RS |
133 | extern int n_comma_elts (const char *); |
134 | extern const char *scan_comma_elt (const char **); | |
24609606 | 135 | extern void upcase_string (char *); |
9f418533 | 136 | extern void traverse_md_constants (htab_trav, void *); |
24609606 | 137 | extern void traverse_enum_types (htab_trav, void *); |
600ab3fc RS |
138 | extern bool read_md_files (int, char **, bool (*) (const char *), |
139 | directive_handler_t); |