emlookup.c 1.4 KB

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