error/warn

This commit is contained in:
James Cherry 2020-12-25 14:00:11 -08:00
parent 078d69fc8d
commit ee86a30338
7 changed files with 84 additions and 25 deletions

View File

@ -47,7 +47,6 @@ public:
va_list args); va_list args);
void print(const string *str); void print(const string *str);
void print(const string &str); void print(const string &str);
virtual void flush() {}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -55,6 +54,9 @@ public:
virtual void warn(int id, virtual void warn(int id,
const char *fmt, ...) const char *fmt, ...)
__attribute__((format (printf, 3, 4))); __attribute__((format (printf, 3, 4)));
virtual void vwarn(int id,
const char *fmt,
va_list args);
// Report warning in a file. // Report warning in a file.
virtual void fileWarn(int id, virtual void fileWarn(int id,
const char *filename, const char *filename,
@ -65,11 +67,14 @@ public:
const char *filename, const char *filename,
int line, int line,
const char *fmt, const char *fmt,
va_list args); va_list args);
virtual void error(int id, virtual void error(int id,
const char *fmt, ...) const char *fmt, ...)
__attribute__((format (printf, 3, 4))); __attribute__((format (printf, 3, 4)));
virtual void verror(int id,
const char *fmt,
va_list args);
// Report error in a file. // Report error in a file.
virtual void fileError(int id, virtual void fileError(int id,
const char *filename, const char *filename,
@ -80,7 +85,7 @@ public:
const char *filename, const char *filename,
int line, int line,
const char *fmt, const char *fmt,
va_list args); va_list args);
// Critical. // Critical.
// Report error condition that should not be possible or that prevents execution. // Report error condition that should not be possible or that prevents execution.

View File

@ -556,7 +556,7 @@ libertyParseError(const char *fmt, ...)
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
sta::liberty_report->vfileError(25, sta::liberty_filename, sta::liberty_line, sta::liberty_report->vfileError(25, sta::liberty_filename, sta::liberty_line,
fmt, args); fmt, args);
va_end(args); va_end(args);
} }

View File

@ -4399,7 +4399,7 @@ LibertyReader::libWarn(int id,
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
report_->vfileWarn(id, filename_, stmt->line(), fmt, args); report_->fileWarn(id, filename_, stmt->line(), fmt, args);
va_end(args); va_end(args);
} }

View File

@ -1943,6 +1943,44 @@ git_sha1()
return STA_GIT_SHA1; return STA_GIT_SHA1;
} }
void
report_error(int id,
const char *msg)
{
Sta::sta()->report()->error(id, "%s", msg);
}
void
report_file_error(int id,
const char *filename,
int line,
const char *msg)
{
Sta::sta()->report()->error(id, filename, line, "%s", msg);
}
void
report_warn(int id,
const char *msg)
{
Sta::sta()->report()->warn(id, "%s", msg);
}
void
report_file_warn(int id,
const char *filename,
int line,
const char *msg)
{
Sta::sta()->report()->fileWarn(id, filename, line, "%s", msg);
}
void
report(const char *msg)
{
Sta::sta()->report()->print(msg);
}
void void
fflush() fflush()
{ {

View File

@ -251,13 +251,13 @@ proc show_cmd_args { cmd } {
################################################################ ################################################################
proc sta_warn { id msg } { proc sta_warn { msg_id msg } {
variable sdc_file variable sdc_file
variable sdc_line variable sdc_line
if { [info exists sdc_file] } { if { [info exists sdc_file] } {
puts "Warning: [file tail $sdc_file], $sdc_line $msg" report_file_warn $msg_id [file tail $sdc_file] $sdc_line $msg
} else { } else {
puts "Warning: $msg" report_warn $msg_id $msg
} }
} }
@ -265,17 +265,17 @@ proc sta_error { id msg } {
variable sdc_file variable sdc_file
variable sdc_line variable sdc_line
if { [info exists sdc_file] } { if { [info exists sdc_file] } {
error "Error: [file tail $sdc_file], $sdc_line $msg" error "Error: [file tail $sdc_file] line $sdc_line, $msg"
} else { } else {
error "Error: $msg" error "Error: $msg"
} }
} }
proc sta_warn_error { id warn_error msg } { proc sta_warn_error { msg_id warn_error msg } {
if { $warn_error == "warn" } { if { $warn_error == "warn" } {
sta_warn $id $msg sta_warn $msg_id $msg
} else { } else {
sta_error $id $msg sta_error $$msg_id $msg
} }
} }

View File

@ -158,6 +158,17 @@ Report::warn(int /* id */,
va_end(args); va_end(args);
} }
void
Report::vwarn(int /* id */,
const char *fmt,
va_list args)
{
printToBuffer("Warning: ");
printToBufferAppend(fmt, args);
printToBufferAppend("\n");
printBuffer();
}
void void
Report::fileWarn(int /* id */, Report::fileWarn(int /* id */,
const char *filename, const char *filename,
@ -167,7 +178,7 @@ Report::fileWarn(int /* id */,
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printToBuffer("Warning: %s, line %d ", filename, line); printToBuffer("Warning: %s line %d, ", filename, line);
printToBufferAppend(fmt, args); printToBufferAppend(fmt, args);
printToBufferAppend("\n"); printToBufferAppend("\n");
printBuffer(); printBuffer();
@ -179,9 +190,9 @@ Report::vfileWarn(int /* id */,
const char *filename, const char *filename,
int line, int line,
const char *fmt, const char *fmt,
va_list args) va_list args)
{ {
printToBuffer("Warning: %s, line %d ", filename, line); printToBuffer("Warning: %s line %d, ", filename, line);
printToBufferAppend(fmt, args); printToBufferAppend(fmt, args);
printToBufferAppend("\n"); printToBufferAppend("\n");
printBuffer(); printBuffer();
@ -193,7 +204,6 @@ void
Report::error(int /* id */, Report::error(int /* id */,
const char *fmt, ...) const char *fmt, ...)
{ {
flush();
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
// No prefix msg, no \n. // No prefix msg, no \n.
@ -202,6 +212,16 @@ Report::error(int /* id */,
throw ExceptionMsg(buffer_); throw ExceptionMsg(buffer_);
} }
void
Report::verror(int /* id */,
const char *fmt,
va_list args)
{
// No prefix msg, no \n.
printToBuffer(fmt, args);
throw ExceptionMsg(buffer_);
}
void void
Report::fileError(int /* id */, Report::fileError(int /* id */,
const char *filename, const char *filename,
@ -209,11 +229,10 @@ Report::fileError(int /* id */,
const char *fmt, const char *fmt,
...) ...)
{ {
flush();
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
// No prefix msg, no \n. // No prefix msg, no \n.
printToBuffer("%s, line %d ", filename, line); printToBuffer("%s line %d, ", filename, line);
printToBufferAppend(fmt, args); printToBufferAppend(fmt, args);
va_end(args); va_end(args);
throw ExceptionMsg(buffer_); throw ExceptionMsg(buffer_);
@ -226,9 +245,8 @@ Report::vfileError(int /* id */,
const char *fmt, const char *fmt,
va_list args) va_list args)
{ {
flush();
// No prefix msg, no \n. // No prefix msg, no \n.
printToBuffer("%s, line %d ", filename, line); printToBuffer("%s line %d, ", filename, line);
printToBufferAppend(fmt, args); printToBufferAppend(fmt, args);
throw ExceptionMsg(buffer_); throw ExceptionMsg(buffer_);
} }
@ -258,7 +276,7 @@ Report::fileCritical(int /* id */,
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
printToBuffer("Critical: %s, line %d ", filename, line, fmt, args); printToBuffer("Critical: %s line %d, ", filename, line, fmt, args);
printToBufferAppend(fmt, args); printToBufferAppend(fmt, args);
printToBufferAppend("\n"); printToBufferAppend("\n");
va_end(args); va_end(args);

View File

@ -2242,10 +2242,8 @@ void verilogFlushBuffer();
int int
VerilogParse_error(const char *msg) VerilogParse_error(const char *msg)
{ {
sta::verilog_reader->report()->fileError(164, sta::verilog_reader->report()->fileError(164, sta::verilog_reader->filename(),
sta::verilog_reader->filename(), sta::verilog_reader->line(), "%s", msg);
sta::verilog_reader->line(),
"%s.\n", msg);
verilogFlushBuffer(); verilogFlushBuffer();
return 0; return 0;
} }