/* bbvars - emit definition for basic block counting data */ static void bbvars(Symbol yylink) { int i, j, n = npoints; Value v; struct map** mp; Symbol coords, files, *p; if (!YYcounts && !yylink) return; if (YYcounts) { if (n <= 0) n = 1; YYcounts->type = array(unsignedtype, n, 0); defglobal(YYcounts, BSS); } files = genident(STATIC, array(charptype, 1, 0), GLOBAL); defglobal(files, LIT); for (p = ltov(&filelist, PERM); *p; p++) defpointer((*p)->u.c.loc); defpointer(NULL); coords = genident(STATIC, array(unsignedtype, n, 0), GLOBAL); defglobal(coords, LIT); for (i = n, mp = ltov(&maplist, PERM); *mp; i -= (*mp)->size, mp++) for (j = 0; j < (*mp)->size; j++) (*IR->defconst)(U, unsignedtype->size, (v.u = (*mp)->u[j].coord, v)); if (i > 0) (*IR->space)(i * coords->type->type->size); defpointer(NULL); defglobal(yylink, DATA); defpointer(NULL); (*IR->defconst)(U, unsignedtype->size, (v.u = n, v)); defpointer(YYcounts); defpointer(coords); defpointer(files); defpointer(funclist); }
#include "c.h" static char rcsid[] = "main.c - faked rcsid"; static void typestab(Symbol, void *); static void stabline(Coordinate *); static void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *); Interface *IR = NULL; int Aflag; /* >= 0 if -A specified */ int Pflag; /* != 0 if -P specified */ int glevel; /* == [0-9] if -g[0-9] specified */ int xref; /* != 0 for cross-reference data */ Symbol YYnull; /* _YYnull symbol if -n or -nvalidate specified */ Symbol YYcheck; /* _YYcheck symbol if -nvalidate,check specified */ static char *comment; static Interface stabIR; static char *currentfile; /* current file name */ static int currentline; /* current line number */ static FILE *srcfp; /* stream for current file, if non-NULL */ static int srcpos; /* position of srcfp, if srcfp is non-NULL */ int main(int argc, char *argv[]) { int i, j; for (i = argc - 1; i > 0; i--) if (strncmp(argv[i], "-target=", 8) == 0) break; if (i > 0) { char *s = strchr(argv[i], '\\'); if (s != NULL) *s = '/'; for (j = 0; bindings[j].name && bindings[j].ir; j++) if (strcmp(&argv[i][8], bindings[j].name) == 0) { IR = bindings[j].ir; break; } if (s != NULL) *s = '\\'; } if (!IR) { fprint(stderr, "%s: unknown target", argv[0]); if (i > 0) fprint(stderr, " `%s'", &argv[i][8]); fprint(stderr, "; must specify one of\n"); for (i = 0; bindings[i].name; i++) fprint(stderr, "\t-target=%s\n", bindings[i].name); exit(EXIT_FAILURE); } init(argc, argv); t = gettok(); (*IR->progbeg)(argc, argv); if (glevel && IR->stabinit) (*IR->stabinit)(firstfile, argc, argv); program(); if (events.end) apply(events.end, NULL, NULL); memset(&events, 0, sizeof events); if (glevel || xref) { Symbol symroot = NULL; Coordinate src; foreach(types, GLOBAL, typestab, &symroot); foreach(identifiers, GLOBAL, typestab, &symroot); src.file = firstfile; src.x = 0; src.y = lineno; if ((glevel > 2 || xref) && IR->stabend) (*IR->stabend)(&src, symroot, ltov(&loci, PERM), ltov(&symbols, PERM), NULL); else if (IR->stabend) (*IR->stabend)(&src, NULL, NULL, NULL, NULL); } finalize(); (*IR->progend)(); deallocate(PERM); return errcnt > 0; }
/* * Return a looped back vnode for the given vnode. * If no lnode exists for this vnode create one and put it * in a table hashed by vnode. If the lnode for * this vnode is already in the table return it (ref count is * incremented by lfind). The lnode will be flushed from the * table when lo_inactive calls freelonode. The creation of * a new lnode can be forced via the LOF_FORCE flag even if * the vnode exists in the table. This is used in the creation * of a terminating lnode when looping is detected. A unique * lnode is required for the correct evaluation of the current * working directory. * NOTE: vp is assumed to be a held vnode. */ struct vnode * makelonode(struct vnode *vp, struct loinfo *li, int flag) { lnode_t *lp, *tlp; struct vfs *vfsp; vnode_t *nvp; lp = NULL; TABLE_LOCK_ENTER(vp, li); if (flag != LOF_FORCE) lp = lfind(vp, li); if ((flag == LOF_FORCE) || (lp == NULL)) { /* * Optimistically assume that we won't need to sleep. */ lp = kmem_cache_alloc(lnode_cache, KM_NOSLEEP); nvp = vn_alloc(KM_NOSLEEP); if (lp == NULL || nvp == NULL) { TABLE_LOCK_EXIT(vp, li); /* The lnode allocation may have succeeded, save it */ tlp = lp; if (tlp == NULL) { tlp = kmem_cache_alloc(lnode_cache, KM_SLEEP); } if (nvp == NULL) { nvp = vn_alloc(KM_SLEEP); } lp = NULL; TABLE_LOCK_ENTER(vp, li); if (flag != LOF_FORCE) lp = lfind(vp, li); if (lp != NULL) { kmem_cache_free(lnode_cache, tlp); vn_free(nvp); VN_RELE(vp); goto found_lnode; } lp = tlp; } atomic_inc_32(&li->li_refct); vfsp = makelfsnode(vp->v_vfsp, li); lp->lo_vnode = nvp; VN_SET_VFS_TYPE_DEV(nvp, vfsp, vp->v_type, vp->v_rdev); nvp->v_flag |= (vp->v_flag & (VNOMOUNT|VNOMAP|VDIROPEN)); vn_setops(nvp, lo_vnodeops); nvp->v_data = (caddr_t)lp; lp->lo_vp = vp; lp->lo_looping = 0; lsave(lp, li); vn_exists(vp); } else { VN_RELE(vp); } found_lnode: TABLE_LOCK_EXIT(vp, li); return (ltov(lp)); }
/* * Lookup a lnode by vp */ static lnode_t * lfind(struct vnode *vp, struct loinfo *li) { lnode_t *lt; ASSERT(MUTEX_HELD(TABLE_LOCK(vp, li))); lt = TABLE_BUCKET(vp, li); while (lt != NULL) { if (lt->lo_vp == vp) { VN_HOLD(ltov(lt)); return (lt); } lt = lt->lo_next; } return (NULL); }
#include "c.h" static char rcsid[] = "$Name: v4_2 $($Id: main.c,v 1.1 2002/08/28 23:12:44 drh Exp $)"; static void typestab(Symbol, void *); static void stabline(Coordinate *); static void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *); Interface *IR = NULL; int Aflag; /* >= 0 if -A specified */ int Pflag; /* != 0 if -P specified */ int glevel; /* == [0-9] if -g[0-9] specified */ int xref; /* != 0 for cross-reference data */ Symbol YYnull; /* _YYnull symbol if -n or -nvalidate specified */ Symbol YYcheck; /* _YYcheck symbol if -nvalidate,check specified */ static char *comment; static Interface stabIR; static char *currentfile; /* current file name */ static int currentline; /* current line number */ static FILE *srcfp; /* stream for current file, if non-NULL */ static int srcpos; /* position of srcfp, if srcfp is non-NULL */ int main(int argc, char *argv[]) { int i, j; for (i = argc - 1; i > 0; i--) if (strncmp(argv[i], "-target=", 8) == 0) break; if (i > 0) { char *s = strchr(argv[i], '\\'); if (s != NULL) *s = '/'; for (j = 0; bindings[j].name && bindings[j].ir; j++) if (strcmp(&argv[i][8], bindings[j].name) == 0) { IR = bindings[j].ir; break; } if (s != NULL) *s = '\\'; } if (!IR) { fprint(stderr, "%s: unknown target", argv[0]); if (i > 0) fprint(stderr, " `%s'", &argv[i][8]); fprint(stderr, "; must specify one of\n"); for (i = 0; bindings[i].name; i++) fprint(stderr, "\t-target=%s\n", bindings[i].name); exit(EXIT_FAILURE); } init(argc, argv); t = gettok(); (*IR->progbeg)(argc, argv); for (i = 1; i < argc; i++) if (strcmp(argv[i], "-n") == 0) { if (!YYnull) { YYnull = install(string("_YYnull"), &globals, GLOBAL, PERM); YYnull->type = func(voidptype, NULL, 1); YYnull->sclass = EXTERN; (*IR->defsymbol)(YYnull); } } else if (strncmp(argv[i], "-n", 2) == 0) { /* -nvalid[,check] */ char *p = strchr(argv[i], ','); if (p) { YYcheck = install(string(p+1), &globals, GLOBAL, PERM); YYcheck->type = func(voidptype, NULL, 1); YYcheck->sclass = EXTERN; (*IR->defsymbol)(YYcheck); p = stringn(argv[i]+2, p - (argv[i]+2)); } else p = string(argv[i]+2); YYnull = install(p, &globals, GLOBAL, PERM); YYnull->type = func(voidptype, NULL, 1); YYnull->sclass = EXTERN; (*IR->defsymbol)(YYnull); } else { profInit(argv[i]); traceInit(argv[i]); } if (glevel && IR->stabinit) (*IR->stabinit)(firstfile, argc, argv); program(); if (events.end) apply(events.end, NULL, NULL); memset(&events, 0, sizeof events); if (glevel || xref) { Symbol symroot = NULL; Coordinate src; foreach(types, GLOBAL, typestab, &symroot); foreach(identifiers, GLOBAL, typestab, &symroot); src.file = firstfile; src.x = 0; src.y = lineno; if ((glevel > 2 || xref) && IR->stabend) (*IR->stabend)(&src, symroot, ltov(&loci, PERM), ltov(&symbols, PERM), NULL); else if (IR->stabend) (*IR->stabend)(&src, NULL, NULL, NULL, NULL); } finalize(); (*IR->progend)(); deallocate(PERM); return errcnt > 0; }
/* * Remove a lnode from the table */ void freelonode(lnode_t *lp) { lnode_t *lt; lnode_t *ltprev = NULL; struct lfsnode *lfs, *nextlfs; struct vfs *vfsp; struct vnode *vp = ltov(lp); struct vnode *realvp = realvp(vp); struct loinfo *li = vtoli(vp->v_vfsp); #ifdef LODEBUG lo_dprint(4, "freelonode lp %p hash %d\n", lp, ltablehash(lp->lo_vp, li)); #endif TABLE_LOCK_ENTER(lp->lo_vp, li); mutex_enter(&vp->v_lock); if (vp->v_count > 1) { vp->v_count--; /* release our hold from vn_rele */ mutex_exit(&vp->v_lock); TABLE_LOCK_EXIT(lp->lo_vp, li); return; } mutex_exit(&vp->v_lock); for (lt = TABLE_BUCKET(lp->lo_vp, li); lt != NULL; ltprev = lt, lt = lt->lo_next) { if (lt == lp) { #ifdef LODEBUG lo_dprint(4, "freeing %p, vfsp %p\n", vp, vp->v_vfsp); #endif atomic_dec_32(&li->li_refct); vfsp = vp->v_vfsp; vn_invalid(vp); if (vfsp != li->li_mountvfs) { mutex_enter(&li->li_lfslock); /* * Check for unused lfs */ lfs = li->li_lfs; while (lfs != NULL) { nextlfs = lfs->lfs_next; if (vfsp == &lfs->lfs_vfs) { lfs_rele(lfs, li); break; } if (lfs->lfs_vfs.vfs_count == 1) { /* * Lfs is idle */ freelfsnode(lfs, li); } lfs = nextlfs; } mutex_exit(&li->li_lfslock); } if (ltprev == NULL) { TABLE_BUCKET(lt->lo_vp, li) = lt->lo_next; } else { ltprev->lo_next = lt->lo_next; } TABLE_COUNT(lt->lo_vp, li)--; TABLE_LOCK_EXIT(lt->lo_vp, li); kmem_cache_free(lnode_cache, lt); vn_free(vp); VN_RELE(realvp); return; } } panic("freelonode"); /*NOTREACHED*/ }