Files
OpenSTA/include/sta/ConcreteLibrary.hh
T

279 lines
9.4 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2026-03-10 13:21:17 -07:00
// Copyright (c) 2026, Parallax Software, Inc.
2018-09-28 08:54:21 -07:00
//
// 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
2022-01-04 10:17:08 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 08:54:21 -07:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
2022-01-04 10:17:08 -07:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2025-01-21 18:54:33 -07:00
//
// 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.
2018-09-28 08:54:21 -07:00
2020-02-15 17:13:16 -07:00
#pragma once
2018-09-28 08:54:21 -07:00
2021-08-12 19:52:50 -07:00
#include <functional>
2026-04-15 09:38:10 -07:00
#include <map>
2026-03-28 19:13:35 -07:00
#include <string_view>
2026-01-03 16:59:35 -08:00
#include <vector>
2021-08-12 19:52:50 -07:00
2020-04-05 14:53:44 -07:00
#include "NetworkClass.hh"
2026-04-15 09:38:10 -07:00
#include "StringUtil.hh"
2018-09-28 08:54:21 -07:00
// The classes defined in this file are a contrete implementation of
// the library API. They can be used by a reader to construct classes
// that implement the library portion of the network API.
namespace sta {
class ConcreteLibrary;
class ConcreteCell;
class ConcretePort;
class ConcreteCellPortBitIterator;
class PatternMatch;
class LibertyCell;
class LibertyPort;
2018-09-28 08:54:21 -07:00
2026-03-28 19:13:35 -07:00
using ConcreteCellMap = std::map<std::string, ConcreteCell*, std::less<>>;
2026-01-03 16:59:35 -08:00
using ConcretePortSeq = std::vector<ConcretePort*>;
2026-03-28 19:13:35 -07:00
using ConcretePortMap = std::map<std::string, ConcretePort*, std::less<>>;
2026-01-03 16:59:35 -08:00
using ConcreteLibraryCellIterator = MapIterator<ConcreteCellMap, ConcreteCell*>;
using ConcreteCellPortIterator = VectorIterator<ConcretePortSeq, ConcretePort*>;
using ConcretePortMemberIterator = VectorIterator<ConcretePortSeq, ConcretePort*>;
2018-09-28 08:54:21 -07:00
class ConcreteLibrary
{
public:
2026-04-02 19:22:08 -07:00
ConcreteLibrary(std::string_view name,
std::string_view filename,
2026-01-03 16:59:35 -08:00
bool is_liberty);
virtual ~ConcreteLibrary();
2026-03-28 19:13:35 -07:00
const std::string &name() const { return name_; }
2023-01-19 11:23:45 -07:00
ObjectId id() const { return id_; }
bool isLiberty() const { return is_liberty_; }
2026-03-28 19:13:35 -07:00
const std::string &filename() const { return filename_; }
2018-09-28 08:54:21 -07:00
void addCell(ConcreteCell *cell);
2026-03-28 19:13:35 -07:00
ConcreteCell *makeCell(std::string_view name,
2026-01-03 16:59:35 -08:00
bool is_leaf,
2026-03-28 19:13:35 -07:00
std::string_view filename);
2018-09-28 08:54:21 -07:00
void deleteCell(ConcreteCell *cell);
ConcreteLibraryCellIterator *cellIterator() const;
2026-03-28 19:13:35 -07:00
ConcreteCell *findCell(std::string_view name) const;
2023-01-19 11:23:45 -07:00
CellSeq findCellsMatching(const PatternMatch *pattern) const;
2021-10-06 16:55:43 -07:00
char busBrktLeft() const { return bus_brkt_left_; }
char busBrktRight() const { return bus_brkt_right_; }
2019-01-16 15:37:31 -08:00
void setBusBrkts(char left,
2026-01-03 16:59:35 -08:00
char right);
2018-09-28 08:54:21 -07:00
protected:
2026-03-28 19:13:35 -07:00
void removeCell(ConcreteCell *cell);
2018-09-28 08:54:21 -07:00
2025-04-11 16:59:48 -07:00
std::string name_;
std::string filename_;
2026-06-26 21:11:13 -07:00
ConcreteCellMap cell_map_;
ObjectId id_;
bool is_liberty_;
2026-04-15 09:38:10 -07:00
char bus_brkt_left_{'['};
char bus_brkt_right_{']'};
2018-09-28 08:54:21 -07:00
private:
friend class ConcreteCell;
};
class ConcreteCell
{
public:
// Use ConcreteLibrary::deleteCell.
virtual ~ConcreteCell();
2026-03-28 19:13:35 -07:00
const std::string &name() const { return name_; }
2023-01-19 11:23:45 -07:00
ObjectId id() const { return id_; }
2026-03-28 19:13:35 -07:00
const std::string &filename() const { return filename_; }
2023-01-19 11:23:45 -07:00
ConcreteLibrary *library() const { return library_; }
2019-06-24 08:35:04 -07:00
LibertyCell *libertyCell() const { return liberty_cell_; }
void setLibertyCell(LibertyCell *cell);
2019-11-13 14:58:38 -07:00
void *extCell() const { return ext_cell_; }
void setExtCell(void *ext_cell);
int portBitCount() const { return port_bit_count_; }
2026-03-28 19:13:35 -07:00
ConcretePort *findPort(std::string_view name) const;
2023-01-19 11:23:45 -07:00
PortSeq findPortsMatching(const PatternMatch *pattern) const;
ConcreteCellPortIterator *portIterator() const;
ConcreteCellPortBitIterator *portBitIterator() const;
bool isLeaf() const { return is_leaf_; }
2018-09-28 08:54:21 -07:00
void setIsLeaf(bool is_leaf);
2026-03-28 19:13:35 -07:00
void setAttribute(std::string_view key,
std::string_view value);
std::string getAttribute(std::string_view key) const;
2025-05-18 09:37:10 -07:00
const AttributeMap &attributeMap() const { return attribute_map_; }
2018-09-28 08:54:21 -07:00
// Cell acts as port factory.
2026-03-28 19:13:35 -07:00
ConcretePort *makePort(std::string_view name);
2018-09-28 08:54:21 -07:00
// Bus port.
2026-03-28 19:13:35 -07:00
ConcretePort *makeBusPort(std::string_view name,
2026-01-03 16:59:35 -08:00
int from_index,
int to_index);
2018-09-28 08:54:21 -07:00
// Bundle port.
2026-03-28 19:13:35 -07:00
ConcretePort *makeBundlePort(std::string_view name,
2026-01-03 16:59:35 -08:00
ConcretePortSeq *members);
2018-09-28 08:54:21 -07:00
// Group previously defined bus bit ports together.
2026-04-13 14:58:16 -07:00
void groupBusPorts(char bus_brkt_left,
char bus_brkt_right,
2026-04-15 09:38:10 -07:00
const std::function<bool(std::string_view)> &port_msb_first);
2018-09-28 08:54:21 -07:00
size_t portCount() const;
2026-03-28 19:13:35 -07:00
void setName(std::string_view name);
2026-04-13 14:58:16 -07:00
virtual void addPort(ConcretePort *port);
2018-09-28 08:54:21 -07:00
void addPortBit(ConcretePort *port);
protected:
2026-03-28 19:13:35 -07:00
ConcreteCell(std::string_view name,
std::string_view filename,
2023-01-19 11:23:45 -07:00
bool is_leaf,
ConcreteLibrary *library);
2026-03-28 19:13:35 -07:00
ConcretePort *makeBusPort(std::string_view name,
2026-01-03 16:59:35 -08:00
int from_index,
int to_index,
ConcretePortSeq *members);
2019-01-16 15:37:31 -08:00
void makeBusPortBits(ConcretePort *bus_port,
2026-03-28 19:13:35 -07:00
std::string_view bus_name,
2026-01-03 16:59:35 -08:00
int from_index,
int to_index);
2018-09-28 08:54:21 -07:00
// Bus port bit (internal to makeBusPortBits).
2026-04-15 09:38:10 -07:00
ConcretePort *makePort(std::string_view bit_name,
2026-01-03 16:59:35 -08:00
int bit_index);
2019-01-16 15:37:31 -08:00
void makeBusPortBit(ConcretePort *bus_port,
2026-03-28 19:13:35 -07:00
std::string_view bus_name,
2026-01-03 16:59:35 -08:00
int index);
2018-09-28 08:54:21 -07:00
2025-04-11 16:59:48 -07:00
std::string name_;
2023-01-19 11:23:45 -07:00
ObjectId id_;
2018-09-28 08:54:21 -07:00
// Filename is optional.
2025-04-11 16:59:48 -07:00
std::string filename_;
2023-01-19 11:23:45 -07:00
ConcreteLibrary *library_;
2026-04-15 09:38:10 -07:00
LibertyCell *liberty_cell_{nullptr};
2019-11-13 14:58:38 -07:00
// External application cell.
2026-04-15 09:38:10 -07:00
void *ext_cell_{nullptr};
2018-09-28 08:54:21 -07:00
// Non-bus and bus ports (but no expanded bus bit ports).
ConcretePortSeq ports_;
ConcretePortMap port_map_;
// Port bit count (expanded buses).
2026-04-15 09:38:10 -07:00
int port_bit_count_{0};
2018-09-28 08:54:21 -07:00
bool is_leaf_;
2022-07-11 08:49:12 -07:00
AttributeMap attribute_map_;
2018-09-28 08:54:21 -07:00
private:
friend class ConcreteLibrary;
friend class ConcreteCellPortBitIterator;
};
class ConcretePort
{
public:
virtual ~ConcretePort();
2026-03-28 19:13:35 -07:00
const std::string &name() const { return name_; }
2023-01-19 11:23:45 -07:00
ObjectId id() const { return id_; }
2026-03-28 19:13:35 -07:00
std::string busName() const;
Cell *cell() const;
ConcreteLibrary *library() const { return cell_->library(); }
PortDirection *direction() const { return direction_; }
2019-07-02 07:07:34 -07:00
LibertyPort *libertyPort() const { return liberty_port_; }
void setLibertyPort(LibertyPort *port);
2019-11-13 14:58:38 -07:00
// External application port.
void *extPort() const { return ext_port_; }
void setExtPort(void *port);
void setDirection(PortDirection *dir);
2018-09-28 08:54:21 -07:00
// Bundles are groups of related ports that do not use
// bus notation.
bool isBundle() const { return is_bundle_; }
ConcretePort *bundlePort() const { return bundle_port_; }
bool isBundleMember() const { return bundle_port_ != nullptr; }
void setBundlePort(ConcretePort *port);
bool isBus() const { return is_bus_; }
2018-09-28 08:54:21 -07:00
// Index of cell bit ports.
// Bus/bundle ports do not have an pin index.
int pinIndex() const { return pin_index_; }
2018-09-28 08:54:21 -07:00
void setPinIndex(int index);
// Size is the bus/bundle member count (1 for non-bus/bundle ports).
int size() const;
int fromIndex() const { return from_index_; }
int toIndex() const { return to_index_; }
2018-09-28 08:54:21 -07:00
// Bus member, bus[subscript].
ConcretePort *findBusBit(int index) const;
2018-09-28 08:54:21 -07:00
// Predicate to determine if subscript is within bus range.
// (toIndex > fromIndex) && fromIndex <= subscript <= toIndex
// || (fromIndex > toIndex) && fromIndex >= subscript >= toIndex
bool busIndexInRange(int index) const;
// A port has members if it is a bundle or bus.
bool hasMembers() const;
ConcretePort *findMember(int index) const;
ConcretePortMemberIterator *memberIterator() const;
2018-09-28 08:54:21 -07:00
void setBusBitIndex(int index);
// Bus bit port functions.
// Bus bit is one bit of a bus port.
bool isBusBit() const;
2018-09-28 08:54:21 -07:00
// Bit index within bus port.
// The bit index of A[3] is 3.
int busBitIndex() const { return to_index_; }
2018-09-28 08:54:21 -07:00
ConcretePortSeq *memberPorts() const { return member_ports_; }
void addPortBit(ConcretePort *port);
protected:
// Constructors for factory in cell class.
2026-03-28 19:13:35 -07:00
ConcretePort(std::string_view name,
2023-01-19 11:23:45 -07:00
bool is_bus,
2026-01-03 16:59:35 -08:00
int from_index,
int to_index,
bool is_bundle,
ConcretePortSeq *member_ports,
2023-01-19 11:23:45 -07:00
ConcreteCell *cell);
2018-09-28 08:54:21 -07:00
2025-04-11 16:59:48 -07:00
std::string name_;
2023-01-19 11:23:45 -07:00
ObjectId id_;
2018-09-28 08:54:21 -07:00
ConcreteCell *cell_;
PortDirection *direction_;
2026-04-15 09:38:10 -07:00
LibertyPort *liberty_port_{nullptr};
2019-11-13 14:58:38 -07:00
// External application port.
2026-04-15 09:38:10 -07:00
void *ext_port_{nullptr};
int pin_index_{-1};
2018-09-28 08:54:21 -07:00
bool is_bundle_;
bool is_bus_;
int from_index_;
int to_index_;
// Expanded bus bit ports (ordered by from_index_ to to_index_)
// or bundle member ports.
ConcretePortSeq *member_ports_;
2026-04-15 09:38:10 -07:00
ConcretePort *bundle_port_{nullptr};
2018-09-28 08:54:21 -07:00
private:
friend class ConcreteCell;
};
class ConcreteCellPortBitIterator : public Iterator<ConcretePort*>
{
public:
2026-01-03 16:59:35 -08:00
ConcreteCellPortBitIterator(const ConcreteCell *cell);
2026-03-08 14:07:40 -07:00
bool hasNext() override;
ConcretePort *next() override;
2018-09-28 08:54:21 -07:00
private:
void findNext();
2026-01-03 16:59:35 -08:00
const ConcretePortSeq &ports_;
ConcretePortSeq::const_iterator port_iter_;
2026-04-15 09:38:10 -07:00
ConcretePortMemberIterator *member_iter_{nullptr};
ConcretePort *next_{nullptr};
2018-09-28 08:54:21 -07:00
};
2026-04-13 14:58:16 -07:00
} // namespace sta