defparse.y 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. %{ /* defparse.y - parser for .def files */
  2. /* Copyright (C) 1995-2022 Free Software Foundation, Inc.
  3. This file is part of GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "libiberty.h"
  19. #include "dlltool.h"
  20. %}
  21. %union {
  22. char *id;
  23. const char *id_const;
  24. int number;
  25. };
  26. %token NAME LIBRARY DESCRIPTION STACKSIZE HEAPSIZE CODE DATA
  27. %token SECTIONS EXPORTS IMPORTS VERSIONK BASE CONSTANT
  28. %token READ WRITE EXECUTE SHARED NONSHARED NONAME PRIVATE
  29. %token SINGLE MULTIPLE INITINSTANCE INITGLOBAL TERMINSTANCE TERMGLOBAL
  30. %token EQUAL
  31. %token <id> ID
  32. %token <number> NUMBER
  33. %type <number> opt_base opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
  34. %type <number> attr attr_list opt_number
  35. %type <id> opt_name opt_name2 opt_equal_name opt_import_name
  36. %type <id_const> keyword_as_name
  37. %%
  38. start: start command
  39. | command
  40. ;
  41. command:
  42. NAME opt_name opt_base { def_name ($2, $3); }
  43. | LIBRARY opt_name opt_base option_list { def_library ($2, $3); }
  44. | EXPORTS explist
  45. | DESCRIPTION ID { def_description ($2);}
  46. | STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
  47. | HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
  48. | CODE attr_list { def_code ($2);}
  49. | DATA attr_list { def_data ($2);}
  50. | SECTIONS seclist
  51. | IMPORTS implist
  52. | VERSIONK NUMBER { def_version ($2,0);}
  53. | VERSIONK NUMBER '.' NUMBER { def_version ($2,$4);}
  54. ;
  55. explist:
  56. /* EMPTY */
  57. | explist expline
  58. ;
  59. expline:
  60. ID opt_equal_name opt_ordinal opt_NONAME opt_CONSTANT opt_DATA opt_PRIVATE
  61. opt_import_name
  62. { def_exports ($1, $2, $3, $4, $5, $6, $7, $8);}
  63. ;
  64. implist:
  65. implist impline
  66. | impline
  67. ;
  68. impline:
  69. ID '=' ID '.' ID '.' ID opt_import_name
  70. { def_import ($1,$3,$5,$7, 0, $8); }
  71. | ID '=' ID '.' ID '.' NUMBER opt_import_name
  72. { def_import ($1,$3,$5, 0,$7, $8); }
  73. | ID '=' ID '.' ID opt_import_name
  74. { def_import ($1,$3, 0,$5, 0, $6); }
  75. | ID '=' ID '.' NUMBER opt_import_name
  76. { def_import ($1,$3, 0, 0,$5, $6); }
  77. | ID '.' ID '.' ID opt_import_name
  78. { def_import ( 0,$1,$3,$5, 0, $6); }
  79. | ID '.' ID '.' NUMBER opt_import_name
  80. { def_import ( 0,$1,$3, 0,$5, $6); }
  81. | ID '.' ID opt_import_name
  82. { def_import ( 0,$1, 0,$3, 0, $4); }
  83. | ID '.' NUMBER opt_import_name
  84. { def_import ( 0,$1, 0, 0,$3, $4); }
  85. ;
  86. seclist:
  87. seclist secline
  88. | secline
  89. ;
  90. secline:
  91. ID attr_list { def_section ($1,$2);}
  92. ;
  93. attr_list:
  94. attr_list opt_comma attr
  95. | attr
  96. ;
  97. opt_comma:
  98. ','
  99. |
  100. ;
  101. opt_number: ',' NUMBER { $$=$2;}
  102. | { $$=-1;}
  103. ;
  104. attr:
  105. READ { $$ = 1; }
  106. | WRITE { $$ = 2; }
  107. | EXECUTE { $$ = 4; }
  108. | SHARED { $$ = 8; }
  109. | NONSHARED { $$ = 0; }
  110. | SINGLE { $$ = 0; }
  111. | MULTIPLE { $$ = 0; }
  112. ;
  113. opt_CONSTANT:
  114. CONSTANT {$$=1;}
  115. | {$$=0;}
  116. ;
  117. opt_NONAME:
  118. NONAME {$$=1;}
  119. | {$$=0;}
  120. ;
  121. opt_DATA:
  122. DATA { $$ = 1; }
  123. | { $$ = 0; }
  124. ;
  125. opt_PRIVATE:
  126. PRIVATE { $$ = 1; }
  127. | { $$ = 0; }
  128. ;
  129. keyword_as_name: NAME { $$ = "NAME"; }
  130. /* Disabled LIBRARY keyword for a quirk in libtool. It places LIBRARY
  131. command after EXPORTS list, which is illegal by specification.
  132. See PR binutils/13710
  133. | LIBRARY { $$ = "LIBRARY"; } */
  134. | DESCRIPTION { $$ = "DESCRIPTION"; }
  135. | STACKSIZE { $$ = "STACKSIZE"; }
  136. | HEAPSIZE { $$ = "HEAPSIZE"; }
  137. | CODE { $$ = "CODE"; }
  138. | DATA { $$ = "DATA"; }
  139. | SECTIONS { $$ = "SECTIONS"; }
  140. | EXPORTS { $$ = "EXPORTS"; }
  141. | IMPORTS { $$ = "IMPORTS"; }
  142. | VERSIONK { $$ = "VERSION"; }
  143. | BASE { $$ = "BASE"; }
  144. | CONSTANT { $$ = "CONSTANT"; }
  145. | NONAME { $$ = "NONAME"; }
  146. | PRIVATE { $$ = "PRIVATE"; }
  147. | READ { $$ = "READ"; }
  148. | WRITE { $$ = "WRITE"; }
  149. | EXECUTE { $$ = "EXECUTE"; }
  150. | SHARED { $$ = "SHARED"; }
  151. | NONSHARED { $$ = "NONSHARED"; }
  152. | SINGLE { $$ = "SINGLE"; }
  153. | MULTIPLE { $$ = "MULTIPLE"; }
  154. | INITINSTANCE { $$ = "INITINSTANCE"; }
  155. | INITGLOBAL { $$ = "INITGLOBAL"; }
  156. | TERMINSTANCE { $$ = "TERMINSTANCE"; }
  157. | TERMGLOBAL { $$ = "TERMGLOBAL"; }
  158. ;
  159. opt_name2: ID { $$ = $1; }
  160. | '.' keyword_as_name
  161. {
  162. char *name = xmalloc (strlen ($2) + 2);
  163. sprintf (name, ".%s", $2);
  164. $$ = name;
  165. }
  166. | '.' opt_name2
  167. {
  168. char *name = xmalloc (strlen ($2) + 2);
  169. sprintf (name, ".%s", $2);
  170. $$ = name;
  171. }
  172. | keyword_as_name '.' opt_name2
  173. {
  174. char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
  175. sprintf (name, "%s.%s", $1, $3);
  176. $$ = name;
  177. }
  178. | ID '.' opt_name2
  179. {
  180. char *name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
  181. sprintf (name, "%s.%s", $1, $3);
  182. $$ = name;
  183. }
  184. ;
  185. opt_name: opt_name2 { $$ =$1; }
  186. | { $$=""; }
  187. ;
  188. opt_ordinal:
  189. '@' NUMBER { $$=$2;}
  190. | { $$=-1;}
  191. ;
  192. opt_import_name:
  193. EQUAL opt_name2 { $$ = $2; }
  194. | { $$ = 0; }
  195. ;
  196. opt_equal_name:
  197. '=' opt_name2 { $$ = $2; }
  198. | { $$ = 0; }
  199. ;
  200. opt_base: BASE '=' NUMBER { $$= $3;}
  201. | { $$=-1;}
  202. ;
  203. option_list:
  204. /* empty */
  205. | option_list opt_comma option
  206. ;
  207. option:
  208. INITINSTANCE
  209. | INITGLOBAL
  210. | TERMINSTANCE
  211. | TERMGLOBAL
  212. ;