Files
OpenSTA/util/Transition.cc
T

234 lines
6.6 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-04-05 14:53:44 -07:00
#include "Transition.hh"
2018-09-28 08:54:21 -07:00
2026-03-02 12:13:13 -08:00
#include <algorithm>
2026-01-03 16:59:35 -08:00
#include "ContainerHelpers.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
2025-03-30 15:27:53 -07:00
const RiseFall RiseFall::rise_("rise", "^", 0);
const RiseFall RiseFall::fall_("fall", "v", 1);
const std::array<const RiseFall*, 2> RiseFall::range_{&rise_, &fall_};
2026-04-13 14:58:16 -07:00
const std::array<size_t, 2> RiseFall::range_index_{rise_.index(), fall_.index()};
2018-09-28 08:54:21 -07:00
2026-03-28 19:13:35 -07:00
RiseFall::RiseFall(std::string_view name,
std::string_view short_name,
2026-04-13 14:58:16 -07:00
size_t sdf_triple_index) :
2018-09-28 08:54:21 -07:00
name_(name),
2025-03-30 15:27:53 -07:00
short_name_(short_name),
2018-09-28 08:54:21 -07:00
sdf_triple_index_(sdf_triple_index)
{
}
2026-03-28 19:13:35 -07:00
const std::string&
2026-03-06 12:02:05 -07:00
RiseFall::to_string(bool use_short) const
{
if (use_short)
return short_name_;
else
return name_;
}
2025-03-30 15:27:53 -07:00
const RiseFall *
2019-11-11 15:30:19 -07:00
RiseFall::opposite() const
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
if (this == &rise_)
return &fall_;
2018-09-28 08:54:21 -07:00
else
2019-07-18 06:19:00 -07:00
return &rise_;
2018-09-28 08:54:21 -07:00
}
2025-03-30 15:27:53 -07:00
const RiseFall *
2026-04-13 14:58:16 -07:00
RiseFall::find(std::string_view rf_name)
2018-09-28 08:54:21 -07:00
{
2026-04-13 14:58:16 -07:00
if (rf_name == rise_.name() || rf_name == rise_.shortName())
2019-07-18 06:19:00 -07:00
return &rise_;
2026-04-13 14:58:16 -07:00
if (rf_name == fall_.name() || rf_name == fall_.shortName())
2019-07-18 06:19:00 -07:00
return &fall_;
2026-03-28 19:13:35 -07:00
return nullptr;
2018-09-28 08:54:21 -07:00
}
2025-03-30 15:27:53 -07:00
const RiseFall *
2026-04-13 14:58:16 -07:00
RiseFall::find(size_t index)
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
if (index == rise_.index())
return &rise_;
2018-09-28 08:54:21 -07:00
else
2019-07-18 06:19:00 -07:00
return &fall_;
2018-09-28 08:54:21 -07:00
}
2025-03-30 15:27:53 -07:00
const RiseFallBoth *
2019-11-11 15:30:19 -07:00
RiseFall::asRiseFallBoth()
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
if (this == &rise_)
2019-11-11 15:30:19 -07:00
return RiseFallBoth::rise();
2018-09-28 08:54:21 -07:00
else
2019-11-11 15:30:19 -07:00
return RiseFallBoth::fall();
2018-09-28 08:54:21 -07:00
}
2019-11-11 15:30:19 -07:00
const RiseFallBoth *
RiseFall::asRiseFallBoth() const
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
if (this == &rise_)
2019-11-11 15:30:19 -07:00
return RiseFallBoth::rise();
2018-09-28 08:54:21 -07:00
else
2019-11-11 15:30:19 -07:00
return RiseFallBoth::fall();
2018-09-28 08:54:21 -07:00
}
2025-03-30 15:27:53 -07:00
const Transition *
2019-11-11 15:30:19 -07:00
RiseFall::asTransition() const
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
if (this == &rise_)
2018-09-28 08:54:21 -07:00
return Transition::rise();
else
return Transition::fall();
}
////////////////////////////////////////////////////////////////
2025-03-30 15:27:53 -07:00
const RiseFallBoth RiseFallBoth::rise_("rise", "^", 0,
RiseFall::rise(),
{RiseFall::rise()},
{RiseFall::riseIndex()});
const RiseFallBoth RiseFallBoth::fall_("fall", "v", 1,
RiseFall::fall(),
{RiseFall::fall()},
{RiseFall::fallIndex()});
const RiseFallBoth RiseFallBoth::rise_fall_("rise_fall", "rf", 2,
nullptr,
{RiseFall::rise(),
RiseFall::fall()},
{RiseFall::riseIndex(),
RiseFall::fallIndex()});
2018-09-28 08:54:21 -07:00
2026-03-28 19:13:35 -07:00
RiseFallBoth::RiseFallBoth(std::string_view name,
std::string_view short_name,
2026-04-13 14:58:16 -07:00
size_t sdf_triple_index,
2025-03-30 15:27:53 -07:00
const RiseFall *as_rise_fall,
2026-04-13 14:58:16 -07:00
const std::vector<const RiseFall*> &range,
const std::vector<size_t> &range_index) :
2018-09-28 08:54:21 -07:00
name_(name),
2025-03-30 15:27:53 -07:00
short_name_(short_name),
2018-09-28 08:54:21 -07:00
sdf_triple_index_(sdf_triple_index),
2019-07-18 06:19:00 -07:00
as_rise_fall_(as_rise_fall),
range_(range),
range_index_(range_index)
2018-09-28 08:54:21 -07:00
{
}
2026-03-28 19:13:35 -07:00
const std::string&
2026-03-06 12:02:05 -07:00
RiseFallBoth::to_string(bool use_short) const
{
if (use_short)
return short_name_;
else
return name_;
}
2025-03-30 15:27:53 -07:00
const RiseFallBoth *
2026-04-13 14:58:16 -07:00
RiseFallBoth::find(std::string_view rf_name)
2018-09-28 08:54:21 -07:00
{
2026-04-13 14:58:16 -07:00
if (rf_name == rise_.name())
2019-07-18 06:19:00 -07:00
return &rise_;
2026-04-13 14:58:16 -07:00
if (rf_name == fall_.name())
2019-07-18 06:19:00 -07:00
return &fall_;
2026-04-13 14:58:16 -07:00
if (rf_name == rise_fall_.name())
2019-07-18 06:19:00 -07:00
return &rise_fall_;
2026-03-28 19:13:35 -07:00
return nullptr;
2018-09-28 08:54:21 -07:00
}
bool
2019-11-11 15:30:19 -07:00
RiseFallBoth::matches(const RiseFall *rf) const
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
return this == &rise_fall_
2019-11-11 15:30:19 -07:00
|| as_rise_fall_ == rf;
2018-09-28 08:54:21 -07:00
}
bool
2019-11-11 15:30:19 -07:00
RiseFallBoth::matches(const Transition *tr) const
2018-09-28 08:54:21 -07:00
{
2019-07-18 06:19:00 -07:00
return this == &rise_fall_
|| (this == &rise_
2026-01-03 16:59:35 -08:00
&& tr == Transition::rise())
2019-07-18 06:19:00 -07:00
|| (this == &fall_
2026-01-03 16:59:35 -08:00
&& tr == Transition::fall());
2018-09-28 08:54:21 -07:00
}
////////////////////////////////////////////////////////////////
2019-07-18 06:19:00 -07:00
TransitionMap Transition::transition_map_;
2026-04-13 14:58:16 -07:00
size_t Transition::max_index_ = 0;
2018-09-28 08:54:21 -07:00
2019-07-18 06:19:00 -07:00
// Sdf triple order defined on Sdf 3.0 spec, pg 3-17.
2025-03-30 15:27:53 -07:00
const Transition Transition::rise_{ "^", "01", RiseFall::rise(), 0};
const Transition Transition::fall_ { "v", "10", RiseFall::fall(), 1};
const Transition Transition::tr_0Z_{"0Z", "0Z", RiseFall::rise(), 2};
const Transition Transition::tr_Z1_{"Z1", "Z1", RiseFall::rise(), 3};
const Transition Transition::tr_1Z_{"1Z", "1Z", RiseFall::fall(), 4};
const Transition Transition::tr_Z0_{"Z0", "Z0", RiseFall::fall(), 5};
const Transition Transition::tr_0X_{"0X", "0X", RiseFall::rise(), 6};
const Transition Transition::tr_X1_{"X1", "X1", RiseFall::rise(), 7};
const Transition Transition::tr_1X_{"1X", "1X", RiseFall::fall(), 8};
const Transition Transition::tr_X0_{"X0", "X0", RiseFall::fall(), 9};
const Transition Transition::tr_XZ_{"XZ", "XZ", nullptr, 10};
const Transition Transition::tr_ZX_{"ZX", "ZX", nullptr, 11};
2026-04-13 14:58:16 -07:00
const Transition Transition::rise_fall_{"*", "**", nullptr, 12};
2018-10-02 16:20:18 -07:00
2026-03-28 19:13:35 -07:00
Transition::Transition(std::string_view name,
std::string_view init_final,
2026-01-03 16:59:35 -08:00
const RiseFall *as_rise_fall,
2026-04-13 14:58:16 -07:00
size_t sdf_triple_index) :
2025-03-30 15:27:53 -07:00
name_(name),
2018-10-02 16:20:18 -07:00
init_final_(init_final),
as_rise_fall_(as_rise_fall),
sdf_triple_index_(sdf_triple_index)
{
2019-07-18 06:19:00 -07:00
transition_map_[name_] = this;
transition_map_[init_final_] = this;
2026-03-02 12:13:13 -08:00
max_index_ = std::max(sdf_triple_index, max_index_);
2018-10-02 16:20:18 -07:00
}
2018-09-28 08:54:21 -07:00
bool
Transition::matches(const Transition *tr) const
{
return this == riseFall() || tr == this;
}
2025-03-30 15:27:53 -07:00
const Transition *
2026-04-13 14:58:16 -07:00
Transition::find(std::string_view tr_name)
2018-09-28 08:54:21 -07:00
{
2026-04-13 14:58:16 -07:00
return findStringKey(transition_map_, tr_name);
2018-09-28 08:54:21 -07:00
}
2019-11-11 15:30:19 -07:00
const RiseFallBoth *
2018-09-28 08:54:21 -07:00
Transition::asRiseFallBoth() const
{
2019-11-11 15:30:19 -07:00
return reinterpret_cast<const RiseFallBoth*>(as_rise_fall_);
2018-09-28 08:54:21 -07:00
}
2026-04-13 14:58:16 -07:00
} // namespace sta