FreeCalypso > hg > ueda-linux
annotate ueda/unet-bind/insthash.c @ 101:ffab0a4424ad
ueda: unet-bind program moved into sensibly named unet-bind subdir
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 29 Sep 2019 22:42:41 +0000 |
parents | ueda/sverp-bind/insthash.c@f7b09a54c2ce |
children |
rev | line source |
---|---|
13
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <stdio.h> |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <stdlib.h> |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <string.h> |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <strings.h> |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include "struct.h" |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #define HASH_SIZE 1103 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 static struct instance *hashtab[HASH_SIZE]; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 static int |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 hash_instname(str) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 char *str; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 { |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 register u_long accum = 0; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 register char *cp; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 register int c, i; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 for (cp = str, i = 1; c = *cp; cp++, i++) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 accum += c * i; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 return(accum % HASH_SIZE); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 } |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 struct instance * |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 enter_instance(newname) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 char *newname; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 { |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 register struct instance *n, **np; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 int namelen; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 for (np = hashtab + hash_instname(newname); n = *np; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 np = &n->nextinhash) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 if (!strcmp(n->name, newname)) { |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 fprintf(stderr, "error: duplicate instance name %s\n", |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 newname); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 exit(1); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 } |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 namelen = strlen(newname); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 n = (struct instance *) malloc(sizeof(struct instance) + namelen + 1); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (!n) { |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 perror("malloc"); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 exit(1); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 } |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 bzero(n, sizeof(struct instance)); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 n->name = (char *)(n + 1); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 strcpy(n->name, newname); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 *np = n; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 return n; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 struct instance * |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 find_instance(soughtname) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 register char *soughtname; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 { |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 register struct instance *n; |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 for (n = hashtab[hash_instname(soughtname)]; n; n = n->nextinhash) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (!strcmp(n->name, soughtname)) |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 return(n); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 return(0); |
1f3283f8e482
unet-bind: instance hash implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 } |
21
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
61 |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
62 check_unclaimed_instances() |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
63 { |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
64 int hb; |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
65 register struct instance *n; |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
66 unsigned unclaimed_count = 0; |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
67 |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
68 for (hb = 0; hb < HASH_SIZE; hb++) |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
69 for (n = hashtab[hb]; n; n = n->nextinhash) |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
70 if (!n->claimed) { |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
71 fprintf(stderr, |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
72 "error: declared instance %s not claimed by input netlist\n", |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
73 n->name); |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
74 unclaimed_count++; |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
75 } |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
76 if (unclaimed_count) { |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
77 fprintf(stderr, "error: unclaimed instances found, aborting\n"); |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
78 exit(1); |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
79 } |
f7b09a54c2ce
unet-bind: implemented the check for unclaimed instances
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
13
diff
changeset
|
80 } |