Annotation of lucent/sys/src/alef/k/cinit.c, revision 1.1

1.1     ! root        1: #include <u.h>
        !             2: #include <libc.h>
        !             3: #include <bio.h>
        !             4: #include <ctype.h>
        !             5: #define Extern extern
        !             6: #include "parl.h"
        !             7: #include "globl.h"
        !             8: 
        !             9: void
        !            10: cominit(Node *v, Type *t, Node *i, int off)
        !            11: {
        !            12:        Type *comt;
        !            13:        int ind, l, cnt, dim, sz;
        !            14:        Node n, **ilist, *in, *treg, *tdat;
        !            15: 
        !            16:        if(opt('i')) {
        !            17:                print("COMINIT %N T %T off %d\n", v, t, off);
        !            18:                ptree(i, 0);
        !            19:        }
        !            20: 
        !            21:        switch(t->type) {
        !            22:        case TINT:
        !            23:        case TUINT:
        !            24:        case TSINT:
        !            25:        case TSUINT:
        !            26:        case TCHAR:
        !            27:        case TFLOAT:
        !            28:        case TIND:
        !            29:        case TCHANNEL:
        !            30:                if(i->sun >= Sucall) {
        !            31:                        treg = stknode(builtype[TIND]);
        !            32:                        v->type = OREGISTER;
        !            33:                        v->t = builtype[TIND];
        !            34:                        assign(v, treg);
        !            35:                        tdat = stknode(i->t);
        !            36:                        n.t = i->t;
        !            37:                        n.type = OASGN;
        !            38:                        n.left = tdat;
        !            39:                        n.right = i;
        !            40:                        n.islval = 0;
        !            41:                        genexp(&n, ZeroN);
        !            42:                        assign(treg, v);
        !            43:                        v->type = OINDREG;
        !            44:                        v->ival = off;
        !            45:                        v->t = t;
        !            46:                        genexp(tdat, v);
        !            47:                        break;
        !            48:                }
        !            49:                v->ival = off;
        !            50:                v->t = t;
        !            51:                n.type = OASGN;
        !            52:                n.t = t;
        !            53:                n.left = v;
        !            54:                n.right = i;
        !            55:                n.islval = 0;
        !            56:                genexp(&n, ZeroN);
        !            57:                break;
        !            58:        
        !            59:        case TARRAY:
        !            60:                veccnt = 0;
        !            61:                listcount(i->left, 0);
        !            62:                ilist = malloc(sizeof(Node*)*veccnt);
        !            63:                veccnt = 0;
        !            64:                listcount(i->left, ilist);
        !            65:                cnt = veccnt;
        !            66: 
        !            67:                sz = t->next->size;
        !            68:                ind = 0;
        !            69:                dim = 0;
        !            70:                for(l = 0; l < cnt; l++) {
        !            71:                        if(ind > dim)
        !            72:                                dim = ind;
        !            73:                        in = ilist[l];
        !            74:                        if(in->type != OINDEX) {
        !            75:                                cominit(v, t->next, in, off+ind);
        !            76:                                ind += sz;
        !            77:                                continue;
        !            78:                        }
        !            79:                        ind = in->left->ival*sz;        
        !            80:                        cominit(v, t->next, in->right, off+ind);
        !            81:                        ind += sz;
        !            82:                }       
        !            83:                break;
        !            84: 
        !            85:        case TADT:
        !            86:        case TUNION:
        !            87:        case TAGGREGATE:
        !            88:                if(i->type != OILIST) {
        !            89:                        if(i->sun >= Sucall) {
        !            90:                                v->ival = 0;
        !            91:                                v->type = OREGISTER;
        !            92:                                v->t = at(TIND, t);
        !            93:                                treg = stknode(v->t);
        !            94:                                assign(v, treg);
        !            95:                                in = an(OADD, treg, con(off));
        !            96:                                in->t = v->t;
        !            97:                                in = an(OIND, in, ZeroN);
        !            98:                                in->t = t;
        !            99:                                n.type = OASGN;
        !           100:                                n.t = t;
        !           101:                                n.left = in;
        !           102:                                n.right = i;
        !           103:                                n.islval = 0;
        !           104:                                genexp(&n, ZeroN);
        !           105:                                assign(treg, v);
        !           106:                                v->type = OINDREG;
        !           107:                                break;
        !           108:                        }
        !           109:                        v->ival = 0;
        !           110:                        v->t = at(TIND, t);
        !           111:                        v->type = OREGISTER;
        !           112:                        in = an(OADD, v, con(off));
        !           113:                        in->t = v->t;
        !           114:                        in = an(OIND, in, ZeroN);
        !           115:                        in->t = t;
        !           116:                        n.type = OASGN;
        !           117:                        n.t = t;
        !           118:                        n.left = in;
        !           119:                        n.right = i;
        !           120:                        n.islval = 0;
        !           121:                        genexp(&n, ZeroN);
        !           122:                        v->type = OINDREG;
        !           123:                        break;
        !           124:                }
        !           125: 
        !           126:                veccnt = 0;
        !           127:                listcount(i->left, 0);
        !           128:                ilist = malloc(sizeof(Node*)*veccnt);
        !           129:                veccnt = 0;
        !           130:                listcount(i->left, ilist);
        !           131: 
        !           132:                cnt = veccnt;
        !           133:                comt = t->next;
        !           134:                for(l = 0; l < cnt; l++) {
        !           135:                        cominit(v, comt, ilist[l], off+comt->offset);
        !           136:                        for(;;) {
        !           137:                                comt = comt->member;
        !           138:                                if(comt == ZeroT)
        !           139:                                        break;
        !           140:                                /* Skip adt prototypes */
        !           141:                                if(comt->type != TFUNC)
        !           142:                                        break;
        !           143:                        }
        !           144:                }
        !           145:                break;
        !           146: 
        !           147:        case TFUNC:
        !           148:        case TVOID:
        !           149:                fatal("cominit");
        !           150:        }
        !           151: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.