2012-04-13 01:08:20 +00:00
|
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Error handling
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2019-01-04 00:17:22 +00:00
|
|
|
|
// Copyright 2003-2019 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#ifndef _V3ERROR_H_
|
|
|
|
|
#define _V3ERROR_H_ 1
|
2018-10-14 17:43:24 +00:00
|
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 17:43:24 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include <bitset>
|
2018-10-14 17:43:24 +00:00
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <deque>
|
2011-10-11 11:07:24 +00:00
|
|
|
|
#include <map>
|
2012-05-22 01:31:52 +00:00
|
|
|
|
#include <set>
|
2018-10-14 17:43:24 +00:00
|
|
|
|
#include <sstream>
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
|
|
class V3ErrorCode {
|
|
|
|
|
public:
|
|
|
|
|
enum en {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
EC_MIN=0, // Keep first
|
|
|
|
|
//
|
|
|
|
|
EC_INFO, // General information out
|
|
|
|
|
EC_FATAL, // Kill the program
|
|
|
|
|
EC_FATALSRC, // Kill the program, for internal source errors
|
|
|
|
|
EC_ERROR, // General error out, can't suppress
|
|
|
|
|
// Boolean information we track per-line, but aren't errors
|
|
|
|
|
I_COVERAGE, // Coverage is on/off from /*verilator coverage_on/off*/
|
|
|
|
|
I_TRACING, // Tracing is on/off from /*verilator tracing_on/off*/
|
|
|
|
|
I_LINT, // All lint messages
|
|
|
|
|
I_DEF_NETTYPE_WIRE, // `default_nettype is WIRE (false=NONE)
|
|
|
|
|
// Error codes:
|
|
|
|
|
E_DETECTARRAY, // Error: Unsupported: Can't detect changes on arrayed variable
|
2019-02-28 02:06:07 +00:00
|
|
|
|
E_PORTSHORT, // Error: Output port is connected to a constant, electrical short
|
|
|
|
|
E_TASKNSVAR, // Error: Task I/O not simple
|
2019-05-19 20:13:13 +00:00
|
|
|
|
//
|
|
|
|
|
// Warning codes:
|
|
|
|
|
EC_FIRST_WARN, // Just a code so the program knows where to start warnings
|
|
|
|
|
//
|
|
|
|
|
ALWCOMBORDER, // Always_comb with unordered statements
|
|
|
|
|
ASSIGNDLY, // Assignment delays
|
|
|
|
|
ASSIGNIN, // Assigning to input
|
|
|
|
|
BLKANDNBLK, // Blocked and non-blocking assignments to same variable
|
|
|
|
|
BLKLOOPINIT, // Delayed assignment to array inside for loops
|
|
|
|
|
BLKSEQ, // Blocking assignments in sequential block
|
|
|
|
|
BSSPACE, // Backslash space
|
|
|
|
|
CASEINCOMPLETE, // Case statement has missing values
|
|
|
|
|
CASEOVERLAP, // Case statements overlap
|
|
|
|
|
CASEWITHX, // Case with X values
|
|
|
|
|
CASEX, // Casex
|
|
|
|
|
CDCRSTLOGIC, // Logic in async reset path
|
|
|
|
|
CLKDATA, // Clock used as data
|
|
|
|
|
CMPCONST, // Comparison is constant due to limited range
|
|
|
|
|
COLONPLUS, // :+ instead of +:
|
2018-11-26 22:58:18 +00:00
|
|
|
|
COMBDLY, // Combinatorial delayed assignment
|
2018-12-01 15:12:10 +00:00
|
|
|
|
CONTASSREG, // Continuous assignment on reg
|
2018-11-26 22:58:18 +00:00
|
|
|
|
DEFPARAM, // Style: Defparam
|
|
|
|
|
DECLFILENAME, // Declaration doesn't match filename
|
2019-05-19 20:13:13 +00:00
|
|
|
|
ENDLABEL, // End lable name mismatch
|
|
|
|
|
GENCLK, // Generated Clock
|
|
|
|
|
IFDEPTH, // If statements too deep
|
2019-09-09 11:50:21 +00:00
|
|
|
|
IGNOREDRETURN, // Ignoring return value (function as task)
|
2019-03-10 18:57:01 +00:00
|
|
|
|
IMPERFECTSCH, // Imperfect schedule (disabled by default)
|
2018-11-28 23:25:34 +00:00
|
|
|
|
IMPLICIT, // Implicit wire
|
|
|
|
|
IMPORTSTAR, // Import::* in $unit
|
|
|
|
|
IMPURE, // Impure function not being inlined
|
2019-05-19 20:13:13 +00:00
|
|
|
|
INCABSPATH, // Include has absolute path
|
2017-12-27 02:35:08 +00:00
|
|
|
|
INFINITELOOP, // Infinite loop
|
2019-05-19 20:13:13 +00:00
|
|
|
|
INITIALDLY, // Initial delayed statement
|
|
|
|
|
LITENDIAN, // Little bit endian vector
|
|
|
|
|
MODDUP, // Duplicate module
|
|
|
|
|
MULTIDRIVEN, // Driven from multiple blocks
|
2019-06-30 20:46:48 +00:00
|
|
|
|
MULTITOP, // Multiple top level modules
|
2019-05-19 20:13:13 +00:00
|
|
|
|
PINMISSING, // Cell pin not specified
|
|
|
|
|
PINNOCONNECT, // Cell pin not connected
|
2018-11-26 22:58:18 +00:00
|
|
|
|
PINCONNECTEMPTY,// Cell pin connected by name with empty reference
|
|
|
|
|
PROCASSWIRE, // Procedural assignment on wire
|
|
|
|
|
REALCVT, // Real conversion
|
2019-05-19 20:13:13 +00:00
|
|
|
|
REDEFMACRO, // Redefining existing define macro
|
|
|
|
|
SELRANGE, // Selection index out of range
|
|
|
|
|
STMTDLY, // Delayed statement
|
|
|
|
|
SYMRSVDWORD, // Symbol is Reserved Word
|
|
|
|
|
SYNCASYNCNET, // Mixed sync + async reset
|
2018-09-23 19:09:47 +00:00
|
|
|
|
TICKCOUNT, // Too large tick count
|
2019-05-19 20:13:13 +00:00
|
|
|
|
UNDRIVEN, // No drivers
|
|
|
|
|
UNOPT, // Unoptimizable block
|
|
|
|
|
UNOPTFLAT, // Unoptimizable block after flattening
|
2018-07-22 16:09:27 +00:00
|
|
|
|
UNOPTTHREADS, // Thread partitioner unable to fill all requested threads
|
2019-05-19 20:13:13 +00:00
|
|
|
|
UNPACKED, // Unsupported unpacked
|
|
|
|
|
UNSIGNED, // Comparison is constant due to unsigned arithmetic
|
|
|
|
|
UNUSED, // No receivers
|
|
|
|
|
USERERROR, // Elaboration time $error
|
|
|
|
|
USERFATAL, // Elaboration time $fatal
|
|
|
|
|
USERINFO, // Elaboration time $info
|
|
|
|
|
USERWARN, // Elaboration time $warning
|
|
|
|
|
VARHIDDEN, // Hiding variable
|
|
|
|
|
WIDTH, // Width mismatch
|
|
|
|
|
WIDTHCONCAT, // Unsized numbers/parameters in concatenations
|
|
|
|
|
_ENUM_MAX
|
|
|
|
|
// ***Add new elements below also***
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
|
|
|
|
enum en m_e;
|
2018-08-25 13:52:45 +00:00
|
|
|
|
inline V3ErrorCode() : m_e(EC_MIN) {}
|
2015-10-04 02:33:06 +00:00
|
|
|
|
// cppcheck-suppress noExplicitConstructor
|
2018-08-25 13:52:45 +00:00
|
|
|
|
inline V3ErrorCode(en _e) : m_e(_e) {}
|
|
|
|
|
explicit V3ErrorCode(const char* msgp); // Matching code or ERROR
|
|
|
|
|
explicit inline V3ErrorCode(int _e) : m_e(static_cast<en>(_e)) {}
|
|
|
|
|
operator en() const { return m_e; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
const char* ascii() const {
|
2019-05-19 20:13:13 +00:00
|
|
|
|
const char* names[] = {
|
|
|
|
|
// Leading spaces indicate it can't be disabled.
|
|
|
|
|
" MIN", " INFO", " FATAL", " FATALSRC", " ERROR",
|
|
|
|
|
// Boolean
|
|
|
|
|
" I_COVERAGE", " I_TRACING", " I_LINT", " I_DEF_NETTYPE_WIRE",
|
2019-02-28 02:06:07 +00:00
|
|
|
|
// Errors
|
2019-06-30 20:46:48 +00:00
|
|
|
|
"DETECTARRAY", "PORTSHORT", "TASKNSVAR",
|
2019-02-28 02:06:07 +00:00
|
|
|
|
// Warnings
|
2019-05-19 20:13:13 +00:00
|
|
|
|
" EC_FIRST_WARN",
|
|
|
|
|
"ALWCOMBORDER", "ASSIGNDLY", "ASSIGNIN",
|
|
|
|
|
"BLKANDNBLK", "BLKLOOPINIT", "BLKSEQ", "BSSPACE",
|
2018-12-01 15:12:10 +00:00
|
|
|
|
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CDCRSTLOGIC", "CLKDATA",
|
|
|
|
|
"CMPCONST", "COLONPLUS", "COMBDLY", "CONTASSREG",
|
2018-11-26 22:58:18 +00:00
|
|
|
|
"DEFPARAM", "DECLFILENAME",
|
|
|
|
|
"ENDLABEL", "GENCLK",
|
2019-03-10 18:57:01 +00:00
|
|
|
|
"IFDEPTH", "IGNOREDRETURN",
|
|
|
|
|
"IMPERFECTSCH", "IMPLICIT", "IMPORTSTAR", "IMPURE",
|
2017-12-27 02:35:08 +00:00
|
|
|
|
"INCABSPATH", "INFINITELOOP", "INITIALDLY",
|
2018-11-26 22:58:18 +00:00
|
|
|
|
"LITENDIAN", "MODDUP",
|
2019-06-30 20:46:48 +00:00
|
|
|
|
"MULTIDRIVEN", "MULTITOP",
|
2018-11-26 22:58:18 +00:00
|
|
|
|
"PINMISSING", "PINNOCONNECT", "PINCONNECTEMPTY", "PROCASSWIRE",
|
2019-05-19 20:13:13 +00:00
|
|
|
|
"REALCVT", "REDEFMACRO",
|
|
|
|
|
"SELRANGE", "STMTDLY", "SYMRSVDWORD", "SYNCASYNCNET",
|
2018-09-23 19:09:47 +00:00
|
|
|
|
"TICKCOUNT",
|
2018-07-22 16:09:27 +00:00
|
|
|
|
"UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNOPTTHREADS",
|
|
|
|
|
"UNPACKED", "UNSIGNED", "UNUSED",
|
2019-05-19 20:13:13 +00:00
|
|
|
|
"USERERROR", "USERFATAL", "USERINFO", "USERWARN",
|
|
|
|
|
"VARHIDDEN", "WIDTH", "WIDTHCONCAT",
|
|
|
|
|
" MAX"
|
|
|
|
|
};
|
|
|
|
|
return names[m_e];
|
2009-07-22 18:38:20 +00:00
|
|
|
|
}
|
2008-08-05 17:41:53 +00:00
|
|
|
|
// Warnings that default to off
|
2010-12-25 20:13:56 +00:00
|
|
|
|
bool defaultsOff() const { return ( m_e==IMPERFECTSCH || styleError()); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Warnings that warn about nasty side effects
|
2009-07-22 18:38:20 +00:00
|
|
|
|
bool dangerous() const { return ( m_e==COMBDLY ); }
|
2006-10-11 15:41:42 +00:00
|
|
|
|
// Warnings we'll present to the user as errors
|
|
|
|
|
// Later -Werror- options may make more of these.
|
2011-10-25 22:57:49 +00:00
|
|
|
|
bool pretendError() const { return ( m_e==ASSIGNIN || m_e==BLKANDNBLK
|
2018-12-01 15:12:10 +00:00
|
|
|
|
|| m_e==BLKLOOPINIT
|
|
|
|
|
|| m_e==CONTASSREG
|
2018-11-26 22:58:18 +00:00
|
|
|
|
|| m_e==IMPURE
|
|
|
|
|
|| m_e==PROCASSWIRE); }
|
2009-07-22 18:38:20 +00:00
|
|
|
|
// Warnings to mention manual
|
2014-05-28 11:24:02 +00:00
|
|
|
|
bool mentionManual() const { return ( m_e==EC_FATALSRC || m_e==SYMRSVDWORD
|
2019-05-19 20:13:13 +00:00
|
|
|
|
|| pretendError() ); }
|
2009-07-22 18:38:20 +00:00
|
|
|
|
|
2007-10-31 21:17:23 +00:00
|
|
|
|
// Warnings that are lint only
|
2013-05-01 02:55:28 +00:00
|
|
|
|
bool lintError() const { return ( m_e==ALWCOMBORDER
|
2019-05-19 20:13:13 +00:00
|
|
|
|
|| m_e==BSSPACE
|
|
|
|
|
|| m_e==CASEINCOMPLETE || m_e==CASEOVERLAP
|
|
|
|
|
|| m_e==CASEWITHX || m_e==CASEX
|
|
|
|
|
|| m_e==CMPCONST
|
|
|
|
|
|| m_e==COLONPLUS
|
|
|
|
|
|| m_e==ENDLABEL
|
|
|
|
|
|| m_e==IMPLICIT
|
|
|
|
|
|| m_e==LITENDIAN
|
|
|
|
|
|| m_e==PINMISSING
|
|
|
|
|
|| m_e==REALCVT
|
|
|
|
|
|| m_e==UNSIGNED
|
|
|
|
|
|| m_e==WIDTH); }
|
2010-12-25 20:13:56 +00:00
|
|
|
|
// Warnings that are style only
|
2011-10-21 00:50:42 +00:00
|
|
|
|
bool styleError() const { return ( m_e==ASSIGNDLY // More than style, but for backward compatibility
|
2019-05-19 20:13:13 +00:00
|
|
|
|
|| m_e==BLKSEQ
|
|
|
|
|
|| m_e==DEFPARAM
|
|
|
|
|
|| m_e==DECLFILENAME
|
2018-11-28 23:25:34 +00:00
|
|
|
|
|| m_e==IMPORTSTAR
|
|
|
|
|
|| m_e==INCABSPATH
|
|
|
|
|
|| m_e==PINCONNECTEMPTY
|
|
|
|
|
|| m_e==PINNOCONNECT
|
2019-05-19 20:13:13 +00:00
|
|
|
|
|| m_e==SYNCASYNCNET
|
|
|
|
|
|| m_e==UNDRIVEN
|
|
|
|
|
|| m_e==UNUSED
|
|
|
|
|
|| m_e==VARHIDDEN ); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
2019-05-19 20:13:13 +00:00
|
|
|
|
inline bool operator==(V3ErrorCode lhs, V3ErrorCode rhs) { return (lhs.m_e == rhs.m_e); }
|
|
|
|
|
inline bool operator==(V3ErrorCode lhs, V3ErrorCode::en rhs) { return (lhs.m_e == rhs); }
|
|
|
|
|
inline bool operator==(V3ErrorCode::en lhs, V3ErrorCode rhs) { return (lhs == rhs.m_e); }
|
2018-02-02 02:24:41 +00:00
|
|
|
|
inline std::ostream& operator<<(std::ostream& os, V3ErrorCode rhs) { return os<<rhs.ascii(); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
|
|
class V3Error {
|
|
|
|
|
// Base class for any object that wants debugging and error reporting
|
2012-05-22 01:31:52 +00:00
|
|
|
|
|
2018-02-02 02:24:41 +00:00
|
|
|
|
typedef std::set<string> MessagesSet;
|
2013-05-25 16:15:38 +00:00
|
|
|
|
typedef void (*ErrorExitCb)(void);
|
2012-05-22 01:31:52 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
private:
|
2019-05-19 20:13:13 +00:00
|
|
|
|
static bool s_describedWarnings; // Told user how to disable warns
|
|
|
|
|
static bool s_describedEachWarn[V3ErrorCode::_ENUM_MAX]; // Told user specifics about this warning
|
|
|
|
|
static bool s_pretendError[V3ErrorCode::_ENUM_MAX]; // Pretend this warning is an error
|
|
|
|
|
static int s_debugDefault; // Option: --debugi Default debugging level
|
|
|
|
|
static int s_errorLimit; // Option: --error-limit Number of errors before exit
|
|
|
|
|
static bool s_warnFatal; // Option: --warnFatal Warnings are fatal
|
|
|
|
|
static int s_errCount; // Error count
|
|
|
|
|
static int s_warnCount; // Warning count
|
|
|
|
|
static int s_tellManual; // Tell user to see manual, 0=not yet, 1=doit, 2=disable
|
2018-08-23 09:09:12 +00:00
|
|
|
|
static std::ostringstream s_errorStr; // Error string being formed
|
2019-05-19 20:13:13 +00:00
|
|
|
|
static V3ErrorCode s_errorCode; // Error string being formed will abort
|
2019-06-22 21:01:39 +00:00
|
|
|
|
static bool s_errorContexted; // Error being formed got context
|
2019-05-19 20:13:13 +00:00
|
|
|
|
static bool s_errorSuppressed; // Error being formed should be suppressed
|
|
|
|
|
static MessagesSet s_messages; // What errors we've outputted
|
|
|
|
|
static ErrorExitCb s_errorExitCb; // Callback when error occurs for dumping
|
2013-05-25 16:15:38 +00:00
|
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
|
enum MaxErrors { MAX_ERRORS = 50 }; // Fatal after this may errors
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2018-02-02 02:24:41 +00:00
|
|
|
|
V3Error() { std::cerr<<("Static class"); abort(); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2017-11-01 22:51:41 +00:00
|
|
|
|
// CONSTRUCTORS
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// ACCESSORS
|
2019-05-19 20:13:13 +00:00
|
|
|
|
static void debugDefault(int level) { s_debugDefault = level; }
|
|
|
|
|
static int debugDefault() { return s_debugDefault; }
|
|
|
|
|
static void errorLimit(int level) { s_errorLimit = level; }
|
|
|
|
|
static int errorLimit() { return s_errorLimit; }
|
|
|
|
|
static void warnFatal(bool flag) { s_warnFatal = flag; }
|
|
|
|
|
static bool warnFatal() { return s_warnFatal; }
|
|
|
|
|
static string msgPrefix(); // returns %Error/%Warn
|
|
|
|
|
static int errorCount() { return s_errCount; }
|
|
|
|
|
static int warnCount() { return s_warnCount; }
|
|
|
|
|
static int errorOrWarnCount() { return errorCount()+warnCount(); }
|
2019-06-22 21:01:39 +00:00
|
|
|
|
static bool errorContexted() { return s_errorContexted; }
|
|
|
|
|
static void errorContexted(bool flag) { s_errorContexted = flag; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// METHODS
|
2019-05-19 20:13:13 +00:00
|
|
|
|
static void incErrors();
|
|
|
|
|
static void incWarnings() { s_warnCount++; }
|
|
|
|
|
static void init();
|
|
|
|
|
static void abortIfErrors() { if (errorCount()) abortIfWarnings(); }
|
|
|
|
|
static void abortIfWarnings();
|
|
|
|
|
static void suppressThisWarning(); // Suppress next %Warn if user has it off
|
|
|
|
|
static void pretendError(V3ErrorCode code, bool flag) { s_pretendError[code] = flag; }
|
|
|
|
|
static bool isError(V3ErrorCode code, bool supp);
|
2018-08-25 13:52:45 +00:00
|
|
|
|
static string lineStr(const char* filename, int lineno);
|
|
|
|
|
static V3ErrorCode errorCode() { return s_errorCode; }
|
2019-06-22 21:01:39 +00:00
|
|
|
|
static void errorExitCb(ErrorExitCb cb) { s_errorExitCb = cb; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2012-05-22 01:24:17 +00:00
|
|
|
|
// When printing an error/warning, print prefix for multiline message
|
|
|
|
|
static string warnMore();
|
2019-07-14 19:06:49 +00:00
|
|
|
|
/// When building an error, don't show context info
|
|
|
|
|
static string warnContextNone() { V3Error::errorContexted(true); return ""; }
|
2012-05-22 01:24:17 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Internals for v3error()/v3fatal() macros only
|
|
|
|
|
// Error end takes the string stream to output, be careful to seek() as needed
|
2012-05-22 01:24:17 +00:00
|
|
|
|
static void v3errorPrep(V3ErrorCode code) {
|
2019-06-22 21:01:39 +00:00
|
|
|
|
s_errorStr.str(""); s_errorCode = code;
|
|
|
|
|
s_errorContexted = false; s_errorSuppressed = false; }
|
2018-02-02 02:24:41 +00:00
|
|
|
|
static std::ostringstream& v3errorStr() { return s_errorStr; }
|
2019-05-19 20:13:13 +00:00
|
|
|
|
static void vlAbort();
|
2019-07-26 16:52:38 +00:00
|
|
|
|
static void v3errorEnd(std::ostringstream& sstr, const string& locationStr = ""); // static, but often overridden in classes.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Global versions, so that if the class doesn't define a operator, we get the functions anyways.
|
|
|
|
|
inline int debug() { return V3Error::debugDefault(); }
|
2018-02-02 02:24:41 +00:00
|
|
|
|
inline void v3errorEnd(std::ostringstream& sstr) { V3Error::v3errorEnd(sstr); }
|
2019-05-19 20:13:13 +00:00
|
|
|
|
inline void v3errorEndFatal(std::ostringstream& sstr) {
|
|
|
|
|
V3Error::v3errorEnd(sstr); assert(0); VL_UNREACHABLE }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2014-11-22 16:48:39 +00:00
|
|
|
|
// Theses allow errors using << operators: v3error("foo"<<"bar");
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Careful, you can't put () around msg, as you would in most macro definitions
|
2012-05-22 01:24:17 +00:00
|
|
|
|
// Note the commas are the comma operator, not separating arguments. These are needed to insure
|
|
|
|
|
// evaluation order as otherwise we couldn't insure v3errorPrep is called first.
|
2018-03-10 21:32:04 +00:00
|
|
|
|
#define v3warnCode(code,msg) \
|
|
|
|
|
v3errorEnd((V3Error::v3errorPrep(code), (V3Error::v3errorStr()<<msg), V3Error::v3errorStr()));
|
|
|
|
|
#define v3warnCodeFatal(code,msg) \
|
|
|
|
|
v3errorEndFatal((V3Error::v3errorPrep(code), (V3Error::v3errorStr()<<msg), \
|
|
|
|
|
V3Error::v3errorStr()));
|
2017-07-07 00:25:59 +00:00
|
|
|
|
#define v3warn(code,msg) v3warnCode(V3ErrorCode::code, msg)
|
|
|
|
|
#define v3info(msg) v3warnCode(V3ErrorCode::EC_INFO, msg)
|
|
|
|
|
#define v3error(msg) v3warnCode(V3ErrorCode::EC_ERROR, msg)
|
|
|
|
|
#define v3fatal(msg) v3warnCodeFatal(V3ErrorCode::EC_FATAL, msg)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Use this instead of fatal() to mention the source code line.
|
2018-02-02 02:24:41 +00:00
|
|
|
|
#define v3fatalSrc(msg) v3warnCodeFatal(V3ErrorCode::EC_FATALSRC, __FILE__<<":"<<std::dec<<__LINE__<<": "<<msg)
|
2018-07-15 00:44:43 +00:00
|
|
|
|
// Use this when normal v3fatal is called in static method that overrides fileline.
|
|
|
|
|
#define v3fatalStatic(msg) \
|
|
|
|
|
::v3errorEndFatal((V3Error::v3errorPrep(V3ErrorCode::EC_FATAL), \
|
|
|
|
|
(V3Error::v3errorStr()<<msg), V3Error::v3errorStr()));
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2019-07-01 02:37:03 +00:00
|
|
|
|
#define UINFO(level,stmsg) {if (VL_UNCOVERABLE(debug()>=(level))) { cout<<"- "<<V3Error::lineStr(__FILE__,__LINE__)<<stmsg; }}
|
|
|
|
|
#define UINFONL(level,stmsg) {if (VL_UNCOVERABLE(debug()>=(level))) { cout<<stmsg; } }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2017-03-31 21:46:15 +00:00
|
|
|
|
#ifdef VL_DEBUG
|
|
|
|
|
# define UDEBUGONLY(stmts) {stmts}
|
|
|
|
|
#else
|
|
|
|
|
# define UDEBUGONLY(stmts) {if (0) {stmts}}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-07-06 16:57:50 +00:00
|
|
|
|
// Assertion without object, generally UOBJASSERT preferred
|
|
|
|
|
#define UASSERT(condition,stmsg) \
|
|
|
|
|
do { if (VL_UNCOVERABLE(!(condition))) { v3fatalSrc(stmsg); }} while(0)
|
|
|
|
|
// Assertion with object
|
|
|
|
|
#define UASSERT_OBJ(condition,obj,stmsg) \
|
|
|
|
|
do { if (VL_UNCOVERABLE(!(condition))) { (obj)->v3fatalSrc(stmsg); }} while(0)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// For use in V3Ast static functions only
|
2018-03-10 21:51:34 +00:00
|
|
|
|
#define UASSERT_STATIC(condition,stmsg) \
|
2019-07-06 16:57:50 +00:00
|
|
|
|
do { if (VL_UNCOVERABLE(!(condition))) { \
|
|
|
|
|
std::cerr<<"Internal Error: "<<__FILE__<<":"<<std::dec<<__LINE__ \
|
|
|
|
|
<<":"<<(stmsg)<<std::endl; abort(); } } while(0)
|
2018-07-14 21:44:39 +00:00
|
|
|
|
// Check self test values for expected value. Safe from side-effects.
|
|
|
|
|
// Type argument can be removed when go to C++11 (use auto).
|
|
|
|
|
#define UASSERT_SELFTEST(Type,got,exp) \
|
|
|
|
|
do { Type g = (got); Type e = (exp); \
|
|
|
|
|
UASSERT(g==e, "Self-test failed '" #got "==" #exp "'"" got=" \
|
|
|
|
|
<<g<<" expected="<<e); } while(0)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2019-07-06 16:57:50 +00:00
|
|
|
|
#define V3ERROR_NA \
|
|
|
|
|
do { v3error("Internal: Unexpected Call"); v3fatalSrc("Unexpected Call"); } while(0)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2018-05-14 10:50:47 +00:00
|
|
|
|
/// Declare a convenience debug() routine that may be added to any class in
|
|
|
|
|
/// Verilator so that --debugi-<srcfile> will work to control UINFOs in
|
|
|
|
|
/// that class:
|
2019-07-06 16:57:50 +00:00
|
|
|
|
#define VL_DEBUG_FUNC \
|
|
|
|
|
static int debug() { \
|
2018-05-14 10:50:47 +00:00
|
|
|
|
static int level = -1; \
|
|
|
|
|
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__); \
|
|
|
|
|
return level; \
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
2018-10-14 20:25:36 +00:00
|
|
|
|
template <class T> std::string cvtToStr(const T& t) {
|
2018-02-02 02:24:41 +00:00
|
|
|
|
std::ostringstream os; os<<t; return os.str();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2018-10-14 20:25:36 +00:00
|
|
|
|
template <class T> std::string cvtToHex(const T* tp) {
|
|
|
|
|
std::ostringstream os; os<<static_cast<const void*>(tp); return os.str();
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2012-04-02 01:04:28 +00:00
|
|
|
|
inline uint32_t cvtToHash(const void* vp) {
|
2008-11-20 14:04:29 +00:00
|
|
|
|
// We can shove a 64 bit pointer into a 32 bit bucket
|
2014-04-30 01:11:57 +00:00
|
|
|
|
// On 32-bit systems, lower is always 0, but who cares?
|
2012-04-02 01:04:28 +00:00
|
|
|
|
union { const void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
|
2019-05-19 20:13:13 +00:00
|
|
|
|
u.l.upper = 0; u.l.lower = 0; u.up = vp;
|
2008-11-20 14:04:29 +00:00
|
|
|
|
return u.l.upper^u.l.lower;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-30 01:11:57 +00:00
|
|
|
|
inline string ucfirst(const string& text) {
|
|
|
|
|
string out = text;
|
|
|
|
|
out[0] = toupper(out[0]);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
|
#endif // Guard
|