📄 probe_comp.c
字号:
#include "atlconf.h"COMPNODE *GetCompNode(void){ COMPNODE *p; p = calloc(1, sizeof(COMPNODE)); assert(p); return(p);}COMPNODE *KillCompNode(COMPNODE *die){ COMPNODE *p=NULL; if (die) { p = die->next; if (die->comp) free(die->comp); if (die->flags) free(die->flags); free(die); } return(p);}void KillAllCompNodes(COMPNODE *kill){ while(kill) kill = KillCompNode(kill);}COMPNODE *CloneCompNode(COMPNODE *orig){ COMPNODE *new; new = GetCompNode();/* * Copy everything but strings wt memcopy */ memcpy(new, orig, sizeof(COMPNODE)); if (orig->comp) { new->comp = malloc(sizeof(char)*(strlen(orig->comp)+1)); assert(new->comp); strcpy(new->comp, orig->comp); } if (orig->flags) { new->flags = malloc(sizeof(char)*(strlen(orig->flags)+1)); assert(new->flags); strcpy(new->flags, orig->flags); } return(new);}void PrintCompNodes(FILE *fpout, COMPNODE *q, char *id){ int i; COMPNODE *p; fprintf(fpout, "\nCompiler nodes: %s\n", id); if (!q) fprintf(fpout, "***NONE***\n"); for (i=0, p=q; p; p=p->next, i++) { fprintf(fpout, "%3d. priority=%d, comps,OS,arch[0]=(%d,%d,%d), comp='%s'\n", i, p->priority, p->comps[0], p->OS[0], p->arch[0], p->comp); fprintf(fpout, " '%s'\n", p->flags); } fprintf(fpout, "\n");}COMPNODE *SortCompsByPriority(COMPNODE *q)/* * Builds new queue out of q, by first adding largest priority to newq, etc. */{ COMPNODE *newq=NULL, *p, *prev, *maxprev; int maxpri; while(q) /* BFI N^2 sort */ {/* * Find remaining element wt largest priority */ maxprev = NULL; prev = q; maxpri = q->priority; for (p=q->next; p; p = p->next) { if (p->priority > maxpri) { maxpri = p->priority; maxprev = prev; } prev = p; }/* * Take max node off of q, add to newq */ if (maxprev) /* max elt wasn't stop of stack (q) */ { p = maxprev->next->next; maxprev->next->next = newq; newq = maxprev->next; maxprev->next = p; } else { p = q->next; q->next = newq; newq = q; q = p; } } return(newq);}void DivideCompsByComp(COMPNODE *q, COMPNODE **comps)/* * Builds individual queues for each compiler camp, and then kills the original * queue. Note that original q is sorted smallest-to-largest, and since we * add in order to a stack, we wind up with largest-to-smallest, as we want. * Note comps is really COMPNODE *comps[NCOMP], and can be indexed by ICC_, etc. */{ int i; COMPNODE *p, *new; for (i=0; i < NCOMP; i++) comps[i] = NULL; for (p=q; p; p = p->next) { for (i=0; i < NCOMP; i++) { if (IsBitSetInField(p->comps, i)) { new = CloneCompNode(p); new->next = comps[i]; comps[i] = new; } } } KillAllCompNodes(q);}static int OSMatches(enum OSTYPE OS, int *bits)/* * RETURNS: 0 if no OS of arch in bitfield, nonzero otherwise */{ if (IsBitSetInField(bits, 0)) /* If 0 bit set, matches all OS */ return(1); if (IsBitSetInField(bits, OS)) /* If OS bit set, matches this OS */ return(2); return(0);}static int ArchMatches(enum MACHTYPE arch, int *bits)/* * RETURNS: 0 if no match of arch in bitfield, nonzero otherwise */{ if (IsBitSetInField(bits, 0)) /* If 0 bit set, matches all archs */ return(1); if (IsBitSetInField(bits, arch)) /* If arch bit set, matches this arch */ return(2); return(0);}COMPNODE *KillBadArchOS(enum OSTYPE OS, enum MACHTYPE arch, COMPNODE *q)/* * Deletes all non-matching OS/arch from queue; Note any node wt these * quantities set to 0 is a wildcard, and so stays */{ COMPNODE *prev, *next, *p; if (!OS && !arch) return(q);/* * Delete all beginning nodes until we find one for this arch */ while(q && (!ArchMatches(arch, q->arch) || !OSMatches(OS, q->OS))) q = KillCompNode(q);/* * With good top of stack, delete trailing nodes that don't match */ if (q) { prev = q; for (p=q->next; p; p = next) { next = p->next; if (!ArchMatches(arch, p->arch) || !OSMatches(OS, p->OS)) prev->next = KillCompNode(p); else prev = p; } } return(q);}int OSNameToInt(char *name){ int i; for (i=1; i < NOS; i++) { if (!strcmp(name, osnam[i])) return(i); } return(0);}int MachNameToInt(char *name){ int i; for (i=1; i < NMACH; i++) { if (!strcmp(name, machnam[i])) return(i); } return(0);}void NamesToBitField(int MACH, char *str, int *bits)/* * Takes a list of machine (MACH=1) or OS (MACH=0) names and translates them * to their enumerated type numbers, and sets the appropriate bit in the * bits field */{ char name[128]; int i=0; while(*str) { if (*str == ',' || *str == ' ' || *str == '\t' || *str == '\n' || *str == '\0') { /* finished a name */ name[i] = '\0'; if (!strcmp(name, "all") || !strcmp(name, "ALL")) i = 0; else { if (MACH) i = MachNameToInt(name); else i = OSNameToInt(name); if (!i) { fprintf(stderr, "Nonsensical %s name in list: %s\n", MACH ? "machine" : "OS", str); exit(1); } } SetBitInField(bits, i); if (*str != ',') /* anything but ',' ends list */ return; str++; i = 0; } else name[i++] = *str++; }}void NumListToBitfield(char *str, int *bits)/* * Takes a list of number like : '5,3,2,8,0' and turns on those bits */{ char num[16], *sp; int i, j; while (*str) { for (sp=num,i=0; i < 15; i++) { if (!isdigit(str[i])) break; *sp++ = str[i]; } assert(i != 15); *sp = '\0'; j = atoi(num); SetBitInField(bits, j); if (str[i] != ',') break; str += i+1; }}COMPNODE *ParseNewCompLine(char *ln){ COMPNODE *p; char *sp; p = GetCompNode(); sp = strstr(ln, "MACH="); assert(sp); sp += 5;/* NumListToBitfield(sp, p->arch); */ NamesToBitField(1, sp, p->arch); sp = strstr(ln, "OS="); assert(sp); sp += 3;/* NumListToBitfield(sp, p->OS); */ NamesToBitField(0, sp, p->OS); sp = strstr(ln, "LVL="); assert(sp); sp += 4; p->priority = atoi(sp);/* * Parse 'COMPS=[icc,smc,dmc,skc,dkc,xcc,f77]', at least one comp must exist */ sp = strstr(ln, "COMPS="); assert(sp); sp += 6; while (*sp) { if (sp[0] == 'i' && sp[1] == 'c' && sp[2] == 'c') SetBitInField(p->comps, ICC_); else if (sp[0] == 's' && sp[1] == 'm' && sp[2] == 'c') SetBitInField(p->comps, SMC_); else if (sp[0] == 'd' && sp[1] == 'm' && sp[2] == 'c') SetBitInField(p->comps, DMC_); else if (sp[0] == 's' && sp[1] == 'k' && sp[2] == 'c') SetBitInField(p->comps, SKC_); else if (sp[0] == 'd' && sp[1] == 'k' && sp[2] == 'c') SetBitInField(p->comps, DKC_); else if (sp[0] == 'x' && sp[1] == 'c' && sp[2] == 'c') SetBitInField(p->comps, XCC_); else if (sp[0] == 'f' && sp[1] == '7' && sp[2] == '7') SetBitInField(p->comps, F77_); else { fprintf(stderr, "WTF(%d of %s): '%s'??\n", __LINE__, __FILE__, sp); exit(-1); } if (sp[3] != ',') break; sp += 4; } return(p);}char *CopySingleQuoteString(char *str, char *out)/* * Finds the leading ' in str, and copies quoted text to out until closing ' * is found or end of string. * RETURNS: pointer in str at closing ', NULL if closing ' not found */{/* * Skip text before staring quote, return if quote not found */ *out = '\0'; while (*str != '\'' && *str) str++; if (*str == '\0') return(NULL);/* * Copy quoted text, return pointer to end quote if it exists */ str++; while (*str != '\'' && *str) *out++ = *str++; *out++ = '\0'; if (*str == '\'') return(str); return(NULL);}COMPNODE *ParseCompLine(char *ln){ static int NewComp=1; static COMPNODE *p=NULL; int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -