int main(int argc, char **argv) { FILE *f; int opt; int i; while ((opt = getopt(argc, argv, "hud:I:")) != -1) { switch (opt) { case 'h': usage(argv[0]); exit(0); break; case 'u': fromuse = 1; break; case 'd': debug = 1; while (optarg && *optarg) debugopt[*optarg++ & 0x7f] = 1; break; case 'I': lappend(&incpaths, &nincpaths, optarg); break; default: usage(argv[0]); exit(0); break; } } for (i = optind; i < argc; i++) { lappend(&incpaths, &nincpaths, Instroot "/lib/myr"); file = mkfile(argv[i]); file->file.exports = mkstab(); file->file.globls = mkstab(); tyinit(file->file.globls); printf("%s:\n", argv[i]); if (fromuse) { f = fopen(argv[i], "r"); if (!f) die("Unable to open usefile %s\n", argv[i]); loaduse(f, file->file.globls); dumpsyms(file->file.globls, 1); } else { tokinit(argv[i]); yyparse(); infer(file); dumpsyms(file->file.globls, 1); } } return 0; }
void dumpsyms(Stab *st, int indent) { size_t i, n; void **k; /* decls */ k = htkeys(st->dcl, &n); for (i = 0; i < n; i++) { dumptypes(getdcl(st, k[i]), indent); } free(k); /* union constructors */ k = htkeys(st->uc, &n); for (i = 0; i < n; i++) dumpucon(getucon(st, k[i]), indent + 1); /* sub-namespaces */ k = htkeys(st->ns, &n); for (i = 0; i < n; i++) { printindent(indent + 1); printf("namespace %s:\n", (char*)k[i]); dumpsyms(getns_str(st, k[i]), indent + 2); } free(k); }
int stabs2acid(Stab *stabs, Biobuf *b) { volatile int fno, i; char c, *desc, *p; char *volatile dir, *volatile fn, *volatile name; Ftypes *f; Type *t, *tt; StabSym sym; dir = nil; fno = 0; fn = nil; for(i=0; stabsym(stabs, i, &sym)>=0; i++){ if(verbose) print("%d %s\n", sym.type, sym.name); switch(sym.type){ case N_SO: if(sym.name){ if(sym.name[0] && sym.name[strlen(sym.name)-1] == '/') dir = sym.name; } denumber(); fstack = nil; fno = 0; break; case N_BINCL: fno++; f = mkftypes(dir, sym.name); f->down = fstack; fstack = f; break; case N_EINCL: if(fstack) fstack = fstack->down; break; case N_EXCL: fno++; if((f = findftypes(dir, sym.name)) == nil){ static int cannotprint; if(cannotprint++ == 0) fprint(2, "cannot find remembered %s\n", sym.name); continue; } renumber(f->list, fno); break; case N_GSYM: case N_FUN: case N_PSYM: case N_LSYM: case N_LCSYM: case N_STSYM: case N_RSYM: name = sym.name; if(name == nil){ if(sym.type==N_FUN) fn = nil; continue; } if((p = findcolon(name)) == nil) continue; name = estrndup(name, p-name); desc = ++p; c = *desc; if(c == 'c'){ fprint(2, "skip constant %s\n", name); continue; } if(setjmp(kaboom)){ static int cannotparse; if(cannotparse++ == 0) fprint(2, "cannot parse %s\n", name); continue; } t = parsename(desc, &p); if(t == nil) continue; if(*p != 0){ static int extradesc; if(extradesc++ == 0) fprint(2, "extra desc '%s' in '%s'\n", p, desc); } /* void is defined as itself */ if(t->ty==Defer && t->sub==t && strcmp(name, "void")==0){ t->ty = Base; t->xsizeof = 0; t->printfmt = '0'; } if(*name==' ' && *(name+1) == 0) *name = 0; /* attach names to structs, unions, enums */ if(c=='T' && *name && t->sue){ t->suename = name; if(t->name == nil) t->name = name; tt = typebysue(t->sue, name); tt->ty = Defer; tt->sub = t; } if(c=='t'){ tt = newtype(); tt->ty = Typedef; tt->name = name; tt->sub = t; } /* define base c types */ if(t->ty==None || t->ty==Range){ if(strcmp(name, "char") == 0){ t->ty = Base; t->xsizeof = 1; t->printfmt = 'x'; } if(strcmp(name, "int") == 0){ t->ty = Base; t->xsizeof = 4; t->printfmt = 'd'; } } /* record declaration in list for later. */ if(c != 't' && c != 'T') switch(sym.type){ case N_GSYM: addsymx(nil, name, t); break; case N_FUN: fn = name; break; case N_PSYM: case N_LSYM: case N_LCSYM: case N_STSYM: case N_RSYM: addsymx(fn, name, t); break; } break; } if(1) print(""); } printtypes(b); dumpsyms(b); freetypes(); return 0; }