]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/gccint/machine-descriptions/output-templates-and-operand-substitution.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / machine-descriptions / output-templates-and-operand-substitution.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. index:: output templates, operand substitution, % in template, percent sign
7
8.. _output-template:
9
10Output Templates and Operand Substitution
11*****************************************
12
13The :dfn:`output template` is a string which specifies how to output the
14assembler code for an instruction pattern. Most of the template is a
15fixed string which is output literally. The character :samp:`%` is used
16to specify where to substitute an operand; it can also be used to
17identify places where different variants of the assembler require
18different syntax.
19
20In the simplest case, a :samp:`%` followed by a digit :samp:`{n}` says to output
21operand :samp:`{n}` at that point in the string.
22
23:samp:`%` followed by a letter and a digit says to output an operand in an
24alternate fashion. Four letters have standard, built-in meanings described
25below. The machine description macro ``PRINT_OPERAND`` can define
26additional letters with nonstandard meanings.
27
28:samp:`%c{digit}` can be used to substitute an operand that is a
29constant value without the syntax that normally indicates an immediate
30operand.
31
32:samp:`%n{digit}` is like :samp:`%c{digit}` except that the value of
33the constant is negated before printing.
34
35:samp:`%a{digit}` can be used to substitute an operand as if it were a
36memory reference, with the actual operand treated as the address. This may
37be useful when outputting a 'load address' instruction, because often the
38assembler syntax for such an instruction requires you to write the operand
39as if it were a memory reference.
40
41:samp:`%l{digit}` is used to substitute a ``label_ref`` into a jump
42instruction.
43
44:samp:`%=` outputs a number which is unique to each instruction in the
45entire compilation. This is useful for making local labels to be
46referred to more than once in a single template that generates multiple
47assembler instructions.
48
49:samp:`%` followed by a punctuation character specifies a substitution that
50does not use an operand. Only one case is standard: :samp:`%%` outputs a
51:samp:`%` into the assembler code. Other nonstandard cases can be
52defined in the ``PRINT_OPERAND`` macro. You must also define
53which punctuation characters are valid with the
54``PRINT_OPERAND_PUNCT_VALID_P`` macro.
55
56.. index:: \, backslash
57
58The template may generate multiple assembler instructions. Write the text
59for the instructions, with :samp:`\\;` between them.
60
61.. index:: matching operands
62
63When the RTL contains two operands which are required by constraint to match
64each other, the output template must refer only to the lower-numbered operand.
65Matching operands are not always identical, and the rest of the compiler
66arranges to put the proper RTL expression for printing into the lower-numbered
67operand.
68
69One use of nonstandard letters or punctuation following :samp:`%` is to
70distinguish between different assembler languages for the same machine; for
71example, Motorola syntax versus MIT syntax for the 68000. Motorola syntax
72requires periods in most opcode names, while MIT syntax does not. For
73example, the opcode :samp:`movel` in MIT syntax is :samp:`move.l` in Motorola
74syntax. The same file of patterns is used for both kinds of output syntax,
75but the character sequence :samp:`%.` is used in each place where Motorola
76syntax wants a period. The ``PRINT_OPERAND`` macro for Motorola syntax
77defines the sequence to output a period; the macro for MIT syntax defines
78it to do nothing.
79
80.. index:: # in template
81
82As a special case, a template consisting of the single character ``#``
83instructs the compiler to first split the insn, and then output the
84resulting instructions separately. This helps eliminate redundancy in the
85output templates. If you have a ``define_insn`` that needs to emit
86multiple assembler instructions, and there is a matching ``define_split``
87already defined, then you can simply use ``#`` as the output template
88instead of writing an output template that emits the multiple assembler
89instructions.
90
91Note that ``#`` only has an effect while generating assembly code;
92it does not affect whether a split occurs earlier. An associated
93``define_split`` must exist and it must be suitable for use after
94register allocation.
95
96If the macro ``ASSEMBLER_DIALECT`` is defined, you can use construct
97of the form :samp:`{option0|option1|option2}` in the templates. These
98describe multiple variants of assembler language syntax.
3ed1b4ce 99See :ref:`instruction-output`.