scc

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

objlookup.c (593B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include <scc/mach.h>
      6 #include <scc/scc.h>
      7 
      8 Objsym *
      9 objlookup(Obj *obj, char *name, int install)
     10 {
     11 	unsigned h;
     12 	Objsym *sym;
     13 
     14 	h = genhash(name) % NR_SYMHASH;
     15 	for (sym = obj->htab[h]; sym; sym = sym->hash) {
     16 		if (!strcmp(name, sym->name))
     17 			return sym;
     18 	}
     19 	if (!install)
     20 		return NULL;
     21 
     22 	if ((sym = malloc(sizeof(*sym))) == NULL)
     23 		return NULL;
     24 
     25 	sym->name = name;
     26 	sym->type = 'U';
     27 	sym->size = 0;
     28 	sym->value = 0;
     29 	sym->hash = obj->htab[h];
     30 	obj->htab[h] = sym;
     31 	sym->next = obj->symbols;
     32 	obj->symbols = sym;
     33 
     34 	return sym;
     35 }