2012-04-13 03:08:20 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Common headers
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2020-03-21 16:24:24 +01:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you
|
|
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
#ifndef _V3GLOBAL_H_
|
|
|
|
|
#define _V3GLOBAL_H_ 1
|
|
|
|
|
|
2020-04-14 04:51:35 +02:00
|
|
|
// clang-format off
|
2006-12-18 20:20:45 +01:00
|
|
|
#include "config_build.h"
|
2018-06-29 00:55:36 +02:00
|
|
|
#ifndef HAVE_CONFIG_BUILD
|
2018-07-02 15:11:20 +02:00
|
|
|
# error "Something failed during ./configure as config_build.h is incomplete. Perhaps you used autoreconf, don't."
|
2018-06-29 00:55:36 +02:00
|
|
|
#endif
|
2020-04-14 04:51:35 +02:00
|
|
|
// clang-format on
|
2018-06-29 00:55:36 +02:00
|
|
|
|
2006-12-18 20:20:45 +01:00
|
|
|
#include "verilatedos.h"
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
#include "V3Error.h"
|
2014-11-22 17:48:39 +01:00
|
|
|
#include "V3FileLine.h"
|
2006-08-26 13:35:28 +02:00
|
|
|
#include "V3Options.h"
|
2011-11-30 04:09:50 +01:00
|
|
|
|
2018-10-14 19:43:24 +02:00
|
|
|
#include <string>
|
2020-05-23 19:31:30 +02:00
|
|
|
#include VL_INCLUDE_UNORDERED_MAP
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2011-11-30 04:09:50 +01:00
|
|
|
class AstNetlist;
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
//======================================================================
|
|
|
|
|
// Statics
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
2015-05-15 03:46:07 +02:00
|
|
|
|
|
|
|
|
class VWidthMinUsage {
|
|
|
|
|
public:
|
2020-04-14 04:51:35 +02:00
|
|
|
enum en { LINT_WIDTH, MATCHES_WIDTH, VERILOG_WIDTH };
|
2015-05-15 03:46:07 +02:00
|
|
|
enum en m_e;
|
2020-04-14 04:51:35 +02:00
|
|
|
inline VWidthMinUsage()
|
|
|
|
|
: m_e(LINT_WIDTH) {}
|
2015-10-04 04:33:06 +02:00
|
|
|
// cppcheck-suppress noExplicitConstructor
|
2020-04-14 04:51:35 +02:00
|
|
|
inline VWidthMinUsage(en _e)
|
|
|
|
|
: m_e(_e) {}
|
|
|
|
|
explicit inline VWidthMinUsage(int _e)
|
|
|
|
|
: m_e(static_cast<en>(_e)) {}
|
2018-08-25 15:52:45 +02:00
|
|
|
operator en() const { return m_e; }
|
2020-02-02 16:34:29 +01:00
|
|
|
};
|
|
|
|
|
inline bool operator==(const VWidthMinUsage& lhs, const VWidthMinUsage& rhs) {
|
|
|
|
|
return lhs.m_e == rhs.m_e;
|
|
|
|
|
}
|
|
|
|
|
inline bool operator==(const VWidthMinUsage& lhs, VWidthMinUsage::en rhs) {
|
|
|
|
|
return lhs.m_e == rhs;
|
|
|
|
|
}
|
|
|
|
|
inline bool operator==(VWidthMinUsage::en lhs, const VWidthMinUsage& rhs) {
|
|
|
|
|
return lhs == rhs.m_e;
|
|
|
|
|
}
|
2015-05-15 03:46:07 +02:00
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// V3Global - The top level class for the entire program
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
class V3Global {
|
|
|
|
|
// Globals
|
2020-03-02 03:39:23 +01:00
|
|
|
AstNetlist* m_rootp; // Root of entire netlist
|
|
|
|
|
VWidthMinUsage m_widthMinUsage; // What AstNode::widthMin() is used for
|
2012-02-02 02:20:43 +01:00
|
|
|
|
2020-03-02 03:39:23 +01:00
|
|
|
int m_debugFileNumber; // Number to append to debug files created
|
|
|
|
|
bool m_assertDTypesResolved; // Tree should have dtypep()'s
|
|
|
|
|
bool m_constRemoveXs; // Const needs to strip any Xs
|
2020-04-05 02:48:03 +02:00
|
|
|
bool m_needC11; // Need C++11
|
2020-03-02 03:39:23 +01:00
|
|
|
bool m_needHeavy; // Need verilated_heavy.h include
|
2020-04-05 02:48:03 +02:00
|
|
|
bool m_needTraceDumper; // Need __Vm_dumperp in symbols
|
2020-03-02 03:39:23 +01:00
|
|
|
bool m_dpi; // Need __Dpi include files
|
2020-05-25 22:12:34 +02:00
|
|
|
bool m_useParallelBuild; // Use parallel build for model
|
2007-11-30 23:38:21 +01:00
|
|
|
|
2020-05-23 19:31:30 +02:00
|
|
|
// Memory address to short string mapping (for debug)
|
|
|
|
|
typedef vl_unordered_map<const void*, std::string> PtrToIdMap; // The map type
|
|
|
|
|
PtrToIdMap m_ptrToId; // The actual 'address' <=> 'short string' bijection
|
|
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
public:
|
2007-11-30 23:38:21 +01:00
|
|
|
// Options
|
2019-05-19 22:13:13 +02:00
|
|
|
V3Options opt; // All options; let user see them directly
|
2006-08-26 13:35:28 +02:00
|
|
|
|
2017-11-01 23:51:41 +01:00
|
|
|
// CONSTRUCTORS
|
2020-04-06 00:30:46 +02:00
|
|
|
V3Global()
|
|
|
|
|
: m_rootp(NULL) // created by makeInitNetlist() so static constructors run first
|
|
|
|
|
, m_widthMinUsage(VWidthMinUsage::LINT_WIDTH)
|
|
|
|
|
, m_debugFileNumber(0)
|
|
|
|
|
, m_assertDTypesResolved(false)
|
|
|
|
|
, m_constRemoveXs(false)
|
|
|
|
|
, m_needC11(false)
|
|
|
|
|
, m_needHeavy(false)
|
|
|
|
|
, m_needTraceDumper(false)
|
2020-05-25 22:12:34 +02:00
|
|
|
, m_dpi(false)
|
|
|
|
|
, m_useParallelBuild(false) {}
|
2011-11-30 04:09:50 +01:00
|
|
|
AstNetlist* makeNetlist();
|
2020-04-14 04:51:35 +02:00
|
|
|
void boot() {
|
|
|
|
|
UASSERT(!m_rootp, "call once");
|
|
|
|
|
m_rootp = makeNetlist();
|
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
// ACCESSORS (general)
|
|
|
|
|
AstNetlist* rootp() const { return m_rootp; }
|
2015-05-15 03:46:07 +02:00
|
|
|
VWidthMinUsage widthMinUsage() const { return m_widthMinUsage; }
|
2011-11-30 04:36:51 +01:00
|
|
|
bool assertDTypesResolved() const { return m_assertDTypesResolved; }
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
void readFiles();
|
2011-11-30 04:09:50 +01:00
|
|
|
void checkTree();
|
2020-04-14 04:51:35 +02:00
|
|
|
static void dumpCheckGlobalTree(const string& stagename, int newNumber = 0,
|
|
|
|
|
bool doDump = true);
|
2011-11-30 04:36:51 +01:00
|
|
|
void assertDTypesResolved(bool flag) { m_assertDTypesResolved = flag; }
|
2015-05-15 03:46:07 +02:00
|
|
|
void widthMinUsage(const VWidthMinUsage& flag) { m_widthMinUsage = flag; }
|
2014-06-10 04:27:04 +02:00
|
|
|
bool constRemoveXs() const { return m_constRemoveXs; }
|
|
|
|
|
void constRemoveXs(bool flag) { m_constRemoveXs = flag; }
|
2020-04-14 04:51:35 +02:00
|
|
|
string debugFilename(const string& nameComment, int newNumber = 0) {
|
2019-05-19 22:13:13 +02:00
|
|
|
++m_debugFileNumber;
|
|
|
|
|
if (newNumber) m_debugFileNumber = newNumber;
|
2020-04-14 04:51:35 +02:00
|
|
|
char digits[100];
|
|
|
|
|
sprintf(digits, "%03d", m_debugFileNumber);
|
|
|
|
|
return opt.makeDir() + "/" + opt.prefix() + "_" + digits + "_" + nameComment;
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2020-04-05 02:48:03 +02:00
|
|
|
bool needC11() const { return m_needC11; }
|
|
|
|
|
void needC11(bool flag) { m_needC11 = flag; }
|
2010-01-17 21:10:37 +01:00
|
|
|
bool needHeavy() const { return m_needHeavy; }
|
2020-03-02 03:39:23 +01:00
|
|
|
void needHeavy(bool flag) { m_needHeavy = flag; }
|
2020-04-05 02:48:03 +02:00
|
|
|
bool needTraceDumper() const { return m_needTraceDumper; }
|
|
|
|
|
void needTraceDumper(bool flag) { m_needTraceDumper = flag; }
|
2009-12-03 12:55:29 +01:00
|
|
|
bool dpi() const { return m_dpi; }
|
|
|
|
|
void dpi(bool flag) { m_dpi = flag; }
|
2020-05-25 22:12:34 +02:00
|
|
|
void useParallelBuild(bool flag) { m_useParallelBuild = flag; }
|
|
|
|
|
bool useParallelBuild() const { return m_useParallelBuild; }
|
2020-05-23 19:31:30 +02:00
|
|
|
const std::string& ptrToId(const void* p);
|
2006-08-26 13:35:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern V3Global v3Global;
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
2019-05-14 01:47:52 +02:00
|
|
|
#endif // guard
|