2020-01-19 13:23:26 +01:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
2022-12-03 00:46:38 +01:00
|
|
|
// DESCRIPTION: Verilator: Common implementations
|
2020-01-19 13:23:26 +01:00
|
|
|
//
|
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2023-01-01 16:18:39 +01:00
|
|
|
// Copyright 2004-2023 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2020-01-19 13:23:26 +01: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
|
2020-01-19 13:23:26 +01:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
2022-08-05 11:56:57 +02:00
|
|
|
|
2020-01-19 13:23:26 +01:00
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3File.h"
|
2020-08-15 15:43:53 +02:00
|
|
|
#include "V3HierBlock.h"
|
2020-01-19 13:23:26 +01:00
|
|
|
#include "V3LinkCells.h"
|
|
|
|
|
#include "V3Parse.h"
|
|
|
|
|
#include "V3ParseSym.h"
|
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
2022-07-13 19:24:48 +02:00
|
|
|
// V3Global
|
2020-01-19 13:23:26 +01:00
|
|
|
|
2022-07-13 19:24:48 +02:00
|
|
|
void V3Global::boot() {
|
|
|
|
|
UASSERT(!m_rootp, "call once");
|
2022-08-30 07:02:39 +02:00
|
|
|
m_rootp = new AstNetlist;
|
2022-07-13 19:24:48 +02:00
|
|
|
}
|
2020-01-19 13:23:26 +01:00
|
|
|
|
2023-01-01 15:22:13 +01:00
|
|
|
void V3Global::shutdown() {
|
|
|
|
|
VL_DO_CLEAR(delete m_hierPlanp, m_hierPlanp = nullptr); // delete nullptr is safe
|
2023-01-01 13:49:28 +01:00
|
|
|
#ifdef VL_LEAK_CHECKS
|
2020-09-11 17:52:30 +02:00
|
|
|
if (m_rootp) VL_DO_CLEAR(m_rootp->deleteTree(), m_rootp = nullptr);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-16 20:55:46 +02:00
|
|
|
void V3Global::checkTree() const { rootp()->checkTree(); }
|
2020-01-19 13:23:26 +01:00
|
|
|
|
|
|
|
|
void V3Global::readFiles() {
|
|
|
|
|
// NODE STATE
|
|
|
|
|
// AstNode::user4p() // VSymEnt* Package and typedef symbol names
|
2022-01-02 19:56:40 +01:00
|
|
|
const VNUser4InUse inuser4;
|
2020-01-19 13:23:26 +01:00
|
|
|
|
2022-11-19 20:45:33 +01:00
|
|
|
VInFilter filter{v3Global.opt.pipeFilter()};
|
|
|
|
|
V3ParseSym parseSyms{v3Global.rootp()}; // Symbol table must be common across all parsing
|
2020-01-19 13:23:26 +01:00
|
|
|
|
|
|
|
|
V3Parse parser(v3Global.rootp(), &filter, &parseSyms);
|
|
|
|
|
// Read top module
|
|
|
|
|
const V3StringList& vFiles = v3Global.opt.vFiles();
|
2020-08-16 18:54:32 +02:00
|
|
|
for (const string& filename : vFiles) {
|
2022-11-19 20:45:33 +01:00
|
|
|
parser.parseFile(new FileLine{FileLine::commandLineFilename()}, filename, false,
|
2020-01-19 13:23:26 +01:00
|
|
|
"Cannot find file containing module: ");
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 16:53:55 +01:00
|
|
|
if (usesStdPackage()) {
|
|
|
|
|
// Parse the std package
|
|
|
|
|
parser.parseFile(new FileLine{FileLine::commandLineFilename()},
|
|
|
|
|
V3Options::getStdPackagePath(), false,
|
2022-12-03 17:31:26 +01:00
|
|
|
"Cannot find verilated_std.sv containing built-in std:: definitions:");
|
2022-11-28 16:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-19 13:23:26 +01:00
|
|
|
// Read libraries
|
|
|
|
|
// To be compatible with other simulators,
|
|
|
|
|
// this needs to be done after the top file is read
|
|
|
|
|
const V3StringSet& libraryFiles = v3Global.opt.libraryFiles();
|
2020-08-16 18:54:32 +02:00
|
|
|
for (const string& filename : libraryFiles) {
|
2022-11-19 20:45:33 +01:00
|
|
|
parser.parseFile(new FileLine{FileLine::commandLineFilename()}, filename, true,
|
2020-01-19 13:23:26 +01:00
|
|
|
"Cannot find file containing library module: ");
|
|
|
|
|
}
|
|
|
|
|
// v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("parse.tree"));
|
|
|
|
|
V3Error::abortIfErrors();
|
|
|
|
|
|
|
|
|
|
if (!v3Global.opt.preprocOnly()) {
|
|
|
|
|
// Resolve all modules cells refer to
|
|
|
|
|
V3LinkCells::link(v3Global.rootp(), &filter, &parseSyms);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 16:33:43 +01:00
|
|
|
string V3Global::debugFilename(const string& nameComment, int newNumber) {
|
|
|
|
|
++m_debugFileNumber;
|
|
|
|
|
if (newNumber) m_debugFileNumber = newNumber;
|
|
|
|
|
return opt.hierTopDataDir() + "/" + opt.prefix() + "_" + digitsFilename(m_debugFileNumber)
|
|
|
|
|
+ "_" + nameComment;
|
|
|
|
|
}
|
|
|
|
|
string V3Global::digitsFilename(int number) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << std::setfill('0') << std::setw(3) << number;
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-19 13:23:26 +01:00
|
|
|
void V3Global::dumpCheckGlobalTree(const string& stagename, int newNumber, bool doDump) {
|
2022-10-01 17:05:33 +02:00
|
|
|
const string treeFilename = v3Global.debugFilename(stagename + ".tree", newNumber);
|
|
|
|
|
v3Global.rootp()->dumpTreeFile(treeFilename, false, doDump);
|
|
|
|
|
if (v3Global.opt.dumpTreeDot()) {
|
|
|
|
|
v3Global.rootp()->dumpTreeDotFile(treeFilename + ".dot", false, doDump);
|
|
|
|
|
}
|
2020-01-19 13:23:26 +01:00
|
|
|
if (v3Global.opt.stats()) V3Stats::statsStage(stagename);
|
|
|
|
|
}
|
2020-05-23 19:31:30 +02:00
|
|
|
|
|
|
|
|
const std::string& V3Global::ptrToId(const void* p) {
|
2020-08-16 17:43:49 +02:00
|
|
|
auto it = m_ptrToId.find(p);
|
2020-05-23 19:31:30 +02:00
|
|
|
if (it == m_ptrToId.end()) {
|
|
|
|
|
std::ostringstream os;
|
|
|
|
|
if (p) {
|
|
|
|
|
os << "(";
|
|
|
|
|
unsigned id = m_ptrToId.size();
|
|
|
|
|
do { os << static_cast<char>('A' + id % 26); } while (id /= 26);
|
|
|
|
|
os << ")";
|
|
|
|
|
} else {
|
|
|
|
|
os << "0";
|
|
|
|
|
}
|
|
|
|
|
it = m_ptrToId.insert(std::make_pair(p, os.str())).first;
|
|
|
|
|
}
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|