You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 line
9.7KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Constant Definitions (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Constant Definitions (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Constant Definitions (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
  30. <link href="Iterators.html#Iterators" rel="next" title="Iterators">
  31. <link href="Define-Subst-Output-Template.html#Define-Subst-Output-Template" rel="prev" title="Define Subst Output Template">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Constant-Definitions"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Iterators.html#Iterators" accesskey="n" rel="next">Iterators</a>, Previous: <a href="Define-Subst.html#Define-Subst" accesskey="p" rel="prev">Define Subst</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Constant-Definitions-1"></a>
  68. <h3 class="section">17.22 Constant Definitions</h3>
  69. <a name="index-constant-definitions"></a>
  70. <a name="index-define_005fconstants"></a>
  71. <p>Using literal constants inside instruction patterns reduces legibility and
  72. can be a maintenance problem.
  73. </p>
  74. <p>To overcome this problem, you may use the <code>define_constants</code>
  75. expression. It contains a vector of name-value pairs. From that
  76. point on, wherever any of the names appears in the MD file, it is as
  77. if the corresponding value had been written instead. You may use
  78. <code>define_constants</code> multiple times; each appearance adds more
  79. constants to the table. It is an error to redefine a constant with
  80. a different value.
  81. </p>
  82. <p>To come back to the a29k load multiple example, instead of
  83. </p>
  84. <div class="smallexample">
  85. <pre class="smallexample">(define_insn &quot;&quot;
  86. [(match_parallel 0 &quot;load_multiple_operation&quot;
  87. [(set (match_operand:SI 1 &quot;gpc_reg_operand&quot; &quot;=r&quot;)
  88. (match_operand:SI 2 &quot;memory_operand&quot; &quot;m&quot;))
  89. (use (reg:SI 179))
  90. (clobber (reg:SI 179))])]
  91. &quot;&quot;
  92. &quot;loadm 0,0,%1,%2&quot;)
  93. </pre></div>
  94. <p>You could write:
  95. </p>
  96. <div class="smallexample">
  97. <pre class="smallexample">(define_constants [
  98. (R_BP 177)
  99. (R_FC 178)
  100. (R_CR 179)
  101. (R_Q 180)
  102. ])
  103. (define_insn &quot;&quot;
  104. [(match_parallel 0 &quot;load_multiple_operation&quot;
  105. [(set (match_operand:SI 1 &quot;gpc_reg_operand&quot; &quot;=r&quot;)
  106. (match_operand:SI 2 &quot;memory_operand&quot; &quot;m&quot;))
  107. (use (reg:SI R_CR))
  108. (clobber (reg:SI R_CR))])]
  109. &quot;&quot;
  110. &quot;loadm 0,0,%1,%2&quot;)
  111. </pre></div>
  112. <p>The constants that are defined with a define_constant are also output
  113. in the insn-codes.h header file as #defines.
  114. </p>
  115. <a name="index-enumerations"></a>
  116. <a name="index-define_005fc_005fenum"></a>
  117. <p>You can also use the machine description file to define enumerations.
  118. Like the constants defined by <code>define_constant</code>, these enumerations
  119. are visible to both the machine description file and the main C code.
  120. </p>
  121. <p>The syntax is as follows:
  122. </p>
  123. <div class="smallexample">
  124. <pre class="smallexample">(define_c_enum &quot;<var>name</var>&quot; [
  125. <var>value0</var>
  126. <var>value1</var>
  127. &hellip;
  128. <var>valuen</var>
  129. ])
  130. </pre></div>
  131. <p>This definition causes the equivalent of the following C code to appear
  132. in <samp>insn-constants.h</samp>:
  133. </p>
  134. <div class="smallexample">
  135. <pre class="smallexample">enum <var>name</var> {
  136. <var>value0</var> = 0,
  137. <var>value1</var> = 1,
  138. &hellip;
  139. <var>valuen</var> = <var>n</var>
  140. };
  141. #define NUM_<var>cname</var>_VALUES (<var>n</var> + 1)
  142. </pre></div>
  143. <p>where <var>cname</var> is the capitalized form of <var>name</var>.
  144. It also makes each <var>valuei</var> available in the machine description
  145. file, just as if it had been declared with:
  146. </p>
  147. <div class="smallexample">
  148. <pre class="smallexample">(define_constants [(<var>valuei</var> <var>i</var>)])
  149. </pre></div>
  150. <p>Each <var>valuei</var> is usually an upper-case identifier and usually
  151. begins with <var>cname</var>.
  152. </p>
  153. <p>You can split the enumeration definition into as many statements as
  154. you like. The above example is directly equivalent to:
  155. </p>
  156. <div class="smallexample">
  157. <pre class="smallexample">(define_c_enum &quot;<var>name</var>&quot; [<var>value0</var>])
  158. (define_c_enum &quot;<var>name</var>&quot; [<var>value1</var>])
  159. &hellip;
  160. (define_c_enum &quot;<var>name</var>&quot; [<var>valuen</var>])
  161. </pre></div>
  162. <p>Splitting the enumeration helps to improve the modularity of each
  163. individual <code>.md</code> file. For example, if a port defines its
  164. synchronization instructions in a separate <samp>sync.md</samp> file,
  165. it is convenient to define all synchronization-specific enumeration
  166. values in <samp>sync.md</samp> rather than in the main <samp>.md</samp> file.
  167. </p>
  168. <p>Some enumeration names have special significance to GCC:
  169. </p>
  170. <dl compact="compact">
  171. <dt><code>unspecv</code></dt>
  172. <dd><a name="index-unspec_005fvolatile-1"></a>
  173. <p>If an enumeration called <code>unspecv</code> is defined, GCC will use it
  174. when printing out <code>unspec_volatile</code> expressions. For example:
  175. </p>
  176. <div class="smallexample">
  177. <pre class="smallexample">(define_c_enum &quot;unspecv&quot; [
  178. UNSPECV_BLOCKAGE
  179. ])
  180. </pre></div>
  181. <p>causes GCC to print &lsquo;<samp>(unspec_volatile &hellip; 0)</samp>&rsquo; as:
  182. </p>
  183. <div class="smallexample">
  184. <pre class="smallexample">(unspec_volatile ... UNSPECV_BLOCKAGE)
  185. </pre></div>
  186. </dd>
  187. <dt><code>unspec</code></dt>
  188. <dd><a name="index-unspec-1"></a>
  189. <p>If an enumeration called <code>unspec</code> is defined, GCC will use
  190. it when printing out <code>unspec</code> expressions. GCC will also use
  191. it when printing out <code>unspec_volatile</code> expressions unless an
  192. <code>unspecv</code> enumeration is also defined. You can therefore
  193. decide whether to keep separate enumerations for volatile and
  194. non-volatile expressions or whether to use the same enumeration
  195. for both.
  196. </p></dd>
  197. </dl>
  198. <a name="index-define_005fenum"></a>
  199. <a name="define_005fenum"></a><p>Another way of defining an enumeration is to use <code>define_enum</code>:
  200. </p>
  201. <div class="smallexample">
  202. <pre class="smallexample">(define_enum &quot;<var>name</var>&quot; [
  203. <var>value0</var>
  204. <var>value1</var>
  205. &hellip;
  206. <var>valuen</var>
  207. ])
  208. </pre></div>
  209. <p>This directive implies:
  210. </p>
  211. <div class="smallexample">
  212. <pre class="smallexample">(define_c_enum &quot;<var>name</var>&quot; [
  213. <var>cname</var>_<var>cvalue0</var>
  214. <var>cname</var>_<var>cvalue1</var>
  215. &hellip;
  216. <var>cname</var>_<var>cvaluen</var>
  217. ])
  218. </pre></div>
  219. <a name="index-define_005fenum_005fattr-1"></a>
  220. <p>where <var>cvaluei</var> is the capitalized form of <var>valuei</var>.
  221. However, unlike <code>define_c_enum</code>, the enumerations defined
  222. by <code>define_enum</code> can be used in attribute specifications
  223. (see <a href="Defining-Attributes.html#define_005fenum_005fattr">define_enum_attr</a>).
  224. </p><hr>
  225. <div class="header">
  226. <p>
  227. Next: <a href="Iterators.html#Iterators" accesskey="n" rel="next">Iterators</a>, Previous: <a href="Define-Subst.html#Define-Subst" accesskey="p" rel="prev">Define Subst</a>, Up: <a href="Machine-Desc.html#Machine-Desc" accesskey="u" rel="up">Machine Desc</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  228. </div>
  229. </body>
  230. </html>