diff options
-rw-r--r-- | 6/insns.def | 68 | ||||
-rw-r--r-- | 6/isel.c | 8 | ||||
-rw-r--r-- | 6/locs.c | 2 | ||||
-rw-r--r-- | 6/main.c | 16 | ||||
-rw-r--r-- | 6/ra.c | 20 | ||||
-rw-r--r-- | 6/simp.c | 4 | ||||
-rw-r--r-- | mk/c.mk | 2 | ||||
-rw-r--r-- | muse/muse.c | 2 | ||||
-rw-r--r-- | myrbuild/myrbuild.c | 63 | ||||
-rw-r--r-- | opt/cfg.c | 2 | ||||
-rw-r--r-- | opt/df.c | 2 | ||||
-rw-r--r-- | opt/fold.c | 2 | ||||
-rw-r--r-- | parse/bitset.c | 2 | ||||
-rw-r--r-- | parse/dump.c | 2 | ||||
-rw-r--r-- | parse/htab.c | 2 | ||||
-rw-r--r-- | parse/infer.c | 2 | ||||
-rw-r--r-- | parse/names.c | 2 | ||||
-rw-r--r-- | parse/node.c | 2 | ||||
-rw-r--r-- | parse/parse.h | 6 | ||||
-rw-r--r-- | parse/specialize.c | 2 | ||||
-rw-r--r-- | parse/stab.c | 2 | ||||
-rw-r--r-- | parse/tok.c | 17 | ||||
-rw-r--r-- | parse/type.c | 2 | ||||
-rw-r--r-- | parse/use.c | 2 | ||||
-rw-r--r-- | parse/util.c | 8 |
25 files changed, 144 insertions, 98 deletions
diff --git a/6/insns.def b/6/insns.def index a04f0e3..6e9aeda 100644 --- a/6/insns.def +++ b/6/insns.def @@ -18,17 +18,17 @@ For technical reasons, the indexing on use and def statments is 1-based, instead of 0-based. (0 is the sentinel value). */ - -Insn(Inone, "BAD_INSN", Use(), Def()) +#define None .l={0},.r={0} +Insn(Inone, "BAD_INSN", Use(None), Def(None)) /* Note, the mov instruction is specified in an overly general manner. */ Insn(Imov, "\tmov%t %x,%x\n", Use(.l={1}), Def(.l={2})) Insn(Imovt, "PSEUDO: TRUNCATE\n", Use(.l={1}), Def(.l={2})) Insn(Imovzx, "\tmovz%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2})) Insn(Imovsx, "\tmovs%1t%2t %x,%x\n", Use(.l={1}), Def(.l={2})) -Insn(Irepmovsb, "\trep movsb\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def()) -Insn(Irepmovsw, "\trep movsw\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def()) -Insn(Irepmovsl, "\trep movsl\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def()) -Insn(Irepmovsq, "\trep movsq\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def()) +Insn(Irepmovsb, "\trep movsb\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None)) +Insn(Irepmovsw, "\trep movsw\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None)) +Insn(Irepmovsl, "\trep movsl\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None)) +Insn(Irepmovsq, "\trep movsq\n", Use(.r={Rrcx,Rrsi,Rrdi}), Def(None)) Insn(Ilea, "\tlea%2t %m,%r\n", Use(.l={1}), Def(.l={2})) Insn(Iadd, "\tadd%t %x,%r\n", Use(.l={1,2}), Def(.l={2})) @@ -47,23 +47,23 @@ Insn(Ishl, "\tsal%2t %u,%r\n", Use(.l={1,2}), Insn(Isar, "\tsar%2t %u,%r\n", Use(.l={1,2}), Def(.l={2})) Insn(Ishr, "\tshr%2t %u,%r\n", Use(.l={1,2}), Def(.l={2})) -Insn(Itest, "\ttest%t %x,%r\n", Use(.l={1,2}), Def(.l={})) -Insn(Icmp, "\tcmp%t %x,%r\n", Use(.l={1,2}), Def(.l={})) +Insn(Itest, "\ttest%t %x,%r\n", Use(.l={1,2}), Def(None)) +Insn(Icmp, "\tcmp%t %x,%r\n", Use(.l={1,2}), Def(None)) -Insn(Ipush, "\tpush%t %r\n", Use(.l={1}), Def()) -Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def()) +Insn(Ipush, "\tpush%t %r\n", Use(.l={1}), Def(None)) +Insn(Ipop, "\tpop%t %r\n", Use(.l={1}), Def(None)) /* branch instructions */ -Insn(Isetz, "\tsetz %v\n", Use(), Def(.l={1})) -Insn(Isetnz, "\tsetnz %v\n", Use(), Def(.l={1})) -Insn(Isetl, "\tsetl %v\n", Use(), Def(.l={1})) -Insn(Isetle, "\tsetle %v\n", Use(), Def(.l={1})) -Insn(Isetg, "\tsetg %v\n", Use(), Def(.l={1})) -Insn(Isetge, "\tsetge %v\n", Use(), Def(.l={1})) -Insn(Isetb, "\tsetb %v\n", Use(), Def(.l={1})) -Insn(Isetbe, "\tsetbe %v\n", Use(), Def(.l={1})) -Insn(Iseta, "\tseta %v\n", Use(), Def(.l={1})) -Insn(Isetae, "\tsetae %v\n", Use(), Def(.l={1})) +Insn(Isetz, "\tsetz %v\n", Use(None), Def(.l={1})) +Insn(Isetnz, "\tsetnz %v\n", Use(None), Def(.l={1})) +Insn(Isetl, "\tsetl %v\n", Use(None), Def(.l={1})) +Insn(Isetle, "\tsetle %v\n", Use(None), Def(.l={1})) +Insn(Isetg, "\tsetg %v\n", Use(None), Def(.l={1})) +Insn(Isetge, "\tsetge %v\n", Use(None), Def(.l={1})) +Insn(Isetb, "\tsetb %v\n", Use(None), Def(.l={1})) +Insn(Isetbe, "\tsetbe %v\n", Use(None), Def(.l={1})) +Insn(Iseta, "\tseta %v\n", Use(None), Def(.l={1})) +Insn(Isetae, "\tsetae %v\n", Use(None), Def(.l={1})) /* fp specific instructions */ Insn(Imovs, "\tmovs%1t %x,%x\n", Use(.l={1}), Def(.l={2})) @@ -75,24 +75,24 @@ Insn(Iadds, "\tadds%t %x,%f\n", Use(.l={1,2}), Insn(Isubs, "\tsubs%t %x,%f\n", Use(.l={1,2}), Def(.l={2})) Insn(Imuls, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2})) Insn(Idivs, "\tdivs%t %x,%f\n", Use(.l={1,2}), Def(.l={2})) -Insn(Icomis, "\tcomis%t %x,%f\n", Use(.l={1,2}), Def()) +Insn(Icomis, "\tcomis%t %x,%f\n", Use(.l={1,2}), Def(None)) Insn(Ixorp, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2})) /* branch instructions */ Insn(Icall, "\tcall %v\n", Use(.l={1}), Def(.r={Rrax,Reax,Rax,Ral,Rah})) Insn(Icallind, "\tcall *%v\n", Use(.l={1}), Def(.r={Rrax,Reax,Rax,Ral,Rah})) -Insn(Ijmp, "\tjmp %v\n", Use(.l={1}), Def()) -Insn(Ijz, "\tjz %v\n", Use(.l={1}), Def()) -Insn(Ijnz, "\tjnz %v\n", Use(.l={1}), Def()) -Insn(Ijl, "\tjl %v\n", Use(.l={1}), Def()) -Insn(Ijle, "\tjle %v\n", Use(.l={1}), Def()) -Insn(Ijg, "\tjg %v\n", Use(.l={1}), Def()) -Insn(Ijge, "\tjge %v\n", Use(.l={1}), Def()) -Insn(Ijb, "\tjb %v\n", Use(.l={1}), Def()) -Insn(Ijbe, "\tjbe %v\n", Use(.l={1}), Def()) -Insn(Ija, "\tja %v\n", Use(.l={1}), Def()) -Insn(Ijae, "\tjae %v\n", Use(.l={1}), Def()) -Insn(Iret, "\tret\n", Use(.r={Rrax,Rxmm0d}), Def()) +Insn(Ijmp, "\tjmp %v\n", Use(.l={1}), Def(None)) +Insn(Ijz, "\tjz %v\n", Use(.l={1}), Def(None)) +Insn(Ijnz, "\tjnz %v\n", Use(.l={1}), Def(None)) +Insn(Ijl, "\tjl %v\n", Use(.l={1}), Def(None)) +Insn(Ijle, "\tjle %v\n", Use(.l={1}), Def(None)) +Insn(Ijg, "\tjg %v\n", Use(.l={1}), Def(None)) +Insn(Ijge, "\tjge %v\n", Use(.l={1}), Def(None)) +Insn(Ijb, "\tjb %v\n", Use(.l={1}), Def(None)) +Insn(Ijbe, "\tjbe %v\n", Use(.l={1}), Def(None)) +Insn(Ija, "\tja %v\n", Use(.l={1}), Def(None)) +Insn(Ijae, "\tjae %v\n", Use(.l={1}), Def(None)) +Insn(Iret, "\tret\n", Use(.r={Rrax,Rxmm0d}), Def(None)) /* not really an insn... */ -Insn(Ilbl, "%v:\n", Use(), Def()) +Insn(Ilbl, "%v:\n", Use(None), Def(None)) @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <inttypes.h> #include <ctype.h> @@ -1067,10 +1067,10 @@ static size_t writelit(FILE *fd, Htab *strtab, Node *v, Type *ty) case Lflt: if (tybase(v->lit.type)->type == Tyflt32) { u.fv = v->lit.fltval; - fprintf(fd, "\t.long 0x%"PRIx32"\n", u.lv); + fprintf(fd, "\t.long 0x%" PRIx32 "\n", u.lv); } else if (tybase(v->lit.type)->type == Tyflt64) { u.dv = v->lit.fltval; - fprintf(fd, "\t.quad 0x%"PRIx64"\n", u.qv); + fprintf(fd, "\t.quad 0x%" PRIx64 "\n", u.qv); } break; case Lstr: @@ -1240,7 +1240,7 @@ void genasm(FILE *fd, Func *fn, Htab *globls, Htab *strtab) is.curbb = is.bb[j]; for (i = 0; i < fn->cfg->bb[j]->nnl; i++) { /* put in a comment that says where this line comes from */ - snprintf(buf, sizeof buf, "\n\t# bb = %zd, bbidx = %zd, %s:%d", + snprintf(buf, sizeof buf, "\n\t# bb = %ld, bbidx = %ld, %s:%d", j, i, file->file.name, fn->cfg->bb[j]->nl[i]->line); g(&is, Ilbl, locstrlbl(buf), NULL); isel(&is, fn->cfg->bb[j]->nl[i]); @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> @@ -1,12 +1,11 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> #include <fcntl.h> #include <unistd.h> -#include <err.h> #include <sys/types.h> #include <sys/stat.h> @@ -70,7 +69,8 @@ static void assem(char *asmsrc, char *path) if (pid == -1) { die("couldn't fork"); } else if (pid == 0) { - execvp(cmd[0], cmd); + if (execvp(cmd[0], cmd) == -1) + die("Couldn't exec assembler\n"); } else { waitpid(pid, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) @@ -93,8 +93,8 @@ static char *gentemp(char *buf, size_t bufsz, char *path, char *suffix) else base = path; gettimeofday(&tv, NULL); - srandom(tv.tv_usec); - snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, random(), (long)tv.tv_usec, base, suffix); + srand(tv.tv_usec); + snprintf(buf, bufsz, "%s/tmp%lx%lx-%s%s", tmpdir, (long)rand(), (long)tv.tv_usec, base, suffix); return buf; } @@ -110,8 +110,10 @@ static void genuse(char *path) else swapsuffix(buf, 1024, path, ".myr", ".use"); f = fopen(buf, "w"); - if (!f) - err(1, "Could not open path %s\n", buf); + if (!f) { + fprintf(stderr, "Could not open path %s\n", buf); + exit(1); + } writeuse(f, file); fclose(f); } @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <assert.h> #include <limits.h> @@ -24,19 +24,23 @@ static void printedge(FILE *fd, char *msg, size_t a, size_t b); /* tables of uses/defs by instruction */ Usemap usetab[] = { +#define Def(...) #define Use(...) {__VA_ARGS__} #define Insn(i, fmt, use, def) use, #include "insns.def" #undef Insn #undef Use +#undef Def }; Usemap deftab[] = { +#define Use(...) #define Def(...) {__VA_ARGS__} #define Insn(i, fmt, use, def) def, #include "insns.def" #undef Insn #undef Def +#undef Use }; /* A map of which registers interfere */ @@ -618,15 +622,17 @@ static void decdegree(Isel *s, regid m) if (found) wldel(s, &s->wlspill, &s->nwlspill, idx); if (moverelated(s, m)) { - if (!found) - assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx)); - else + if (!found) { + assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx) != 0); + } else { wlput(&s->wlfreeze, &s->nwlfreeze, locmap[m]); + } } else { - if (!found) + if (!found) { assert(wlfind(s->wlsimp, s->nwlsimp, m, &idx)); - else + } else { wlput(&s->wlsimp, &s->nwlsimp, locmap[m]); + } } } } @@ -916,7 +922,7 @@ static int paint(Isel *s) spilled = 0; while (s->nselstk) { - bzero(taken, Nreg*sizeof(int)); + memset(taken, 0, Nreg*sizeof(int)); n = lpop(&s->selstk, &s->nselstk); for (j = 0; j < s->ngadj[n->reg.id];j++) { @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> @@ -1289,6 +1289,7 @@ static Node *simpucon(Simp *s, Node *n, Node *dst) static Node *simpuget(Simp *s, Node *n, Node *dst) { die("No uget simplification yet"); + return NULL; } /* simplifies @@ -1338,6 +1339,7 @@ static Node *simplazy(Simp *s, Node *n) static Node *comparecomplex(Simp *s, Node *n, Op op) { fatal(n->line, "Complex comparisons not yet supported\n"); + return NULL; } static Node *compare(Simp *s, Node *n, int fields) @@ -50,7 +50,7 @@ subdirs-install: ); done clean: subdirs-clean - rm -f ${BIN} ${OBJ} ${CLEAN} + rm -f ${BIN} ${OBJ} ${CLEAN} ${LIB} install: subdirs-install $(INSTBIN) $(INSTLIB) $(INSTHDR) $(INSTPKG) @for i in $(INSTBIN); do \ diff --git a/muse/muse.c b/muse/muse.c index 74220df..2cc54ac 100644 --- a/muse/muse.c +++ b/muse/muse.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> diff --git a/myrbuild/myrbuild.c b/myrbuild/myrbuild.c index 8eb1aa9..0572866 100644 --- a/myrbuild/myrbuild.c +++ b/myrbuild/myrbuild.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <stdarg.h> +#include <inttypes.h> #include <string.h> #include <assert.h> #include <sys/types.h> @@ -10,8 +11,6 @@ #include <ctype.h> #include <fcntl.h> #include <unistd.h> -#include <regex.h> -#include <err.h> #include "parse.h" @@ -44,10 +43,18 @@ char *ldscript; char *sysname; -regex_t usepat; Htab *compiled; /* used as string set */ Htab *loopdetect; /* used as string set */ +static void fail(int status, char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + exit(status); +} + static void usage(char *prog) { printf("%s [-h] [-I path] [-l lib] [-b bin] inputs...\n", prog); @@ -125,10 +132,10 @@ void run(char **cmd) pid = fork(); status = 0; if (pid == -1) { - err(1, "Could not fork"); + fail(1, "Could not fork"); } else if (pid == 0) { if (execvp(cmd[0], cmd) == -1) - err(1, "Failed to exec %s", cmd[0]); + fail(1, "Failed to exec %s", cmd[0]); } else { waitpid(pid, &status, 0); } @@ -143,7 +150,7 @@ int isfresh(char *from, char *to) struct stat from_sb, to_sb; if (stat(from, &from_sb)) - err(1, "Could not find %s", from); + fail(1, "Could not find %s", from); if (stat(to, &to_sb) == -1) return 0; @@ -160,26 +167,48 @@ int inlist(char **list, size_t sz, char *str) return 0; } +int finddep(char *buf, char **dep) +{ + char *end, *w, *p; + p = buf; + + + end = buf + strlen(buf); + while (isspace(*p) && p != end) + p++; + if (strncmp(p, "use", 3) != 0) + return 0; + p += 3; + if (!isspace(*p)) + return 0; + while (isspace(*p) && p != end) + p++; + + w = p; + while (!isspace(*p) && p != end) + p++; + if (p == w) + return 0; + *dep = strdupn(w, p - w); + return 1; +} + void getdeps(char *file, char **deps, size_t depsz, size_t *ndeps) { char buf[2048]; - regmatch_t m[2]; size_t i; FILE *f; char *dep; f = fopen(file, "r"); if (!f) - err(1, "Could not open file \"%s\"", file); + fail(1, "Could not open file \"%s\"", file); i = 0; while (fgets(buf, sizeof buf, f)) { - if (regexec(&usepat, buf, 2, m, 0) == REG_NOMATCH) + if (!finddep(buf, &dep)) continue; - if (i == depsz) - die("Too many deps for file %s", file); - dep = strdupn(&buf[m[1].rm_so], m[1].rm_eo - m[1].rm_so); if (!inlist(deps, i, dep)) deps[i++] = dep; else @@ -205,7 +234,8 @@ FILE *openlib(char *lib) f = fopen(buf, "r"); if (f) return f; - err(1, "could not open library file %s\n", lib); + fail(1, "could not open library file %s\n", lib); + return NULL; } void scrapelib(Htab *g, char *lib) @@ -221,7 +251,7 @@ void scrapelib(Htab *g, char *lib) ndeps = 0; use = openlib(lib); if (fgetc(use) != 'U') - err(1, "library \"%s\" is not a usefile.", lib); + fail(1, "library \"%s\" is not a usefile.", lib); /* we don't care about the usefile's name */ free(rdstr(use)); while (fgetc(use) == 'L') { @@ -358,7 +388,7 @@ void visit(char ***args, size_t *nargs, size_t head, Htab *g, char *n, Htab *loo char buf[1024]; if (hthas(looped, n)) - err(1, "cycle in library dependency graph involving %s\n", n); + fail(1, "cycle in library dependency graph involving %s\n", n); if (hthas(marked, n)) return; htput(looped, n, n); @@ -502,7 +532,6 @@ int main(int argc, char **argv) libgraph = mkht(strhash, streq); compiled = mkht(strhash, streq); loopdetect = mkht(strhash, streq); - regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED); for (i = optind; i < argc; i++) { lappend(&stack, &nstack, argv[i]); compile(argv[i], &stack, &nstack); @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> diff --git a/parse/bitset.c b/parse/bitset.c index 84f2402..177a3b2 100644 --- a/parse/bitset.c +++ b/parse/bitset.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <assert.h> #include <limits.h> #include <string.h> diff --git a/parse/dump.c b/parse/dump.c index 496ab65..4364998 100644 --- a/parse/dump.c +++ b/parse/dump.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> diff --git a/parse/htab.c b/parse/htab.c index 88c2232..0a8c740 100644 --- a/parse/htab.c +++ b/parse/htab.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <assert.h> #include <limits.h> #include <string.h> diff --git a/parse/infer.c b/parse/infer.c index dcf94f7..cc7d216 100644 --- a/parse/infer.c +++ b/parse/infer.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <inttypes.h> #include <ctype.h> #include <string.h> diff --git a/parse/names.c b/parse/names.c index 5ecca05..dddd649 100644 --- a/parse/names.c +++ b/parse/names.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> diff --git a/parse/node.c b/parse/node.c index 4fdffa0..cdd0eb9 100644 --- a/parse/node.c +++ b/parse/node.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> diff --git a/parse/parse.h b/parse/parse.h index 363dc59..7ecd4fc 100644 --- a/parse/parse.h +++ b/parse/parse.h @@ -1,4 +1,8 @@ -#define FATAL __attribute__((noreturn)) +#ifdef __GNUC__ +# define FATAL __attribute__((noreturn)) +#else +# define FATAL +#endif typedef uint8_t byte; typedef unsigned int uint; diff --git a/parse/specialize.c b/parse/specialize.c index 38c150a..0e50daa 100644 --- a/parse/specialize.c +++ b/parse/specialize.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> diff --git a/parse/stab.c b/parse/stab.c index 0aa8399..32c6ee6 100644 --- a/parse/stab.c +++ b/parse/stab.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> diff --git a/parse/tok.c b/parse/tok.c index a2dc27a..33782a6 100644 --- a/parse/tok.c +++ b/parse/tok.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> @@ -8,7 +8,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <errno.h> -#include <err.h> #include <unistd.h> #include "parse.h" @@ -321,7 +320,7 @@ static int hexval(char c) } /* \u{abc} */ -static int32_t unichar() +static int32_t unichar(void) { uint32_t v; int c; @@ -382,7 +381,7 @@ static int decode(char **buf, size_t *len, size_t *sz) return v; } -static Tok *strlit() +static Tok *strlit(void) { Tok *t; int c; @@ -442,7 +441,7 @@ static uint32_t readutf(char c, char **buf, size_t *buflen, size_t *sz) { return val; } -static Tok *charlit() +static Tok *charlit(void) { Tok *t; int c; @@ -737,7 +736,7 @@ static Tok *numlit(void) return t; } -static Tok *typaram() +static Tok *typaram(void) { Tok *t; char buf[1024]; @@ -792,8 +791,10 @@ void tokinit(char *file) fd = open(file, O_RDONLY); - if (fd == -1) - err(errno, "Unable to open file %s", file); + if (fd == -1) { + fprintf(stderr, "Unable to open file %s\n", file); + exit(1); + } nread = 0; fbuf = malloc(4096); diff --git a/parse/type.c b/parse/type.c index 96f5c11..55ecde8 100644 --- a/parse/type.c +++ b/parse/type.c @@ -1,7 +1,7 @@ #include <assert.h> #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> diff --git a/parse/use.c b/parse/use.c index 571283e..5f46825 100644 --- a/parse/use.c +++ b/parse/use.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <ctype.h> #include <string.h> #include <assert.h> diff --git a/parse/util.c b/parse/util.c index 25fcdb0..b3755e0 100644 --- a/parse/util.c +++ b/parse/util.c @@ -1,6 +1,6 @@ #include <stdlib.h> #include <stdio.h> -#include <stdint.h> +#include <inttypes.h> #include <stdarg.h> #include <ctype.h> #include <string.h> @@ -40,7 +40,7 @@ void *zrealloc(void *mem, size_t oldsz, size_t sz) p = xrealloc(mem, sz); if (sz > oldsz) - bzero(&p[oldsz], sz - oldsz); + memset(&p[oldsz], 0, sz - oldsz); return p; } @@ -210,11 +210,13 @@ long host32(byte buf[4]) return v; } -void wrbuf(FILE *fd, void *buf, size_t sz) +void wrbuf(FILE *fd, void *ptr, size_t sz) { size_t n; + char *buf; n = 0; + buf = ptr; while (n < sz) { n += fwrite(buf + n, 1, sz - n, fd); if (feof(fd)) |