lookup.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Header$";
  3. #endif
  4. #include "param.h"
  5. #include "types.h"
  6. #include "shc.h"
  7. #include "lookup.h"
  8. #include "alloc.h"
  9. #include "proinf.h"
  10. /*
  11. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  12. * See the copyright notice in the ACK home directory, in the file "Copyright".
  13. *
  14. * Author: Hans van Staveren
  15. */
  16. unsigned hash(string) char *string; {
  17. register char *p;
  18. register unsigned i,sum;
  19. for (sum=i=0,p=string;*p;i += 3)
  20. sum ^= (*p++)<<(i&07);
  21. return(sum);
  22. }
  23. sym_p symlookup(name,status,flags) char *name; int status,flags; {
  24. register sym_p *spp,sp;
  25. register i;
  26. static short genfrag = 32767;
  27. spp = &symhash[hash(name)%NSYMHASH];
  28. while (*spp != (sym_p) 0)
  29. if (strncmp((*spp)->s_name,name,IDL)==0) {
  30. sp = *spp;
  31. if ((sp->s_flags^flags)&SYMPRO)
  32. error("%s is both proc and datalabel",name);
  33. if (status == DEFINING) {
  34. if (sp->s_flags&SYMDEF)
  35. error("redefined symbol %s",name);
  36. sp->s_flags |= SYMDEF;
  37. }
  38. return(sp);
  39. } else
  40. spp = &(*spp)->s_next;
  41. /*
  42. * symbol not found, enter in table
  43. */
  44. i = strlen(name) + 1;
  45. if (i & 1)
  46. i++;
  47. if (i > IDL)
  48. i = IDL;
  49. *spp = sp = newsym(i);
  50. strncpy(sp->s_name,name,i);
  51. sp->s_flags = flags;
  52. if (status == DEFINING)
  53. sp->s_flags |= SYMDEF;
  54. sp->s_frag = genfrag--;
  55. return(sp);
  56. }
  57. num_p numlookup(number) unsigned number; {
  58. register num_p *npp, np;
  59. npp = &curpro.numhash[number%NNUMHASH];
  60. while (*npp != (num_p) 0)
  61. if ((*npp)->n_number == number)
  62. return(*npp);
  63. else
  64. npp = &(*npp)->n_next;
  65. /*
  66. * local label not found, enter in tabel
  67. */
  68. *npp = np = newnum();
  69. np->n_number = number;
  70. np->n_repl = np;
  71. return(np);
  72. }