Merge branch 'master' into netgen-1.5

This commit is contained in:
Tim Edwards 2019-08-13 03:00:07 -04:00
commit 6e63f49d53
1 changed files with 96 additions and 15 deletions

View File

@ -313,7 +313,7 @@ int GetBusTok(struct bus *wb)
int GetBus(char *astr, struct bus *wb) int GetBus(char *astr, struct bus *wb)
{ {
char *colonptr, *brackstart, *brackend; char *colonptr, *brackstart, *brackend, *sigend, sdelim;
int result, start, end; int result, start, end;
if (wb == NULL) return 0; if (wb == NULL) return 0;
@ -321,6 +321,40 @@ int GetBus(char *astr, struct bus *wb)
wb->start = -1; wb->start = -1;
wb->end = -1; wb->end = -1;
} }
/* Check for wire bundles. If there are bundles, process each */
/* section separately and concatenate the sizes. */
/* To be done: Handle nested bundles, including N-times concatenation */
if (*astr == '{') {
struct bus wbb;
astr++;
wb->end = 0;
while((*astr != '\0') && (*astr != '}')) {
sigend = strchr(astr, ',');
if (sigend == NULL) sigend = strchr(astr, '}');
if (sigend == NULL) {
Printf("Badly formed wire bundle \"%s\"\n", astr - 1);
return 1;
}
sdelim = *sigend;
*sigend = '\0';
if (GetBus(astr, &wbb) == 0) {
if (wbb.start > wbb.end)
wb->start += (wbb.start - wbb.end + 1);
else
wb->start += (wbb.end - wbb.start + 1);
}
else {
wb->start++;
}
*sigend = sdelim;
astr = sigend + 1;
}
return 0;
}
brackstart = strchr(astr, '['); brackstart = strchr(astr, '[');
if (brackstart != NULL) { if (brackstart != NULL) {
brackend = strchr(astr, ']'); brackend = strchr(astr, ']');
@ -1115,7 +1149,7 @@ skip_endmodule:
while (1) { while (1) {
SkipTokNoNewline(VLOG_DELIMITERS); SkipTokNoNewline(VLOG_DELIMITERS);
if (match(nexttok, ",")) { if (match(nexttok, ",")) {
SkipTokNoNewline(VLOG_DELIMITERS); SkipTokComments(VLOG_DELIMITERS);
if (LookupObject(nexttok, CurrentCell) == NULL) { if (LookupObject(nexttok, CurrentCell) == NULL) {
Node(nexttok); Node(nexttok);
lhs = LookupObject(nexttok, CurrentCell); lhs = LookupObject(nexttok, CurrentCell);
@ -1140,7 +1174,7 @@ skip_endmodule:
else { else {
lhs = LookupObject(nexttok, CurrentCell); lhs = LookupObject(nexttok, CurrentCell);
} }
SkipTokNoNewline(VLOG_DELIMITERS); SkipTokComments(VLOG_DELIMITERS);
if (lhs && ((!nexttok) || (!match(nexttok, "=")))) { if (lhs && ((!nexttok) || (!match(nexttok, "=")))) {
fprintf(stderr, "Empty assignment for net %s\n", lhs->name); fprintf(stderr, "Empty assignment for net %s\n", lhs->name);
} }
@ -1160,7 +1194,7 @@ skip_endmodule:
i = wb.start; i = wb.start;
while (1) { while (1) {
SkipTokNoNewline(VLOG_PIN_CHECK_DELIMITERS); SkipTokComments(VLOG_PIN_CHECK_DELIMITERS);
if (!nexttok) break; if (!nexttok) break;
if (match(nexttok, "{")) { if (match(nexttok, "{")) {
@ -1216,18 +1250,17 @@ skip_endmodule:
join(nodename, assignname); join(nodename, assignname);
if (j == wb2.end) break;
if (i == wb.end) break; if (i == wb.end) break;
i += (wb.end > wb.start) ? 1 : -1;
if (j == wb2.end) break;
j += (wb2.end > wb2.start) ? 1 : -1; j += (wb2.end > wb2.start) ? 1 : -1;
} }
} }
i += (wb.end > wb.start) ? 1 : -1;
} }
} }
do { while (nexttok && !match(nexttok, ";"))
SkipTokNoNewline(VLOG_DELIMITERS); SkipTokComments(VLOG_DELIMITERS);
} while (nexttok && match(nexttok, ";"));
} }
else if (match(nexttok, "endmodule")) { else if (match(nexttok, "endmodule")) {
// No action---new module is started with next 'module' statement, // No action---new module is started with next 'module' statement,
@ -1609,19 +1642,44 @@ skip_endmodule:
// Otherwise, net is bit-sliced across array of instances. // Otherwise, net is bit-sliced across array of instances.
} }
else if (wb.start > wb.end) { else if (wb.start > wb.end) {
char *bptr; char *bptr, *cptr, cchar, *netname;
unsigned char is_bundle = 0;
struct bus wbb;
i = wb.start; i = wb.start;
j = portstart; j = portstart;
netname = scan->net;
if (*netname == '{') {
is_bundle = 1;
netname++;
cptr = strchr(netname, ',');
if (cptr == NULL) cptr = strchr(netname, '}');
if (cptr == NULL) cptr = netname + strlen(netname) - 1;
cchar = *cptr;
*cptr = '\0';
}
// Remove indexed part of scan->net // Remove indexed part of scan->net
if ((bptr = strchr(scan->net, '[')) != NULL) if (GetBus(netname, &wbb) == 0) {
i = wbb.start;
if ((bptr = strchr(netname, '[')) != NULL)
*bptr = '\0'; *bptr = '\0';
}
else
i = -1;
if (is_bundle) *cptr = cchar; /* Restore bundle delimiter */
while (1) { while (1) {
new_port = (struct portelement *)CALLOC(1, new_port = (struct portelement *)CALLOC(1,
sizeof(struct portelement)); sizeof(struct portelement));
sprintf(vname, "%s[%d]", scan->name, j); sprintf(vname, "%s[%d]", scan->name, j);
new_port->name = strsave(vname); new_port->name = strsave(vname);
sprintf(vname, "%s[%d]", scan->net, i); if (i == -1)
sprintf(vname, "%s", netname);
else
sprintf(vname, "%s[%d]", netname, i);
new_port->net = strsave(vname); new_port->net = strsave(vname);
if (last == NULL) if (last == NULL)
@ -1636,8 +1694,31 @@ skip_endmodule:
if (portstart > portend) j--; if (portstart > portend) j--;
else j++; else j++;
if (wb.start > wb.end) i--; if (wbb.start > wbb.end) i--;
else i++; else i++;
if (is_bundle &&
((i == -1) ||
((wbb.start > wbb.end) && (i < wbb.end)) ||
((wbb.start < wbb.end) && (i > wbb.end)))) {
if (bptr) *bptr = '[';
netname = cptr + 1;
cptr = strchr(netname, ',');
if (cptr == NULL) cptr = strchr(netname, '}');
if (cptr == NULL) cptr = netname + strlen(netname) - 1;
cchar = *cptr;
*cptr = '\0';
if (GetBus(netname, &wbb) == 0) {
i = wbb.start;
if ((bptr = strchr(netname, '[')) != NULL)
*bptr = '\0';
}
else i = -1;
*cptr = cchar; /* Restore delimiter */
}
} }
FREE(scan); FREE(scan);
scan = last; scan = last;