emlookup.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. void enter(char *name, int value);
  17. struct emhashmnem {
  18. char h_name[3];
  19. char h_value;
  20. } emhashmnem[HASHSIZE];
  21. void initemhash()
  22. {
  23. int i;
  24. for(i=0;i<=sp_lmnem-sp_fmnem;i++)
  25. enter(em_mnem[i],i+sp_fmnem);
  26. enter("lab", op_lab);
  27. }
  28. unsigned int emhash(char *name)
  29. {
  30. unsigned int sum;
  31. int i;
  32. for (sum=i=0;*name;i+=3)
  33. sum ^= (*name++)<<(i&07);
  34. return(sum);
  35. }
  36. void enter(char *name, int value)
  37. {
  38. unsigned int h;
  39. h=emhash(name)%HASHSIZE;
  40. while (emhashmnem[h].h_name[0] != 0)
  41. h = (h+1)%HASHSIZE;
  42. strncpy(emhashmnem[h].h_name,name,3);
  43. emhashmnem[h].h_value = value;
  44. }
  45. int mlookup(char *name)
  46. {
  47. unsigned int h;
  48. h = emhash(name)%HASHSIZE;
  49. while (strncmp(emhashmnem[h].h_name,name,3) != 0 &&
  50. emhashmnem[h].h_name[0] != 0)
  51. h = (h+1)%HASHSIZE;
  52. return(emhashmnem[h].h_value&0xFF); /* 0 if not found */
  53. }
  54. extern char em_flag[];
  55. int argtyp(int mn)
  56. {
  57. switch(em_flag[mn-sp_fmnem]&EM_PAR) {
  58. case PAR_W:
  59. case PAR_S:
  60. case PAR_Z:
  61. case PAR_O:
  62. case PAR_N:
  63. case PAR_L:
  64. case PAR_F:
  65. case PAR_R:
  66. case PAR_C:
  67. return(TYPINT);
  68. default:
  69. return(TYPADDR);
  70. }
  71. }