For each expression type `rtl.def
' specifies the number of
contained objects and their kinds, with four possibilities: `e
' for
expression (actually a pointer to an expression), `i
' for integer,
`w
' for wide integer, `s
' for string, and `E
' for vector
of expressions. The sequence of letters for an expression code is
called its format. Thus, the format of subreg
is
`ei
'.
A few other format characters are used occasionally:
u
u
' is equivalent to `e
' except that it is printed differently
in debugging dumps. It is used for pointers to insns.
n
n
' is equivalent to `i
' except that it is printed differently
in debugging dumps. It is used for the line number or code number of a
note
insn.
S
S
' indicates a string which is optional. In the RTL objects in
core, `S
' is equivalent to `s
', but when the object is read,
from an `md
' file, the string value of this operand may be omitted.
An omitted string is taken to be the null string.
V
V
' indicates a vector which is optional. In the RTL objects in
core, `V
' is equivalent to `E
', but when the object is read
from an `md
' file, the vector value of this operand may be omitted.
An omitted vector is effectively the same as a vector of no elements.
0
0
' means a slot whose contents do not fit any normal category.
`0
' slots are not printed at all in dumps, and are often used in
special ways by small parts of the compiler.
There are macros to get the number of operands, the format, and the class of an expression code:
GET_RTX_LENGTH (code)
GET_RTX_FORMAT (code)
GET_RTX_CLASS (code)
The following classes are defined:
o
reg
or
mem
. subreg
is not in this class.
<
NE
, EQ
, LE
, LT
, GE
, GT
,
LEU
, LTU
, GEU
, GTU
.
1
neg
.
c
NE
and EQ
(which have class `<
').
2
MINUS
.
b
ZERO_EXTRACT
or
SIGN_EXTRACT
.
3
IF_THEN_ELSE
.
i
INSN
, JUMP_INSN
, and
CALL_INSN
).
m
MATCH_DUP
.
x
Operands of expressions are accessed using the macros XEXP
,
XINT
, XWINT
and XSTR
. Each of these macros takes
two arguments: an expression-pointer (RTX) and an operand number
(counting from zero). Thus,
XEXP (x, 2)
accesses operand 2 of expression x, as an expression.
XINT (x, 2)
accesses the same operand as an integer. XSTR
, used in the same
fashion, would access it as a string.
Any operand can be accessed as an integer, as an expression or as a string. You must choose the correct method of access for the kind of value actually stored in the operand. You would do this based on the expression code of the containing expression. That is also how you would know how many operands there are.
For example, if x is a subreg
expression, you know that it has
two operands which can be correctly accessed as XEXP (x, 0)
and XINT (x, 1)
. If you did XINT (x, 0)
, you
would get the address of the expression operand but cast as an integer;
that might occasionally be useful, but it would be cleaner to write
(int) XEXP (x, 0)
. XEXP (x, 1)
would also
compile without error, and would return the second, integer operand cast as
an expression pointer, which would probably result in a crash when
accessed. Nothing stops you from writing XEXP (x, 28)
either,
but this will access memory past the end of the expression with
unpredictable results.
Access to operands which are vectors is more complicated. You can use the
macro XVEC
to get the vector-pointer itself, or the macros
XVECEXP
and XVECLEN
to access the elements and length of a
vector.
XVEC (exp, idx)
XVECLEN (exp, idx)
int
.
XVECEXP (exp, idx, eltnum)
It is up to you to make sure that eltnum is not negative
and is less than XVECLEN (exp, idx)
.
All the macros defined in this section expand into lvalues and therefore can be used to assign the operands, lengths and vector elements as well as to access them.