Back to wiki

RCS History

/ TOP / internals / node_structure.mdwn

Revision 1.4

The main data structure used through the whole compiler is the NODE. The parse trees are built out of NODEs and it is the underlying data structure when generating code.

The NODE structure contains lots of fields in unions to kefep the size down of the struct. Different NODE types uses different elements in the structure. The NODE struct is declared like this:

    typedef struct node {
        int     n_op;
        int     n_rall;
        TWORD   n_type;
        TWORD   n_qual;
        int     n_su;
        union {
                char *  _name;
                int     _stsize;
                union   dimfun *_df;
        } n_5;
        union {
                int     _label;
                int     _stalign;
                struct  suedef *_sue;
        } n_6;
        union {
                struct {
                        union {
                                struct node *_left;
                                CONSZ _lval;
                                SPECLVAL _slval;
                        } n_l;
                        union {
                                struct node *_right;
                                int _rval;
                                struct symtab *_sp;
                        } n_r;
                } n_u;
                long double     _dcon;
        } n_f;
    } NODE;
    #define n_name  n_5._name
    #define n_stsize n_5._stsize
    #define n_df    n_5._df
    #define n_label n_6._label
    #define n_stalign n_6._stalign
    #define n_sue   n_6._sue
    #define n_left  n_f.n_u.n_l._left
    #define n_lval  n_f.n_u.n_l._lval
    #define n_slval n_f.n_u.n_l._slval
    #define n_right n_f.n_u.n_r._right
    #define n_rval  n_f.n_u.n_r._rval
    #define n_sp    n_f.n_u.n_r._sp
    #define n_dcon  n_f._dcon

## NODE fields

### All Nodes

The fields that are valid in all nodes are:

- n\_op

    Tells which op the node is. 

- n\_type/n\_qual

    Keeps the encoded type of the node. 

- n\_rall/n\_su

    Used in [[pass2]] to generate code. 

### Leaf Nodes


    n\_lval has offset to the NAME (in bits). In [[pass1]], n\_sp is a pointer to this node symtab entry, in [[pass2]] the name string is stored in n\_name.


    Holds an integer constant in n\_lval. If it is a memory referenced constant, n\_sp is a pointer to this node symtab entry in [[pass1]] and n\_name points to its name in [[pass2]]. 


    Holds a floating point constant in n\_dcon. 


    Reference to a register. The register number is held in n\_rval. 


    An indirect reference to memory via an offset to a register. The register number is held in n\_rval, the offset in n\_lval. 

### Unary Nodes

The node leg is always the left leg.


    Complements the left node. 


    Type indirection operator; does PTR int -> int. 


    Negates the left node. 


    The left leg is a bitfield reference. n\_rval holds the bit offsets in packed format. 


    Type converts any type to an integer or float type. 


    The same as SCONV but the result is a pointer. 


    Used to do struct offset calculations. Mostly they can be replaced in [[pass1]]. 


    Call to a function without arguments. UFORTCALL is to call a fortran function, USTCALL for functions returning structures or unions.


    Forces the return value from a function to end up in the return register. 


    Just goto the left-node label. 


    Return from a function. 


    Make the tree result an argument for a function to call. 


    The inverse of UMUL, get the address of an object.

Powered by rcshistory.cgi 0.3