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
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2018-01-02 23:05:06 +00:00
|
|
|
|
// Copyright 2003-2018 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
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <bitset>
|
2011-10-11 11:07:24 +00:00
|
|
|
|
#include <map>
|
2012-05-22 01:31:52 +00:00
|
|
|
|
#include <set>
|
2011-10-11 11:07:24 +00:00
|
|
|
|
#include <deque>
|
2017-07-07 00:25:59 +00:00
|
|
|
|
#include <cassert>
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
|
|
class V3ErrorCode {
|
|
|
|
|
public:
|
|
|
|
|
enum en {
|
2010-02-02 01:15:48 +00:00
|
|
|
|
EC_MIN=0, // Keep first
|
2008-12-11 20:23:44 +00:00
|
|
|
|
//
|
2010-02-02 01:15:48 +00:00
|
|
|
|
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
|
2008-12-11 21:01:41 +00:00
|
|
|
|
// 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*/
|
2010-12-30 11:58:02 +00:00
|
|
|
|
I_LINT, // All lint messages
|
2010-02-23 14:27:16 +00:00
|
|
|
|
I_DEF_NETTYPE_WIRE, // `default_nettype is WIRE (false=NONE)
|
2006-10-18 13:45:50 +00:00
|
|
|
|
// Error codes:
|
2011-11-30 21:20:43 +00:00
|
|
|
|
E_DETECTARRAY, // Error: Unsupported: Can't detect changes on arrayed variable
|
2009-11-30 23:36:31 +00:00
|
|
|
|
E_MULTITOP, // Error: Multiple top level modules
|
|
|
|
|
E_TASKNSVAR, // Error: Task I/O not simple
|
2010-12-25 20:13:56 +00:00
|
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Warning codes:
|
2010-02-02 01:15:48 +00:00
|
|
|
|
EC_FIRST_WARN, // Just a code so the program knows where to start warnings
|
2006-10-18 13:45:50 +00:00
|
|
|
|
//
|
2013-05-01 02:55:28 +00:00
|
|
|
|
ALWCOMBORDER, // Always_comb with unordered statements
|
2011-10-21 00:50:42 +00:00
|
|
|
|
ASSIGNDLY, // Assignment delays
|
2011-10-25 22:57:49 +00:00
|
|
|
|
ASSIGNIN, // Assigning to input
|
2006-08-26 11:35:28 +00:00
|
|
|
|
BLKANDNBLK, // Blocked and non-blocking assignments to same variable
|
2017-10-02 03:23:02 +00:00
|
|
|
|
BLKLOOPINIT, // Delayed assignment to array inside for loops
|
2010-12-31 23:36:29 +00:00
|
|
|
|
BLKSEQ, // Blocking assignments in sequential block
|
2017-11-16 01:19:12 +00:00
|
|
|
|
BSSPACE, // Backslash space
|
2006-08-26 11:35:28 +00:00
|
|
|
|
CASEINCOMPLETE, // Case statement has missing values
|
|
|
|
|
CASEOVERLAP, // Case statements overlap
|
2008-07-22 17:07:19 +00:00
|
|
|
|
CASEWITHX, // Case with X values
|
2006-08-26 11:35:28 +00:00
|
|
|
|
CASEX, // Casex
|
2010-01-07 21:41:19 +00:00
|
|
|
|
CDCRSTLOGIC, // Logic in async reset path
|
2015-03-12 23:20:46 +00:00
|
|
|
|
CLKDATA, // Clock used as data
|
2006-08-26 11:35:28 +00:00
|
|
|
|
CMPCONST, // Comparison is constant due to limited range
|
2017-11-16 01:19:12 +00:00
|
|
|
|
COLONPLUS, // :+ instead of +:
|
2006-08-26 11:35:28 +00:00
|
|
|
|
COMBDLY, // Combinatorial delayed assignment
|
2010-12-25 20:13:56 +00:00
|
|
|
|
DEFPARAM, // Style: Defparam
|
2010-12-25 21:31:22 +00:00
|
|
|
|
DECLFILENAME, // Declaration doesn't match filename
|
2012-03-08 01:14:18 +00:00
|
|
|
|
ENDLABEL, // End lable name mismatch
|
2006-08-26 11:35:28 +00:00
|
|
|
|
GENCLK, // Generated Clock
|
2010-12-26 14:31:09 +00:00
|
|
|
|
IFDEPTH, // If statements too deep
|
2008-08-05 17:41:53 +00:00
|
|
|
|
IMPERFECTSCH, // Imperfect schedule (disabled by default)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
IMPLICIT, // Implicit wire
|
2006-10-11 15:41:42 +00:00
|
|
|
|
IMPURE, // Impure function not being inlined
|
2010-12-25 20:50:07 +00:00
|
|
|
|
INCABSPATH, // Include has absolute path
|
2017-12-27 02:35:08 +00:00
|
|
|
|
INFINITELOOP, // Infinite loop
|
2012-04-27 00:40:13 +00:00
|
|
|
|
INITIALDLY, // Initial delayed statement
|
2009-10-25 20:53:55 +00:00
|
|
|
|
LITENDIAN, // Little bit endian vector
|
2010-01-08 01:25:15 +00:00
|
|
|
|
MODDUP, // Duplicate module
|
2006-08-26 11:35:28 +00:00
|
|
|
|
MULTIDRIVEN, // Driven from multiple blocks
|
2012-04-26 22:43:12 +00:00
|
|
|
|
PINMISSING, // Cell pin not specified
|
|
|
|
|
PINNOCONNECT, // Cell pin not connected
|
2014-03-28 01:36:52 +00:00
|
|
|
|
PINCONNECTEMPTY,// Cell pin connected by name with empty reference: ".name()" (can be used to mark unused pins)
|
2011-07-24 19:01:51 +00:00
|
|
|
|
REALCVT, // Real conversion
|
2008-03-19 15:05:08 +00:00
|
|
|
|
REDEFMACRO, // Redefining existing define macro
|
2012-04-05 01:55:20 +00:00
|
|
|
|
SELRANGE, // Selection index out of range
|
2010-12-26 14:31:09 +00:00
|
|
|
|
STMTDLY, // Delayed statement
|
|
|
|
|
SYMRSVDWORD, // Symbol is Reserved Word
|
2010-12-31 12:51:14 +00:00
|
|
|
|
SYNCASYNCNET, // Mixed sync + async reset
|
2006-08-26 11:35:28 +00:00
|
|
|
|
UNDRIVEN, // No drivers
|
|
|
|
|
UNOPT, // Unoptimizable block
|
|
|
|
|
UNOPTFLAT, // Unoptimizable block after flattening
|
2013-10-29 00:41:05 +00:00
|
|
|
|
UNPACKED, // Unsupported unpacked
|
2006-08-26 11:35:28 +00:00
|
|
|
|
UNSIGNED, // Comparison is constant due to unsigned arithmetic
|
|
|
|
|
UNUSED, // No receivers
|
2015-10-23 22:13:25 +00:00
|
|
|
|
USERERROR, // Elaboration time $error
|
|
|
|
|
USERFATAL, // Elaboration time $fatal
|
|
|
|
|
USERINFO, // Elaboration time $info
|
|
|
|
|
USERWARN, // Elaboration time $warning
|
2006-08-26 11:35:28 +00:00
|
|
|
|
VARHIDDEN, // Hiding variable
|
|
|
|
|
WIDTH, // Width mismatch
|
2008-04-02 12:53:53 +00:00
|
|
|
|
WIDTHCONCAT, // Unsized numbers/parameters in concatenations
|
2010-02-02 01:15:48 +00:00
|
|
|
|
_ENUM_MAX
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// ***Add new elements below also***
|
|
|
|
|
};
|
|
|
|
|
enum en m_e;
|
2011-08-05 01:58:45 +00:00
|
|
|
|
inline V3ErrorCode () : m_e(EC_MIN) {}
|
2015-10-04 02:33:06 +00:00
|
|
|
|
// cppcheck-suppress noExplicitConstructor
|
2009-07-22 18:38:20 +00:00
|
|
|
|
inline V3ErrorCode (en _e) : m_e(_e) {}
|
2015-10-04 02:33:06 +00:00
|
|
|
|
explicit V3ErrorCode (const char* msgp); // Matching code or ERROR
|
2009-07-22 18:38:20 +00:00
|
|
|
|
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 {
|
|
|
|
|
const char* names[] = {
|
|
|
|
|
// Leading spaces indicate it can't be disabled.
|
2010-12-30 13:41:23 +00:00
|
|
|
|
" MIN", " INFO", " FATAL", " FATALSRC", " ERROR",
|
2008-12-11 21:01:41 +00:00
|
|
|
|
// Boolean
|
2010-12-30 11:58:02 +00:00
|
|
|
|
" I_COVERAGE", " I_TRACING", " I_LINT", " I_DEF_NETTYPE_WIRE",
|
2008-12-11 21:01:41 +00:00
|
|
|
|
// Errors
|
2017-10-02 03:23:02 +00:00
|
|
|
|
"DETECTARRAY", "MULTITOP", "TASKNSVAR",
|
2008-12-11 21:01:41 +00:00
|
|
|
|
// Warnings
|
2010-12-25 20:13:56 +00:00
|
|
|
|
" EC_FIRST_WARN",
|
2013-05-01 02:55:28 +00:00
|
|
|
|
"ALWCOMBORDER", "ASSIGNDLY", "ASSIGNIN",
|
2017-11-16 01:19:12 +00:00
|
|
|
|
"BLKANDNBLK", "BLKLOOPINIT", "BLKSEQ", "BSSPACE",
|
2015-03-12 23:20:46 +00:00
|
|
|
|
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CDCRSTLOGIC", "CLKDATA",
|
2017-11-16 01:19:12 +00:00
|
|
|
|
"CMPCONST", "COLONPLUS", "COMBDLY", "DEFPARAM", "DECLFILENAME",
|
2012-03-08 01:14:18 +00:00
|
|
|
|
"ENDLABEL", "GENCLK",
|
2012-04-27 00:40:13 +00:00
|
|
|
|
"IFDEPTH", "IMPERFECTSCH", "IMPLICIT", "IMPURE",
|
2017-12-27 02:35:08 +00:00
|
|
|
|
"INCABSPATH", "INFINITELOOP", "INITIALDLY",
|
2010-01-08 01:25:15 +00:00
|
|
|
|
"LITENDIAN", "MODDUP",
|
2010-12-31 23:36:29 +00:00
|
|
|
|
"MULTIDRIVEN",
|
2014-03-28 01:36:52 +00:00
|
|
|
|
"PINMISSING", "PINNOCONNECT", "PINCONNECTEMPTY",
|
2011-07-24 19:01:51 +00:00
|
|
|
|
"REALCVT", "REDEFMACRO",
|
2012-04-05 01:55:20 +00:00
|
|
|
|
"SELRANGE", "STMTDLY", "SYMRSVDWORD", "SYNCASYNCNET",
|
2013-10-29 00:41:05 +00:00
|
|
|
|
"UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNPACKED", "UNSIGNED", "UNUSED",
|
2015-10-23 22:13:25 +00:00
|
|
|
|
"USERERROR", "USERFATAL", "USERINFO", "USERWARN",
|
2008-04-02 12:53:53 +00:00
|
|
|
|
"VARHIDDEN", "WIDTH", "WIDTHCONCAT",
|
2006-08-26 11:35:28 +00:00
|
|
|
|
" 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
|
2017-10-02 03:23:02 +00:00
|
|
|
|
|| m_e==BLKLOOPINIT
|
2014-05-28 11:24:02 +00:00
|
|
|
|
|| m_e==IMPURE || m_e==MODDUP); }
|
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
|
|
|
|
|
|| 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
|
2017-11-16 01:19:12 +00:00
|
|
|
|
|| m_e==BSSPACE
|
2013-05-01 02:55:28 +00:00
|
|
|
|
|| m_e==CASEINCOMPLETE || m_e==CASEOVERLAP
|
2008-07-22 17:07:19 +00:00
|
|
|
|
|| m_e==CASEWITHX || m_e==CASEX
|
|
|
|
|
|| m_e==CMPCONST
|
2017-11-16 01:19:12 +00:00
|
|
|
|
|| m_e==COLONPLUS
|
2012-03-08 01:14:18 +00:00
|
|
|
|
|| m_e==ENDLABEL
|
2007-10-31 21:17:23 +00:00
|
|
|
|
|| m_e==IMPLICIT
|
2009-10-25 20:53:55 +00:00
|
|
|
|
|| m_e==LITENDIAN
|
2012-04-26 22:43:12 +00:00
|
|
|
|
|| m_e==PINMISSING
|
2011-07-24 19:01:51 +00:00
|
|
|
|
|| m_e==REALCVT
|
2010-12-26 15:17:35 +00:00
|
|
|
|
|| m_e==UNSIGNED
|
2009-07-22 18:38:20 +00:00
|
|
|
|
|| 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
|
|
|
|
|
|| m_e==BLKSEQ
|
2010-12-31 23:36:29 +00:00
|
|
|
|
|| m_e==DEFPARAM
|
2010-12-25 21:31:22 +00:00
|
|
|
|
|| m_e==DECLFILENAME
|
2010-12-25 20:50:07 +00:00
|
|
|
|
|| m_e==INCABSPATH
|
2014-03-28 01:36:52 +00:00
|
|
|
|
|| m_e==PINCONNECTEMPTY
|
2012-04-26 22:43:12 +00:00
|
|
|
|
|| m_e==PINNOCONNECT
|
2010-12-31 12:51:14 +00:00
|
|
|
|
|| m_e==SYNCASYNCNET
|
2010-12-26 15:17:35 +00:00
|
|
|
|
|| m_e==UNDRIVEN
|
|
|
|
|
|| m_e==UNUSED
|
2010-12-25 20:28:13 +00:00
|
|
|
|
|| m_e==VARHIDDEN ); }
|
2006-08-26 11:35:28 +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:
|
|
|
|
|
static bool s_describedWarnings; // Told user how to disable warns
|
2010-02-02 01:15:48 +00:00
|
|
|
|
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
|
2014-11-22 16:48:39 +00:00
|
|
|
|
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
|
2007-06-12 19:39:10 +00:00
|
|
|
|
static int s_errCount; // Error count
|
2014-11-22 16:48:39 +00:00
|
|
|
|
static int s_warnCount; // Warning count
|
2009-06-21 23:37:15 +00:00
|
|
|
|
static int s_tellManual; // Tell user to see manual, 0=not yet, 1=doit, 2=disable
|
2018-02-02 02:24:41 +00:00
|
|
|
|
static std::ostringstream s_errorStr; // Error string being formed
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static V3ErrorCode s_errorCode; // Error string being formed will abort
|
2010-12-30 13:41:23 +00:00
|
|
|
|
static bool s_errorSuppressed; // Error being formed should be suppressed
|
2012-05-22 01:31:52 +00:00
|
|
|
|
static MessagesSet s_messages; // What errors we've outputted
|
2013-05-25 16:15:38 +00:00
|
|
|
|
static ErrorExitCb s_errorExitCb; // Callback when error occurs for dumping
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
enum MaxErrors { MAX_ERRORS = 50 }; // Fatal after this may errors
|
|
|
|
|
|
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
|
|
|
|
|
static void debugDefault(int level) { s_debugDefault = level; }
|
|
|
|
|
static int debugDefault() { return s_debugDefault; }
|
2014-11-22 16:48:39 +00:00
|
|
|
|
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; }
|
2012-05-22 01:24:17 +00:00
|
|
|
|
static string msgPrefix(); // returns %Error/%Warn
|
2007-06-12 19:39:10 +00:00
|
|
|
|
static int errorCount() { return s_errCount; }
|
|
|
|
|
static int warnCount() { return s_warnCount; }
|
|
|
|
|
static int errorOrWarnCount() { return errorCount()+warnCount(); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// METHODS
|
2007-11-02 11:23:03 +00:00
|
|
|
|
static void incErrors();
|
2014-11-22 14:04:14 +00:00
|
|
|
|
static void incWarnings() { s_warnCount++; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static void init();
|
2014-11-22 14:04:14 +00:00
|
|
|
|
static void abortIfErrors() { if (errorCount()) abortIfWarnings(); }
|
2007-06-12 19:39:10 +00:00
|
|
|
|
static void abortIfWarnings();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static void suppressThisWarning(); // Suppress next %Warn if user has it off
|
|
|
|
|
static void pretendError(V3ErrorCode code, bool flag) { s_pretendError[code]=flag; }
|
2010-12-30 13:41:23 +00:00
|
|
|
|
static bool isError(V3ErrorCode code, bool supp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static string lineStr (const char* filename, int lineno);
|
|
|
|
|
static V3ErrorCode errorCode() { return s_errorCode; }
|
2013-05-25 16:15:38 +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();
|
|
|
|
|
|
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) {
|
|
|
|
|
s_errorStr.str(""); s_errorCode=code; s_errorSuppressed=false; }
|
2018-02-02 02:24:41 +00:00
|
|
|
|
static std::ostringstream& v3errorStr() { return s_errorStr; }
|
2009-10-04 21:01:28 +00:00
|
|
|
|
static void vlAbort();
|
2018-02-02 02:24:41 +00:00
|
|
|
|
static void v3errorEnd(std::ostringstream& sstr); // 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); }
|
|
|
|
|
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.
|
|
|
|
|
#define v3warnCode(code,msg) v3errorEnd((V3Error::v3errorPrep(code), (V3Error::v3errorStr()<<msg), V3Error::v3errorStr()));
|
2017-07-07 00:25:59 +00:00
|
|
|
|
#define v3warnCodeFatal(code,msg) v3errorEndFatal((V3Error::v3errorPrep(code), (V3Error::v3errorStr()<<msg), V3Error::v3errorStr()));
|
|
|
|
|
#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)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2010-08-10 15:19:45 +00:00
|
|
|
|
#define UINFO(level,stmsg) {if(VL_UNLIKELY(debug()>=(level))) { cout<<"- "<<V3Error::lineStr(__FILE__,__LINE__)<<stmsg; }}
|
|
|
|
|
#define UINFONL(level,stmsg) {if(VL_UNLIKELY(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
|
|
|
|
|
|
2010-08-10 15:19:45 +00:00
|
|
|
|
#define UASSERT(condition,stmsg) { if (VL_UNLIKELY(!(condition))) { v3fatalSrc(stmsg); }}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// For use in V3Ast static functions only
|
2018-02-02 02:24:41 +00:00
|
|
|
|
#define UASSERT_STATIC(condition,stmsg) { if (VL_UNLIKELY(!(condition))) { std::cerr<<"Internal Error: "<<__FILE__<<":"<<std::dec<<__LINE__<<":"<<(stmsg)<<std::endl; abort(); } }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2010-01-17 19:48:39 +00:00
|
|
|
|
#define V3ERROR_NA { v3error("Internal: Unexpected Call"); v3fatalSrc("Unexpected Call"); }
|
2006-08-26 11:35:28 +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
|
|
|
|
}
|
|
|
|
|
|
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;
|
2008-11-20 14:04:29 +00:00
|
|
|
|
u.l.upper=0; u.l.lower=0; u.up=vp;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#endif // Guard
|