/* +--------------------------------------------------------------------------+ | FlowMap: LUT-Based FPGA Technology Mapping Package (Release B 0.2) | +--------------------------------------------------------------------------+ | Copyright (C) 1991-1994 the Regents of University of California | +--------------------------------------------------------------------------+ | Restricted distribution only -- see "release.statement" | +--------------------------------------------------------------------------+ | Author: Eugene Ding, VLSI CAD Lab, UCLA CS Dept. | +--------------------------------------------------------------------------+ | File Name: flmapini.c | | Description: routines supporitng partial mapping initialization | +--------------------------------------------------------------------------+ */ #include "flowmap.h" #define AVGNML 16 #define MAXNML 64 #define WHITESPACE(X) ((X)==' ' || (X)=='\t' || (X)=='\n') int flow_read_clusters(nodevec, k, cfp) array_t *nodevec; int k; FILE *cfp; { char sep = '|', *buf; char token[MAXNML]; network_t *network; node_t *root, *node, *node2; array_t *members; int i, j, l, m, count = 0, bad_count = 0; if (array_n(nodevec) <= 0) return (-1); network = node_network(array_fetch(node_t *, nodevec, 0)); buf = ALLOC(char, array_n(nodevec) * (AVGNML + 1) + 1); while (fgets(buf, array_n(nodevec) * (AVGNML + 1), cfp) != NULL) { buf[strlen(buf) + 1] = '\0'; count++; i = 0; for (j = 0; (token[j] = buf[i++]) != sep; j++) if (token[j] == '\n' || token[j] == '\0') break; if (j == 0) { if (token[0] == sep && buf[i++] == '=' && buf[i++] == '=') sep = buf[i++]; continue; } if (token[j] != sep) { for (l = 0; l < j; l++) if (!WHITESPACE(token[l])) break; if (l < j) { fprintf(siserr, "Warning: illegal cluster specification ignored at line %d.\n", count); bad_count++; if (bad_count >= 3 && bad_count >= count) { fprintf(siserr, "Error: too many illegal clusters -- initialization aborted.\n"); FREE(buf); return (-1); } } continue; } token[j] = '\0'; root = network_find_node(network, token); if (root == NULL) { fprintf(siserr, "Warning: illegal cluster specification ignored at line %d.\n", count); bad_count++; if (bad_count >= 3 && bad_count >= count) { fprintf(siserr, "Error: too many illegal clusters -- initialization aborted.\n"); FREE(buf); return (-1); } continue; } if (root->type == PRIMARY_OUTPUT) root = root->fanin[0]; else if (root->type == PRIMARY_INPUT) continue; for (j = 0; (token[j] = buf[i++]) != sep; j++) if (token[j] == '\n' || token[j] == '\0') break; m = token[j]; token[j] = '\0'; if (j > 0) l = atoi(token); else l = -1; if (l < 0 || (l > 0 && m != sep)) { fprintf(siserr, "Warning: illegal cluster specification skipped at line %d.\n", count); bad_count++; if (bad_count >= 3 && bad_count >= count) { fprintf(siserr, "Error: too many illegal clusters -- initialization aborted.\n"); FREE(buf); return (-1); } continue; } if (l == 0) continue; members = array_alloc(node_t *, l); for (m = 0; m < l; m++) { if (i > strlen(buf)) { fprintf(siserr, "Warning: illegal cluster spec skipped at line %d.\n", count); bad_count++; if (bad_count >= 3 && bad_count >= count) { fprintf(siserr, "Error: too many illegal clusters -- initialization aborted.\n"); FREE(buf); array_free(members); return (-1); } l = -1; break; } for (j = 0; (token[j] = buf[i++]) != sep; j++) if (token[j] == '\n' || token[j] == '\0') break; token[j] = '\0'; if (j == 0) node = NULL; else node = network_find_node(network, token); if (node == NULL) { fprintf(siserr, "Warning: illegal cluster spec ignored at line %d.\n", count); bad_count++; if (bad_count >= 3 && bad_count >= count) { fprintf(siserr, "Error: too many illegal clusters -- initialization aborted.\n"); FREE(buf); array_free(members); return (-1); } l = -1; break; } if (node->type == PRIMARY_OUTPUT) node = node->fanin[0]; array_insert(node_t *, members, m, node); } if (l == -1) array_free(members); else { j = 0; foreach_fanin(root, l, node) { Label(node) = 1; j++; } for (l = 0; l < array_n(members); l++) { node = array_fetch(node_t *, members, l); if (Label(node) != 1) { l = -2; break; } j--; foreach_fanin(node, m, node2) if (Label(node2) != 1) { Label(node2) = 1; j++; } } if (l == -2) j = k + 1; for (l = 0; l < array_n(members); l++) { node = array_fetch(node_t *, members, l); Label(node) = 0; foreach_fanin(node, m, node2) Label(node2) = 0; } if (j > k) { fprintf(siserr, "Warning: infeasible cluster ignored at line %d.\n", count); array_free(members); } else if (Cluster(root) == NULL) { Cluster(root) = members; for (j = 0; (token[j] = buf[i++]) != sep; j++) if (token[j] == '\n' || token[j] == '\0') break; token[j] = '\0'; if (token[0] == 'p' || token[0] == 'P') Mark(root) = PERMMARK; } else { fprintf(siserr, "Warning: multiple cluster definition ignored at line %d.\n", count); array_free(members); } } } FREE(buf); return (1); }