rm TokenParser
Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
parent
cd21c43693
commit
e76f54a068
|
|
@ -237,7 +237,6 @@ set(STA_SOURCE
|
||||||
util/StringSeq.cc
|
util/StringSeq.cc
|
||||||
util/StringSet.cc
|
util/StringSet.cc
|
||||||
util/StringUtil.cc
|
util/StringUtil.cc
|
||||||
util/TokenParser.cc
|
|
||||||
util/Transition.cc
|
util/Transition.cc
|
||||||
|
|
||||||
verilog/VerilogReader.cc
|
verilog/VerilogReader.cc
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@
|
||||||
|
|
||||||
namespace sta {
|
namespace sta {
|
||||||
|
|
||||||
|
using StdStringSeq = std::vector<std::string>;
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
stringEq(const char *str1,
|
stringEq(const char *str1,
|
||||||
const char *str2)
|
const char *str2)
|
||||||
|
|
@ -201,12 +203,9 @@ deleteTmpStrings();
|
||||||
void
|
void
|
||||||
trimRight(std::string &str);
|
trimRight(std::string &str);
|
||||||
|
|
||||||
using StringVector = std::vector<std::string>;
|
// Spit text into delimiter separated tokens and skip whitepace.
|
||||||
|
StdStringSeq
|
||||||
void
|
parseTokens(const std::string &s,
|
||||||
split(const std::string &text,
|
const char delimiter);
|
||||||
const std::string &delims,
|
|
||||||
// Return values.
|
|
||||||
StringVector &tokens);
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
// 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 <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace sta {
|
|
||||||
|
|
||||||
using StdStringSeq = std::vector<std::string>;
|
|
||||||
|
|
||||||
// Iterate over the tokens in str separated by character sep.
|
|
||||||
// Similar in functionality to strtok, but does not leave the string
|
|
||||||
// side-effected. This is preferable to using strtok because it leaves
|
|
||||||
// string terminators where the separators were.
|
|
||||||
// Using STL string functions to parse tokens is messy and extremely slow
|
|
||||||
// on the RogueWave/Solaris implementation, apparently because of mutexes
|
|
||||||
// on temporary strings.
|
|
||||||
class TokenParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TokenParser(const char *str,
|
|
||||||
const char *delimiters);
|
|
||||||
bool hasNext();
|
|
||||||
char *next();
|
|
||||||
|
|
||||||
private:
|
|
||||||
const char *delimiters_;
|
|
||||||
char *token_;
|
|
||||||
char *token_end_;
|
|
||||||
char token_delimiter_;
|
|
||||||
bool first_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse delimiter separated tokens and skipp spaces.
|
|
||||||
StdStringSeq
|
|
||||||
parseTokens(const std::string &s,
|
|
||||||
const char delimiter);
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
@ -33,7 +33,6 @@
|
||||||
#include "EnumNameMap.hh"
|
#include "EnumNameMap.hh"
|
||||||
#include "Report.hh"
|
#include "Report.hh"
|
||||||
#include "Debug.hh"
|
#include "Debug.hh"
|
||||||
#include "TokenParser.hh"
|
|
||||||
#include "Units.hh"
|
#include "Units.hh"
|
||||||
#include "Transition.hh"
|
#include "Transition.hh"
|
||||||
#include "FuncExpr.hh"
|
#include "FuncExpr.hh"
|
||||||
|
|
|
||||||
|
|
@ -213,8 +213,7 @@ WriteSpice::writeSubckts(StdStringSet &cell_names)
|
||||||
string line;
|
string line;
|
||||||
while (getline(lib_subckts_stream, line)) {
|
while (getline(lib_subckts_stream, line)) {
|
||||||
// .subckt <cell_name> [args..]
|
// .subckt <cell_name> [args..]
|
||||||
StringVector tokens;
|
StdStringSeq tokens = parseTokens(line, ' ');
|
||||||
split(line, " \t", tokens);
|
|
||||||
if (tokens.size() >= 2
|
if (tokens.size() >= 2
|
||||||
&& stringEqual(tokens[0].c_str(), ".subckt")) {
|
&& stringEqual(tokens[0].c_str(), ".subckt")) {
|
||||||
const char *cell_name = tokens[1].c_str();
|
const char *cell_name = tokens[1].c_str();
|
||||||
|
|
@ -261,11 +260,11 @@ WriteSpice::writeSubckts(StdStringSet &cell_names)
|
||||||
|
|
||||||
void
|
void
|
||||||
WriteSpice::recordSpicePortNames(const char *cell_name,
|
WriteSpice::recordSpicePortNames(const char *cell_name,
|
||||||
StringVector &tokens)
|
StdStringSeq &tokens)
|
||||||
{
|
{
|
||||||
LibertyCell *cell = network_->findLibertyCell(cell_name);
|
LibertyCell *cell = network_->findLibertyCell(cell_name);
|
||||||
if (cell) {
|
if (cell) {
|
||||||
StringVector &spice_port_names = cell_spice_port_names_[cell_name];
|
StdStringSeq &spice_port_names = cell_spice_port_names_[cell_name];
|
||||||
for (size_t i = 2; i < tokens.size(); i++) {
|
for (size_t i = 2; i < tokens.size(); i++) {
|
||||||
const char *port_name = tokens[i].c_str();
|
const char *port_name = tokens[i].c_str();
|
||||||
LibertyPort *port = cell->findLibertyPort(port_name);
|
LibertyPort *port = cell->findLibertyPort(port_name);
|
||||||
|
|
@ -290,8 +289,7 @@ WriteSpice::findCellSubckts(StdStringSet &cell_names)
|
||||||
string line;
|
string line;
|
||||||
while (getline(lib_subckts_stream, line)) {
|
while (getline(lib_subckts_stream, line)) {
|
||||||
// .subckt <cell_name> [args..]
|
// .subckt <cell_name> [args..]
|
||||||
StringVector tokens;
|
StdStringSeq tokens = parseTokens(line, ' ');
|
||||||
split(line, " \t", tokens);
|
|
||||||
if (tokens.size() >= 2
|
if (tokens.size() >= 2
|
||||||
&& stringEqual(tokens[0].c_str(), ".subckt")) {
|
&& stringEqual(tokens[0].c_str(), ".subckt")) {
|
||||||
const char *cell_name = tokens[1].c_str();
|
const char *cell_name = tokens[1].c_str();
|
||||||
|
|
@ -304,7 +302,7 @@ WriteSpice::findCellSubckts(StdStringSet &cell_names)
|
||||||
else {
|
else {
|
||||||
// Process previous statement.
|
// Process previous statement.
|
||||||
if (tolower(stmt[0]) == 'x') {
|
if (tolower(stmt[0]) == 'x') {
|
||||||
split(stmt, " \t", tokens);
|
StdStringSeq tokens = parseTokens(line, ' ');
|
||||||
string &subckt_cell = tokens[tokens.size() - 1];
|
string &subckt_cell = tokens[tokens.size() - 1];
|
||||||
cell_names.insert(subckt_cell);
|
cell_names.insert(subckt_cell);
|
||||||
}
|
}
|
||||||
|
|
@ -329,7 +327,7 @@ WriteSpice::writeSubcktInst(const Instance *inst)
|
||||||
const char *inst_name = network_->pathName(inst);
|
const char *inst_name = network_->pathName(inst);
|
||||||
LibertyCell *cell = network_->libertyCell(inst);
|
LibertyCell *cell = network_->libertyCell(inst);
|
||||||
const char *cell_name = cell->name();
|
const char *cell_name = cell->name();
|
||||||
StringVector &spice_port_names = cell_spice_port_names_[cell_name];
|
StdStringSeq &spice_port_names = cell_spice_port_names_[cell_name];
|
||||||
streamPrint(spice_stream_, "x%s", inst_name);
|
streamPrint(spice_stream_, "x%s", inst_name);
|
||||||
for (string subckt_port_name : spice_port_names) {
|
for (string subckt_port_name : spice_port_names) {
|
||||||
const char *subckt_port_cname = subckt_port_name.c_str();
|
const char *subckt_port_cname = subckt_port_name.c_str();
|
||||||
|
|
@ -357,7 +355,7 @@ WriteSpice::writeSubcktInstVoltSrcs(const Instance *inst,
|
||||||
{
|
{
|
||||||
LibertyCell *cell = network_->libertyCell(inst);
|
LibertyCell *cell = network_->libertyCell(inst);
|
||||||
const char *cell_name = cell->name();
|
const char *cell_name = cell->name();
|
||||||
StringVector &spice_port_names = cell_spice_port_names_[cell_name];
|
StdStringSeq &spice_port_names = cell_spice_port_names_[cell_name];
|
||||||
const char *inst_name = network_->pathName(inst);
|
const char *inst_name = network_->pathName(inst);
|
||||||
|
|
||||||
debugPrint(debug_, "write_spice", 2, "subckt %s", cell->name());
|
debugPrint(debug_, "write_spice", 2, "subckt %s", cell->name());
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@
|
||||||
namespace sta {
|
namespace sta {
|
||||||
|
|
||||||
using ParasiticNodeMap = std::map<const ParasiticNode*, int>;
|
using ParasiticNodeMap = std::map<const ParasiticNode*, int>;
|
||||||
using CellSpicePortNames = std::map<std::string, StringVector>;
|
|
||||||
using LibertyPortLogicValues = std::map<const LibertyPort*, LogicValue>;
|
|
||||||
using StdStringSeq = std::vector<std::string>;
|
using StdStringSeq = std::vector<std::string>;
|
||||||
|
using CellSpicePortNames = std::map<std::string, StdStringSeq>;
|
||||||
|
using LibertyPortLogicValues = std::map<const LibertyPort*, LogicValue>;
|
||||||
|
|
||||||
// Utilities for writing a spice deck.
|
// Utilities for writing a spice deck.
|
||||||
class WriteSpice : public StaState
|
class WriteSpice : public StaState
|
||||||
|
|
@ -69,7 +69,7 @@ protected:
|
||||||
void writeSubckts(StdStringSet &cell_names);
|
void writeSubckts(StdStringSet &cell_names);
|
||||||
void findCellSubckts(StdStringSet &cell_names);
|
void findCellSubckts(StdStringSet &cell_names);
|
||||||
void recordSpicePortNames(const char *cell_name,
|
void recordSpicePortNames(const char *cell_name,
|
||||||
StringVector &tokens);
|
StdStringSeq &tokens);
|
||||||
void writeSubcktInst(const Instance *inst);
|
void writeSubcktInst(const Instance *inst);
|
||||||
void writeSubcktInstVoltSrcs(const Instance *inst,
|
void writeSubcktInstVoltSrcs(const Instance *inst,
|
||||||
LibertyPortLogicValues &port_values,
|
LibertyPortLogicValues &port_values,
|
||||||
|
|
|
||||||
|
|
@ -269,12 +269,11 @@ trimRight(string &str)
|
||||||
str.erase(str.find_last_not_of(" ") + 1);
|
str.erase(str.find_last_not_of(" ") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
StdStringSeq
|
||||||
split(const string &text,
|
split(const string &text,
|
||||||
const string &delims,
|
const string &delims)
|
||||||
// Return values.
|
|
||||||
StringVector &tokens)
|
|
||||||
{
|
{
|
||||||
|
StdStringSeq tokens;
|
||||||
auto start = text.find_first_not_of(delims);
|
auto start = text.find_first_not_of(delims);
|
||||||
auto end = text.find_first_of(delims, start);
|
auto end = text.find_first_of(delims, start);
|
||||||
while (end != string::npos) {
|
while (end != string::npos) {
|
||||||
|
|
@ -284,6 +283,28 @@ split(const string &text,
|
||||||
}
|
}
|
||||||
if (start != string::npos)
|
if (start != string::npos)
|
||||||
tokens.push_back(text.substr(start));
|
tokens.push_back(text.substr(start));
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse space separated tokens.
|
||||||
|
StdStringSeq
|
||||||
|
parseTokens(const std::string &s,
|
||||||
|
const char delimiter)
|
||||||
|
{
|
||||||
|
StdStringSeq tokens;
|
||||||
|
size_t i = 0;
|
||||||
|
while (i < s.size()) {
|
||||||
|
while (i < s.size() && std::isspace(s[i]))
|
||||||
|
++i;
|
||||||
|
size_t start = i;
|
||||||
|
while (i < s.size() && s[i] != delimiter)
|
||||||
|
++i;
|
||||||
|
if (start < i) {
|
||||||
|
tokens.emplace_back(s, start, i - start);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
#include "TokenParser.hh"
|
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace sta {
|
|
||||||
|
|
||||||
TokenParser::TokenParser(const char *str,
|
|
||||||
const char *delimiters) :
|
|
||||||
delimiters_(delimiters),
|
|
||||||
token_(const_cast<char*>(str)),
|
|
||||||
token_delimiter_('\0'),
|
|
||||||
first_(true)
|
|
||||||
{
|
|
||||||
// Skip leading spaces.
|
|
||||||
while (*token_ != '\0' && isspace(*token_))
|
|
||||||
token_++;
|
|
||||||
token_end_ = strpbrk(token_, delimiters_);
|
|
||||||
if (token_end_) {
|
|
||||||
// Save the delimiter.
|
|
||||||
token_delimiter_ = *token_end_;
|
|
||||||
// Replace the separator with a terminator.
|
|
||||||
*token_end_ = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
TokenParser::hasNext()
|
|
||||||
{
|
|
||||||
if (!first_) {
|
|
||||||
// Replace the previous separator.
|
|
||||||
if (token_end_) {
|
|
||||||
*token_end_ = token_delimiter_;
|
|
||||||
token_ = token_end_ + 1;
|
|
||||||
// Skip spaces.
|
|
||||||
while (*token_ != '\0' && isspace(*token_))
|
|
||||||
token_++;
|
|
||||||
// Skip delimiters.
|
|
||||||
while (*token_ != '\0' && strchr(delimiters_,*token_) != nullptr)
|
|
||||||
token_++;
|
|
||||||
if (*token_ == '\0')
|
|
||||||
token_ = nullptr;
|
|
||||||
else {
|
|
||||||
token_end_ = strpbrk(token_, delimiters_);
|
|
||||||
if (token_end_) {
|
|
||||||
// Save the delimiter.
|
|
||||||
token_delimiter_ = *token_end_;
|
|
||||||
// Replace the separator with a terminator.
|
|
||||||
*token_end_ = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
token_ = nullptr;
|
|
||||||
}
|
|
||||||
return token_ != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
TokenParser::next()
|
|
||||||
{
|
|
||||||
first_ = false;
|
|
||||||
return token_;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Parse space separated tokens.
|
|
||||||
StdStringSeq
|
|
||||||
parseTokens(const std::string &s,
|
|
||||||
const char delimiter)
|
|
||||||
{
|
|
||||||
StdStringSeq tokens;
|
|
||||||
size_t i = 0;
|
|
||||||
while (i < s.size()) {
|
|
||||||
while (i < s.size() && std::isspace(s[i]))
|
|
||||||
++i;
|
|
||||||
size_t start = i;
|
|
||||||
while (i < s.size() && s[i] != delimiter)
|
|
||||||
++i;
|
|
||||||
if (start < i) {
|
|
||||||
tokens.emplace_back(s, start, i - start);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tokens;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
Loading…
Reference in New Issue