read-md.h 4.6 KB

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