Files
OpenSTA/include/sta/Property.hh
T

311 lines
12 KiB
C++
Raw Normal View History

2018-12-26 11:03:31 -08:00
// OpenSTA, Static Timing Analyzer
2026-03-10 13:21:17 -07:00
// Copyright (c) 2026, Parallax Software, Inc.
2018-12-26 11:03:31 -08: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-12-26 11:03:31 -08: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-12-26 11:03:31 -08:00
2020-02-15 17:13:16 -07:00
#pragma once
2018-12-26 11:03:31 -08:00
2026-04-15 09:38:10 -07:00
#include <functional>
2025-05-26 15:33:51 -07:00
#include <map>
2019-01-16 15:37:31 -08:00
#include <string>
2026-01-03 16:59:35 -08:00
#include <string_view>
#include <utility>
2020-04-05 11:35:51 -07:00
2020-04-05 14:53:44 -07:00
#include "LibertyClass.hh"
#include "NetworkClass.hh"
2020-07-31 09:42:24 -07:00
#include "PowerClass.hh"
2026-04-15 09:38:10 -07:00
#include "SdcClass.hh"
#include "SearchClass.hh"
2018-12-26 11:03:31 -08:00
namespace sta {
class Sta;
2025-05-26 15:33:51 -07:00
class PropertyValue;
2025-06-02 21:36:33 -07:00
class Sta;
class PropertyValue;
2026-06-30 12:18:56 -04:00
class Scene;
class Mode;
2025-06-02 21:36:33 -07:00
2025-05-26 15:33:51 -07:00
template<class TYPE>
class PropertyRegistry
{
public:
2026-04-13 14:58:16 -07:00
using PropertyHandler = std::function<PropertyValue (TYPE object, Sta *sta)>;
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
2025-06-20 10:29:12 -07:00
PropertyHandler handler);
2025-06-02 21:36:33 -07:00
PropertyValue getProperty(TYPE object,
2026-03-28 19:13:35 -07:00
std::string_view property,
std::string_view type_name,
2025-06-02 21:36:33 -07:00
Sta *sta);
2025-05-26 15:33:51 -07:00
private:
2026-03-28 19:13:35 -07:00
std::map<std::string, PropertyHandler, std::less<>> registry_;
2025-05-26 15:33:51 -07:00
};
// Adding a new property type
// value union (string values use std::string* so the union stays trivial)
// enum Type
// constructor
// copy constructor switch clause
// move constructor switch clause
// operator= & switch clause
// operator= && switch clause
// StaTcl.i swig %typemap(out) PropertyValue switch clause
class PropertyValue
{
public:
enum class Type { none, string, float_, bool_,
library, cell, port,
liberty_library, liberty_cell, liberty_port,
instance, pin, pins, net,
clk, clks, paths, pwr_activity };
PropertyValue();
PropertyValue(std::string_view value);
PropertyValue(std::string value);
PropertyValue(float value,
const Unit *unit);
PropertyValue(bool value);
PropertyValue(const Library *value);
PropertyValue(const Cell *value);
PropertyValue(const Port *value);
PropertyValue(const LibertyLibrary *value);
PropertyValue(const LibertyCell *value);
PropertyValue(const LibertyPort *value);
PropertyValue(const Instance *value);
PropertyValue(const Pin *value);
PropertyValue(PinSeq *value);
PropertyValue(PinSet *value);
PropertyValue(const PinSet &value);
PropertyValue(const Net *value);
PropertyValue(const Clock *value);
PropertyValue(ClockSeq *value);
PropertyValue(ClockSet *value);
PropertyValue(ConstPathSeq *value);
PropertyValue(PwrActivity *value);
PropertyValue(const PropertyValue &value);
PropertyValue(PropertyValue &&value) noexcept;
~PropertyValue();
Type type() const { return type_; }
const Unit *unit() const { return unit_; }
std::string to_string(const Network *network) const;
const std::string &stringValue() const; // valid for type string
float floatValue() const; // valid for type float
bool boolValue() const; // valid for type bool
const LibertyLibrary *libertyLibrary() const { return liberty_library_; }
const LibertyCell *libertyCell() const { return liberty_cell_; }
const LibertyPort *libertyPort() const { return liberty_port_; }
const Library *library() const { return library_; }
const Cell *cell() const { return cell_; }
const Port *port() const { return port_; }
const Instance *instance() const { return inst_; }
const Pin *pin() const { return pin_; }
PinSeq *pins() const { return pins_; }
const Net *net() const { return net_; }
const Clock *clock() const { return clk_; }
ClockSeq *clocks() const { return clks_; }
ConstPathSeq *paths() const { return paths_; }
PwrActivity pwrActivity() const { return pwr_activity_; }
// Copy assignment.
PropertyValue &operator=(const PropertyValue &);
// Move assignment.
PropertyValue &operator=(PropertyValue &&) noexcept;
private:
void destroyActive();
Type type_;
union {
// Use heap string to simplify initialization/destrucction.
std::string *string_;
float float_;
bool bool_;
const Library *library_;
const Cell *cell_;
const Port *port_;
const LibertyLibrary *liberty_library_;
const LibertyCell *liberty_cell_;
const LibertyPort *liberty_port_;
const Instance *inst_;
const Pin *pin_;
PinSeq *pins_;
const Net *net_;
const Clock *clk_;
ClockSeq *clks_;
ConstPathSeq *paths_;
PwrActivity pwr_activity_;
};
const Unit *unit_;
};
// Key for user-defined property values: the object instance and the
// property name.
class PropertyKey
{
public:
PropertyKey(const void *object,
std::string_view property);
bool operator<(const PropertyKey &key) const;
private:
const void *object_;
std::string property_;
};
2025-05-26 15:33:51 -07:00
class Properties
{
public:
Properties(Sta *sta);
PropertyValue getProperty(const Library *lib,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const LibertyLibrary *lib,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const Cell *cell,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const LibertyCell *cell,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const Port *port,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const LibertyPort *port,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const Instance *inst,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const Pin *pin,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const Net *net,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(Edge *edge,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(const Clock *clk,
2026-03-28 19:13:35 -07:00
std::string_view property);
2026-06-30 12:18:56 -04:00
PropertyValue getProperty(const Scene *scene,
std::string_view property);
PropertyValue getProperty(const Mode *mode,
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(PathEnd *end,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(Path *path,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
PropertyValue getProperty(TimingArcSet *arc_set,
2026-03-28 19:13:35 -07:00
std::string_view property);
2025-05-26 15:33:51 -07:00
2025-06-02 21:36:33 -07:00
// Define handler for external property.
2025-09-17 14:19:22 -07:00
// properties->defineProperty("foo",
// [] (const Instance *, Sta *) -> PropertyValue {
// return PropertyValue("bar");
// });
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Library *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const LibertyLibrary *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Cell *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const LibertyCell *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Port *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const LibertyPort *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Instance *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Pin *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Net *>::PropertyHandler &handler);
2026-01-03 16:59:35 -08:00
void defineProperty(std::string_view property,
const PropertyRegistry<const Clock *>::PropertyHandler &handler);
void defineProperty(std::string_view property,
const PropertyRegistry<const Scene *>::PropertyHandler &handler);
void defineProperty(std::string_view property,
const PropertyRegistry<const Mode *>::PropertyHandler &handler);
// User-defined, per-object mutable properties. defineProperty registers
// a property of the given value type ("bool", "float" or "string");
// setProperty sets the value on one object. Objects the property was never
// set on read back as an empty (none) value. The property is read through
// the same registry path as every other property so get_property /
// get_* -filter work unchanged.
template<class TYPE>
void defineProperty(std::string_view object_type,
std::string_view property,
std::string_view value_type);
void setProperty(const void *object,
std::string_view object_type,
std::string_view property,
std::string_view value);
2025-06-02 21:36:33 -07:00
protected:
2025-05-26 15:33:51 -07:00
PropertyValue portSlew(const Port *port,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *rf,
2025-05-26 15:33:51 -07:00
const MinMax *min_max);
PropertyValue portSlack(const Port *port,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *rf,
2025-05-26 15:33:51 -07:00
const MinMax *min_max);
PropertyValue pinArrival(const Pin *pin,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *rf,
2025-05-26 15:33:51 -07:00
const MinMax *min_max);
PropertyValue pinSlack(const Pin *pin,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *rf,
2025-05-26 15:33:51 -07:00
const MinMax *min_max);
PropertyValue pinSlew(const Pin *pin,
2026-01-03 16:59:35 -08:00
const RiseFallBoth *rf,
2025-05-26 15:33:51 -07:00
const MinMax *min_max);
PropertyValue delayPropertyValue(Delay delay);
PropertyValue resistancePropertyValue(float res);
PropertyValue capacitancePropertyValue(float cap);
PropertyValue edgeDelay(Edge *edge,
const RiseFall *rf,
const MinMax *min_max);
PropertyValue::Type propertyType(std::string_view type);
PropertyValue coercePropertyValue(PropertyValue::Type type,
std::string_view value);
2025-05-26 15:33:51 -07:00
2025-06-02 21:36:33 -07:00
PropertyRegistry<const Library*> registry_library_;
PropertyRegistry<const LibertyLibrary*> registry_liberty_library_;
2025-05-26 15:33:51 -07:00
PropertyRegistry<const Cell*> registry_cell_;
PropertyRegistry<const LibertyCell*> registry_liberty_cell_;
PropertyRegistry<const Port*> registry_port_;
PropertyRegistry<const LibertyPort*> registry_liberty_port_;
2025-06-02 21:36:33 -07:00
PropertyRegistry<const Instance*> registry_instance_;
2025-05-26 15:33:51 -07:00
PropertyRegistry<const Pin*> registry_pin_;
PropertyRegistry<const Net*> registry_net_;
2025-09-17 14:19:22 -07:00
PropertyRegistry<const Clock*> registry_clock_;
PropertyRegistry<const Scene*> registry_scene_;
PropertyRegistry<const Mode*> registry_mode_;
2025-06-02 21:36:33 -07:00
// Value types of user-defined properties keyed by object type name and
// property name.
std::map<std::pair<std::string, std::string>, PropertyValue::Type> prop_types_;
// User-defined property values.
std::map<PropertyKey, PropertyValue> prop_values_;
2019-07-02 07:07:34 -07:00
Sta *sta_;
2018-12-26 11:03:31 -08:00
};
2026-04-13 14:58:16 -07:00
} // namespace sta