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