scc

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

commit 35c819e31cdf871d0a61973b77484eea926267d6
parent 1b0d7ac17e996392d061fe4ae076094ccf569325
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 Feb 2019 18:27:57 +0000

Merge branch 'master' of ssh://simple-cc.org:/var/gitrepos/scc

Diffstat:
Mdoc/scc.1 | 13+++++--------
Minclude/scc/scc/scc.h | 1+
Msrc/cmd/Makefile | 30+++++++++++++++---------------
Msrc/cmd/as/symbol.c | 7++-----
Msrc/cmd/ld/Makefile | 4++--
Msrc/cmd/ld/main.c | 5+----
Msrc/cmd/ranlib.c | 6++----
Msrc/cmd/scc/cc1/symbol.c | 5++---
Msrc/cmd/scc/posix/scc.c | 12++++++++----
Msrc/libc/stdlib/atoi.c | 3+++
Msrc/libc/stdlib/atol.c | 3+++
Msrc/libc/stdlib/atoll.c | 3+++
Msrc/libc/stdlib/malloc.c | 1+
Msrc/libmach/objlookup.c | 7++-----
Msrc/libscc/Makefile | 1+
Asrc/libscc/genhash.c | 11+++++++++++
16 files changed, 62 insertions(+), 50 deletions(-)

diff --git a/doc/scc.1 b/doc/scc.1 @@ -3,7 +3,7 @@ scc \- simple C compiler with magic .SH SYNOPSIS .B scc -.RB [ \-cdgkqQsw ] +.RB [ \-cdgkqQsWw ] .RB [ \-M | \-E | \-S ] .RB [ \-D .IR def[=val] ] ... @@ -23,8 +23,6 @@ scc \- simple C compiler with magic .IR level ] .RB [ \-t .IR sys ] -.RB [ \-W -.IR warn ] .RB sourcefile ... .SH DESCRIPTION .B scc @@ -117,12 +115,11 @@ Undefine a previously defined .I define by the -D parameter. .TP -.B \-w -Do show warning messages. +.B \-W +Show warning messages. .TP -.BI \-W " warnings" -This option only activates -w and is otherwise ignored for compatibility -reasons. +.B \-w +Do not show warning messages (default). .SH ENVIRONMENT VARIABLES Certain environment variables control the behaviour of scc. .TP diff --git a/include/scc/scc/scc.h b/include/scc/scc/scc.h @@ -39,3 +39,4 @@ extern int lpack(unsigned char *dst, char *fmt, ...); extern int lunpack(unsigned char *src, char *fmt, ...); extern int bpack(unsigned char *dst, char *fmt, ...); extern int bunpack(unsigned char *src, char *fmt, ...); +extern unsigned genhash(char *name); diff --git a/src/cmd/Makefile b/src/cmd/Makefile @@ -12,36 +12,36 @@ TARGET = $(BINDIR)/nm \ $(BINDIR)/objcopy \ $(BINDIR)/addr2line \ -LIBS = -lmach DIRS = as ld scc +LIBMACH = $(LIBDIR)/libmach.a +LIBSCC = $(LIBDIR)/libscc.a + all: $(TARGET) $(DIRS) $(DIRS): FORCE @+cd $@ && $(MAKE) -$(TARGET): $(LIBDIR)/libmach.a - -$(BINDIR)/nm: nm.o - $(CC) $(SCC_LDFLAGS) nm.o -lmach -o $@ +$(BINDIR)/nm: nm.o $(LIBMACH) $(LIBSCC) + $(CC) $(SCC_LDFLAGS) nm.o -lmach -lscc -o $@ -$(BINDIR)/strip: strip.o - $(CC) $(SCC_LDFLAGS) strip.o -lmach -o $@ +$(BINDIR)/strip: strip.o $(LIBMACH) $(LIBSCC) + $(CC) $(SCC_LDFLAGS) strip.o -lmach -lscc -o $@ -$(BINDIR)/size: size.o - $(CC) $(SCC_LDFLAGS) size.o -lmach -o $@ +$(BINDIR)/size: size.o $(LIBMACH) $(LIBSCC) + $(CC) $(SCC_LDFLAGS) size.o -lmach -lscc -o $@ -$(BINDIR)/ranlib: ranlib.o $(DRIVER).o - $(CC) $(SCC_LDFLAGS) ranlib.o $(DRIVER).o -lmach -o $@ +$(BINDIR)/ranlib: ranlib.o $(DRIVER).o $(LIBMACH) $(LIBSCC) + $(CC) $(SCC_LDFLAGS) ranlib.o $(DRIVER).o -lmach -lscc -o $@ -$(BINDIR)/objdump: objdump.o +$(BINDIR)/objdump: objdump.o $(LIBMACH) $(CC) $(SCC_LDFLAGS) objdump.o -lmach -o $@ -$(BINDIR)/objcopy: objcopy.o +$(BINDIR)/objcopy: objcopy.o $(LIBMACH) $(CC) $(SCC_LDFLAGS) objcopy.o -lmach -o $@ -$(BINDIR)/addr2line: addr2line.o - $(CC) $(SCC_LDFLAGS) addr2line.o -lmach -o $@ +$(BINDIR)/addr2line: addr2line.o $(LIBMACH) $(LIBSCC) + $(CC) $(SCC_LDFLAGS) addr2line.o -lmach -lscc -o $@ $(BINDIR)/ar: ar.o $(DRIVER).o $(CC) $(SCC_LDFLAGS) ar.o $(DRIVER).o -o $@ diff --git a/src/cmd/as/symbol.c b/src/cmd/as/symbol.c @@ -47,12 +47,9 @@ lookup(char *name) unsigned h; Symbol *sym, **list; int c, symtype; - char *t, *s; + char *t; - h = 0; - for (s = name; c = *s; ++s) - h = h*33 ^ c; - h &= HASHSIZ-1; + h = genhash(name) & HASHSIZ-1; c = toupper(*name); list = &hashtbl[h]; diff --git a/src/cmd/ld/Makefile b/src/cmd/ld/Makefile @@ -9,10 +9,10 @@ TARGET = $(BINDIR)/ld all: $(TARGET) -$(TARGET): $(LIBDIR)/libscc.a +$(TARGET): $(LIBDIR)/libscc.a $(LIBDIR)/libscc.a $(TARGET): $(OBJS) - $(CC) $(SCC_LDFLAGS) $(OBJS) -lmach -o $@ + $(CC) $(SCC_LDFLAGS) $(OBJS) -lmach -lscc -o $@ dep: inc-dep diff --git a/src/cmd/ld/main.c b/src/cmd/ld/main.c @@ -98,10 +98,7 @@ lookup(char *name, int install) unsigned h; Symbol *sym; - h = 0; - for (s = name; *s; s++) - h += *s; - h %= NR_SYMBOL; + h = genhash(name) % NR_SYMBOL; for (sym = symtab[h]; sym; sym = sym->hash) { if (!strcmp(name, sym->name)) diff --git a/src/cmd/ranlib.c b/src/cmd/ranlib.c @@ -10,6 +10,7 @@ #include <scc/ar.h> #include <scc/arg.h> #include <scc/mach.h> +#include <scc/scc.h> #include "sys.h" @@ -52,10 +53,7 @@ lookup(char *name) char *s; size_t len; - h = 0; - for (s = name; *s; s++) - h += *s; - h %= NR_SYMDEF; + h = genhash(name) % NR_SYMDEF; for (dp = htab[h]; dp; dp = dp->next) { if (!strcmp(dp->name, name)) diff --git a/src/cmd/scc/cc1/symbol.c b/src/cmd/scc/cc1/symbol.c @@ -66,11 +66,10 @@ dumpstab(Symbol **tbl, char *msg) static Symbol ** hash(char *s, int ns) { - unsigned c, h, size; + unsigned h, size; Symbol **tab; - for (h = 0; c = *s; ++s) - h = h*33 ^ c; + h = genhash(s); switch (ns) { case NS_CPP: diff --git a/src/cmd/scc/posix/scc.c b/src/cmd/scc/posix/scc.c @@ -60,7 +60,8 @@ static char *prefix, *objfile, *outfile; static char *tmpdir; static size_t tmpdirln; static struct items objtmp, objout; -static int Mflag, Eflag, Sflag, cflag, dflag, kflag, sflag, Qflag = 1; /* TODO: Remove Qflag */ +static int Mflag, Eflag, Sflag, Wflag, + cflag, dflag, kflag, sflag, Qflag = 1; /* TODO: Remove Qflag */ static int devnullfd = -1; extern int failure; @@ -120,6 +121,8 @@ inittool(int tool) switch (tool) { case CC1: + if (Wflag) + addarg(tool, "-w"); for (n = 0; sysincludes[n]; ++n) { addarg(tool, "-I"); addarg(tool, sysincludes[n]); @@ -554,10 +557,11 @@ main(int argc, char *argv[]) case 't': sys = EARGF(usage()); break; - case 'W': - EARGF(usage()); case 'w': - addarg(CC1, "-w"); + Wflag = 0; + break; + case 'W': + Wflag = 1; break; case 'q': Qflag = 0; diff --git a/src/libc/stdlib/atoi.c b/src/libc/stdlib/atoi.c @@ -1,5 +1,8 @@ #include <ctype.h> #include <stdlib.h> + +#include "../libc.h" + #undef atoi int diff --git a/src/libc/stdlib/atol.c b/src/libc/stdlib/atol.c @@ -1,5 +1,8 @@ #include <ctype.h> #include <stdlib.h> + +#include "../libc.h" + #undef atol long diff --git a/src/libc/stdlib/atoll.c b/src/libc/stdlib/atoll.c @@ -1,5 +1,8 @@ #include <ctype.h> #include <stdlib.h> + +#include "../libc.h" + #undef atoll long long diff --git a/src/libc/stdlib/malloc.c b/src/libc/stdlib/malloc.c @@ -5,6 +5,7 @@ #include "malloc.h" #include "../syscall.h" +#include "../libc.h" #define MAXADDR ((char *)-1) #define ERRADDR ((char *)-1) diff --git a/src/libmach/objlookup.c b/src/libmach/objlookup.c @@ -3,6 +3,7 @@ #include <string.h> #include <scc/mach.h> +#include <scc/scc.h> Objsym * objlookup(Obj *obj, char *name, int install) @@ -12,11 +13,7 @@ objlookup(Obj *obj, char *name, int install) char *s; Objsym *sym; - h = 0; - for (s = name; *s; s++) - h += *s; - h %= NR_SYMHASH; - + h = genhash(name) % NR_SYMHASH; for (sym = obj->htab[h]; sym; sym = sym->hash) { if (!strcmp(name, sym->name)) return sym; diff --git a/src/libscc/Makefile b/src/libscc/Makefile @@ -12,6 +12,7 @@ OBJS = debug.o \ xstrdup.o \ alloc.o \ casecmp.o \ + genhash.o TARGET = $(LIBDIR)/libscc.a diff --git a/src/libscc/genhash.c b/src/libscc/genhash.c @@ -0,0 +1,11 @@ +unsigned +genhash(char *name) +{ + unsigned h; + char c; + + for (h = 0; c = *name; ++name) + h = h*33 ^ c; + + return h; +}