Fix for GitHub issue #239 - segfault when library file has syntax errors.
If there are errors when parsing a file, it is not safe to elaborate any modules that have been found in that file.
This commit is contained in:
parent
8cd8bed22e
commit
0cb1ebddf1
|
|
@ -2233,7 +2233,8 @@ void PGModule::elaborate_scope(Design*des, NetScope*sc) const
|
||||||
// Not a module or primitive that I know about yet, so try to
|
// Not a module or primitive that I know about yet, so try to
|
||||||
// load a library module file (which parses some new Verilog
|
// load a library module file (which parses some new Verilog
|
||||||
// code) and try again.
|
// code) and try again.
|
||||||
if (load_module(type_)) {
|
int parser_errors = 0;
|
||||||
|
if (load_module(type_, parser_errors)) {
|
||||||
|
|
||||||
// Try again to find the module type
|
// Try again to find the module type
|
||||||
mod = pform_modules.find(type_);
|
mod = pform_modules.find(type_);
|
||||||
|
|
@ -2248,6 +2249,10 @@ void PGModule::elaborate_scope(Design*des, NetScope*sc) const
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parser_errors) {
|
||||||
|
cerr << get_fileline() << ": error: Failed to parse library file." << endl;
|
||||||
|
des->errors += parser_errors + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Not a module or primitive that I know about or can find by
|
// Not a module or primitive that I know about or can find by
|
||||||
// any means, so give up.
|
// any means, so give up.
|
||||||
|
|
|
||||||
|
|
@ -54,11 +54,13 @@ extern FILE *depend_file;
|
||||||
* Use the type name as a key, and search the module library for a
|
* Use the type name as a key, and search the module library for a
|
||||||
* file name that has that key.
|
* file name that has that key.
|
||||||
*/
|
*/
|
||||||
bool load_module(const char*type)
|
bool load_module(const char*type, int&parser_errors)
|
||||||
{
|
{
|
||||||
char path[4096];
|
char path[4096];
|
||||||
char*ltype = strdup(type);
|
char*ltype = strdup(type);
|
||||||
|
|
||||||
|
parser_errors = 0;
|
||||||
|
|
||||||
for (char*tmp = ltype ; *tmp ; tmp += 1)
|
for (char*tmp = ltype ; *tmp ; tmp += 1)
|
||||||
*tmp = tolower(*tmp);
|
*tmp = tolower(*tmp);
|
||||||
|
|
||||||
|
|
@ -85,12 +87,12 @@ bool load_module(const char*type)
|
||||||
if (verbose_flag)
|
if (verbose_flag)
|
||||||
cerr << "Loading library file " << path << "." << endl;
|
cerr << "Loading library file " << path << "." << endl;
|
||||||
|
|
||||||
pform_parse(path);
|
parser_errors = pform_parse(path);
|
||||||
|
|
||||||
if (verbose_flag)
|
if (verbose_flag)
|
||||||
cerr << "... Load module complete." << endl << flush;
|
cerr << "... Load module complete." << endl << flush;
|
||||||
|
|
||||||
return true;
|
return parser_errors == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
2
util.h
2
util.h
|
|
@ -34,7 +34,7 @@ class NetScope;
|
||||||
* looking for a plausible Verilog file to hold the module, and
|
* looking for a plausible Verilog file to hold the module, and
|
||||||
* invoking the parser to bring in that file's contents.
|
* invoking the parser to bring in that file's contents.
|
||||||
*/
|
*/
|
||||||
extern bool load_module(const char*type);
|
extern bool load_module(const char*type, int&parser_errors);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue