FreeCalypso > hg > ueda-linux
comparison ueda/sverp/prim.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children | 7b4f78fcca08 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cd92449fdb51 |
---|---|
1 /* | |
2 * Parsing of the primitives definition file happens here. | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <strings.h> | |
7 #include "../libueda/xga.h" | |
8 #include "struct.h" | |
9 #include "lexer.h" | |
10 | |
11 extern char *malloc(); | |
12 | |
13 extern struct grid_pkg_desc *read_grid_pkg_file(); | |
14 | |
15 extern struct module_def *glob_module_list; | |
16 | |
17 extern char *parser_filename; | |
18 extern FILE *parser_readF; | |
19 extern int parser_lineno; | |
20 extern char parser_read_word[]; | |
21 extern int parser_read_number; | |
22 extern int pushback_token; | |
23 | |
24 static struct module_def *curmod; | |
25 | |
26 static void | |
27 create_module() | |
28 { | |
29 register struct module_def *mod, **modp; | |
30 char *buf; | |
31 | |
32 for (modp = &glob_module_list; mod = *modp; modp = &mod->next) { | |
33 if (!strcmp(mod->name, parser_read_word)) | |
34 parse_error("primitive conflicts with a module name"); | |
35 } | |
36 buf = malloc(sizeof(struct module_def) + strlen(parser_read_word) + 1); | |
37 if (!buf) { | |
38 perror("malloc"); | |
39 exit(1); | |
40 } | |
41 mod = (struct module_def *) buf; | |
42 bzero(mod, sizeof(struct module_def)); | |
43 buf += sizeof(struct module_def); | |
44 strcpy(buf, parser_read_word); | |
45 mod->name = buf; | |
46 mod->is_primitive = 1; | |
47 *modp = mod; | |
48 curmod = mod; | |
49 } | |
50 | |
51 static void | |
52 add_pin(pinname) | |
53 register char *pinname; | |
54 { | |
55 register struct module_net_def *n, **np; | |
56 char *buf; | |
57 | |
58 for (np = &curmod->nets; n = *np; np = &n->next) { | |
59 if (!strcmp(n->name, pinname)) | |
60 parse_error("duplicate pin name"); | |
61 } | |
62 buf = malloc(sizeof(struct module_net_def) + strlen(pinname) + 1); | |
63 if (!buf) { | |
64 perror("malloc"); | |
65 exit(1); | |
66 } | |
67 n = (struct module_net_def *) buf; | |
68 bzero(n, sizeof(struct module_net_def)); | |
69 buf += sizeof(struct module_net_def); | |
70 strcpy(buf, pinname); | |
71 n->name = buf; | |
72 n->is_port = 1; | |
73 n->def_complete = 1; | |
74 n->bus_width = 1; | |
75 n->array_index = curmod->nports; | |
76 *np = n; | |
77 curmod->nports++; | |
78 curmod->nwires_ports++; | |
79 } | |
80 | |
81 static void | |
82 handle_num_pins() | |
83 { | |
84 int t; | |
85 register int i; | |
86 char namebuf[MAXDIGITS+5]; | |
87 | |
88 curmod->prim_numeric_pins = 1; | |
89 t = get_token(); | |
90 if (t != NUMBER) | |
91 parse_error("expected a number after numpins"); | |
92 for (i = 1; i <= parser_read_number; i++) { | |
93 sprintf(namebuf, "pin_%d", i); | |
94 add_pin(namebuf); | |
95 } | |
96 } | |
97 | |
98 static void | |
99 handle_named_pins(ismapped) | |
100 { | |
101 register int t; | |
102 | |
103 curmod->prim_is_mapped = ismapped; | |
104 t = get_token(); | |
105 if (t != '(') | |
106 parse_error("expected '(' after named_pins or mapped_pins"); | |
107 for (;;) { | |
108 t = get_token(); | |
109 if (t == ')') | |
110 return; | |
111 if (t != WORD) | |
112 parse_error("expected pin name"); | |
113 add_pin(parser_read_word); | |
114 t = get_token(); | |
115 if (t == ')') | |
116 return; | |
117 if (t != ',') | |
118 parse_error("expected ',' or ')' in pin name list"); | |
119 } | |
120 } | |
121 | |
122 static void | |
123 handle_grid_pkg() | |
124 { | |
125 int t; | |
126 register struct grid_pkg_desc *desc; | |
127 register int r, c; | |
128 char namebuf[32]; | |
129 | |
130 t = get_token(); | |
131 if (t != QSTRING) | |
132 parse_error("expected quoted filename after grid"); | |
133 desc = read_grid_pkg_file(parser_read_word); | |
134 for (r = 0; r < desc->nrows; r++) | |
135 for (c = 0; c < desc->ncolumns; c++) { | |
136 if (desc->holes_array[r * desc->ncolumns + c]) | |
137 continue; | |
138 sprintf(namebuf, "%c%d", desc->row_letters[r], c + 1); | |
139 add_pin(namebuf); | |
140 } | |
141 free_grid_pkg_desc(desc); | |
142 } | |
143 | |
144 read_primitives_file(filename_arg) | |
145 char *filename_arg; | |
146 { | |
147 register int t; | |
148 | |
149 parser_filename = filename_arg; | |
150 parser_readF = fopen(parser_filename, "r"); | |
151 if (!parser_readF) { | |
152 perror(parser_filename); | |
153 exit(1); | |
154 } | |
155 parser_lineno = 1; | |
156 pushback_token = 0; | |
157 | |
158 for (;;) { | |
159 t = get_token(); | |
160 if (!t) | |
161 break; | |
162 if (t != WORD) | |
163 parse_error("expected primitive name"); | |
164 create_module(); | |
165 t = get_token(); | |
166 if (t != WORD) | |
167 parse_error("expected pins type keyword"); | |
168 if (!strcmp(parser_read_word, "numpins")) | |
169 handle_num_pins(); | |
170 else if (!strcmp(parser_read_word, "grid")) | |
171 handle_grid_pkg(); | |
172 else if (!strcmp(parser_read_word, "named_pins")) | |
173 handle_named_pins(0); | |
174 else if (!strcmp(parser_read_word, "mapped_pins")) | |
175 handle_named_pins(1); | |
176 else { | |
177 fprintf(stderr, | |
178 "%s line %d: \"%s\" is not an understood primitive type\n", | |
179 parser_filename, parser_lineno, | |
180 parser_read_word); | |
181 exit(1); | |
182 } | |
183 t = get_token(); | |
184 if (t != ';') | |
185 parse_error("expected terminating ';'"); | |
186 } | |
187 | |
188 fclose(parser_readF); | |
189 return(0); | |
190 } |