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

📄 symbol.c

📁 微软的基于HMM的人脸识别原代码, 非常经典的说
💻 C
📖 第 1 页 / 共 2 页
字号:
	  case t_struct:
	    if(type->alias)
		break;
	    s = EiC_getInf(type);
	    /*
	     * REM must allow for incomplete
	     * types.
	     */
	    if(!s)
		break;
	    xmark(s,mark);
	    if(!s->cl)
		break;
	    xmark(s->offset,mark);
	    xmark(s->id,mark);
	    xmark(s->type,mark);
	    for(i=0;i<s->n;i++) {
		xmark(s->id[i],mark);
		EiC_marktype(s->type[i],mark);
	    }
	    if(s->ntags) {
		xmark(s->tag,mark);
		for(i=0;i<s->ntags;++i)
		    EiC_marktype(s->tag[i],mark);
	    }
	    break;
	}
	type = nextType(type);
    }
}

static void marklabel(Label_t *l,char mark) 
{
    while(l) {
	xmark(l,mark);
	xmark(l->name,mark);
	l = l->nxt;
    }
}

static void markcode(symentry_t *sym,char mark)
{
    int i;
    InsT_t *inst;
    code_t * code;
    code = EiC_ENV->AR[sym->val.ival].v.p.p;
    xmark(code,mark);
    xmark(code->inst,mark);
    marklabel(code->labels,mark);
    marklabel(code->gotos,mark);

    inst = code->inst;
    for(i=0;i<code->nextinst;i++,inst++)
	if(inst->opcode == jmptab) {
	    eicstack_t * s;
	    s = inst->val.p.p;
	    xmark(s->val,mark);
	    xmark(s,mark);
	} else if(inst->opcode == assigntype)
	    EiC_marktype(inst->val.p.p,mark);
}


void EiC_marksyms(char mark)
{
    void EiC_markmacros(char);
    void EiC_markENV(char);
    
    int i;
    symentry_t * sym;

    EiC_markmacros(mark);
    
    if(EiC_ENV->AR)
	xmark(EiC_ENV->AR,mark);
    if(EiC_ENV->ARgar.n) 
	xmark(EiC_ENV->ARgar.val,mark);
    if(EiC_ENV->LAR)
	xmark(EiC_ENV->LAR,mark);
    if(EiC_ENV->CODE.nextinst)
	xmark(EiC_ENV->CODE.inst,mark);
    xmark(EiC_ENV,mark);

    EiC_markENV(mark);
    
    for(i=0;i<HSIZE;i++) {
	sym = EiC_HTAB[i];
	while(sym) {
	    /*printf("marking %s\n",sym->id);*/
	    if(strcmp(sym->id,"p") == 0)
	      sym->id = sym->id;
	    xmark(sym,mark);
	    xmark(sym->id,mark);
	    EiC_marktype(sym->type,mark);	    
	    if(sym->nspace != tag_tab)
		switch(EiC_gettype(sym->type)) {
		  case t_func: markcode(sym,mark); break;
		  case t_array:
		  case t_union:
		  case t_struct:
		    if(isconst(sym->type))
		       xmark(sym->val.p.p,mark);
		    else
			if(sym->sclass != c_typedef && sym->val.ival >= 0)
			    xmark(EiC_ENV->AR[sym->val.ival].v.p.p,mark);
		    break;
		}
	    sym = sym->next;
	}
    }
}


char * EiC_strsave(char *s)
{
    char *p;
    int n;

    for(n = 0,p =s; *p != '\0';++p,++n)
	;
    n++;
    p = xcalloc(n,sizeof(char));
    if(p) 
	while((*p++ = *s++));
    return p - n;
}

void EiC_newsymtype(symentry_t *sym, type_expr *t)
{
    if(sym) {
	if(sym->type && sym->type != t)
	    EiC_freetype(sym->type);
	sym->type = t;
    }
}

int nextstackitem(int level)
{
    if(level == 1) {		/* static variables */
	val_t v;
	if(!EiC_eicpop(&EiC_ENV->ARgar,&v))  { /* check for spare slots */
	    if(EiC_ENV->sp == EiC_ENV->ARsize) {
		if(!EiC_ENV->ARsize)
		    EiC_ENV->AR = (AR_t*)xcalloc(sizeof(AR_t),1);
		else
		    EiC_ENV->AR = (AR_t*)xrealloc(EiC_ENV->AR,
					      (EiC_ENV->sp+1)*sizeof(AR_t));
		EiC_ENV->ARsize++;
	    }
	    v.ival = EiC_ENV->sp;
	    EiC_ENV->sp++;
	}
	return v.ival;
    } else {			/* automatic variables */
	if(EiC_ENV->lsp == EiC_ENV->LARsize) {
	    if(!EiC_ENV->LARsize)
		EiC_ENV->LAR = (AR_t*)xcalloc(sizeof(AR_t),1);
	    else
		EiC_ENV->LAR = (AR_t*)xrealloc(EiC_ENV->LAR,(EiC_ENV->lsp+1)*
					   sizeof(AR_t));
	    EiC_ENV->LARsize++;
	}
	EiC_ENV->lsp++;
	return EiC_ENV->lsp - 1;
    }
}

int EiC_stackit(symentry_t * sym,int level)
{
    int i;
    AR_t * ar;
    
    i = nextstackitem(level);
    if(level == 1)		/* static variables */
	ar = EiC_ENV->AR;
    else 			/* local variable */	
	ar = EiC_ENV->LAR;

    sym->val.ival = i;

    ar[i].v.dval = 0; /* NULL it */
    ar[i].type = sym->type;
    return i;
}


/*------------------------------------------------*/
void EiC_inittoken(token_t * e1)
{
    e1->Pflag = 0;
    e1->Code.binst = e1->Code.nextinst = 0;
    e1->Code.labels = e1->Code.gotos = NULL;
    e1->Typequal = e1->Sclass = 0;
    e1->Sym = NULL;
    e1->Val.sym = NULL;
    e1->Type = NULL;
}
void EiC_freetoken(token_t * e1)
{
    EiC_freetype(e1->Type);
    e1->Type = NULL;
}
void initcode(code_t * code)
{
    code->binst = code->nextinst = 0;
}


void EiC_cleancode(code_t * code)
{
    unsigned int i;
    InsT_t *inst;

    if(!code)
	return;
    inst = code->inst;
    /* printf("Next instr: %d\n", code->nextinst); */
    /* rem free up other info also */
    for(i=0;i<code->nextinst;i++,inst++)
	if(inst->opcode == jmptab) {
	    eicstack_t *s;
	    s = inst->val.p.p;
	    xfree(s->val);
	    xfree(s);
	} else if(inst->opcode == assigntype)
	    EiC_freetype(inst->val.p.p);

}    

static void freeCodeLabels(code_t *code)
{
    void EiCp_freeLabels(Label_t *lab);
    if(code->labels) {
	EiCp_freeLabels(code->labels);
	code->labels = NULL;
    }
    if(code->gotos) {
	EiCp_freeLabels(code->gotos);
	code->gotos = NULL;
    }
}

void EiC_killcode(symentry_t *sym)
{
    code_t * code;
    code = EiC_ENV->AR[sym->val.ival].v.p.p;
    if(!code)
	return;
    EiC_cleancode(code);
    freeCodeLabels(code);
    xfree(code->inst);
    xfree(code);
}
void EiC_freecode(code_t * code)
{

    if(code && code->binst > 0) {
	xfree(code->inst);
	code->nextinst = code->binst = 0;
	freeCodeLabels(code);
    }
}

#define ModSize 5

void EiC_generate(code_t * code, int opcode,val_t *val,int ext)
{
    InsT_t * inst;
    inst = code->inst;
    if(code->nextinst == code->binst)
	if(!(code->binst%ModSize)) {
	    if(!code->binst)
		inst = (InsT_t*)xcalloc(1,sizeof(InsT_t)*ModSize);
	    else
		inst = (InsT_t*)
		    xrealloc(inst,(code->binst+ModSize)*sizeof(InsT_t));
	    code->binst += ModSize;
	}
    code->inst = inst;
    inst[code->nextinst].opcode = opcode;
    inst[code->nextinst].val = *val;
    inst[code->nextinst].ext = ext;
    inst[code->nextinst].line = CurrentLineNo();
    code->nextinst++;
}

#if 0
void copycode(code_t * c1, code_t * c2)
{
    /* this function needs to handle label and gotos */
    unsigned int i;
    InsT_t *inst;
    inst = c2->inst;
    for(i=0;i<c2->nextinst;++i,++inst) {
	EiC_generate(c1,inst->opcode,&inst->val,inst->ext);
	c1->inst[c1->nextinst-1].line = inst->line;
    }
}
#else
void copycode(code_t * c1, code_t * c2)
{
    Label_t * EiCp_addLabel(Label_t *, char *, int, int);
    InsT_t *inst;
    int h, Tsize;
    Label_t *lab;

    if(!c2->nextinst)
	return;
    /* concatenate labels*/
    if(c2->labels) {
	lab = c2->labels;
	while(lab) {
	    c1->labels = EiCp_addLabel(c1->labels,lab->name,lab->loc+c1->nextinst,1);
	    lab = lab->nxt;
	}
    }
    /* conatenate gotos */
    if(c2->gotos) {
	lab = c2->gotos;
	while(lab) {
	    c1->gotos = EiCp_addLabel(c1->gotos,lab->name,lab->loc+c1->nextinst,0);
	    lab = lab->nxt;
	}
    }

    Tsize = c1->nextinst + c2->nextinst;
    /* make memory size a multiple of ModSize */
    h = Tsize;
    if(Tsize%ModSize) 
	Tsize += ModSize - (Tsize%ModSize);
    if(c1->binst)
	c1->inst = xrealloc(c1->inst,Tsize*sizeof(InsT_t));
    else
	c1->inst = xcalloc(Tsize,sizeof(InsT_t));
    inst = c1->inst;
    memcpy(&inst[c1->nextinst], c2->inst, c2->nextinst * sizeof(InsT_t));
    c1->binst = Tsize;
    c1->nextinst = h;
}

#endif

void EiC_concode(code_t * c1, code_t * c2)
{
    copycode(c1,c2);
    EiC_freecode(c2);
}
void EiC_contoken(token_t * e1, token_t * e2)
{
    EiC_concode(&e1->Code,&e2->Code);
    e1->Type = EiC_getcontype(e1->Type,e2->Type);
    EiC_freetoken(e2);
}

void EiC_swaptokens(token_t *e1, token_t * e2)
{
    token_t e3;
    e3 = *e2;
    *e2 = *e1;
    *e1 = e3;
}
    

#if 0

typedef struct list_t {
    char * fname;
    struct list_t *nxt;
}list_t;


typdef struct llist_t {
    list_t **list;
    int n;
} llist_t;

static llist_t ** includes = NULL, ** included = NULL;

static int inllist(llist_t **list, char *fname)
{
    /* returns -1 if not in list */
    int i;
    for(i=0;i<list->n,++i) {
	if(fname == list->list[i]->fname == 0)
	    return i;
    }
    return -1;
}

static list_t * add2list(list_t *list, char *fname)
{
   list_t n = calloc(sizeof(list_t),1);
   n->fname = fname;
   n->nxt = list;
   return n;
}


static void add2includes(char *file, char * includes)
{
    int i = inlist(includes,file);

    if(i < 0) {
	i = includes->n;
	includes->list = realloc(includes->list, 
				 (includes->n + 1) * sizeof(*includes->list));
	
	includes->list = 
	includes





#endif

















⌨️ 快捷键说明

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