scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 68cbeec5a7dc36dfa0809236e1cfcf15b2f6489a
parent b38f3c52fdf2354319064557247cfd1c1df6f8f0
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Feb 2019 05:59:53 +0000

[libmach] Use Obj prefix for public types

Diffstat:
Minclude/scc/scc/mach.h | 38++++++++++++++++++++------------------
Msrc/cmd/nm.c | 14+++++++-------
Msrc/cmd/ranlib.c | 12++++++------
Msrc/libmach/arindex.c | 2+-
Msrc/libmach/coff32/coff32index.c | 2+-
Msrc/libmach/coff32/coff32read.c | 6+++---
Msrc/libmach/coffelf32.c | 4++--
Msrc/libmach/libmach.h | 6+++---
Msrc/libmach/objfree.c | 2+-
Msrc/libmach/objlookup.c | 4++--
Msrc/libmach/objsize.c | 2+-
Msrc/libmach/objtraverse.c | 4++--
12 files changed, 49 insertions(+), 47 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -1,8 +1,8 @@ #define NR_SYMHASH 32 -typedef struct section Section; -typedef struct symbol Symbol; -typedef struct symdef Symdef; +typedef struct objsect Objsect; +typedef struct objsym Objsym; +typedef struct objsymdef Objsymdef; typedef struct object Obj; enum sectype { @@ -16,7 +16,7 @@ enum sectype { SSHARED = 1 << 7, }; -struct section { +struct objsect { char *name; int type; unsigned flags; @@ -25,55 +25,57 @@ struct section { unsigned long long size; }; -struct symbol { +struct objsym { char type; char *name; unsigned long long size; unsigned long long value; - Symbol *next; - Symbol *hash; + Objsym *next, *hash; }; -struct symdef { +struct objsymdef { char *name; int type; long offset; - Symdef *hash, *next; + Objsymdef *hash, *next; }; struct object { int type; - Symbol *htab[NR_SYMHASH]; - Symbol *head; + Objsym *htab[NR_SYMHASH]; + Objsym *head; fpos_t pos; int nsecs; - Section *sections; + Objsect *sections; void *data; }; -extern int archive(FILE *fp); -extern long armember(FILE *fp, char *member); extern int artraverse(FILE *fp, int (*fn)(FILE *, char *, void *), void *data); +extern int objtraverse(Obj *obj, + int (*fn)(Objsym *sym, void *data), + void *data); + +extern int archive(FILE *fp); +extern long armember(FILE *fp, char *member); extern int objtype(FILE *fp, char **name); extern Obj *objnew(int type); extern int objdel(Obj *obj); extern int objreset(Obj *obj); extern int objread(Obj *obj, FILE *fp); -extern Symbol *objlookup(Obj *obj, char *name); -extern int objtraverse(Obj *obj, int (*fn)(Symbol *sym, void *data), void *data); +extern Objsym *objlookup(Obj *obj, char *name); extern int objstrip(Obj *obj); extern int objsize(Obj *obj, unsigned long long *text, unsigned long long *data, unsigned long long *bss); -extern long arindex(int type, long nsyms, Symdef *def, FILE *fp); +extern long arindex(int type, long nsyms, Objsymdef *def, FILE *fp); +extern int objwrite(Obj *obj, FILE *fp); /* TODO */ extern int objload(Obj *obj, Obj *to); extern int objreloc(Obj *obj, char *sect, void *rel); -extern int objwrite(Obj *obj, FILE *fp); extern int addr2line(Obj *obj, unsigned long long addr, char *fname, int *line); diff --git a/src/cmd/nm.c b/src/cmd/nm.c @@ -13,7 +13,7 @@ static char sccsid[] = "@(#) ./nm/main.c"; struct symtbl { - Symbol **buf; + Objsym **buf; size_t nsyms; }; @@ -46,8 +46,8 @@ error(char *fmt, ...) static int cmp(const void *p1, const void *p2) { - Symbol **s1 = (Symbol **) p1, **s2 = (Symbol **) p2; - Symbol *sym1 = *s1, *sym2 = *s2; + Objsym **s1 = (Objsym **) p1, **s2 = (Objsym **) p2; + Objsym *sym1 = *s1, *sym2 = *s2; if (vflag) { if (sym1->value > sym2->value) @@ -67,7 +67,7 @@ cmp(const void *p1, const void *p2) } static void -printsyms(Symbol **syms, size_t nsym) +printsyms(Objsym **syms, size_t nsym) { size_t i; @@ -77,7 +77,7 @@ printsyms(Symbol **syms, size_t nsym) printf("%s:\n", (membname) ? membname : filename); for (i = 0; i < nsym; i++) { - Symbol *sym = syms[i]; + Objsym *sym = syms[i]; int type = sym->type; char *fmt; @@ -114,10 +114,10 @@ printsyms(Symbol **syms, size_t nsym) } static int -newsym(Symbol *sym, void *data) +newsym(Objsym *sym, void *data) { struct symtbl *tbl = data; - Symbol **p; + Objsym **p; size_t n, size; int type = sym->type; diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -18,7 +18,7 @@ static long nsymbols; static int status, artype, nolib; static char *filename, *membname; -static Symdef *htab[NR_SYMDEF], *head; +static Objsymdef *htab[NR_SYMDEF], *head; static long offset; char *argv0; @@ -44,11 +44,11 @@ error(char *fmt, ...) status = EXIT_FAILURE; } -Symdef * +Objsymdef * lookup(char *name) { unsigned h; - Symdef *dp; + Objsymdef *dp; char *s; size_t len; @@ -85,9 +85,9 @@ lookup(char *name) } static int -newsymbol(Symbol *sym, void *data) +newsymbol(Objsym *sym, void *data) { - Symdef *np; + Objsymdef *np; if (!isupper(sym->type) || sym->type == 'N') return 1; @@ -165,7 +165,7 @@ error: static void freehash(void) { - Symdef **npp, *next, *np; + Objsymdef **npp, *next, *np; for (npp = htab; npp < &htab[NR_SYMDEF]; npp++) *npp = NULL; diff --git a/src/libmach/arindex.c b/src/libmach/arindex.c @@ -7,7 +7,7 @@ extern indexfun_t indexv[]; long -arindex(int type, long nsyms, Symdef *head, FILE *fp) +arindex(int type, long nsyms, Objsymdef *head, FILE *fp) { int fmt; indexfun_t fn; diff --git a/src/libmach/coff32/coff32index.c b/src/libmach/coff32/coff32index.c @@ -6,7 +6,7 @@ #include "coff32.h" long -coff32index(int type, long nsymbols, Symdef *head, FILE *fp) +coff32index(int type, long nsymbols, Objsymdef *head, FILE *fp) { return coff32idx(BIG_ENDIAN, nsymbols, head, fp); } diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c @@ -144,13 +144,13 @@ loadsections(Obj *obj, FILE *fp) FILHDR *hdr; struct coff32 *coff; SCNHDR *scn; - Section *secs, *sp; + Objsect *secs, *sp; coff = obj->data; hdr = &coff->hdr; scn = coff->scns; - secs = malloc(sizeof(Section) * hdr->f_nscns); + secs = malloc(sizeof(Objsect) * hdr->f_nscns); if (!secs) return 0; obj->sections = secs; @@ -373,7 +373,7 @@ loadsyms(Obj *obj) int t; long i; char *s; - Symbol *sym; + Objsym *sym; SYMENT *ent; Coff32 *coff = obj->data; diff --git a/src/libmach/coffelf32.c b/src/libmach/coffelf32.c @@ -6,11 +6,11 @@ #include "libmach.h" long -coff32idx(int order, long nsyms, Symdef *head, FILE *fp) +coff32idx(int order, long nsyms, Objsymdef *head, FILE *fp) { long i, n; size_t len; - Symdef *def; + Objsymdef *def; unsigned char buff[4]; pack(order, buff, "l", nsyms); diff --git a/src/libmach/libmach.h b/src/libmach/libmach.h @@ -28,7 +28,7 @@ enum freeflags { FREESECT, }; -typedef long (*indexfun_t)(int, long, Symdef *, FILE *); +typedef long (*indexfun_t)(int, long, Objsymdef *, FILE *); typedef int (*newfun_t)(Obj *obj); typedef int (*readfun_t)(Obj *obj, FILE *fp); typedef void (*delfun_t)(Obj *new); @@ -43,11 +43,11 @@ extern int objpos(Obj *obj, FILE *fp, long pos); extern void objfree(Obj *obj, int what); /* idx functions */ -extern long coff32idx(int order, long nsyms, Symdef *def, FILE *fp); +extern long coff32idx(int order, long nsyms, Objsymdef *def, FILE *fp); /* coff32 functions */ -extern long coff32index(int type, long nsyms, Symdef *head, FILE *fp); +extern long coff32index(int type, long nsyms, Objsymdef *head, FILE *fp); extern int coff32new(Obj *obj); extern void coff32del(Obj *obj); extern int coff32read(Obj *obj, FILE *fp); diff --git a/src/libmach/objfree.c b/src/libmach/objfree.c @@ -9,7 +9,7 @@ static void delsyms(Obj *obj) { - Symbol *sym, *next; + Objsym *sym, *next; for (sym = obj->head; sym; sym = next) { next = sym->next; diff --git a/src/libmach/objlookup.c b/src/libmach/objlookup.c @@ -4,13 +4,13 @@ #include <scc/mach.h> -Symbol * +Objsym * objlookup(Obj *obj, char *name) { unsigned h; size_t len; char *s; - Symbol *sym; + Objsym *sym; h = 0; for (s = name; *s; s++) diff --git a/src/libmach/objsize.c b/src/libmach/objsize.c @@ -11,7 +11,7 @@ objsize(Obj *obj, unsigned long long *data, unsigned long long *bss) { - Section *sp, *secs = obj->sections; + Objsect *sp, *secs = obj->sections; unsigned long long *p; *text = 0; diff --git a/src/libmach/objtraverse.c b/src/libmach/objtraverse.c @@ -5,9 +5,9 @@ #include "libmach.h" int -objtraverse(Obj *obj, int (*fn)(Symbol *, void *), void *data) +objtraverse(Obj *obj, int (*fn)(Objsym *, void *), void *data) { - Symbol *sym; + Objsym *sym; for (sym = obj->head; sym; sym = sym->next) { if (!(*fn)(sym, data))