gccint: Accessors

1 
1 14.3 Access to Operands
1 =======================
1 
1 Operands of expressions are accessed using the macros 'XEXP', 'XINT',
1 'XWINT' and 'XSTR'.  Each of these macros takes two arguments: an
1 expression-pointer (RTX) and an operand number (counting from zero).
1 Thus,
1 
1      XEXP (X, 2)
1 
1 accesses operand 2 of expression X, as an expression.
1 
1      XINT (X, 2)
1 
1 accesses the same operand as an integer.  'XSTR', used in the same
1 fashion, would access it as a string.
1 
1  Any operand can be accessed as an integer, as an expression or as a
1 string.  You must choose the correct method of access for the kind of
1 value actually stored in the operand.  You would do this based on the
1 expression code of the containing expression.  That is also how you
1 would know how many operands there are.
1 
1  For example, if X is an 'int_list' expression, you know that it has two
1 operands which can be correctly accessed as 'XINT (X, 0)' and 'XEXP (X,
1 1)'.  Incorrect accesses like 'XEXP (X, 0)' and 'XINT (X, 1)' would
1 compile, but would trigger an internal compiler error when rtl checking
1 is enabled.  Nothing stops you from writing 'XEXP (X, 28)' either, but
1 this will access memory past the end of the expression with
1 unpredictable results.
1 
1  Access to operands which are vectors is more complicated.  You can use
1 the macro 'XVEC' to get the vector-pointer itself, or the macros
1 'XVECEXP' and 'XVECLEN' to access the elements and length of a vector.
1 
1 'XVEC (EXP, IDX)'
1      Access the vector-pointer which is operand number IDX in EXP.
1 
1 'XVECLEN (EXP, IDX)'
1      Access the length (number of elements) in the vector which is in
1      operand number IDX in EXP.  This value is an 'int'.
1 
1 'XVECEXP (EXP, IDX, ELTNUM)'
1      Access element number ELTNUM in the vector which is in operand
1      number IDX in EXP.  This value is an RTX.
1 
1      It is up to you to make sure that ELTNUM is not negative and is
1      less than 'XVECLEN (EXP, IDX)'.
1 
1  All the macros defined in this section expand into lvalues and
1 therefore can be used to assign the operands, lengths and vector
1 elements as well as to access them.
1