OpenSTA/util/Transition.cc

254 lines
6.6 KiB
C++
Raw Normal View History

2018-09-28 17:54:21 +02:00
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2025, 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/>.
//
// 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 17:54:21 +02:00
2020-04-05 23:53:44 +02:00
#include "Transition.hh"
2018-09-28 17:54:21 +02:00
namespace sta {
using std::max;
2019-11-11 23:30:19 +01:00
RiseFall RiseFall::rise_("rise", "^", 0);
RiseFall RiseFall::fall_("fall", "v", 1);
const std::array<RiseFall*, 2> RiseFall::range_{&rise_, &fall_};
const std::array<int, 2> RiseFall::range_index_{rise_.index(), fall_.index()};
2018-09-28 17:54:21 +02:00
2019-11-11 23:30:19 +01:00
RiseFall::RiseFall(const char *name,
2018-09-28 17:54:21 +02:00
const char *short_name,
int sdf_triple_index) :
name_(name),
short_name_(stringCopy(short_name)),
sdf_triple_index_(sdf_triple_index)
{
}
2019-11-11 23:30:19 +01:00
RiseFall::~RiseFall()
{
stringDelete(short_name_);
}
2018-09-28 17:54:21 +02:00
void
2019-11-11 23:30:19 +01:00
RiseFall::setShortName(const char *short_name)
2018-09-28 17:54:21 +02:00
{
stringDelete(short_name_);
2018-09-28 17:54:21 +02:00
short_name_ = stringCopy(short_name);
}
2019-11-11 23:30:19 +01:00
RiseFall *
RiseFall::opposite() const
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
if (this == &rise_)
return &fall_;
2018-09-28 17:54:21 +02:00
else
2019-07-18 15:19:00 +02:00
return &rise_;
2018-09-28 17:54:21 +02:00
}
2019-11-11 23:30:19 +01:00
RiseFall *
RiseFall::find(const char *rf_str)
2018-09-28 17:54:21 +02:00
{
if (stringEq(rf_str, rise_.name())
|| stringEq(rf_str, rise_.shortName()))
2019-07-18 15:19:00 +02:00
return &rise_;
else if (stringEq(rf_str, fall_.name())
|| stringEq(rf_str, fall_.shortName()))
2019-07-18 15:19:00 +02:00
return &fall_;
2018-09-28 17:54:21 +02:00
else
2019-03-13 01:25:53 +01:00
return nullptr;
2018-09-28 17:54:21 +02:00
}
2019-11-11 23:30:19 +01:00
RiseFall *
RiseFall::find(int index)
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
if (index == rise_.index())
return &rise_;
2018-09-28 17:54:21 +02:00
else
2019-07-18 15:19:00 +02:00
return &fall_;
2018-09-28 17:54:21 +02:00
}
2019-11-11 23:30:19 +01:00
RiseFallBoth *
RiseFall::asRiseFallBoth()
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
if (this == &rise_)
2019-11-11 23:30:19 +01:00
return RiseFallBoth::rise();
2018-09-28 17:54:21 +02:00
else
2019-11-11 23:30:19 +01:00
return RiseFallBoth::fall();
2018-09-28 17:54:21 +02:00
}
2019-11-11 23:30:19 +01:00
const RiseFallBoth *
RiseFall::asRiseFallBoth() const
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
if (this == &rise_)
2019-11-11 23:30:19 +01:00
return RiseFallBoth::rise();
2018-09-28 17:54:21 +02:00
else
2019-11-11 23:30:19 +01:00
return RiseFallBoth::fall();
2018-09-28 17:54:21 +02:00
}
Transition *
2019-11-11 23:30:19 +01:00
RiseFall::asTransition() const
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
if (this == &rise_)
2018-09-28 17:54:21 +02:00
return Transition::rise();
else
return Transition::fall();
}
////////////////////////////////////////////////////////////////
2019-11-11 23:30:19 +01:00
RiseFallBoth RiseFallBoth::rise_("rise", "^", 0,
RiseFall::rise(),
{RiseFall::rise()},
{RiseFall::riseIndex()});
2019-11-11 23:30:19 +01:00
RiseFallBoth RiseFallBoth::fall_("fall", "v", 1,
RiseFall::fall(),
{RiseFall::fall()},
{RiseFall::fallIndex()});
2019-11-11 23:30:19 +01:00
RiseFallBoth RiseFallBoth::rise_fall_("rise_fall", "rf", 2,
nullptr,
{RiseFall::rise(),
RiseFall::fall()},
{RiseFall::riseIndex(),
RiseFall::fallIndex()});
2018-09-28 17:54:21 +02:00
2019-11-11 23:30:19 +01:00
RiseFallBoth::RiseFallBoth(const char *name,
const char *short_name,
int sdf_triple_index,
RiseFall *as_rise_fall,
std::vector<RiseFall*> range,
std::vector<int> range_index) :
2018-09-28 17:54:21 +02:00
name_(name),
2018-10-03 01:20:18 +02:00
short_name_(stringCopy(short_name)),
2018-09-28 17:54:21 +02:00
sdf_triple_index_(sdf_triple_index),
2019-07-18 15:19:00 +02:00
as_rise_fall_(as_rise_fall),
range_(range),
range_index_(range_index)
2018-09-28 17:54:21 +02:00
{
}
2019-11-11 23:30:19 +01:00
RiseFallBoth::~RiseFallBoth()
{
stringDelete(short_name_);
}
2019-11-11 23:30:19 +01:00
RiseFallBoth *
RiseFallBoth::find(const char *tr_str)
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
if (stringEq(tr_str, rise_.name()))
return &rise_;
else if (stringEq(tr_str, fall_.name()))
return &fall_;
else if (stringEq(tr_str, rise_fall_.name()))
return &rise_fall_;
2018-09-28 17:54:21 +02:00
else
2019-03-13 01:25:53 +01:00
return nullptr;
2018-09-28 17:54:21 +02:00
}
bool
2019-11-11 23:30:19 +01:00
RiseFallBoth::matches(const RiseFall *rf) const
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
return this == &rise_fall_
2019-11-11 23:30:19 +01:00
|| as_rise_fall_ == rf;
2018-09-28 17:54:21 +02:00
}
bool
2019-11-11 23:30:19 +01:00
RiseFallBoth::matches(const Transition *tr) const
2018-09-28 17:54:21 +02:00
{
2019-07-18 15:19:00 +02:00
return this == &rise_fall_
|| (this == &rise_
2018-09-28 17:54:21 +02:00
&& tr == Transition::rise())
2019-07-18 15:19:00 +02:00
|| (this == &fall_
2018-09-28 17:54:21 +02:00
&& tr == Transition::fall());
}
2018-10-03 01:20:18 +02:00
void
2019-11-11 23:30:19 +01:00
RiseFallBoth::setShortName(const char *short_name)
2018-10-03 01:20:18 +02:00
{
stringDelete(short_name_);
2018-10-03 01:20:18 +02:00
short_name_ = stringCopy(short_name);
}
2018-09-28 17:54:21 +02:00
////////////////////////////////////////////////////////////////
2019-07-18 15:19:00 +02:00
TransitionMap Transition::transition_map_;
2018-09-28 17:54:21 +02:00
int Transition::max_index_ = 0;
2019-07-18 15:19:00 +02:00
// Sdf triple order defined on Sdf 3.0 spec, pg 3-17.
2019-11-11 23:30:19 +01:00
Transition Transition::rise_{ "^", "01", RiseFall::rise(), 0};
Transition Transition::fall_ { "v", "10", RiseFall::fall(), 1};
Transition Transition::tr_0Z_{"0Z", "0Z", RiseFall::rise(), 2};
Transition Transition::tr_Z1_{"Z1", "Z1", RiseFall::rise(), 3};
Transition Transition::tr_1Z_{"1Z", "1Z", RiseFall::fall(), 4};
Transition Transition::tr_Z0_{"Z0", "Z0", RiseFall::fall(), 5};
Transition Transition::tr_0X_{"0X", "0X", RiseFall::rise(), 6};
Transition Transition::tr_X1_{"X1", "X1", RiseFall::rise(), 7};
Transition Transition::tr_1X_{"1X", "1X", RiseFall::fall(), 8};
Transition Transition::tr_X0_{"X0", "X0", RiseFall::fall(), 9};
2019-07-18 15:19:00 +02:00
Transition Transition::tr_XZ_{"XZ", "XZ", nullptr, 10};
Transition Transition::tr_ZX_{"ZX", "ZX", nullptr, 11};
Transition Transition::rise_fall_{"*", "**", nullptr, -1};
2018-10-03 01:20:18 +02:00
Transition::Transition(const char *name,
const char *init_final,
2019-11-11 23:30:19 +01:00
RiseFall *as_rise_fall,
2018-10-03 01:20:18 +02:00
int sdf_triple_index) :
name_(stringCopy(name)),
init_final_(init_final),
as_rise_fall_(as_rise_fall),
sdf_triple_index_(sdf_triple_index)
{
2019-07-18 15:19:00 +02:00
transition_map_[name_] = this;
transition_map_[init_final_] = this;
2018-10-03 01:20:18 +02:00
max_index_ = max(sdf_triple_index, max_index_);
}
Transition::~Transition()
{
stringDelete(name_);
2018-09-28 17:54:21 +02:00
}
bool
Transition::matches(const Transition *tr) const
{
return this == riseFall() || tr == this;
}
Transition *
Transition::find(const char *tr_str)
{
2019-07-18 15:19:00 +02:00
return transition_map_.findKey(tr_str);
2018-09-28 17:54:21 +02:00
}
2019-11-11 23:30:19 +01:00
const RiseFallBoth *
2018-09-28 17:54:21 +02:00
Transition::asRiseFallBoth() const
{
2019-11-11 23:30:19 +01:00
return reinterpret_cast<const RiseFallBoth*>(as_rise_fall_);
2018-09-28 17:54:21 +02:00
}
2018-10-03 01:20:18 +02:00
void
Transition::setName(const char *name)
{
stringDelete(name_);
2018-10-03 01:20:18 +02:00
name_ = stringCopy(name);
}
2018-09-28 17:54:21 +02:00
} // namespace