예제 #1
0
파일: ialias.c 프로젝트: jossk/OrangeC
static void CreateMem(IMODE *im)
{
    ALIASNAME *p;
    if (im->offset->type != en_pc && im->offset->type != en_sub)
    {
        if (im->mode == i_immed)
        {
            p = LookupMem(im->offset->v.sp->imvalue);
        }
        else
        {
            ALIASADDRESS *aa;
            p = LookupMem(im);
            p = LookupAliasName(p, 0);
        }
        if (im->size == ISZ_ADDR || im->offset->type == en_label || im->offset->type == en_global)
        {
            ALIASADDRESS *aa;
            aa = LookupAddress(p, 0);
            if (!aa->pointsto)
            {
                ALIASNAME *an = LookupAliasName(p, 0);
                aa->pointsto = aAlloc(sizeof(ALIASLIST));
                aa->pointsto->address = LookupAddress(an, 0);
            }
        }
    }
}
예제 #2
0
void AliasUses(BITINT *bits, IMODE *im, BOOLEAN rhs)
{
    if (im)
    {
        if (rhs)
        {
            if (im->offset->type == en_tempref)
            {
                ormap(bits, tempInfo[im->offset->v.sp->value.i]->modifiedBy);
                if (im->mode == i_direct)
                {
                    im = LookupLoadTemp(im, im);
                }
                setbit(bits, termMap[im->offset->v.sp->value.i]);
            }
            else if (im->mode == i_direct)
            {
                ALIASNAME *an = LookupMem(im);
                ALIASADDRESS *aa ;
                an = LookupAliasName(an, 0);
                aa = LookupAddress(an, 0);
                while (aa->merge) aa = aa->merge;
                if (aa->modifiedBy)
                    ormap(bits, aa->modifiedBy);
                im = GetLoadTemp(im);
                if (im)
                {
                    setbit(bits, termMap[im->offset->v.sp->value.i]);
                }
            }
            else if (im->mode == i_immed && !isintconst(im->offset) && 
                     !iscomplexconst(im->offset) &&
                     !isfloatconst(im->offset) && im->offset->type != en_labcon)
            {
                ALIASNAME *an = LookupMem(im);
                ALIASADDRESS *aa ;
                aa = LookupAddress(an, 0);
                while (aa->merge) aa = aa->merge;
                if (aa->modifiedBy)
                    ormap(bits, aa->modifiedBy);
                im = im->offset->v.sp->imvalue;
                if (im)
                {
                    im = GetLoadTemp(im);
                    if (im)
                    {
                        setbit(bits, termMap[im->offset->v.sp->value.i]);
                    }
                }
            }
        }
        else
        {
            setbit(bits, termMap[im->offset->v.sp->value.i]);
        }
    }
}
예제 #3
0
파일: ialias.c 프로젝트: jossk/OrangeC
static void HandleAssnBlock(QUAD *head)
{
    ALIASLIST *src=NULL, *dest=NULL;
    int i, n = head->ans->offset->v.i;
    if ((head->temps & TEMP_LEFT) && head->dc.left->mode == i_direct)
    {
        dest = tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto;
    }
    else if (head->dc.left->mode == i_immed)
    {
        ALIASNAME *an = LookupMem(head->dc.left);
        ALIASADDRESS *aa;
        an = LookupAliasName(an, 0);
        aa = LookupAddress(an, 0);
        dest = aa->pointsto;
    }
    else
    {
        diag("HandleAssnBlock: invalid dest type");
    }
    
    if (head->dc.right->mode == i_direct && ((head->temps & TEMP_RIGHT) || head->dc.right->retval))
    {
        src = tempInfo[head->dc.right->offset->v.sp->value.i]->pointsto;
    }
    else if (head->dc.right->mode == i_immed)
    {
        ALIASNAME *an = LookupMem(head->dc.right);
        ALIASADDRESS *aa;
        an = LookupAliasName(an, 0);
        aa = LookupAddress(an, 0);
        src = aa->pointsto;
    }
    else
    {
        diag("HandleAssnBlock: invalid src type");
    }
    for (i=0; i < n; i++)
    {
        ALIASLIST *lsrc = src;
        while (lsrc)
        {
            ALIASADDRESS *aasrc = GetAddress(lsrc->address->name, i);
			if (aasrc)
			{
				ALIASLIST *ldest = dest;
				while (ldest)
				{
					ALIASADDRESS *aadest = LookupAddress(ldest->address->name, i);
					AliasUnion(&aadest->pointsto, aasrc->pointsto);
					ldest = ldest->next;
				}
			}
			lsrc = lsrc->next;
		}
    }
}
예제 #4
0
static void HandleAssnBlock(QUAD *head)
{
    ALIASNAME *dest = NULL;
    if ((head->temps & TEMP_LEFT) && head->dc.left->mode == i_direct)
    {
        // we don't support writing to arbitrary memory, e.g. a pointer returned from a function call
        return;
    }
    else if (head->dc.left->mode == i_immed)
    {
        dest = LookupMem(head->dc.left);
        dest = LookupAliasName(dest, 0);
    }
    else
    {
        diag("HandleAssnBlock: invalid dest type");
    }
    
    if (head->dc.right->mode == i_direct && ((head->temps & TEMP_RIGHT) || head->dc.right->retval))
    {
        ALIASLIST *src = tempInfo[head->dc.right->offset->v.sp->value.i]->pointsto;
        while (src)
        {
            ALIASNAME *srcn = src->address->name;
            LIST *addr = srcn->addresses;
            while (addr)
            {
                ALIASADDRESS *aa= (ALIASADDRESS *)addr  ->data;
    		    ALIASADDRESS *aadest = LookupAddress(dest, aa->offset);
                AliasUnion(&aadest->pointsto, aa->pointsto);
                addr = addr->next;
            }
            src = src->next;
        }
    }
    else if (head->dc.right->mode == i_immed)
    {
        ALIASNAME *src = LookupMem(head->dc.right);
        LIST *addr;
        addr = src->addresses;
        while (addr)
        {
            ALIASADDRESS *aa= (ALIASADDRESS *)addr->data;
		    ALIASADDRESS *aadest = LookupAddress(dest, aa->offset);
            AliasUnion(&aadest->pointsto, aa->pointsto);
            addr = addr->next;
        }
    }
    else
    {
        diag("HandleAssnBlock: invalid src type");
    }
}
예제 #5
0
void AliasStruct(BITINT *bits, IMODE *ans, IMODE *left, IMODE *right)
{
    ALIASLIST *src;
    int i, n = ans->offset->v.i;
    if (left->offset->type == en_tempref && left->mode == i_direct)
    {
        src = tempInfo[left->offset->v.sp->value.i]->pointsto;
        while (src)
        {
            ALIASADDRESS *aa = src->address;
            while (aa->merge) aa = aa->merge;
            for (i=0; i < n; i++)
            {
                ALIASNAME *an = GetAliasName(aa->name, i);
				if (an)
				{
					ALIASADDRESS *aa2 = LookupAddress(an, 0);
					while (aa2->merge) aa2 = aa2->merge;
					if (aa2 && aa2->modifiedBy)
					{
						ormap(bits, aa2->modifiedBy);
					}
				}
            }
            src = src->next;
        }
        setbit(bits, termMap[left->offset->v.sp->value.i]);
        return;
    }
    else if (left->mode == i_immed)
    {
        ALIASNAME *an = LookupMem(left);
        ALIASADDRESS *aa;
        for (i=0; i < n; i++)
        {
            ALIASNAME *an2 = GetAliasName(an, i);
			if (an2)
			{
				aa = LookupAddress(an2, 0);
				while (aa->merge) aa = aa->merge;
				if (aa && aa->modifiedBy)
				{
					ormap(bits, aa->modifiedBy);
				}
				ResetProcessed();
				scanDepends(bits, aa->pointsto);
			}
        }
        return;
    }
    else
    {
        diag("AliasStruct: invalid src type");
    }	
}
예제 #6
0
static void HandleParm(QUAD *head)
{
    if (head->dc.left->size == ISZ_ADDR)
    {
        // temp, mem
        ALIASLIST *result = NULL, **base = NULL, *addr;
        if (head->temps & TEMP_LEFT)
        {
            base = &tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto;
        }
        else if (!isintconst(head->dc.left->offset))
        {
            ALIASNAME *an;
            ALIASADDRESS *aa;
            switch (head->dc.left->offset->type)
            {
                case en_labcon:
                case en_global:
                case en_label:
                case en_pc:
                case en_threadlocal:
                    return;
                default:
                    break;
            }
            an = LookupMem(head->dc.left->offset->v.sp->imvalue);
            if (head->dc.left->mode == i_direct)
                an = LookupAliasName(an, 0);
            aa = LookupAddress(an, 0);
            base = &aa->pointsto;
        }
        if (base)
        {
            addr = *base;
            AliasUnionParm(&parmList, (*base));
            while (addr)
            {
                if (addr->address->name->byUIV)
                {
                    if (!IntersectsUIV(addr->address->pointsto))
                    {
                        ALIASNAME *an = LookupAliasName(addr->address->name, 0);
                        ALIASADDRESS *aa = LookupAddress(an, 0);
                        ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                        al->address = aa;
                        AliasUnion(&addr->address->pointsto, al);
                    }
                }
                addr = addr->next;
            }
        }
    }
}
예제 #7
0
static void CreateMem(IMODE *im)
{
    ALIASNAME *p;
    if (im->offset->type != en_pc && im->offset->type != en_sub)
    {
        if (im->mode == i_immed)
        {
            if (!im->offset->v.sp->imvalue)
            {
                // make one in the case of global addresses that aren't used
                // directly
                IMODE *ap2 = (IMODE *)Alloc(sizeof(IMODE));
                ap2->offset = im->offset;
                ap2->mode = i_direct;
                ap2->size = ISZ_ADDR;
                im->offset->v.sp->imvalue = ap2;
            }
            p = LookupMem(im->offset->v.sp->imvalue);
        }
        else
        {
            ALIASADDRESS *aa;
            p = LookupMem(im);
            p = LookupAliasName(p, 0);
        }
        if (im->size == ISZ_ADDR || im->offset->type == en_label || im->offset->type == en_global)
        {
            ALIASADDRESS *aa;
            aa = LookupAddress(p, 0);
            if (!aa->pointsto)
            {
                ALIASNAME *an = LookupAliasName(p, 0);
                aa->pointsto = aAlloc(sizeof(ALIASLIST));
                aa->pointsto->address = LookupAddress(an, 0);
            }
        }
    }
}
예제 #8
0
static void HandleAdd(QUAD *head)
{
    if ((head->ans->size == ISZ_ADDR) && (head->temps & TEMP_ANS))
    {
        if (head->dc.opcode == i_add && head->dc.left->mode == i_immed)
        {
            if (head->temps & TEMP_RIGHT)
            {
                if (isintconst(head->dc.left->offset))
                {
                    // C + R
                    ALIASLIST *scan = tempInfo[head->dc.right->offset->v.sp->value.i]->pointsto;
                    ALIASLIST *result = NULL;
                    BOOLEAN xchanged = changed;
                    while (scan)
                    {
                        ALIASADDRESS *addr = LookupAddress(scan->address->name, scan->address->offset + head->dc.left->offset->v.i);
                        ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                        al->address = addr;
                        AliasUnion(&result, al);
                        scan = scan->next;
                    }
                    changed = xchanged;
                    AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, result);
                }
                else 
                {
                    // p + R
                    if (head->dc.left->offset->type != en_labcon) // needed for exports
                    {
                        ALIASNAME *nm = LookupMem(head->dc.left->offset->v.sp->imvalue);
                        ALIASADDRESS *aa = LookupAddress(nm, 0);
                        ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                        al->address = aa;
                        Infer(head->ans, head->dc.right, al);
                    }
                }
            }
            else if (head->dc.right->mode == i_immed)
            {
                if (!isintconst(head->dc.left->offset) && head->dc.left->offset->type != en_labcon)
                {
                    // p + C
                    ALIASNAME *nm = LookupMem(head->dc.left->offset->v.sp->imvalue);
                    ALIASADDRESS *aa = LookupAddress(nm, head->dc.right->offset->v.i);
                    ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                    al->address = aa;
                    AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto,al);
                }
                else if (!isintconst(head->dc.right->offset) && head->dc.right->offset->type != en_labcon)
                {
                    // C + p
                    ALIASNAME *nm = LookupMem(head->dc.right->offset->v.sp->imvalue);
                    ALIASADDRESS *aa = LookupAddress(nm, head->dc.left->offset->v.i);
                    ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                    al->address = aa;
                    AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, al);
                }
            }
        }
        else if (head->dc.right->mode == i_immed)
        {

            if (head->temps & TEMP_LEFT)
            {
                if (isintconst(head->dc.right->offset))
                {
                    // R+C
                    int c = head->dc.opcode == i_add ? head->dc.right->offset->v.i : -head->dc.right->offset->v.i;
                    ALIASLIST *scan = tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto;
                    ALIASLIST *result = NULL;
                    BOOLEAN xchanged = changed;
                    while (scan)
                    {
                        ALIASADDRESS *addr = LookupAddress(scan->address->name, scan->address->offset + c);
                        ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                        al->address = addr;
                        AliasUnion(&result, al);
                        scan = scan->next;
                    }
                    changed = xchanged;
                    AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, result);
                }
                else
                {
                    // R + p
                    if (head->dc.right->offset->type != en_labcon) // needed for exports
                    {
                        ALIASNAME *nm = LookupMem(head->dc.right->offset->v.sp->imvalue);
                        ALIASADDRESS *aa = LookupAddress(nm, 0);
                        ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                        al->address = aa;
                        Infer(head->ans, head->dc.left, al);
                    }
                }
            }
        }
        else if ((head ->temps & (TEMP_LEFT | TEMP_RIGHT)) == (TEMP_LEFT | TEMP_RIGHT))
        {
            // R+R
            ALIASLIST *src;
            IMODE *one = head->dc.left;
            IMODE *two = head->dc.right;
            if (two->size == ISZ_ADDR)
            {
                IMODE *three = one;
                one = two;
                two = three;
            }
            if (one->size == ISZ_ADDR)
            {
                // now one has the pointer, two has something else
                src = tempInfo[one->offset->v.sp->value.i]->pointsto;
                Infer(head->ans, two, src);
            }
        }
    }
}
예제 #9
0
static void HandleAssn(QUAD *head)
{
    if (head->ans == head->dc.left)
        return;
    if (head->ans->mode == i_ind)
    {
        if (head->temps & TEMP_LEFT)
        {
            // ind, temp
            ALIASLIST *addr;
            ALIASLIST *src = tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto;
            addr = tempInfo[head->ans->offset->v.sp->value.i]->pointsto;
            while (addr)
            {
                AliasUnion(&addr->address->pointsto, src);
                addr = addr->next;
            }
        }
        else if (head->dc.left->mode == i_immed && head->dc.left->size == ISZ_ADDR && head->dc.left->offset->type != en_labcon )
        {
            // ind, immed
            ALIASLIST *addr;
            ALIASNAME *an = LookupMem(head->ans->offset->v.sp->imvalue);
            ALIASADDRESS *aa;
            if (head->ans->mode == i_direct)
                an = LookupAliasName(an, 0);
            aa = LookupAddress(an, 0);
            addr = tempInfo[head->ans->offset->v.sp->value.i]->pointsto;
            while (addr)
            {
                AliasUnion(&addr->address->pointsto, aa->pointsto);
                addr = addr->next;
            }
        }
    }
    else if (head->dc.left->mode == i_ind && (head->temps & TEMP_ANS))
    {
        // temp, ind
        ALIASLIST *result = NULL;
        ALIASLIST *addr = tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto;
        BOOLEAN xchanged = changed;
        while (addr)
        {
            if (addr->address->name->byUIV)
            {
                if (!IntersectsUIV(addr->address->pointsto))
                {
                    ALIASNAME *an = LookupAliasName(addr->address->name, addr->address->offset);
                    ALIASADDRESS *aa = LookupAddress(an, 0);
                    ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                    al->address = aa;
                    AliasUnion(&addr->address->pointsto, al);
                }
            }
            AliasUnion(&result, addr->address->pointsto);
            addr = addr->next;
        }
        changed = xchanged;
        tempInfo[head->ans->offset->v.sp->value.i]->pointsto = result;
    }
    else if (head->ans->size == ISZ_ADDR)
    {
        if (!(head->temps & TEMP_ANS) && !head->ans->retval)
        {
            if (head->temps & TEMP_LEFT)
            {
                // mem, temp
                ALIASLIST *al;
                ALIASNAME *an = LookupMem(head->ans);
                ALIASADDRESS *aa;
                an = LookupAliasName(an, 0);
                aa = LookupAddress(an, 0);
                AliasUnion(&aa->pointsto, tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto);
            }
            else if (head->dc.left->mode == i_immed && head->dc.left->size == ISZ_ADDR && head->dc.left->offset->type != en_labcon )
            {
                // mem, immed
                ALIASNAME *an2 = LookupMem(head->dc.left);
                ALIASADDRESS *aa2 = LookupAddress(an2, 0);
                ALIASNAME *an = LookupMem(head->ans->offset->v.sp->imvalue);
                ALIASADDRESS *aa;
                ALIASLIST *al = aAlloc(sizeof(ALIASLIST));
                al->address = aa2;
                if (head->ans->mode == i_direct)
                    an = LookupAliasName(an, 0);
                aa = LookupAddress(an, 0);
                AliasUnion(&aa->pointsto, al);
            }
        }
        else if (head->temps & TEMP_ANS)
        {			
            if (head->dc.left->mode == i_immed && head->dc.left->size == ISZ_ADDR && head->dc.left->offset->type != en_labcon&& !isintconst(head->dc.left->offset) )
            {
                // temp, immed
                BOOLEAN xchanged = changed;
                ALIASNAME *an = LookupMem(head->dc.left);
                ALIASADDRESS *aa = LookupAddress(an, 0);
                ALIASLIST *al = (ALIASLIST *)aAlloc(sizeof(ALIASLIST));
                al->address = aa;
                tempInfo[head->ans->offset->v.sp->value.i]->pointsto = NULL;
                AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, al);
                changed = xchanged;
            }
            else if (head->dc.left->retval)
            {
                AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, parmList);
            }
            else if (!(head->temps & TEMP_LEFT) && head->dc.left->mode == i_direct)
            {
                // temp, mem
                ALIASLIST *result = NULL;
                ALIASNAME *an = LookupMem(head->dc.left);
                ALIASADDRESS *aa;
                ALIASLIST *addr;
                BOOLEAN xchanged = changed;
                an = LookupAliasName(an, 0);
                aa = LookupAddress(an, 0);
                AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, aa->pointsto);
                changed = xchanged;
            }
            else if (head->temps & TEMP_LEFT)
            {
                // temp, temp
                AliasUnion(&tempInfo[head->ans->offset->v.sp->value.i]->pointsto, tempInfo[head->dc.left->offset->v.sp->value.i]->pointsto);
            }
        }
    }
}