Exemplo n.º 1
0
void
symstr_component_dump(struct symstr_component *sc)
{
	if (sc->alphasym == NULL) {
		if (sc->op == SYMSTR_OP_NOP) {
			symbol_print(sc->sym);
		} else {
			fprintf(stderr, "(");
			if (sc->op == SYMSTR_OP_PRED)
				fprintf(stderr, "pred ");
			else if (sc->op == SYMSTR_OP_SUCC)
				fprintf(stderr, "succ ");
			else if (sc->op == SYMSTR_OP_PREV)
				fprintf(stderr, "prev ");
			else if (sc->op == SYMSTR_OP_NEXT)
				fprintf(stderr, "next ");
			symbol_print(sc->sym);
			if (sc->fmode != NULL) {
				fprintf(stderr, " | ");
				symstr_components_dump(sc->fmode->head);
			}
			fprintf(stderr, ")");
		}
	} else {
		fprintf(stderr, "(");
		symbol_print(sc->sym);
		fprintf(stderr, " = ");
		symbol_print(sc->alphasym);
		if (sc->many)
			fprintf(stderr, "+");
		fprintf(stderr, ")");
	}
}
Exemplo n.º 2
0
void expr_resolve( struct expr *e )
{
	if (!e) return;
	expr_resolve(e->left);
	expr_resolve(e->right);
	
	if (e->kind == EXPR_NAME) {
		struct symbol *s = scope_lookup(e->name);
		if (s) {
			e->symbol = s;
			printf("%s resovles to ", e->name );
			symbol_print( s );
			printf("\n");
		} else {
			printf("variable %s not defined\n", e->name);
			exit(1);
		}
	}

	if (e->kind == EXPR_FUNCTION_VAL) {
		struct symbol *s = scope_lookup(e->name);
		if (s) {
			e->symbol = s;
			printf("%s resovles to ", e->name );
			symbol_print( s );
			printf("\n");			
		} else {
			printf("variable function %s not defined\n", e->name);
			exit(1);
		}
	}

	expr_resolve(e->next);
}
Exemplo n.º 3
0
void
symbol_table_dump(Symbol *symtab)
{
    Symbol *temp = symtab;

    for (temp = symtab->next; temp != NULL; temp = temp->next)
        symbol_print(temp);
}
Exemplo n.º 4
0
void
symbol_show(object_t *obj)
{
    symbol_t *p;

    for (p = (symbol_t *)obj; p != NULL; p = p->next)
        symbol_print(p);
}
Exemplo n.º 5
0
void symbol_print_all(FILE* fp)
{
   Symbol* sym;
   
   assert(fp != NULL);

   for(sym = anchor; sym != NULL; sym = sym->next)
      symbol_print(fp, sym);
}
Exemplo n.º 6
0
Arquivo: cgcs.c Projeto: denis-sh/dmd
STATIC void touchlvalue(elem *e)
{ register int i;

  if (e->Eoper == OPind)                /* if indirect store            */
  {
        /* NOTE: Some types of array assignments do not need
         * to touch all variables. (Like a[5], where a is an
         * array instead of a pointer.)
         */

        touchfunc(0);
        return;
  }

  for (i = hcstop; --i >= 0;)
  {     if (hcstab[i].Helem &&
            hcstab[i].Helem->EV.sp.Vsym == e->EV.sp.Vsym)
                hcstab[i].Helem = NULL;
  }

    assert(e->Eoper == OPvar || e->Eoper == OPrelconst);
    switch (e->EV.sp.Vsym->Sclass)
    {
        case SCregpar:
        case SCregister:
        case SCtmp:
        case SCpseudo:
            break;
        case SCauto:
        case SCparameter:
        case SCfastpar:
        case SCshadowreg:
        case SCbprel:
            if (e->EV.sp.Vsym->Sflags & SFLunambig)
                break;
            /* FALL-THROUGH */
        case SCstatic:
        case SCextern:
        case SCglobal:
        case SClocstat:
        case SCcomdat:
        case SCinline:
        case SCsinline:
        case SCeinline:
        case SCcomdef:
            touchstar();
            break;
        default:
#ifdef DEBUG
            elem_print(e);
            symbol_print(e->EV.sp.Vsym);
#endif
            assert(0);
    }
}
Exemplo n.º 7
0
void
symbol_list_print (const symbol_list *l, FILE *f)
{
  for (/* Nothing. */; l && l->sym; l = l->next)
    {
      symbol_print (l->sym, f);
      fprintf (stderr, l->used ? " used" : " unused");
      if (l && l->sym)
	fprintf (f, ", ");
    }
}
Exemplo n.º 8
0
void
symbol_list_syms_print (const symbol_list *l, FILE *f)
{
  for (/* Nothing. */; l && l->content.sym; l = l->next)
    {
      symbol_print (l->content.sym, f);
      fprintf (stderr, l->action_props.is_value_used ? " used" : " unused");
      if (l && l->content.sym)
	fprintf (f, ", ");
    }
}
Exemplo n.º 9
0
STATIC int cpp_protection(symbol *s)
{   int i;

    switch (s->Sflags & SFLpmask)
    {   case SFLprivate:        i = 0;  break;
        case SFLprotected:      i = 1;  break;
        case SFLpublic:         i = 2;  break;
        default:
            symbol_print(s);
            assert(0);
    }
    return i;
}
Exemplo n.º 10
0
//Resolves the name of an expression
void expr_resolve(struct expr *e){
	if(!e) return;
	expr_resolve(e->left);
	expr_resolve(e->right);
	if(e->kind == EXPR_IDENT) {
		e->symbol = scope_lookup(e->name);
		if(e->symbol) {
			printf("%s resolves to ");
			symbol_print(e->symbol);
		} else { //not defined in this scope
			e->symbol = 0;
			resolve_error(e->name);
		}
	}
}
Exemplo n.º 11
0
void
symbol_list_syms_print (const symbol_list *l, FILE *f)
{
  char const *sep = "";
  for (/* Nothing. */; l && l->content.sym; l = l->next)
    {
      fputs (sep, f);
      fputs (l->content_type == SYMLIST_SYMBOL ? "symbol: "
             : l->content_type == SYMLIST_TYPE ? "type: "
             : "invalid content_type: ",
             f);
      symbol_print (l->content.sym, f);
      fputs (l->action_props.is_value_used ? " used" : " unused", f);
      sep = ", ";
    }
}
Exemplo n.º 12
0
void sliceStructs()
{
    if (debugc) printf("sliceStructs()\n");
    size_t sia_length = globsym.top;
    /* 3 is because it is used for two arrays, sia[] and sia2[].
     * sia2[] can grow to twice the size of sia[], as symbols can get split into two.
     */
    SymInfo *sia = (SymInfo *)malloc(3 * sia_length * sizeof(SymInfo));
    assert(sia);
    SymInfo *sia2 = sia + sia_length;

    bool anySlice = false;
    for (int si = 0; si < globsym.top; si++)
    {
        Symbol *s = globsym.tab[si];
        //printf("slice1: %s\n", s->Sident);

        if ((s->Sflags & (GTregcand | SFLunambig)) != (GTregcand | SFLunambig))
        {
            sia[si].canSlice = false;
            continue;
        }

        targ_size_t sz = type_size(s->Stype);
        if (sz != 2 * REGSIZE ||
            tyfv(s->Stype->Tty) || tybasic(s->Stype->Tty) == TYhptr)    // because there is no TYseg
        {
            sia[si].canSlice = false;
            continue;
        }

        switch (s->Sclass)
        {
            case SCfastpar:
            case SCregister:
            case SCauto:
            case SCshadowreg:
            case SCparameter:
                anySlice = true;
                sia[si].canSlice = true;
                sia[si].accessSlice = false;
                // We can't slice whole XMM registers
                if (tyxmmreg(s->Stype->Tty) &&
                    s->Spreg >= XMM0 && s->Spreg <= XMM15 && s->Spreg2 == NOREG)
                {
                    sia[si].canSlice = false;
                }
                break;

            case SCstack:
            case SCpseudo:
            case SCstatic:
            case SCbprel:
                sia[si].canSlice = false;
                break;

            default:
                symbol_print(s);
                assert(0);
        }
    }

    if (!anySlice)
        goto Ldone;

    for (block *b = startblock; b; b = b->Bnext)
    {
        if (b->BC == BCasm)
            goto Ldone;
        if (b->Belem)
            sliceStructs_Gather(sia, b->Belem);
    }

    {   // scope needed because of goto skipping declarations
        bool any = false;
        int n = 0;              // the number of symbols added
        for (int si = 0; si < sia_length; si++)
        {
            sia2[si + n].canSlice = false;
            if (sia[si].canSlice)
            {
                // If never did access it as a slice, don't slice
                if (!sia[si].accessSlice)
                {
                    sia[si].canSlice = false;
                    continue;
                }

                /* Split slice-able symbol sold into two symbols,
                 * (sold,snew) in adjacent slots in the symbol table.
                 */
                Symbol *sold = globsym.tab[si + n];

                size_t idlen = 2 + strlen(sold->Sident) + 2;
                char *id = (char *)malloc(idlen + 1);
                assert(id);
                sprintf(id, "__%s_%d", sold->Sident, REGSIZE);
                if (debugc) printf("creating slice symbol %s\n", id);
                Symbol *snew = symbol_calloc(id, idlen);
                free(id);
                snew->Sclass = sold->Sclass;
                snew->Sfl = sold->Sfl;
                snew->Sflags = sold->Sflags;
                if (snew->Sclass == SCfastpar || snew->Sclass == SCshadowreg)
                {
                    snew->Spreg = sold->Spreg2;
                    snew->Spreg2 = NOREG;
                    sold->Spreg2 = NOREG;
                }
                type_free(sold->Stype);
                sold->Stype = type_fake(sia[si].ty0);
                sold->Stype->Tcount++;
                snew->Stype = type_fake(sia[si].ty1);
                snew->Stype->Tcount++;

                SYMIDX sinew = symbol_add(snew);
                for (int i = sinew; i > si + n + 1; --i)
                {
                    globsym.tab[i] = globsym.tab[i - 1];
                    globsym.tab[i]->Ssymnum += 1;
                }
                globsym.tab[si + n + 1] = snew;
                snew->Ssymnum = si + n + 1;

                sia2[si + n].canSlice = true;
                sia2[si + n].si0 = si + n;
                sia2[si + n].ty0 = sia[si].ty0;
                sia2[si + n].ty1 = sia[si].ty1;
                ++n;
                any = true;
            }
        }
        if (!any)
            goto Ldone;
    }

    for (int si = 0; si < globsym.top; si++)
    {
        Symbol *s = globsym.tab[si];
        assert(s->Ssymnum == si);
    }

    for (block *b = startblock; b; b = b->Bnext)
    {
        if (b->Belem)
            sliceStructs_Replace(sia2, b->Belem);
    }

Ldone:
    free(sia);
}