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-08-15 16:03:34 +02:00
|
|
|
#include <unordered_map>
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2011-11-30 04:09:50 +01:00
|
|
|
class AstNetlist;
|
2020-08-15 15:43:53 +02:00
|
|
|
class V3HierBlockPlan;
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
//======================================================================
|
2020-08-25 03:10:43 +02:00
|
|
|
// Restorer
|
|
|
|
|
|
|
|
|
|
/// Save a given variable's value on the stack, restoring it at
|
|
|
|
|
/// end-of-stope.
|
|
|
|
|
// Object must be named, or it will not persist until end-of-scope.
|
|
|
|
|
// Constructor needs () or GCC 4.8 false warning.
|
|
|
|
|
#define VL_RESTORER(var) const VRestorer<decltype(var)> restorer_##var(var);
|
|
|
|
|
|
|
|
|
|
// Object used by VL_RESTORER. This object must be an auto variable, not
|
|
|
|
|
// allocated on the heap or otherwise.
|
|
|
|
|
template <typename T> class VRestorer {
|
|
|
|
|
T& m_ref; // Reference to object we're saving and restoring
|
|
|
|
|
const T m_saved; // Value saved, for later restore
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
VRestorer(T& permr)
|
|
|
|
|
: m_ref(permr)
|
|
|
|
|
, m_saved(permr) {}
|
|
|
|
|
~VRestorer() { m_ref = m_saved; }
|
|
|
|
|
VL_UNCOPYABLE(VRestorer);
|
|
|
|
|
};
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
//######################################################################
|
2015-05-15 03:46:07 +02:00
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class VWidthMinUsage final {
|
2015-05-15 03:46:07 +02:00
|
|
|
public:
|
2020-08-16 18:05:35 +02:00
|
|
|
enum en : uint8_t { LINT_WIDTH, MATCHES_WIDTH, VERILOG_WIDTH };
|
2015-05-15 03:46:07 +02:00
|
|
|
enum en m_e;
|
2020-12-02 00:49:03 +01:00
|
|
|
VWidthMinUsage()
|
2020-08-16 17:40:42 +02:00
|
|
|
: m_e{LINT_WIDTH} {}
|
2015-10-04 04:33:06 +02:00
|
|
|
// cppcheck-suppress noExplicitConstructor
|
2020-12-02 00:49:03 +01:00
|
|
|
VWidthMinUsage(en _e)
|
2020-08-16 17:40:42 +02:00
|
|
|
: m_e{_e} {}
|
2020-12-02 00:49:03 +01:00
|
|
|
explicit VWidthMinUsage(int _e)
|
2020-08-18 14:10:44 +02:00
|
|
|
: m_e(static_cast<en>(_e)) {} // Need () or GCC 4.8 false warning
|
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
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class V3Global final {
|
2006-08-26 13:35:28 +02:00
|
|
|
// Globals
|
2020-03-02 03:39:23 +01:00
|
|
|
AstNetlist* m_rootp; // Root of entire netlist
|
2020-08-15 16:12:55 +02:00
|
|
|
V3HierBlockPlan* m_hierPlanp; // Hierarchical verilation plan, nullptr unless hier_block
|
2020-03-02 03:39:23 +01:00
|
|
|
VWidthMinUsage m_widthMinUsage; // What AstNode::widthMin() is used for
|
2012-02-02 02:20:43 +01:00
|
|
|
|
2020-08-15 19:11:27 +02:00
|
|
|
int m_debugFileNumber = 0; // Number to append to debug files created
|
|
|
|
|
bool m_assertDTypesResolved = false; // Tree should have dtypep()'s
|
2020-11-14 22:13:06 +01:00
|
|
|
bool m_assertScoped = false; // Tree is scoped
|
2020-08-15 19:11:27 +02:00
|
|
|
bool m_constRemoveXs = false; // Const needs to strip any Xs
|
|
|
|
|
bool m_needHeavy = false; // Need verilated_heavy.h include
|
|
|
|
|
bool m_needTraceDumper = false; // Need __Vm_dumperp in symbols
|
|
|
|
|
bool m_dpi = false; // Need __Dpi include files
|
|
|
|
|
bool m_useParallelBuild = false; // Use parallel build for model
|
2020-12-07 23:55:22 +01:00
|
|
|
bool m_useRandomizeMethods = false; // Need to define randomize() class methods
|
2007-11-30 23:38:21 +01:00
|
|
|
|
2020-05-23 19:31:30 +02:00
|
|
|
// Memory address to short string mapping (for debug)
|
2020-08-15 16:03:34 +02:00
|
|
|
typedef std::unordered_map<const void*, std::string> PtrToIdMap; // The map type
|
2020-05-23 19:31:30 +02:00
|
|
|
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()
|
2020-08-16 15:55:36 +02:00
|
|
|
: m_rootp{nullptr} // created by makeInitNetlist(} so static constructors run first
|
|
|
|
|
, m_hierPlanp{nullptr} // Set via hierPlanp(V3HierBlockPlan*} when use hier_block
|
|
|
|
|
, m_widthMinUsage{VWidthMinUsage::LINT_WIDTH} {}
|
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();
|
|
|
|
|
}
|
2020-09-11 17:52:30 +02:00
|
|
|
void clear();
|
2020-08-15 15:43:53 +02:00
|
|
|
void shutdown(); // Release allocated resorces
|
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; }
|
2020-11-14 22:13:06 +01:00
|
|
|
bool assertScoped() const { return m_assertScoped; }
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
void readFiles();
|
2020-08-16 20:55:46 +02:00
|
|
|
void checkTree() const;
|
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; }
|
2020-11-14 22:13:06 +01:00
|
|
|
void assertScoped(bool flag) { m_assertScoped = 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);
|
2020-08-15 15:43:53 +02:00
|
|
|
return opt.hierTopDataDir() + "/" + opt.prefix() + "_" + digits + "_" + nameComment;
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
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-08-15 15:43:53 +02:00
|
|
|
V3HierBlockPlan* hierPlanp() const { return m_hierPlanp; }
|
|
|
|
|
void hierPlanp(V3HierBlockPlan* plan) {
|
|
|
|
|
UASSERT(!m_hierPlanp, "call once");
|
|
|
|
|
m_hierPlanp = plan;
|
|
|
|
|
}
|
2020-05-25 22:12:34 +02:00
|
|
|
void useParallelBuild(bool flag) { m_useParallelBuild = flag; }
|
|
|
|
|
bool useParallelBuild() const { return m_useParallelBuild; }
|
2020-12-07 23:55:22 +01:00
|
|
|
void useRandomizeMethods(bool flag) { m_useRandomizeMethods = flag; }
|
|
|
|
|
bool useRandomizeMethods() const { return m_useRandomizeMethods; }
|
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
|