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