OpenSTA/include/sta/Transition.hh

196 lines
6.2 KiB
C++
Raw Permalink Normal View History

2018-09-28 17:54:21 +02:00
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2024, Parallax Software, Inc.
2018-09-28 17:54:21 +02: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
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 17:54:21 +02:00
// 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/>.
2018-09-28 17:54:21 +02:00
2020-02-16 01:13:16 +01:00
#pragma once
2018-09-28 17:54:21 +02:00
2019-07-18 15:19:00 +02:00
#include <array>
#include <vector>
2020-04-05 23:53:44 +02:00
#include "Iterator.hh"
#include "Map.hh"
#include "StringUtil.hh"
2018-09-28 17:54:21 +02:00
namespace sta {
class Transition;
2019-11-11 23:30:19 +01:00
class RiseFall;
class RiseFallBoth;
2018-09-28 17:54:21 +02:00
typedef Map<const char*, Transition*, CharPtrLess> TransitionMap;
// Rise/fall transition.
2019-11-11 23:30:19 +01:00
class RiseFall
2018-09-28 17:54:21 +02:00
{
public:
// Singleton accessors.
2019-11-11 23:30:19 +01:00
static RiseFall *rise() { return &rise_; }
static RiseFall *fall() { return &fall_; }
2019-07-18 15:19:00 +02:00
static int riseIndex() { return rise_.sdf_triple_index_; }
static int fallIndex() { return fall_.sdf_triple_index_; }
2018-09-28 17:54:21 +02:00
const char *asString() const { return short_name_; }
const char *name() const { return name_; }
const char *shortName() const { return short_name_; }
void setShortName(const char *short_name);
int index() const { return sdf_triple_index_; }
2019-11-11 23:30:19 +01:00
RiseFallBoth *asRiseFallBoth();
const RiseFallBoth *asRiseFallBoth() const;
2018-09-28 17:54:21 +02:00
Transition *asTransition() const;
// Find transition corresponding to tr_str.
2019-11-11 23:30:19 +01:00
static RiseFall *find(const char *tr_str);
2018-09-28 17:54:21 +02:00
// Find transition from index.
2019-11-11 23:30:19 +01:00
static RiseFall *find(int index);
RiseFall *opposite() const;
2018-09-28 17:54:21 +02:00
2019-07-18 15:19:00 +02:00
// for range support.
// for (auto rf : RiseFall::range()) {}
2019-11-11 23:30:19 +01:00
static const std::array<RiseFall*, 2> &range() { return range_; }
// for (auto rf_index : RiseFall::rangeIndex()) {}
2019-07-18 15:19:00 +02:00
static const std::array<int, 2> &rangeIndex() { return range_index_; }
2018-09-28 17:54:21 +02:00
static const int index_count = 2;
static const int index_max = (index_count - 1);
static const int index_bit_count = 1;
protected:
2019-11-11 23:30:19 +01:00
RiseFall(const char *name,
2018-09-28 17:54:21 +02:00
const char *short_name,
int sdf_triple_index);
2019-11-11 23:30:19 +01:00
~RiseFall();
2018-09-28 17:54:21 +02:00
const char *name_;
const char *short_name_;
const int sdf_triple_index_;
2019-11-11 23:30:19 +01:00
static RiseFall rise_;
static RiseFall fall_;
static const std::array<RiseFall*, 2> range_;
2019-07-18 15:19:00 +02:00
static const std::array<int, 2> range_index_;
2018-09-28 17:54:21 +02:00
};
// Rise/fall/risefall transition.
2019-11-11 23:30:19 +01:00
class RiseFallBoth
2018-09-28 17:54:21 +02:00
{
public:
// Singleton accessors.
2019-11-11 23:30:19 +01:00
static RiseFallBoth *rise() { return &rise_; }
static RiseFallBoth *fall() { return &fall_; }
static RiseFallBoth *riseFall() { return &rise_fall_; }
2018-09-28 17:54:21 +02:00
const char *asString() const { return short_name_; }
const char *name() const { return name_; }
const char *shortName() const { return short_name_; }
2018-10-03 01:20:18 +02:00
void setShortName(const char *short_name);
2018-09-28 17:54:21 +02:00
int index() const { return sdf_triple_index_; }
2019-11-11 23:30:19 +01:00
bool matches(const RiseFall *rf) const;
2018-09-28 17:54:21 +02:00
bool matches(const Transition *tr) const;
2019-11-11 23:30:19 +01:00
RiseFall *asRiseFall() const { return as_rise_fall_; }
2018-09-28 17:54:21 +02:00
// Find transition corresponding to string.
2019-11-11 23:30:19 +01:00
static RiseFallBoth *find(const char *tr_str);
// for (const auto rf : rf->range()) {}
2019-11-11 23:30:19 +01:00
const std::vector<RiseFall*> &range() const { return range_; }
// for (const auto rf_index : rf->rangeIndex()) {}
2019-07-18 15:19:00 +02:00
const std::vector<int> &rangeIndex() const { return range_index_; }
2018-09-28 17:54:21 +02:00
static const int index_count = 3;
static const int index_max = (index_count - 1);
static const int index_bit_count = 2;
protected:
2019-11-11 23:30:19 +01:00
RiseFallBoth(const char *name,
2018-09-28 17:54:21 +02:00
const char *short_name,
int sdf_triple_index,
2019-11-11 23:30:19 +01:00
RiseFall *as_rise_fall,
std::vector<RiseFall*> range,
2019-07-18 15:19:00 +02:00
std::vector<int> range_index);
2019-11-11 23:30:19 +01:00
~RiseFallBoth();
2018-09-28 17:54:21 +02:00
const char *name_;
const char *short_name_;
const int sdf_triple_index_;
2019-11-11 23:30:19 +01:00
RiseFall *as_rise_fall_;
const std::vector<RiseFall*> range_;
2019-07-18 15:19:00 +02:00
const std::vector<int> range_index_;
2018-09-28 17:54:21 +02:00
2019-11-11 23:30:19 +01:00
static RiseFallBoth rise_;
static RiseFallBoth fall_;
static RiseFallBoth rise_fall_;
2018-09-28 17:54:21 +02:00
};
// General SDF transition.
class Transition
{
public:
// Singleton accessors.
2019-07-18 15:19:00 +02:00
static Transition *rise() { return &rise_; }
static Transition *fall() { return &fall_; }
static Transition *tr0Z() { return &tr_0Z_; }
static Transition *trZ1() { return &tr_Z1_; }
static Transition *tr1Z() { return &tr_1Z_; }
static Transition *trZ0() { return &tr_Z0_; }
static Transition *tr0X() { return &tr_0X_; }
static Transition *trX1() { return &tr_X1_; }
static Transition *tr1X() { return &tr_1X_; }
static Transition *trX0() { return &tr_X0_; }
static Transition *trXZ() { return &tr_XZ_; }
static Transition *trZX() { return &tr_ZX_; }
2018-10-03 01:20:18 +02:00
void setName(const char *name);
2018-09-28 17:54:21 +02:00
// Matches rise and fall.
2019-07-18 15:19:00 +02:00
static Transition *riseFall() { return &rise_fall_; }
2018-09-28 17:54:21 +02:00
const char *asString() const { return name_; }
// As initial/final value pair.
const char *asInitFinalString() const { return init_final_; }
int sdfTripleIndex() const { return sdf_triple_index_; }
int index() const { return sdf_triple_index_; }
2019-11-11 23:30:19 +01:00
RiseFall *asRiseFall() const { return as_rise_fall_; }
const RiseFallBoth *asRiseFallBoth() const;
2018-09-28 17:54:21 +02:00
bool matches(const Transition *tr) const;
// Find transition corresponding to string.
static Transition *find(const char *tr_str);
static int maxIndex() { return max_index_; }
private:
Transition(const char *name,
const char *init_final,
2019-11-11 23:30:19 +01:00
RiseFall *as_rise_fall,
2018-09-28 17:54:21 +02:00
int sdf_triple_index);
2018-10-03 01:20:18 +02:00
~Transition();
2018-09-28 17:54:21 +02:00
const char *name_;
const char *init_final_;
2019-11-11 23:30:19 +01:00
RiseFall *as_rise_fall_;
2018-09-28 17:54:21 +02:00
const int sdf_triple_index_;
2019-07-18 15:19:00 +02:00
static Transition rise_;
static Transition fall_;
static Transition tr_0Z_;
static Transition tr_Z1_;
static Transition tr_1Z_;
static Transition tr_Z0_;
static Transition tr_0X_;
static Transition tr_X1_;
static Transition tr_1X_;
static Transition tr_X0_;
static Transition tr_XZ_;
static Transition tr_ZX_;
static Transition rise_fall_;
2018-09-28 17:54:21 +02:00
static const int index_count = 13;
static const int index_max = (index_count - 1);
static const int index_bit_count = 4;
2019-07-18 15:19:00 +02:00
static TransitionMap transition_map_;
2018-09-28 17:54:21 +02:00
static int max_index_;
};
} // namespace