Copyright (C) 2000-2012 |
GNU Info (gcc-295.info)AccessorsAccess to Operands ================== 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)' Access the vector-pointer which is operand number IDX in EXP. `XVECLEN (EXP, IDX)' Access the length (number of elements) in the vector which is in operand number IDX in EXP. This value is an `int'. `XVECEXP (EXP, IDX, ELTNUM)' Access element number ELTNUM in the vector which is in operand number IDX in EXP. This value is an RTX. 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. |