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