diff options
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | cc.h | 4 | ||||
-rw-r--r-- | decl.c | 12 | ||||
-rw-r--r-- | deps.mk | 10 | ||||
-rw-r--r-- | htab.h | 13 | ||||
-rw-r--r-- | map.c (renamed from htab.c) | 30 | ||||
-rw-r--r-- | map.h | 13 | ||||
-rw-r--r-- | qbe.c | 12 | ||||
-rw-r--r-- | scope.c | 34 |
9 files changed, 69 insertions, 69 deletions
@@ -23,16 +23,16 @@ SRC=\ decl.c\ eval.c\ expr.c\ - htab.c\ init.c\ main.c\ + map.c\ pp.c\ scan.c\ scope.c\ siphash.c\ stmt.c\ - tree.c\ token.c\ + tree.c\ type.c\ util.c\ $(BACKEND).c @@ -45,19 +45,19 @@ $(objdir)/decl.o : decl.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ decl.c $(objdir)/driver.o : driver.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ driver.c $(objdir)/eval.o : eval.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ eval.c $(objdir)/expr.o : expr.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ expr.c -$(objdir)/htab.o : htab.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ htab.c $(objdir)/init.o : init.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ init.c $(objdir)/main.o : main.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ main.c +$(objdir)/map.o : map.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ map.c $(objdir)/pp.o : pp.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ pp.c +$(objdir)/qbe.o : qbe.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ qbe.c $(objdir)/scan.o : scan.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ scan.c $(objdir)/scope.o : scope.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ scope.c $(objdir)/siphash.o : siphash.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ siphash.c $(objdir)/stmt.o : stmt.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ stmt.c -$(objdir)/tree.o : tree.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ tree.c $(objdir)/token.o : token.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ token.c +$(objdir)/tree.o : tree.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ tree.c $(objdir)/type.o : type.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ type.c $(objdir)/util.o : util.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ util.c -$(objdir)/qbe.o : qbe.c $(stagedeps) ; $(CC) $(CFLAGS) -c -o $@ qbe.c .PHONY: stage2 stage2: all @@ -264,8 +264,8 @@ struct decl { }; struct scope { - struct hashtable *tags; - struct hashtable *decls; + struct map *tags; + struct map *decls; struct value *breaklabel; struct value *continuelabel; struct switchcases *switchcases; @@ -8,7 +8,7 @@ #include <string.h> #include "util.h" #include "cc.h" -#include "htab.h" +#include "map.h" static struct list tentativedefns = {&tentativedefns, &tentativedefns}; @@ -954,16 +954,16 @@ decl(struct scope *s, struct func *f) struct decl *stringdecl(struct expr *expr) { - static struct hashtable *strings; - struct hashtablekey key; + static struct map *strings; + struct mapkey key; void **entry; struct decl *d; if (!strings) - strings = mkhtab(64); + strings = mkmap(64); assert(expr->kind == EXPRSTRING); - htabbufkey(&key, expr->string.data, expr->string.size); - entry = htabput(strings, &key); + mapbufkey(&key, expr->string.data, expr->string.size); + entry = mapput(strings, &key); d = *entry; if (!d) { d = mkdecl(DECLOBJECT, expr->type, QUALNONE, LINKNONE); @@ -1,18 +1,18 @@ $(objdir)/driver.o: driver.c util.h config.h $(objdir)/util.o: util.c util.h -$(objdir)/decl.o: decl.c util.h cc.h htab.h +$(objdir)/decl.o: decl.c util.h cc.h map.h $(objdir)/eval.o: eval.c util.h cc.h $(objdir)/expr.o: expr.c util.h cc.h -$(objdir)/htab.o: htab.c util.h htab.h $(objdir)/init.o: init.c util.h cc.h $(objdir)/main.o: main.c util.h arg.h cc.h +$(objdir)/map.o: map.c util.h map.h $(objdir)/pp.o: pp.c util.h cc.h $(objdir)/scan.o: scan.c util.h cc.h -$(objdir)/scope.o: scope.c util.h cc.h htab.h +$(objdir)/scope.o: scope.c util.h cc.h map.h $(objdir)/siphash.o: siphash.c $(objdir)/stmt.o: stmt.c util.h cc.h -$(objdir)/tree.o: tree.c util.h tree.h $(objdir)/token.o: token.c util.h cc.h +$(objdir)/tree.o: tree.c util.h tree.h $(objdir)/type.o: type.c util.h cc.h $(objdir)/util.o: util.c util.h -$(objdir)/qbe.o: qbe.c util.h cc.h htab.h tree.h ops.h +$(objdir)/qbe.o: qbe.c util.h cc.h map.h tree.h ops.h @@ -1,13 +0,0 @@ -struct hashtablekey { - uint64_t hash; - const char *str; - size_t len; -}; - -void htabstrkey(struct hashtablekey *, const char *); -void htabbufkey(struct hashtablekey *, const char *, size_t); - -struct hashtable *mkhtab(size_t); -void delhtab(struct hashtable *, void(void *)); -void **htabput(struct hashtable *, struct hashtablekey *); -void *htabget(struct hashtable *, struct hashtablekey *); @@ -4,11 +4,11 @@ #include <stdlib.h> #include <string.h> #include "util.h" -#include "htab.h" +#include "map.h" -struct hashtable { +struct map { size_t len, cap; - struct hashtablekey *keys; + struct mapkey *keys; void **vals; }; @@ -25,7 +25,7 @@ hash(const void *ptr, size_t len) } void -htabbufkey(struct hashtablekey *k, const char *s, size_t n) +mapbufkey(struct mapkey *k, const char *s, size_t n) { k->str = s; k->len = n; @@ -33,15 +33,15 @@ htabbufkey(struct hashtablekey *k, const char *s, size_t n) } void -htabstrkey(struct hashtablekey *k, const char *s) +mapstrkey(struct mapkey *k, const char *s) { - htabbufkey(k, s, strlen(s)); + mapbufkey(k, s, strlen(s)); } -struct hashtable * -mkhtab(size_t cap) +struct map * +mkmap(size_t cap) { - struct hashtable *h; + struct map *h; size_t i; assert(!(cap & cap - 1)); @@ -57,7 +57,7 @@ mkhtab(size_t cap) } void -delhtab(struct hashtable *h, void del(void *)) +delmap(struct map *h, void del(void *)) { size_t i; @@ -75,7 +75,7 @@ delhtab(struct hashtable *h, void del(void *)) } static bool -keyequal(struct hashtablekey *k1, struct hashtablekey *k2) +keyequal(struct mapkey *k1, struct mapkey *k2) { if (k1->hash != k2->hash || k1->len != k2->len) return false; @@ -83,7 +83,7 @@ keyequal(struct hashtablekey *k1, struct hashtablekey *k2) } static size_t -keyindex(struct hashtable *h, struct hashtablekey *k) +keyindex(struct map *h, struct mapkey *k) { size_t i; @@ -94,9 +94,9 @@ keyindex(struct hashtable *h, struct hashtablekey *k) } void ** -htabput(struct hashtable *h, struct hashtablekey *k) +mapput(struct map *h, struct mapkey *k) { - struct hashtablekey *oldkeys; + struct mapkey *oldkeys; void **oldvals; size_t i, j, oldcap; @@ -128,7 +128,7 @@ htabput(struct hashtable *h, struct hashtablekey *k) } void * -htabget(struct hashtable *h, struct hashtablekey *k) +mapget(struct map *h, struct mapkey *k) { size_t i; @@ -0,0 +1,13 @@ +struct mapkey { + uint64_t hash; + const char *str; + size_t len; +}; + +void mapstrkey(struct mapkey *, const char *); +void mapbufkey(struct mapkey *, const char *, size_t); + +struct map *mkmap(size_t); +void delmap(struct map *, void(void *)); +void **mapput(struct map *, struct mapkey *); +void *mapget(struct map *, struct mapkey *); @@ -7,7 +7,7 @@ #include <inttypes.h> #include "util.h" #include "cc.h" -#include "htab.h" +#include "map.h" #include "tree.h" struct name { @@ -73,7 +73,7 @@ struct func { struct decl *namedecl; struct type *type; struct block *start, *end; - struct hashtable *gotos; + struct map *gotos; uint64_t lastid; }; @@ -379,7 +379,7 @@ mkfunc(char *name, struct type *t, struct scope *s) f->name = name; f->type = t; f->start = f->end = (struct block *)mkblock("start"); - f->gotos = mkhtab(8); + f->gotos = mkmap(8); f->lastid = 0; emittype(t->base); @@ -460,10 +460,10 @@ funcgoto(struct func *f, char *name) { void **entry; struct gotolabel *g; - struct hashtablekey key; + struct mapkey key; - htabstrkey(&key, name); - entry = htabput(f->gotos, &key); + mapstrkey(&key, name); + entry = mapput(f->gotos, &key); g = *entry; if (!g) { g = xmalloc(sizeof(*g)); @@ -4,7 +4,7 @@ #include <string.h> #include "util.h" #include "cc.h" -#include "htab.h" +#include "map.h" struct scope filescope; @@ -56,9 +56,9 @@ delscope(struct scope *s) struct scope *parent = s->parent; if (s->decls) - delhtab(s->decls, NULL); + delmap(s->decls, NULL); if (s->tags) - delhtab(s->tags, NULL); + delmap(s->tags, NULL); free(s); return parent; @@ -68,11 +68,11 @@ struct decl * scopegetdecl(struct scope *s, const char *name, bool recurse) { struct decl *d; - struct hashtablekey k; + struct mapkey k; - htabstrkey(&k, name); + mapstrkey(&k, name); do { - d = s->decls ? htabget(s->decls, &k) : NULL; + d = s->decls ? mapget(s->decls, &k) : NULL; s = s->parent; } while (!d && s && recurse); @@ -83,11 +83,11 @@ struct type * scopegettag(struct scope *s, const char *name, bool recurse) { struct type *t; - struct hashtablekey k; + struct mapkey k; - htabstrkey(&k, name); + mapstrkey(&k, name); do { - t = s->tags ? htabget(s->tags, &k) : NULL; + t = s->tags ? mapget(s->tags, &k) : NULL; s = s->parent; } while (!t && s && recurse); @@ -97,21 +97,21 @@ scopegettag(struct scope *s, const char *name, bool recurse) void scopeputdecl(struct scope *s, const char *name, struct decl *d) { - struct hashtablekey k; + struct mapkey k; if (!s->decls) - s->decls = mkhtab(32); - htabstrkey(&k, name); - *htabput(s->decls, &k) = d; + s->decls = mkmap(32); + mapstrkey(&k, name); + *mapput(s->decls, &k) = d; } void scopeputtag(struct scope *s, const char *name, struct type *t) { - struct hashtablekey k; + struct mapkey k; if (!s->tags) - s->tags = mkhtab(32); - htabstrkey(&k, name); - *htabput(s->tags, &k) = t; + s->tags = mkmap(32); + mapstrkey(&k, name); + *mapput(s->tags, &k) = t; } |