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