2025-02-01 23:49:30 +01:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
|
|
|
|
// Copyright (c) 2025, Parallax Software, Inc.
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program 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.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
|
|
|
|
//
|
|
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
|
|
|
|
//
|
|
|
|
|
// This notice may not be removed or altered from any source distribution.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "StringSet.hh"
|
|
|
|
|
#include "Vector.hh"
|
|
|
|
|
#include "Map.hh"
|
|
|
|
|
#include "NetworkClass.hh"
|
|
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
class VerilogScanner;
|
|
|
|
|
class VerilogParse;
|
|
|
|
|
class Debug;
|
|
|
|
|
class Report;
|
|
|
|
|
class VerilogAttrEntry;
|
|
|
|
|
class VerilogAttrStmt;
|
|
|
|
|
class VerilogReader;
|
|
|
|
|
class VerilogStmt;
|
|
|
|
|
class VerilogNet;
|
|
|
|
|
class VerilogNetScalar;
|
|
|
|
|
class VerilogModule;
|
|
|
|
|
class VerilogInst;
|
|
|
|
|
class VerilogModuleInst;
|
|
|
|
|
class VerilogLibertyInst;
|
|
|
|
|
class VerilogDcl;
|
|
|
|
|
class VerilogDclBus;
|
|
|
|
|
class VerilogDclArg;
|
|
|
|
|
class VerilogAssign;
|
|
|
|
|
class VerilogNetConcat;
|
|
|
|
|
class VerilogNetConstant;
|
|
|
|
|
class VerilogNetBitSelect;
|
|
|
|
|
class VerilogNetPartSelect;
|
|
|
|
|
class StringRegistry;
|
|
|
|
|
class VerilogBindingTbl;
|
|
|
|
|
class VerilogNetNameIterator;
|
|
|
|
|
class VerilogNetPortRef;
|
|
|
|
|
class VerilogError;
|
|
|
|
|
class LibertyCell;
|
|
|
|
|
|
|
|
|
|
typedef Map<Cell*, VerilogModule*> VerilogModuleMap;
|
|
|
|
|
typedef Vector<VerilogStmt*> VerilogStmtSeq;
|
|
|
|
|
typedef Vector<VerilogNet*> VerilogNetSeq;
|
|
|
|
|
typedef Vector<VerilogDclArg*> VerilogDclArgSeq;
|
|
|
|
|
typedef Vector<VerilogAttrStmt*> VerilogAttrStmtSeq;
|
|
|
|
|
typedef Vector<VerilogAttrEntry*> VerilogAttrEntrySeq;
|
|
|
|
|
typedef Vector<VerilogError*> VerilogErrorSeq;
|
|
|
|
|
|
|
|
|
|
class VerilogReader
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
VerilogReader(NetworkReader *network);
|
|
|
|
|
~VerilogReader();
|
|
|
|
|
bool read(const char *filename);
|
|
|
|
|
|
2025-04-12 01:59:48 +02:00
|
|
|
void makeModule(const std::string *module_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
VerilogNetSeq *ports,
|
|
|
|
|
VerilogStmtSeq *stmts,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
int line);
|
2025-04-12 01:59:48 +02:00
|
|
|
void makeModule(const std::string *module_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
VerilogStmtSeq *port_dcls,
|
|
|
|
|
VerilogStmtSeq *stmts,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
int line);
|
|
|
|
|
VerilogDcl *makeDcl(PortDirection *dir,
|
|
|
|
|
VerilogDclArgSeq *args,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
int line);
|
|
|
|
|
VerilogDcl *makeDcl(PortDirection *dir,
|
|
|
|
|
VerilogDclArg *arg,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
int line);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogDclArg *makeDclArg(const std::string *net_name);
|
2025-02-01 23:49:30 +01:00
|
|
|
VerilogDclArg*makeDclArg(VerilogAssign *assign);
|
|
|
|
|
VerilogDclBus *makeDclBus(PortDirection *dir,
|
|
|
|
|
int from_index,
|
|
|
|
|
int to_index,
|
|
|
|
|
VerilogDclArg *arg,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
int line);
|
|
|
|
|
VerilogDclBus *makeDclBus(PortDirection *dir,
|
|
|
|
|
int from_index,
|
|
|
|
|
int to_index,
|
|
|
|
|
VerilogDclArgSeq *args,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
int line);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogInst *makeModuleInst(const std::string *module_name,
|
|
|
|
|
const std::string *inst_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
VerilogNetSeq *pins,
|
|
|
|
|
VerilogAttrStmtSeq *attr_stmts,
|
|
|
|
|
const int line);
|
|
|
|
|
VerilogAssign *makeAssign(VerilogNet *lhs,
|
|
|
|
|
VerilogNet *rhs,
|
|
|
|
|
int line);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetScalar *makeNetScalar(const std::string *name);
|
|
|
|
|
VerilogNetPortRef *makeNetNamedPortRefScalarNet(const std::string *port_vname);
|
|
|
|
|
VerilogNetPortRef *makeNetNamedPortRefScalarNet(const std::string *port_name,
|
|
|
|
|
const std::string *net_name);
|
|
|
|
|
VerilogNetPortRef *makeNetNamedPortRefBitSelect(const std::string *port_name,
|
|
|
|
|
const std::string *bus_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
int index);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetPortRef *makeNetNamedPortRefScalar(const std::string *port_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
VerilogNet *net);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetPortRef *makeNetNamedPortRefBit(const std::string *port_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
int index,
|
|
|
|
|
VerilogNet *net);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetPortRef *makeNetNamedPortRefPart(const std::string *port_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
int from_index,
|
|
|
|
|
int to_index,
|
|
|
|
|
VerilogNet *net);
|
|
|
|
|
VerilogNetConcat *makeNetConcat(VerilogNetSeq *nets);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetConstant *makeNetConstant(const std::string *constant,
|
2025-02-01 23:49:30 +01:00
|
|
|
int line);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetBitSelect *makeNetBitSelect(const std::string *name,
|
2025-02-01 23:49:30 +01:00
|
|
|
int index);
|
2025-04-12 01:59:48 +02:00
|
|
|
VerilogNetPartSelect *makeNetPartSelect(const std::string *name,
|
2025-02-01 23:49:30 +01:00
|
|
|
int from_index,
|
|
|
|
|
int to_index);
|
|
|
|
|
VerilogModule *module(Cell *cell);
|
|
|
|
|
Instance *linkNetwork(const char *top_cell_name,
|
2025-02-05 22:54:03 +01:00
|
|
|
bool make_black_boxes,
|
|
|
|
|
bool delete_modules);
|
2025-02-01 23:49:30 +01:00
|
|
|
const char *filename() const { return filename_.c_str(); }
|
|
|
|
|
void incrLine();
|
|
|
|
|
Report *report() const { return report_; }
|
|
|
|
|
void error(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt, ...);
|
|
|
|
|
void warn(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt, ...);
|
2025-04-12 01:59:48 +02:00
|
|
|
const std::string &zeroNetName() const { return zero_net_name_; }
|
|
|
|
|
const std::string &oneNetName() const { return one_net_name_; }
|
2025-02-01 23:49:30 +01:00
|
|
|
void deleteModules();
|
|
|
|
|
void reportStmtCounts();
|
2025-04-12 01:59:48 +02:00
|
|
|
const std::string &constant10Max() const { return constant10_max_; }
|
2025-02-01 23:49:30 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void init(const char *filename);
|
|
|
|
|
void makeCellPorts(Cell *cell,
|
|
|
|
|
VerilogModule *module,
|
|
|
|
|
VerilogNetSeq *ports);
|
|
|
|
|
Port *makeCellPort(Cell *cell,
|
|
|
|
|
VerilogModule *module,
|
2025-04-12 01:59:48 +02:00
|
|
|
const std::string &port_name);
|
2025-02-01 23:49:30 +01:00
|
|
|
void makeNamedPortRefCellPorts(Cell *cell,
|
|
|
|
|
VerilogModule *module,
|
|
|
|
|
VerilogNet *mod_port,
|
|
|
|
|
StdStringSet &port_names);
|
|
|
|
|
void checkModuleDcls(VerilogModule *module,
|
2025-04-12 01:59:48 +02:00
|
|
|
std::set<std::string> &port_names);
|
2025-02-01 23:49:30 +01:00
|
|
|
void makeModuleInstBody(VerilogModule *module,
|
|
|
|
|
Instance *inst,
|
|
|
|
|
VerilogBindingTbl *bindings,
|
|
|
|
|
bool make_black_boxes);
|
|
|
|
|
void makeModuleInstNetwork(VerilogModuleInst *mod_inst,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogModule *parent_module,
|
|
|
|
|
VerilogBindingTbl *parent_bindings,
|
|
|
|
|
bool make_black_boxes);
|
|
|
|
|
void makeLibertyInst(VerilogLibertyInst *lib_inst,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogModule *parent_module,
|
|
|
|
|
VerilogBindingTbl *parent_bindings);
|
|
|
|
|
void bindGlobalNets(VerilogBindingTbl *bindings);
|
|
|
|
|
void makeNamedInstPins1(Cell *cell,
|
|
|
|
|
Instance *inst,
|
|
|
|
|
VerilogModuleInst *mod_inst,
|
|
|
|
|
VerilogBindingTbl *bindings,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogBindingTbl *parent_bindings,
|
|
|
|
|
bool is_leaf);
|
|
|
|
|
void makeNamedInstPins(Cell *cell,
|
|
|
|
|
Instance *inst,
|
|
|
|
|
VerilogModuleInst *mod_inst,
|
|
|
|
|
VerilogBindingTbl *bindings,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogModule *parent_module,
|
|
|
|
|
VerilogBindingTbl *parent_bindings,
|
|
|
|
|
bool is_leaf);
|
|
|
|
|
void makeOrderedInstPins(Cell *cell,
|
|
|
|
|
Instance *inst,
|
|
|
|
|
VerilogModuleInst *mod_inst,
|
|
|
|
|
VerilogBindingTbl *bindings,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogModule *parent_module,
|
|
|
|
|
VerilogBindingTbl *parent_bindings,
|
|
|
|
|
bool is_leaf);
|
|
|
|
|
void mergeAssignNet(VerilogAssign *assign,
|
|
|
|
|
VerilogModule *module,
|
|
|
|
|
Instance *inst,
|
|
|
|
|
VerilogBindingTbl *bindings);
|
|
|
|
|
void makeInstPin(Instance *inst,
|
|
|
|
|
Port *port,
|
|
|
|
|
VerilogNetNameIterator *net_name_iter,
|
|
|
|
|
VerilogBindingTbl *bindings,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogBindingTbl *parent_bindings,
|
|
|
|
|
bool is_leaf);
|
|
|
|
|
void makeInstPin(Instance *inst,
|
|
|
|
|
Port *port,
|
2025-04-12 01:59:48 +02:00
|
|
|
const std::string &net_name,
|
2025-02-01 23:49:30 +01:00
|
|
|
VerilogBindingTbl *bindings,
|
|
|
|
|
Instance *parent,
|
|
|
|
|
VerilogBindingTbl *parent_bindings,
|
|
|
|
|
bool is_leaf);
|
|
|
|
|
void linkWarn(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *msg, ...)
|
|
|
|
|
__attribute__((format (printf, 5, 6)));
|
|
|
|
|
void linkError(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *msg, ...)
|
|
|
|
|
__attribute__((format (printf, 5, 6)));
|
|
|
|
|
bool reportLinkErrors();
|
|
|
|
|
bool haveLinkErrors();
|
|
|
|
|
Cell *makeBlackBox(VerilogModuleInst *mod_inst,
|
|
|
|
|
VerilogModule *parent_module);
|
|
|
|
|
void makeBlackBoxNamedPorts(Cell *cell,
|
|
|
|
|
VerilogModuleInst *mod_inst,
|
|
|
|
|
VerilogModule *parent_module);
|
|
|
|
|
void makeBlackBoxOrderedPorts(Cell *cell,
|
|
|
|
|
VerilogModuleInst *mod_inst,
|
|
|
|
|
VerilogModule *parent_module);
|
|
|
|
|
bool isBlackBox(Cell *cell);
|
|
|
|
|
bool hasScalarNamedPortRefs(LibertyCell *liberty_cell,
|
|
|
|
|
VerilogNetSeq *pins);
|
|
|
|
|
|
2025-04-12 01:59:48 +02:00
|
|
|
std::string filename_;
|
2025-02-01 23:49:30 +01:00
|
|
|
Report *report_;
|
|
|
|
|
Debug *debug_;
|
|
|
|
|
NetworkReader *network_;
|
|
|
|
|
|
|
|
|
|
Library *library_;
|
|
|
|
|
int black_box_index_;
|
|
|
|
|
VerilogModuleMap module_map_;
|
|
|
|
|
VerilogErrorSeq link_errors_;
|
2025-04-12 01:59:48 +02:00
|
|
|
const std::string zero_net_name_;
|
|
|
|
|
const std::string one_net_name_;
|
|
|
|
|
std::string constant10_max_;
|
2025-02-01 23:49:30 +01:00
|
|
|
ViewType *view_type_;
|
|
|
|
|
bool report_stmt_stats_;
|
|
|
|
|
int module_count_;
|
|
|
|
|
int inst_mod_count_;
|
|
|
|
|
int inst_lib_count_;
|
|
|
|
|
int inst_lib_net_arrays_;
|
|
|
|
|
int port_names_;
|
|
|
|
|
int inst_module_names_;
|
|
|
|
|
int inst_names_;
|
|
|
|
|
int dcl_count_;
|
|
|
|
|
int dcl_bus_count_;
|
|
|
|
|
int dcl_arg_count_;
|
|
|
|
|
int net_scalar_count_;
|
|
|
|
|
int net_scalar_names_;
|
|
|
|
|
int net_bus_names_;
|
|
|
|
|
int net_part_select_count_;
|
|
|
|
|
int net_bit_select_count_;
|
|
|
|
|
int net_port_ref_scalar_count_;
|
|
|
|
|
int net_port_ref_scalar_net_count_;
|
|
|
|
|
int net_port_ref_bit_count_;
|
|
|
|
|
int net_port_ref_part_count_;
|
|
|
|
|
int net_constant_count_;
|
|
|
|
|
int assign_count_;
|
|
|
|
|
int concat_count_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace sta
|