GCC Middle and Back End API Reference
read-md.h
Go to the documentation of this file.
1 /* MD reader definitions.
2  Copyright (C) 1987-2013 Free Software Foundation, Inc.
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 
20 #include "obstack.h"
21 #include "hashtab.h"
22 
23 /* Holds one symbol or number in the .md file. */
24 struct md_name {
25  /* The name as it appeared in the .md file. Names are syntactically
26  limited to the length of this buffer. */
27  char buffer[256];
28 
29  /* The name that should actually be used by the generator programs.
30  This is an expansion of NAME, after things like constant substitution. */
31  char *string;
32 };
33 
34 /* This structure represents a constant defined by define_constant,
35  define_enum, or such-like. */
36 struct md_constant {
37  /* The name of the constant. */
38  char *name;
39 
40  /* The string to which the constants expands. */
41  char *value;
42 
43  /* If the constant is associated with a enumeration, this field
44  points to that enumeration, otherwise it is null. */
45  struct enum_type *parent_enum;
46 };
47 
48 /* This structure represents one value in an enum_type. */
49 struct enum_value {
50  /* The next value in the enum, or null if this is the last. */
51  struct enum_value *next;
52 
53  /* The name of the value as it appears in the .md file. */
54  char *name;
55 
56  /* The definition of the related C value. */
57  struct md_constant *def;
58 };
59 
60 /* This structure represents an enum defined by define_enum or the like. */
61 struct enum_type {
62  /* The C name of the enumeration. */
63  char *name;
64 
65  /* True if this is an md-style enum (DEFINE_ENUM) rather than
66  a C-style enum (DEFINE_C_ENUM). */
67  bool md_p;
68 
69  /* The values of the enumeration. There is always at least one. */
70  struct enum_value *values;
71 
72  /* A pointer to the null terminator in VALUES. */
73  struct enum_value **tail_ptr;
74 
75  /* The number of enumeration values. */
76  unsigned int num_values;
77 };
78 
79 /* A callback that handles a single .md-file directive, up to but not
80  including the closing ')'. It takes two arguments: the line number on
81  which the directive started, and the name of the directive. The next
82  unread character is the optional space after the directive name. */
83 typedef void (*directive_handler_t) (int, const char *);
84 
85 extern const char *in_fname;
86 extern FILE *read_md_file;
87 extern int read_md_lineno;
88 extern const char *read_md_filename;
89 extern struct obstack string_obstack;
90 extern void (*include_callback) (const char *);
91 
92 /* Read the next character from the MD file. */
93 
94 static inline int
95 read_char (void)
96 {
97  int ch;
98 
99  ch = getc (read_md_file);
100  if (ch == '\n')
101  read_md_lineno++;
102  return ch;
103 }
104 
105 /* Put back CH, which was the last character read from the MD file. */
106 
107 static inline void
108 unread_char (int ch)
109 {
110  if (ch == '\n')
111  read_md_lineno--;
112  ungetc (ch, read_md_file);
113 }
114 
115 extern hashval_t leading_string_hash (const void *);
116 extern int leading_string_eq_p (const void *, const void *);
117 extern void copy_md_ptr_loc (const void *, const void *);
118 extern void print_md_ptr_loc (const void *);
119 extern void fprint_md_ptr_loc (FILE *, const void *);
120 extern const char *join_c_conditions (const char *, const char *);
121 extern void print_c_condition (const char *);
122 extern void fprint_c_condition (FILE *, const char *);
123 extern void message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
124 extern void error_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
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);
129 extern void read_name (struct md_name *);
130 extern char *read_quoted_string (void);
131 extern char *read_string (int);
132 extern void read_skip_construct (int, int);
133 extern int n_comma_elts (const char *);
134 extern const char *scan_comma_elt (const char **);
135 extern void upcase_string (char *);
136 extern void traverse_md_constants (htab_trav, void *);
137 extern void traverse_enum_types (htab_trav, void *);
138 extern struct enum_type *lookup_enum_type (const char *);
139 extern bool read_md_files (int, char **, bool (*) (const char *),