mirror of
https://github.com/RTimothyEdwards/netgen.git
synced 2026-08-27 16:36:42 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74e8c3e168 | ||
|
|
f12d03fcff | ||
|
|
95a29fcd8c | ||
|
|
723a950fd3 | ||
|
|
f04c72b984 | ||
|
|
e3368cb22a | ||
|
|
f06e6548bb | ||
|
|
d38bd77825 | ||
|
|
ea4083893c | ||
|
|
72ed19ff36 | ||
|
|
39b8e3d14a | ||
|
|
3dc70148d1 | ||
|
|
b63dfa8638 |
+206
-30
@@ -47,6 +47,18 @@ static FILE *outfile;
|
||||
static int Graph = 0;
|
||||
int File;
|
||||
|
||||
/*------------------------------------------------------*/
|
||||
/* Structure for stacking nested `if[n]def in verilog */
|
||||
/*------------------------------------------------------*/
|
||||
|
||||
struct ifstack {
|
||||
int invert;
|
||||
struct property *kl;
|
||||
struct ifstack *next;
|
||||
};
|
||||
|
||||
struct ifstack *condstack = NULL;
|
||||
|
||||
extern char *SetExtension(char *buffer, char *path, char *extension)
|
||||
/* add 'extension' to 'path' (overwriting previous extension, if any),
|
||||
write it into buffer (if buffer is null, malloc a buffer).
|
||||
@@ -191,6 +203,8 @@ struct filestack {
|
||||
|
||||
static struct filestack *OpenFiles = NULL;
|
||||
|
||||
struct hashdict *definitions = (struct hashdict *)NULL;
|
||||
|
||||
#define WHITESPACE_DELIMITER " \t\n\r"
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@@ -251,7 +265,6 @@ void TrimQuoted(char *line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@@ -265,39 +278,202 @@ void TrimQuoted(char *line)
|
||||
|
||||
int GetNextLineNoNewline(char *delimiter)
|
||||
{
|
||||
char *newbuf;
|
||||
int testc;
|
||||
char *newbuf;
|
||||
int testc;
|
||||
int nested = 0;
|
||||
|
||||
if (feof(infile)) return -1;
|
||||
if (feof(infile)) return -1;
|
||||
|
||||
// This is more reliable than feof() ...
|
||||
testc = getc(infile);
|
||||
if (testc == -1) return -1;
|
||||
ungetc(testc, infile);
|
||||
while (1) { /* May loop indefinitely in an `if[n]def conditional */
|
||||
|
||||
if (linesize == 0) {
|
||||
/* Allocate memory for line */
|
||||
linesize = 500;
|
||||
line = (char *)MALLOC(linesize);
|
||||
linetok = (char *)MALLOC(linesize);
|
||||
}
|
||||
fgets(line, linesize, infile);
|
||||
while (strlen(line) == linesize - 1) {
|
||||
newbuf = (char *)MALLOC(linesize + 500);
|
||||
strcpy(newbuf, line);
|
||||
FREE(line);
|
||||
line = newbuf;
|
||||
fgets(line + linesize - 1, 501, infile);
|
||||
linesize += 500;
|
||||
FREE(linetok);
|
||||
linetok = (char *)MALLOC(linesize);
|
||||
}
|
||||
linenum++;
|
||||
strcpy(linetok, line);
|
||||
TrimQuoted(linetok);
|
||||
// This is more reliable than feof() ...
|
||||
testc = getc(infile);
|
||||
if (testc == -1) return -1;
|
||||
ungetc(testc, infile);
|
||||
|
||||
nexttok = strdtok(linetok, WHITESPACE_DELIMITER, delimiter);
|
||||
return 0;
|
||||
if (linesize == 0) {
|
||||
/* Allocate memory for line */
|
||||
linesize = 500;
|
||||
line = (char *)MALLOC(linesize);
|
||||
linetok = (char *)MALLOC(linesize);
|
||||
}
|
||||
fgets(line, linesize, infile);
|
||||
while (strlen(line) == linesize - 1) {
|
||||
newbuf = (char *)MALLOC(linesize + 500);
|
||||
strcpy(newbuf, line);
|
||||
FREE(line);
|
||||
line = newbuf;
|
||||
fgets(line + linesize - 1, 501, infile);
|
||||
linesize += 500;
|
||||
FREE(linetok);
|
||||
linetok = (char *)MALLOC(linesize);
|
||||
}
|
||||
|
||||
/* Check for substitutions (verilog only). Make sure linetok is */
|
||||
/* large enough to hold the entire line after substitutions. */
|
||||
|
||||
if (definitions != NULL) {
|
||||
char *s, *w, e;
|
||||
struct property *kl;
|
||||
int len, dlen, vlen, addin = 0;
|
||||
unsigned char found = FALSE;
|
||||
|
||||
for (s = line; *s != '\0'; s++) {
|
||||
if (*s == '`') {
|
||||
w = s + 1;
|
||||
while (isalnum(*w)) w++;
|
||||
e = *w;
|
||||
*w = '\0';
|
||||
kl = (struct property *)HashLookup(s + 1, definitions);
|
||||
if (kl != NULL) {
|
||||
dlen = strlen(s);
|
||||
if (kl->type == PROP_STRING) {
|
||||
vlen = strlen(kl->pdefault.string);
|
||||
}
|
||||
else vlen = 12; /* Leave room for numeric conversion */
|
||||
addin += vlen - dlen + 1;
|
||||
found = TRUE;
|
||||
}
|
||||
*w = e;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
len = strlen(line);
|
||||
if (len + addin > linesize) {
|
||||
while (len + addin > linesize) linesize += 500;
|
||||
FREE(linetok);
|
||||
linetok = (char *)MALLOC(linesize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make definition substitutions (verilog only) */
|
||||
|
||||
if (definitions != NULL) {
|
||||
char *s, *t, *w, e;
|
||||
struct property *kl;
|
||||
|
||||
t = linetok;
|
||||
for (s = line; *s != '\0'; s++) {
|
||||
if (*s == '`') {
|
||||
w = s + 1;
|
||||
while (isalnum(*w)) w++;
|
||||
e = *w;
|
||||
*w = '\0';
|
||||
kl = (struct property *)HashLookup(s + 1, definitions);
|
||||
if (kl != NULL) {
|
||||
if (kl->type == PROP_STRING)
|
||||
strcpy(t, kl->pdefault.string);
|
||||
else if (kl->type == PROP_INTEGER)
|
||||
sprintf(t, "%d", kl->pdefault.ival);
|
||||
else if (kl->type == PROP_DOUBLE)
|
||||
sprintf(t, "%g", kl->pdefault.dval);
|
||||
t += strlen(t);
|
||||
s = w - 1;
|
||||
}
|
||||
else *t++ = *s;
|
||||
*w = e;
|
||||
}
|
||||
else *t++ = *s;
|
||||
}
|
||||
*t = '\0';
|
||||
}
|
||||
else
|
||||
strcpy(linetok, line);
|
||||
|
||||
TrimQuoted(linetok);
|
||||
linenum++;
|
||||
|
||||
nexttok = strdtok(linetok, WHITESPACE_DELIMITER, delimiter);
|
||||
if (nexttok == NULL) return 0;
|
||||
|
||||
/* Handle `ifdef, `ifndef, `elsif, `else, and `endif (verilog */
|
||||
/* only, where indicated by a non-NULL "definitions") */
|
||||
|
||||
if (definitions == NULL) return 0;
|
||||
|
||||
/* If currently skipping through a section, handle conditionals differently */
|
||||
|
||||
if (condstack) {
|
||||
if (((condstack->invert == 0) && (condstack->kl == NULL))
|
||||
|| ((condstack->invert == 1) && (condstack->kl != NULL))) {
|
||||
if (match(nexttok, "`ifdef") || match(nexttok, "`ifndef")) {
|
||||
nested++;
|
||||
continue;
|
||||
}
|
||||
else if (nested > 0) {
|
||||
if (match(nexttok, "`endif")) nested--;
|
||||
continue;
|
||||
}
|
||||
else if (nexttok[0] != '`') continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle conditionals (that is not being skipped over) */
|
||||
|
||||
if (match(nexttok, "`endif")) {
|
||||
if (condstack == NULL) {
|
||||
fprintf(stderr, "Error: `endif without corresponding `if[n]def\n");
|
||||
}
|
||||
else {
|
||||
struct ifstack *iftop = condstack;
|
||||
condstack = condstack->next;
|
||||
FREE(iftop);
|
||||
}
|
||||
}
|
||||
|
||||
/* Note that `if[n]def may be nested. */
|
||||
|
||||
else if (match(nexttok, "`ifdef") || match(nexttok, "`ifndef") ||
|
||||
match(nexttok, "`elsif") || match(nexttok, "`else")) {
|
||||
|
||||
/* Every `ifdef or `ifndef increases condstack by 1 */
|
||||
if (nexttok[1] == 'i') {
|
||||
struct ifstack *newif = (struct ifstack *)MALLOC(sizeof(struct ifstack));
|
||||
newif->next = condstack;
|
||||
condstack = newif;
|
||||
}
|
||||
if (condstack == NULL) {
|
||||
fprintf(stderr, "Error: %s without `if[n]def\n", nexttok);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (match(nexttok, "`else")) {
|
||||
/* Invert the sense of the if[n]def scope */
|
||||
condstack->invert = (condstack->invert == 1) ? 0 : 1;
|
||||
}
|
||||
else if (match(nexttok, "`elsif")) {
|
||||
nexttok = strdtok(NULL, WHITESPACE_DELIMITER, delimiter);
|
||||
if (nexttok == NULL) {
|
||||
fprintf(stderr, "Error: `elsif with no conditional.\n");
|
||||
return 0;
|
||||
}
|
||||
/* Keep the same scope but redefine the parameter */
|
||||
condstack->invert = 0;
|
||||
condstack->kl = (struct property *)HashLookup(nexttok, definitions);
|
||||
}
|
||||
else {
|
||||
condstack->invert = (nexttok[3] == 'n') ? 1 : 0;
|
||||
nexttok = strdtok(NULL, WHITESPACE_DELIMITER, delimiter);
|
||||
if (nexttok == NULL) {
|
||||
fprintf(stderr, "Error: %s with no conditional.\n", nexttok);
|
||||
return 0;
|
||||
}
|
||||
condstack->kl = (struct property *)HashLookup(nexttok, definitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (condstack) {
|
||||
if (((condstack->invert == 0) && (condstack->kl == NULL))
|
||||
|| ((condstack->invert == 1) && (condstack->kl != NULL)))
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
@@ -24,6 +24,7 @@ extern void FlushString (char *format, ...);
|
||||
extern char *SetExtension(char *buffer, char *path, char *extension);
|
||||
|
||||
extern int File;
|
||||
extern struct hashdict *definitions;
|
||||
|
||||
/* input routines */
|
||||
|
||||
@@ -32,6 +33,7 @@ extern char *nexttok;
|
||||
extern char *strdtok(char *pstring, char *delim1, char *delim2);
|
||||
extern void SkipTok(char *delimiter);
|
||||
extern void SkipTokNoNewline(char *delimiter);
|
||||
extern void SkipTokComments(char *delimiter);
|
||||
extern void SkipNewLine(char *delimiter);
|
||||
extern void SpiceTokNoNewline(void); /* handles SPICE "+" continuation line */
|
||||
extern void SpiceSkipNewLine(void); /* handles SPICE "+" continuation line */
|
||||
|
||||
+224
-179
@@ -121,19 +121,33 @@ int GetBusTok(struct bus *wb)
|
||||
if (match(nexttok, "[")) {
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
|
||||
// Check for parameter names and substitute values if found.
|
||||
if (nexttok[0] == '`') {
|
||||
kl = (struct property *)HashLookup(nexttok + 1, &verilogdefs);
|
||||
result = sscanf(nexttok, "%d", &start);
|
||||
if (result != 1) {
|
||||
char *aptr = NULL;
|
||||
char addin;
|
||||
|
||||
// Check for "+/-(n)" at end of a parameter name
|
||||
aptr = strrchr(nexttok, '+');
|
||||
if (aptr == NULL) aptr = strrchr(nexttok, '-');
|
||||
if (aptr != NULL) {
|
||||
addin = *aptr;
|
||||
*aptr = '\0';
|
||||
}
|
||||
|
||||
// Is name in the parameter list?
|
||||
kl = (struct property *)HashLookup(nexttok, &verilogparams);
|
||||
if (kl == NULL) {
|
||||
Printf("Unknown definition %s found in array notation.\n", nexttok);
|
||||
Printf("Array value %s is not a number or a parameter.\n",
|
||||
nexttok);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
if (kl->type == PROP_STRING) {
|
||||
result = sscanf(kl->pdefault.string, "%d", &start);
|
||||
if (result != 1) {
|
||||
Printf("Cannot parse first digit from parameter %s value %s\n",
|
||||
nexttok, kl->pdefault.string);
|
||||
return 1;
|
||||
Printf("Parameter %s has value %s that cannot be parsed"
|
||||
" as an integer.\n", nexttok, kl->pdefault.string);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (kl->type == PROP_INTEGER) {
|
||||
@@ -142,54 +156,25 @@ int GetBusTok(struct bus *wb)
|
||||
else if (kl->type == PROP_DOUBLE) {
|
||||
start = (int)kl->pdefault.dval;
|
||||
if ((double)start != kl->pdefault.dval) {
|
||||
Printf("Cannot parse first digit from parameter %s value %g\n",
|
||||
nexttok, kl->pdefault.dval);
|
||||
return 1;
|
||||
Printf("Parameter %s has value %g that cannot be parsed"
|
||||
" as an integer.\n", nexttok, kl->pdefault.dval);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Printf("Parameter %s has unknown type; don't know how to parse.\n",
|
||||
nexttok);
|
||||
Printf("Parameter %s has unknown type; don't know how"
|
||||
" to parse.\n", nexttok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = sscanf(nexttok, "%d", &start);
|
||||
if (result != 1) {
|
||||
// Is name in the parameter list?
|
||||
kl = (struct property *)HashLookup(nexttok, &verilogparams);
|
||||
if (kl == NULL) {
|
||||
Printf("Array value %s is not a number or a parameter.\n",
|
||||
nexttok);
|
||||
if (aptr != NULL) {
|
||||
int addval;
|
||||
*aptr = addin;
|
||||
if (sscanf(aptr + 1, "%d", &addval) != 1) {
|
||||
Printf("Unable to parse parameter increment '%s'\n", aptr);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
if (kl->type == PROP_STRING) {
|
||||
result = sscanf(kl->pdefault.string, "%d", &start);
|
||||
if (result != 1) {
|
||||
Printf("Parameter %s has value %s that cannot be parsed"
|
||||
" as an integer.\n", nexttok, kl->pdefault.string);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (kl->type == PROP_INTEGER) {
|
||||
start = kl->pdefault.ival;
|
||||
}
|
||||
else if (kl->type == PROP_DOUBLE) {
|
||||
start = (int)kl->pdefault.dval;
|
||||
if ((double)start != kl->pdefault.dval) {
|
||||
Printf("Parameter %s has value %g that cannot be parsed"
|
||||
" as an integer.\n", nexttok, kl->pdefault.dval);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Printf("Parameter %s has unknown type; don't know how"
|
||||
" to parse.\n", nexttok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
start += (addin == '+') ? addval : -addval;
|
||||
}
|
||||
}
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
@@ -204,18 +189,33 @@ int GetBusTok(struct bus *wb)
|
||||
else {
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
|
||||
// Check for parameter names and substitute values if found.
|
||||
if (nexttok[0] == '`') {
|
||||
kl = (struct property *)HashLookup(nexttok + 1, &verilogdefs);
|
||||
result = sscanf(nexttok, "%d", &end);
|
||||
if (result != 1) {
|
||||
char *aptr = NULL;
|
||||
char addin;
|
||||
|
||||
// Check for "+/-(n)" at end of a parameter name
|
||||
aptr = strrchr(nexttok, '+');
|
||||
if (aptr == NULL) aptr = strrchr(nexttok, '-');
|
||||
if (aptr != NULL) {
|
||||
addin = *aptr;
|
||||
*aptr = '\0';
|
||||
}
|
||||
|
||||
// Is name in the parameter list?
|
||||
kl = (struct property *)HashLookup(nexttok, &verilogparams);
|
||||
if (kl == NULL) {
|
||||
Printf("Unknown definition %s found in array notation.\n", nexttok);
|
||||
Printf("Array value %s is not a number or a parameter.\n",
|
||||
nexttok);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
if (kl->type == PROP_STRING) {
|
||||
result = sscanf(kl->pdefault.string, "%d", &end);
|
||||
if (result != 1) {
|
||||
Printf("Cannot parse second digit from parameter "
|
||||
"%s value %s\n", nexttok, kl->pdefault.string);
|
||||
if (result != 1) {
|
||||
Printf("Parameter %s has value %s that cannot be parsed"
|
||||
" as an integer.\n", nexttok,
|
||||
kl->pdefault.string);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -232,48 +232,18 @@ int GetBusTok(struct bus *wb)
|
||||
}
|
||||
else {
|
||||
Printf("Parameter %s has unknown type; don't know how"
|
||||
" to parse.\n", nexttok);
|
||||
" to parse.\n", nexttok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = sscanf(nexttok, "%d", &end);
|
||||
if (result != 1) {
|
||||
// Is name in the parameter list?
|
||||
kl = (struct property *)HashLookup(nexttok, &verilogparams);
|
||||
if (kl == NULL) {
|
||||
Printf("Array value %s is not a number or a parameter.\n",
|
||||
nexttok);
|
||||
if (aptr != NULL) {
|
||||
int addval;
|
||||
*aptr = addin;
|
||||
if (sscanf(aptr + 1, "%d", &addval) != 1) {
|
||||
Printf("Unable to parse parameter increment '%s'\n", aptr);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
if (kl->type == PROP_STRING) {
|
||||
result = sscanf(kl->pdefault.string, "%d", &end);
|
||||
if (result != 1) {
|
||||
Printf("Parameter %s has value %s that cannot be parsed"
|
||||
" as an integer.\n", nexttok,
|
||||
kl->pdefault.string);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (kl->type == PROP_INTEGER) {
|
||||
end = kl->pdefault.ival;
|
||||
}
|
||||
else if (kl->type == PROP_DOUBLE) {
|
||||
end = (int)kl->pdefault.dval;
|
||||
if ((double)end != kl->pdefault.dval) {
|
||||
Printf("Cannot parse second digit from parameter "
|
||||
"%s value %g\n", nexttok, kl->pdefault.dval);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Printf("Parameter %s has unknown type; don't know how"
|
||||
" to parse.\n", nexttok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
end += (addin == '+') ? addval : -addval;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -630,7 +600,7 @@ void ReadVerilogFile(char *fname, int filenum, struct cellstack **CellStackPtr,
|
||||
instname[255] = '\0';
|
||||
in_module = (char)0;
|
||||
in_param = (char)0;
|
||||
|
||||
|
||||
while (!EndParseFile()) {
|
||||
|
||||
SkipTokComments(VLOG_DELIMITERS); /* get the next token */
|
||||
@@ -655,6 +625,81 @@ void ReadVerilogFile(char *fname, int filenum, struct cellstack **CellStackPtr,
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle parameters by treating as a localparam or definition. */
|
||||
/* Currently anything other than a constant value is not handled */
|
||||
/* and so will flag a warning. */
|
||||
|
||||
else if (match(nexttok, "parameter") || match(nexttok, "localparam")) {
|
||||
char *paramkey = NULL;
|
||||
char *paramval = NULL;
|
||||
|
||||
// Pick up key = value pairs and store in current cell. Look only
|
||||
// at the keyword before "=". Then set the defition as everything
|
||||
// remaining in the line, excluding comments, until the end-of-statement
|
||||
|
||||
while (nexttok != NULL)
|
||||
{
|
||||
struct property *kl = NULL;
|
||||
|
||||
/* Parse for parameters used in expressions. Save */
|
||||
/* parameters in the "verilogparams" hash table. */
|
||||
|
||||
SkipTok(VLOG_DELIMITERS);
|
||||
if ((nexttok == NULL) || (nexttok[0] == '\0')) break;
|
||||
if (match(nexttok, "=")) {
|
||||
/* Pick up remainder of statement */
|
||||
while (nexttok != NULL) {
|
||||
SkipTokNoNewline("X///**/X;,");
|
||||
if (nexttok == NULL) break;
|
||||
if (match(nexttok, ";") || match(nexttok, ",")) break;
|
||||
if (paramval == NULL) paramval = strsave(nexttok);
|
||||
else {
|
||||
char *paramlast;
|
||||
/* Append nexttok to paramval */
|
||||
paramlast = paramval;
|
||||
paramval = (char *)MALLOC(strlen(paramlast) + strlen(nexttok)
|
||||
+ 2);
|
||||
sprintf(paramval, "%s %s", paramlast, nexttok);
|
||||
FREE(paramlast);
|
||||
}
|
||||
}
|
||||
|
||||
kl = NewProperty();
|
||||
kl->key = strsave(paramkey);
|
||||
kl->idx = 0;
|
||||
kl->merge = MERGE_NONE;
|
||||
|
||||
if (ConvertStringToInteger(paramval, &ival) == 1) {
|
||||
kl->type = PROP_INTEGER;
|
||||
kl->slop.ival = 0;
|
||||
kl->pdefault.ival = ival;
|
||||
}
|
||||
else if (ConvertStringToFloat(paramval, &dval) == 1) {
|
||||
kl->type = PROP_DOUBLE;
|
||||
kl->slop.dval = 0.01;
|
||||
kl->pdefault.dval = dval;
|
||||
}
|
||||
else {
|
||||
kl->type = PROP_STRING;
|
||||
kl->slop.dval = 0.0;
|
||||
kl->pdefault.string = strsave(paramval);
|
||||
}
|
||||
|
||||
HashPtrInstall(paramkey, kl, &verilogparams);
|
||||
FREE(paramval);
|
||||
paramval = NULL;
|
||||
|
||||
if ((nexttok == NULL) || match(nexttok, ";")) break;
|
||||
}
|
||||
else {
|
||||
if (paramkey != NULL) FREE(paramkey);
|
||||
paramkey = strsave(nexttok);
|
||||
}
|
||||
}
|
||||
if (paramval != NULL) FREE(paramval);
|
||||
if (paramkey != NULL) FREE(paramkey);
|
||||
}
|
||||
|
||||
else if (match(nexttok, "module")) {
|
||||
InitializeHashTable(&buses, OBJHASHSIZE);
|
||||
SkipTokNoNewline(VLOG_DELIMITERS);
|
||||
@@ -731,7 +776,7 @@ void ReadVerilogFile(char *fname, int filenum, struct cellstack **CellStackPtr,
|
||||
inlined_decls = (char)0;
|
||||
|
||||
if (tp != NULL) {
|
||||
struct bus wb;
|
||||
struct bus wb, *nb;
|
||||
|
||||
PushStack(tp->name, CellStackPtr);
|
||||
|
||||
@@ -795,7 +840,8 @@ void ReadVerilogFile(char *fname, int filenum, struct cellstack **CellStackPtr,
|
||||
else {
|
||||
if (!match(nexttok, "input") && !match(nexttok, "output") &&
|
||||
!match(nexttok, "inout") && !match(nexttok, "real") &&
|
||||
!match(nexttok, "logic") && !match(nexttok, "integer")) {
|
||||
!match(nexttok, "wire") && !match(nexttok, "logic") &&
|
||||
!match(nexttok, "integer")) {
|
||||
if (match(nexttok, "[")) {
|
||||
if (GetBusTok(&wb) != 0) {
|
||||
// Didn't parse as a bus, so wing it
|
||||
@@ -817,6 +863,12 @@ void ReadVerilogFile(char *fname, int filenum, struct cellstack **CellStackPtr,
|
||||
Port(portname);
|
||||
}
|
||||
}
|
||||
/* Also register this port as a bus */
|
||||
nb = NewBus();
|
||||
nb->start = wb.start;
|
||||
nb->end = wb.end;
|
||||
HashPtrInstall(nexttok, nb, &buses);
|
||||
|
||||
wb.start = wb.end = -1;
|
||||
}
|
||||
else {
|
||||
@@ -1026,77 +1078,29 @@ skip_endmodule:
|
||||
}
|
||||
HashPtrInstall(kl->key, kl, &verilogdefs);
|
||||
}
|
||||
else if (match(nexttok, "localparam")) {
|
||||
// Pick up key = value pairs and store in current cell
|
||||
while (nexttok != NULL)
|
||||
{
|
||||
struct property *kl = NULL;
|
||||
else if (match(nexttok, "`undef")) {
|
||||
struct property *kl = NULL;
|
||||
|
||||
/* Parse for parameters used in expressions. Save */
|
||||
/* parameters in the "verilogparams" hash table. */
|
||||
SkipTokNoNewline(VLOG_DELIMITERS);
|
||||
if ((nexttok == NULL) || (nexttok[0] == '\0')) break;
|
||||
|
||||
SkipTokNoNewline(VLOG_DELIMITERS);
|
||||
if ((nexttok == NULL) || (nexttok[0] == '\0')) break;
|
||||
if ((eqptr = strchr(nexttok, '=')) != NULL) {
|
||||
*eqptr = '\0';
|
||||
kl = NewProperty();
|
||||
kl->key = strsave(nexttok);
|
||||
kl->idx = 0;
|
||||
kl->merge = MERGE_NONE;
|
||||
|
||||
if (ConvertStringToInteger(eqptr + 1, &ival) == 1) {
|
||||
kl->type = PROP_INTEGER;
|
||||
kl->slop.ival = 0;
|
||||
kl->pdefault.ival = ival;
|
||||
}
|
||||
else if (ConvertStringToFloat(eqptr + 1, &dval) == 1) {
|
||||
kl->type = PROP_DOUBLE;
|
||||
kl->slop.dval = 0.01;
|
||||
kl->pdefault.dval = dval;
|
||||
}
|
||||
else {
|
||||
kl->type = PROP_STRING;
|
||||
kl->slop.dval = 0.0;
|
||||
kl->pdefault.string = strsave(eqptr + 1);
|
||||
}
|
||||
HashPtrInstall(nexttok, kl, &verilogparams);
|
||||
}
|
||||
kl = HashLookup(nexttok, &verilogdefs);
|
||||
if (kl != NULL) {
|
||||
HashDelete(nexttok, &verilogdefs);
|
||||
if (kl->type == PROP_STRING)
|
||||
if (kl->pdefault.string != NULL)
|
||||
FREE(kl->pdefault.string);
|
||||
FREE(kl->key);
|
||||
}
|
||||
/* Presumably it is not an error to undefine an undefined keyword */
|
||||
}
|
||||
|
||||
/* Note: This is just the most basic processing of conditionals, */
|
||||
/* although it does handle nested conditionals. */
|
||||
|
||||
else if (match(nexttok, "`ifdef") || match(nexttok, "`ifndef")) {
|
||||
struct property *kl;
|
||||
int nested = 0;
|
||||
int invert = (nexttok[3] == 'n') ? 1 : 0;
|
||||
|
||||
SkipTokNoNewline(VLOG_DELIMITERS);
|
||||
|
||||
/* To be done: Handle boolean arithmetic on conditionals */
|
||||
|
||||
kl = (struct property *)HashLookup(nexttok, &verilogdefs);
|
||||
if (((invert == 0) && (kl == NULL))
|
||||
|| ((invert == 1) && (kl != NULL))) {
|
||||
/* Skip to matching `endif */
|
||||
while (1) {
|
||||
SkipNewLine(VLOG_DELIMITERS);
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
if (EndParseFile()) break;
|
||||
if (match(nexttok, "`ifdef") || match(nexttok, "`ifndef")) {
|
||||
nested++;
|
||||
}
|
||||
else if (match(nexttok, "`endif")) {
|
||||
if (nested == 0)
|
||||
break;
|
||||
else
|
||||
nested--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (match(nexttok, "real") || match(nexttok, "integer")) {
|
||||
Printf("Ignoring '%s' in module '%s'\n", nexttok, model);
|
||||
/* Do not skip to end of module, as these can be in the middle of */
|
||||
/* I/O assignments, which need to be parsed. */
|
||||
while (!match(nexttok, ";")) SkipTok("X///**/X,;");
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (match(nexttok, "wire") || match(nexttok, "assign")) { /* wire = node */
|
||||
struct bus wb, wb2, *nb;
|
||||
char nodename[128], noderoot[100];
|
||||
@@ -1226,14 +1230,26 @@ skip_endmodule:
|
||||
}
|
||||
}
|
||||
else {
|
||||
j = -1;
|
||||
rhs = LookupObject(nexttok, CurrentCell);
|
||||
}
|
||||
if ((lhs == NULL) || (rhs == NULL)) {
|
||||
/* Not parsable, probably behavioral verilog? */
|
||||
Printf("Module '%s' is not structural verilog, "
|
||||
"making black-box.\n", model);
|
||||
SetClass(CLASS_MODULE);
|
||||
goto skip_endmodule;
|
||||
if (rhs != NULL) {
|
||||
Printf("Improper assignment; left-hand side cannot "
|
||||
"be parsed.\n");
|
||||
Printf("Right-hand side is \"%s\".\n", rhs->name);
|
||||
break;
|
||||
}
|
||||
if (lhs != NULL) {
|
||||
Printf("Improper assignment; right-hand side cannot "
|
||||
"be parsed.\n");
|
||||
Printf("Left-hand side is \"%s\".\n", lhs->name);
|
||||
/* Not parsable, probably behavioral verilog? */
|
||||
Printf("Module '%s' is not structural verilog, "
|
||||
"making black-box.\n", model);
|
||||
SetClass(CLASS_MODULE);
|
||||
goto skip_endmodule;
|
||||
}
|
||||
}
|
||||
while (1) {
|
||||
/* Assign bits in turn from bundle in RHS to bits of LHS */
|
||||
@@ -1266,12 +1282,15 @@ skip_endmodule:
|
||||
// No action---new module is started with next 'module' statement,
|
||||
// if any.
|
||||
SkipNewLine(VLOG_DELIMITERS);
|
||||
in_module = (char)0; /* Should have been done already */
|
||||
}
|
||||
else if (nexttok[0] == '`') {
|
||||
// Ignore any other directive starting with a backtick
|
||||
// Ignore any other directive starting with a backtick (e.g., `timescale)
|
||||
SkipNewLine(VLOG_DELIMITERS);
|
||||
}
|
||||
else if (match(nexttok, "reg") || match(nexttok, "always")) {
|
||||
else if (match(nexttok, "reg") || match(nexttok, "always") ||
|
||||
match(nexttok, "specify") || match(nexttok, "initial")) {
|
||||
Printf("Behavioral keyword '%s' found in source.\n", nexttok);
|
||||
Printf("Module '%s' is not structural verilog, making black-box.\n", model);
|
||||
// To be done: Remove any contents (but may not be necessary)
|
||||
// Recast as module
|
||||
@@ -1281,6 +1300,7 @@ skip_endmodule:
|
||||
else { /* module instances */
|
||||
char instancename[100], modulename[100];
|
||||
int itype, arraystart, arrayend, arraymax, arraymin;
|
||||
char ignore;
|
||||
|
||||
instancename[99] = '\0';
|
||||
modulename[99] = '\0';
|
||||
@@ -1300,9 +1320,12 @@ skip_endmodule:
|
||||
PushStack(fname, CellStackPtr);
|
||||
}
|
||||
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
|
||||
nextinst:
|
||||
ignore = FALSE;
|
||||
head = NULL;
|
||||
tail = NULL;
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
|
||||
// Next token must be '#(' (parameters) or an instance name
|
||||
|
||||
@@ -1375,19 +1398,21 @@ skip_endmodule:
|
||||
// Read the pin list
|
||||
while (nexttok != NULL) {
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
// NOTE: Deal with `ifdef et al. properly. Ignoring for now.
|
||||
while (nexttok[0] == '`') {
|
||||
SkipNewLine(VLOG_DELIMITERS);
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
}
|
||||
if (match(nexttok, ")")) break;
|
||||
else if (match(nexttok, ",")) continue;
|
||||
|
||||
// We need to look for pins of the type ".name(value)"
|
||||
|
||||
if (nexttok[0] != '.') {
|
||||
Printf("Badly formed subcircuit pin line at \"%s\"\n", nexttok);
|
||||
SkipNewLine(VLOG_DELIMITERS);
|
||||
Printf("Warning: Ignoring subcircuit with no pin names "
|
||||
"at \"%s\"\n", nexttok);
|
||||
InputParseError(stderr);
|
||||
while (nexttok != NULL) {
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
if (match(nexttok, ";")) break;
|
||||
}
|
||||
ignore = TRUE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
new_port = (struct portelement *)CALLOC(1, sizeof(struct portelement));
|
||||
@@ -1402,7 +1427,13 @@ skip_endmodule:
|
||||
char localnet[100];
|
||||
// Empty parens, so create a new local node
|
||||
savetok = (char)1;
|
||||
sprintf(localnet, "_noconnect_%d_", localcount++);
|
||||
if (arraystart != -1) {
|
||||
/* No-connect on an instance array must also be an array */
|
||||
sprintf(localnet, "_noconnect_%d_[%d:%d]", localcount++,
|
||||
arraystart, arrayend);
|
||||
}
|
||||
else
|
||||
sprintf(localnet, "_noconnect_%d_", localcount++);
|
||||
new_port->net = strsave(localnet);
|
||||
}
|
||||
else {
|
||||
@@ -1462,10 +1493,21 @@ skip_endmodule:
|
||||
else {
|
||||
Printf("Expected to find instance pin block but got \"%s\"\n", nexttok);
|
||||
}
|
||||
/* Instance should end with a semicolon */
|
||||
if (ignore == TRUE) continue; /* moving along. . . */
|
||||
|
||||
/* Verilog allows multiple instances of a single cell type to be chained */
|
||||
/* together with commas. */
|
||||
|
||||
SkipTokComments(VLOG_DELIMITERS);
|
||||
if (!match(nexttok, ";")) {
|
||||
if (match(nexttok, ",")) {
|
||||
goto nextinst;
|
||||
}
|
||||
|
||||
/* Otherwise, instance must end with a semicolon */
|
||||
|
||||
else if (!match(nexttok, ";")) {
|
||||
Printf("Expected to find end of instance but got \"%s\"\n", nexttok);
|
||||
InputParseError(stderr);
|
||||
}
|
||||
|
||||
/* Check for ignored class */
|
||||
@@ -1813,7 +1855,7 @@ skip_endmodule:
|
||||
// Instance must be an array
|
||||
char netname[128];
|
||||
int slice;
|
||||
if (wb.start > wb.end && arraystart > arrayend)
|
||||
if (wb.start >= wb.end && arraystart >= arrayend)
|
||||
slice = wb.start - (arraystart - i);
|
||||
else if (wb.start < wb.end && arraystart > arrayend)
|
||||
slice = wb.start + (arraystart - i);
|
||||
@@ -1821,6 +1863,7 @@ skip_endmodule:
|
||||
slice = wb.start - (arraystart + i);
|
||||
else // (wb.start < wb.end && arraystart < arrayend)
|
||||
slice = wb.start + (arraystart + i);
|
||||
|
||||
sprintf(netname, "%s[%d]", scanroot, slice);
|
||||
if (LookupObject(netname, CurrentCell) == NULL) Node(netname);
|
||||
join(netname, obptr->name);
|
||||
@@ -1909,6 +1952,7 @@ char *ReadVerilogTop(char *fname, int *fnum, int blackbox)
|
||||
|
||||
InitializeHashTable(&verilogparams, OBJHASHSIZE);
|
||||
InitializeHashTable(&verilogdefs, OBJHASHSIZE);
|
||||
definitions = &verilogdefs;
|
||||
|
||||
/* Add the pre-defined key "LVS" to verilogdefs */
|
||||
|
||||
@@ -1931,6 +1975,7 @@ char *ReadVerilogTop(char *fname, int *fnum, int blackbox)
|
||||
HashKill(&verilogparams);
|
||||
RecurseHashTable(&verilogdefs, freeprop);
|
||||
HashKill(&verilogdefs);
|
||||
definitions = (struct hashdict *)NULL;
|
||||
|
||||
// Record the top level file.
|
||||
if (LookupCellFile(fname, filenum) == NULL) CellDef(fname, filenum);
|
||||
|
||||
Reference in New Issue
Block a user