emlookup.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. #ifndef NORCSID
  6. static char rcsid[]= "$Id$";
  7. #endif
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "param.h"
  11. #include "expr.h"
  12. #include <em_spec.h>
  13. #include <em_flag.h>
  14. extern char em_mnem[][4];
  15. #define HASHSIZE (2*(sp_lmnem-sp_fmnem))
  16. struct emhashmnem {
  17. char h_name[3];
  18. char h_value;
  19. } emhashmnem[HASHSIZE];
  20. initemhash() {
  21. register i;
  22. for(i=0;i<=sp_lmnem-sp_fmnem;i++)
  23. enter(em_mnem[i],i+sp_fmnem);
  24. enter("lab", op_lab);
  25. }
  26. unsigned emhash(name) register char *name; {
  27. register unsigned sum;
  28. register i;
  29. for (sum=i=0;*name;i+=3)
  30. sum ^= (*name++)<<(i&07);
  31. return(sum);
  32. }
  33. enter(name,value) char *name; {
  34. register unsigned h;
  35. h=emhash(name)%HASHSIZE;
  36. while (emhashmnem[h].h_name[0] != 0)
  37. h = (h+1)%HASHSIZE;
  38. strncpy(emhashmnem[h].h_name,name,3);
  39. emhashmnem[h].h_value = value;
  40. }
  41. int mlookup(name) char *name; {
  42. register unsigned h;
  43. h = emhash(name)%HASHSIZE;
  44. while (strncmp(emhashmnem[h].h_name,name,3) != 0 &&
  45. emhashmnem[h].h_name[0] != 0)
  46. h = (h+1)%HASHSIZE;
  47. return(emhashmnem[h].h_value&0xFF); /* 0 if not found */
  48. }
  49. extern char em_flag[];
  50. argtyp(mn) {
  51. switch(em_flag[mn-sp_fmnem]&EM_PAR) {
  52. case PAR_W:
  53. case PAR_S:
  54. case PAR_Z:
  55. case PAR_O:
  56. case PAR_N:
  57. case PAR_L:
  58. case PAR_F:
  59. case PAR_R:
  60. case PAR_C:
  61. return(TYPINT);
  62. default:
  63. return(TYPADDR);
  64. }
  65. }