hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2016 Free Software Foundation, Inc.
 
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".
 
(a) The FSF's Front-Cover Text is:
 
A GNU Manual
 
(b) The FSF's Back-Cover Text is:
 
You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Compiler Collection (GCC) Internals: Output Template</title>
 
<meta name="description" content="GNU Compiler Collection (GCC) Internals: Output Template">
<meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Output Template">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Machine-Desc.html#Machine-Desc" rel="up" title="Machine Desc">
<link href="Output-Statement.html#Output-Statement" rel="next" title="Output Statement">
<link href="RTL-Template.html#RTL-Template" rel="prev" title="RTL Template">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
 
 
</head>
 
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Output-Template"></a>
<div class="header">
<p>
Next: <a href="Output-Statement.html#Output-Statement" accesskey="n" rel="next">Output Statement</a>, Previous: <a href="RTL-Template.html#RTL-Template" accesskey="p" rel="prev">RTL Template</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>
</div>
<hr>
<a name="Output-Templates-and-Operand-Substitution"></a>
<h3 class="section">16.5 Output Templates and Operand Substitution</h3>
<a name="index-output-templates"></a>
<a name="index-operand-substitution"></a>
 
<a name="index-_0025-in-template"></a>
<a name="index-percent-sign"></a>
<p>The <em>output template</em> is a string which specifies how to output the
assembler code for an instruction pattern.  Most of the template is a
fixed string which is output literally.  The character &lsquo;<samp>%</samp>&rsquo; is used
to specify where to substitute an operand; it can also be used to
identify places where different variants of the assembler require
different syntax.
</p>
<p>In the simplest case, a &lsquo;<samp>%</samp>&rsquo; followed by a digit <var>n</var> says to output
operand <var>n</var> at that point in the string.
</p>
<p>&lsquo;<samp>%</samp>&rsquo; followed by a letter and a digit says to output an operand in an
alternate fashion.  Four letters have standard, built-in meanings described
below.  The machine description macro <code>PRINT_OPERAND</code> can define
additional letters with nonstandard meanings.
</p>
<p>&lsquo;<samp>%c<var>digit</var></samp>&rsquo; can be used to substitute an operand that is a
constant value without the syntax that normally indicates an immediate
operand.
</p>
<p>&lsquo;<samp>%n<var>digit</var></samp>&rsquo; is like &lsquo;<samp>%c<var>digit</var></samp>&rsquo; except that the value of
the constant is negated before printing.
</p>
<p>&lsquo;<samp>%a<var>digit</var></samp>&rsquo; can be used to substitute an operand as if it were a
memory reference, with the actual operand treated as the address.  This may
be useful when outputting a &ldquo;load address&rdquo; instruction, because often the
assembler syntax for such an instruction requires you to write the operand
as if it were a memory reference.
</p>
<p>&lsquo;<samp>%l<var>digit</var></samp>&rsquo; is used to substitute a <code>label_ref</code> into a jump
instruction.
</p>
<p>&lsquo;<samp>%=</samp>&rsquo; outputs a number which is unique to each instruction in the
entire compilation.  This is useful for making local labels to be
referred to more than once in a single template that generates multiple
assembler instructions.
</p>
<p>&lsquo;<samp>%</samp>&rsquo; followed by a punctuation character specifies a substitution that
does not use an operand.  Only one case is standard: &lsquo;<samp>%%</samp>&rsquo; outputs a
&lsquo;<samp>%</samp>&rsquo; into the assembler code.  Other nonstandard cases can be
defined in the <code>PRINT_OPERAND</code> macro.  You must also define
which punctuation characters are valid with the
<code>PRINT_OPERAND_PUNCT_VALID_P</code> macro.
</p>
<a name="index-_005c"></a>
<a name="index-backslash"></a>
<p>The template may generate multiple assembler instructions.  Write the text
for the instructions, with &lsquo;<samp>\;</samp>&rsquo; between them.
</p>
<a name="index-matching-operands"></a>
<p>When the RTL contains two operands which are required by constraint to match
each other, the output template must refer only to the lower-numbered operand.
Matching operands are not always identical, and the rest of the compiler
arranges to put the proper RTL expression for printing into the lower-numbered
operand.
</p>
<p>One use of nonstandard letters or punctuation following &lsquo;<samp>%</samp>&rsquo; is to
distinguish between different assembler languages for the same machine; for
example, Motorola syntax versus MIT syntax for the 68000.  Motorola syntax
requires periods in most opcode names, while MIT syntax does not.  For
example, the opcode &lsquo;<samp>movel</samp>&rsquo; in MIT syntax is &lsquo;<samp>move.l</samp>&rsquo; in Motorola
syntax.  The same file of patterns is used for both kinds of output syntax,
but the character sequence &lsquo;<samp>%.</samp>&rsquo; is used in each place where Motorola
syntax wants a period.  The <code>PRINT_OPERAND</code> macro for Motorola syntax
defines the sequence to output a period; the macro for MIT syntax defines
it to do nothing.
</p>
<a name="index-_0023-in-template"></a>
<p>As a special case, a template consisting of the single character <code>#</code>
instructs the compiler to first split the insn, and then output the
resulting instructions separately.  This helps eliminate redundancy in the
output templates.   If you have a <code>define_insn</code> that needs to emit
multiple assembler instructions, and there is a matching <code>define_split</code>
already defined, then you can simply use <code>#</code> as the output template
instead of writing an output template that emits the multiple assembler
instructions.
</p>
<p>If the macro <code>ASSEMBLER_DIALECT</code> is defined, you can use construct
of the form &lsquo;<samp>{option0|option1|option2}</samp>&rsquo; in the templates.  These
describe multiple variants of assembler language syntax.
See <a href="Instruction-Output.html#Instruction-Output">Instruction Output</a>.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Output-Statement.html#Output-Statement" accesskey="n" rel="next">Output Statement</a>, Previous: <a href="RTL-Template.html#RTL-Template" accesskey="p" rel="prev">RTL Template</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>
</div>
 
 
 
</body>
</html>