write_verilog remove_cells use std::vector

This commit is contained in:
James Cherry 2020-07-15 11:56:11 -07:00
parent 4fa9e46235
commit a5722ae63c
4 changed files with 43 additions and 13 deletions

View File

@ -16,16 +16,18 @@
#pragma once
#include <vector>
#include "LibertyClass.hh"
namespace sta {
using std::vector;
class Network;
void
writeVerilog(const char *filename,
bool sort,
LibertyCellSeq *remove_cells,
vector<LibertyCell*> *remove_cells,
Network *network);
} // namespace

View File

@ -106,6 +106,8 @@ typedef MinMaxAll MinMaxAllNull;
typedef ClockSet TmpClockSet;
typedef StringSeq TmpStringSeq;
using std::vector;
class CmdErrorNetworkNotLinked : public Exception
{
public:
@ -188,6 +190,30 @@ tclListSeq(Tcl_Obj *const source,
return nullptr;
}
template <class TYPE>
vector<TYPE> *
tclListStdSeq(Tcl_Obj *const source,
swig_type_info *swig_type,
Tcl_Interp *interp)
{
int argc;
Tcl_Obj **argv;
if (Tcl_ListObjGetElements(interp, source, &argc, &argv) == TCL_OK
&& argc > 0) {
vector<TYPE> *seq = new vector<TYPE>;
for (int i = 0; i < argc; i++) {
void *obj;
// Ignore returned TCL_ERROR because can't get swig_type_info.
SWIG_ConvertPtr(argv[i], &obj, swig_type, false);
seq->push_back(reinterpret_cast<TYPE>(obj));
}
return seq;
}
else
return nullptr;
}
LibertyLibrarySeq *
tclListSeqLibertyLibrary(Tcl_Obj *const source,
Tcl_Interp *interp)
@ -195,11 +221,11 @@ tclListSeqLibertyLibrary(Tcl_Obj *const source,
return tclListSeq<LibertyLibrary*>(source, SWIGTYPE_p_LibertyLibrary, interp);
}
LibertyCellSeq *
vector<LibertyCell*> *
tclListSeqLibertyCell(Tcl_Obj *const source,
Tcl_Interp *interp)
{
return tclListSeq<LibertyCell*>(source, SWIGTYPE_p_LibertyCell, interp);
return tclListStdSeq<LibertyCell*>(source, SWIGTYPE_p_LibertyCell, interp);
}
template <class TYPE>
@ -429,10 +455,6 @@ using namespace sta;
Tcl_SetObjResult(interp, list);
}
%typemap(in) LibertyCellSeq* {
$1 = tclListSeqLibertyCell($input, interp);
}
%typemap(out) TmpCellSeq* {
Tcl_Obj *list = Tcl_NewListObj(0, nullptr);
CellSeq *cells = $1;
@ -446,6 +468,10 @@ using namespace sta;
delete cells;
}
%typemap(in) vector<LibertyCell*> * {
$1 = tclListSeqLibertyCell($input, interp);
}
%typemap(out) LibertyCellSeq* {
Tcl_Obj *list = Tcl_NewListObj(0, nullptr);
LibertyCellSeq *cells = $1;

View File

@ -53,7 +53,7 @@ delete_verilog_reader()
void
write_verilog_cmd(const char *filename,
bool sort,
LibertyCellSeq *remove_cells)
vector<LibertyCell*> *remove_cells)
{
// This does NOT want the SDC (cmd) network because it wants
// to see the sta internal names.

View File

@ -32,7 +32,7 @@ class VerilogWriter
public:
VerilogWriter(const char *filename,
bool sort,
LibertyCellSeq *remove_cells,
vector<LibertyCell*> *remove_cells,
FILE *stream,
Network *network);
void writeModule(Instance *inst);
@ -67,7 +67,7 @@ protected:
void
writeVerilog(const char *filename,
bool sort,
LibertyCellSeq *remove_cells,
vector<LibertyCell*> *remove_cells,
Network *network)
{
if (network->topInstance()) {
@ -84,7 +84,7 @@ writeVerilog(const char *filename,
VerilogWriter::VerilogWriter(const char *filename,
bool sort,
LibertyCellSeq *remove_cells,
vector<LibertyCell*> *remove_cells,
FILE *stream,
Network *network) :
filename_(filename),
@ -93,8 +93,10 @@ VerilogWriter::VerilogWriter(const char *filename,
network_(network),
unconnected_net_index_(1)
{
for(LibertyCell *lib_cell : *remove_cells)
remove_cells_.insert(network->cell(lib_cell));
if (remove_cells) {
for(LibertyCell *lib_cell : *remove_cells)
remove_cells_.insert(network->cell(lib_cell));
}
}
void