⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
                    if (!strcmp(sp1->name,lastid)) 
                        break ;
                    sp1 = sp1->next;
                }
                if (!sp1)
                    gensymerror(ERR_UNDEFINED,lastid) ;
                else
                    sp = sp1;
                getsym();
                needpunc(assign,0);
            }
            else
                gensymerror(ERR_UNDEFINED,lastid) ;
        } 
        sptr = &sp->init;
        sp->init = 0;
        inittype(sp->tp);
        sp = sp->next;
        if (lastst == comma)
            if (sp)
                getsym();
            else if (has_begin)
                if (!sp)
                {
                    getsym();
                    break ;
                }
                else
                    getsym();
            else
                break;
        else if (!sp || lastst == end)
            break;
        else
            expecttoken(end, 0);
    }
    sp = tp->lst.head; /* start at top of symbol table */
    sptr = osptr;
    while (sp) {
        startbit = sp->tp->startbit;
        bits = sp->tp->bits;
        if (nbytes < sp->value.i)
            makestorage(sp->value.i - nbytes);
        nbytes = sp->value.i;
        if (bits !=  - 1)
        {
            SYM *sp1 = sp;
            int newbits;
            while (sp1 && sp1->value.i == sp->value.i)
                sp1 = sp1->next;
            if (sp1)
                newbits = sp1->value.i - sp->value.i;
            else
                newbits = tp->size - sp->value.i;
            if (newbits != curbitsize && curbitsize !=  - 1)
                agbits( - 1, 0);
            curbitsize = newbits;
            if (sp->init)
                agbits(newbits,sp->init->val.i) ;
            else
                agbits(newbits,0);
        } 
        else
        {
            nbytes += agbits( - 1, 0);
            *sptr = sp->init;
            while (*sptr) {
                switch((*sptr)->mode) 
                {
                    case dd_byte:
                        nbytes++;
                        ;
                        break;
                    case dd_word:
                        nbytes += stdshortsize;
                        break;
	                case dd_enum:
        	            nbytes += stdenumsize;
            	        break;
					case dd_int:
						nbytes += stdintsize ;
						break;
                    case dd_long:
                        nbytes += stdlongsize;
                        break;
                    case dd_longlong:
                        nbytes += stdlonglongsize;
                        break;
                    case dd_float:
                        nbytes += stdfloatsize;
                        break;
                    case dd_double:
                        nbytes += stddoublesize;
                        break;
                    case dd_ldouble:
                        nbytes += stdldoublesize;
                        break;
                    case dd_fcomplex:
                        nbytes += stdfloatsize * 2;
                        break;
                    case dd_rcomplex:
                        nbytes += stddoublesize * 2;
                        break;
                    case dd_lrcomplex:
                        nbytes += stdldoublesize * 2;
                        break;
                    case dd_pcname:
                        nbytes += stdaddrsize;
                        break;
                    case dd_dataname:
                        nbytes += stdaddrsize;
                        break;
                    case dd_storage:
                        nbytes += (*sptr)->val.i;
                        break;
                    case dd_label:
                        nbytes += stdaddrsize;
                        break;
                    case dd_farpointer:
                        nbytes += stdaddrsize + stdshortsize;
                        break;
                }
                sptr = &(*sptr)->link;
            }
        }
        sp->init = 0;
        sp = sp->next;
    }
    nbytes += agbits( - 1, 0);
    if (nbytes < tp->size)
    {
        makestorage(tp->size - nbytes);
    }
    if (has_begin)
        needpunc(end, skm_declend);
    return tp->size;
}

//-------------------------------------------------------------------------

int makelabel(int id)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    q->val.i = id;
    sptr = &(*sptr)->link;
    q->mode = dd_label;
    return q->val.i;
}

//-------------------------------------------------------------------------

int makeref(int ispc, SYM *sp, int offset)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    SetExtFlag(sp, TRUE);
        if (sp->value.classdata.gdeclare)
            sp->value.classdata.gdeclare->mainsym->extflag = TRUE;
    q->val.sp = sp;
    q->offset = offset;
    sptr = &(*sptr)->link;
    q->mode = ispc ? dd_pcname : dd_dataname;
}

//-------------------------------------------------------------------------

int makestorage(long val)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    if (curbitsize !=  - 1)
    {
        val -= agflush(curbitsize, totbits);
        curbitsize =  - 1;
        totbits = 0;
    } 
	if (val < 0)
        DIAG("makestorage - bit field mismatch");
    if (val)
    {
        q->val.i = val;
        sptr = &(*sptr)->link;
        q->mode = dd_storage;
    }
}

//-------------------------------------------------------------------------

int agflush(int size, LLONG_TYPE val)
/*
 * flush a bit field when it is full
 */
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    q->val.i = val;
    sptr = &(*sptr)->link;
	if (size == stdshortsize) {
            q->mode = dd_word;
            return stdshortsize;
	} else if (size == stdintsize) {
            q->mode = dd_int;
            return stdintsize;
	} else if (size == stdlongsize) {
            q->mode = dd_long;
            return stdlongsize;
	} else if (size == stdlonglongsize) {
            q->mode = dd_longlong;
            return stdlonglongsize;
	} else if (size == stdaddrsize + stdshortsize) {
            q->mode = dd_farpointer;
            return stdaddrsize + stdshortsize;
	}
    q->mode = dd_byte;
    return 1;
}

/* Aggregate bits */
int agbits(int size, LLONG_TYPE value)
/*
 * combine bit declarations into a bit field
 */
{
    long rv = 0;
    if (size ==  - 1 && bits !=  - 1)
    {
        rv = agflush(curbitsize, totbits);
        curbitsize =  - 1;
        totbits = 0;
        bits =  - 1;
    }
    else
    {
        if (bits ==  - 1 && size !=  - 1)
            rv = agflush(size, value);
        else if (bits !=  - 1)
        {
            totbits |= (value &mod_mask(bits)) << startbit;
            if (bits + startbit >= size *8)
            {
                rv += agflush(curbitsize, totbits);
                totbits = 0;
            }
        }
    }
    startbit =  - 1;
    return (rv);
}

/* handle floating point init
 */
long double cppfloat(int size, int imaginary)
{
    TYP *t1;
    ENODE *ep;
    allocated = TRUE;

        t1 = exprnc(&ep);
        opt4(&ep);
        if (isintconst(ep->nodetype))
            if (imaginary)
                return 0;
            else
                return ep->v.i;
        else if (isfloatconst(ep->nodetype))
            if (imaginary)
                return 0;
            else
                return ep->v.f;
        else if (isimaginaryconst(ep->nodetype))
            if (!imaginary)
                return 0;
            else
                return ep->v.f;
        else if (iscomplexconst(ep->nodetype))
            if (imaginary)
                return ep->v.c.i ;
            else
                return ep->v.c.r ;
        else
        {
            if (!isscalar(t1) || !ep || !prm_cplusplus)
                generror(ERR_NEEDCONST, 0, 0);
            else
            {
                ENODE *node1;
                int typ;
                switch (size)
                {
                    case 6:
                        typ = en_floatref;
                        break;
                    case 8:
                        typ = en_doubleref;
                        break;
                    case 10:
                        typ = en_longdoubleref;
                        break;
                }
                cppinitassign(ep);
                #ifdef XXXXX
                    node1 = makenode(typ, makenode(en_nacon, locsp, 0), 0);
                    node1 = makenode(en_assign, node1, ep);
                    cppinitinsert(node1);
                #endif 
            }
        }
        return 0.0;
}

//-------------------------------------------------------------------------

int arr(ENODE *ep)
{
    if (lvalue(ep))
        return TRUE;
    switch (ep->nodetype)
    {
        case en_nacon:
        case en_napccon:
        case en_nalabcon:
            return TRUE;
        default:
            return FALSE;
    }
}

//-------------------------------------------------------------------------

int intconstinit(int type, LLONG_TYPE *val)
{
    TYP *t1;
    ENODE *ep;
    int done = TRUE;

    int began = 0;
    if (lastst == begin)
    {
        began++;
        getsym();
    }
    t1 = exprnc(&ep);
    opt4(&ep);
    if (!ep)
    {
        generror(ERR_ILLINIT, 0, 0);
        return TRUE;
    }
    if (began)
        if (!needpunc(end, 0))
            return TRUE;
    opt4(&ep);
    if (!type)
    {
        if (t1->type == bt_pointer || t1->type == bt_segpointer || t1->type ==
            bt_farpointer || t1->type == bt_func || t1->type == bt_ifunc)
        {
            generror(ERR_NONPORT, 0, 0);
        }
        else
        {
            if (!isscalar(t1))
                generror(ERR_NEEDCONST, 0, 0);
        }
    }
    else
    {
        if (t1->type != bt_pointer && t1->type != bt_farpointer && t1->type !=
            bt_segpointer && t1->type != bt_func && t1->type != bt_ifunc)
        if (isscalar(t1))
        {
            if (ep->v.i)
                generror(ERR_NONPORT, 0, 0);
        }
        else
            generror(ERR_NEEDCONST, 0, 0);
    }
    while (castvalue(ep))
        ep = ep->v.p[0];
    if (ep && ep->nodetype == en_labcon)
    {
        makelabel(ep->v.i);
    }
    else if (isintconst(ep->nodetype))
    {
        *val = ep->v.i;
        done = FALSE;
    }
    else if (isfloatconst(ep->nodetype))
    {
        *val = ep->v.f;
        done = FALSE;
    }
    else
    {
        if (lvalue(ep))
        {
            ep = ep->v.p[0];
        }
        if (ep->nodetype == en_nacon || ep->nodetype == en_napccon || ep
            ->nodetype == en_nalabcon)
        {
            makeref(ep->nodetype == en_napccon, ((SYM*)(ep->v.sp)), 0);
        }
        else
        {
            if (ep->nodetype == en_add || ep->nodetype == en_addstruc || ep->nodetype == en_array)
            {
                ENODE *ep3,  *ep4;
                ep3 = ep->v.p[0];
                ep4 = ep->v.p[1];
                while (castvalue(ep3))
                    ep3 = ep3->v.p[0];
                while (castvalue(ep4))
                    ep4 = ep4->v.p[0];
                if (!arr(ep3))
                {
                    ep = ep3;
                    ep3 = ep4;
                    ep4 = ep;
                }
                if (arr(ep3))
                {
                    if (lvalue(ep3))
                        ep3 = ep3->v.p[0];
                    if (arr(ep4))
                        generror(ERR_NEEDCONST, 0, 0);
                    else if (isintconst(ep4->nodetype))
                    {
                        makeref(ep3->nodetype == en_napccon ? 1 : 0, ((SYM*)
                            (ep3->v.sp)), ep4->v.i);
                    }
                    else if (isfloatconst(ep4->nodetype))
                    {
                        makeref(ep3->nodetype == en_napccon ? 1 : 0, ((SYM*)
                            (ep3->v.sp)), ep4->v.f);
                    }
                    else
                        generror(ERR_NEEDCONST, 0, 0);
                }
                else
                    generror(ERR_NEEDCONST, 0, 0);

            }
            else if (ep->nodetype == en_sub)
            {
                ENODE *ep3,  *ep4;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -