OpenSTA/search/PathVertexRep.cc

239 lines
5.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-04-05 23:53:44 +02:00
#include "PathVertexRep.hh"
2020-04-05 20:35:51 +02:00
2020-04-05 23:53:44 +02:00
#include "Graph.hh"
#include "SearchClass.hh"
#include "Tag.hh"
#include "TagGroup.hh"
#include "Search.hh"
#include "PathVertex.hh"
2018-09-28 17:54:21 +02:00
namespace sta {
PathVertexRep::PathVertexRep()
{
init();
}
PathVertexRep::PathVertexRep(const PathVertexRep *path)
{
init(path);
}
PathVertexRep::PathVertexRep(const PathVertexRep &path)
{
init(path);
}
PathVertexRep::PathVertexRep(const PathVertex *path,
const StaState *sta)
{
init(path, sta);
}
PathVertexRep::PathVertexRep(const PathVertex &path,
const StaState *sta)
{
init(path, sta);
}
2019-11-11 17:38:25 +01:00
PathVertexRep::PathVertexRep(VertexId vertex_id,
2018-09-28 17:54:21 +02:00
TagIndex tag_index,
bool is_enum) :
2019-11-11 17:38:25 +01:00
vertex_id_(vertex_id),
2018-09-28 17:54:21 +02:00
tag_index_(tag_index),
is_enum_(is_enum)
{
}
void
PathVertexRep::init()
{
2019-11-11 17:38:25 +01:00
vertex_id_ = 0;
2018-09-28 17:54:21 +02:00
tag_index_ = tag_index_null;
is_enum_ = false;
}
void
PathVertexRep::init(const PathVertexRep *path)
{
if (path) {
2019-11-11 17:38:25 +01:00
vertex_id_ = path->vertex_id_;
2018-09-28 17:54:21 +02:00
tag_index_ = path->tag_index_;
is_enum_ = false;
}
else
init();
}
void
PathVertexRep::init(const PathVertexRep &path)
{
2019-11-11 17:38:25 +01:00
vertex_id_ = path.vertex_id_;
2018-09-28 17:54:21 +02:00
tag_index_ = path.tag_index_;
is_enum_ = false;
}
void
PathVertexRep::init(const PathVertex *path,
const StaState *sta)
{
2019-03-13 01:25:53 +01:00
if (path == nullptr || path->isNull())
2018-09-28 17:54:21 +02:00
init();
else {
2019-11-11 17:38:25 +01:00
vertex_id_ = sta->graph()->id(path->vertex(sta));
2018-09-28 17:54:21 +02:00
tag_index_ = path->tag(sta)->index();
is_enum_ = false;
}
}
void
PathVertexRep::init(const PathVertex &path,
const StaState *sta)
{
if (path.isNull())
init();
else {
2019-11-11 17:38:25 +01:00
vertex_id_ = sta->graph()->id(path.vertex(sta));
2018-09-28 17:54:21 +02:00
tag_index_ = path.tag(sta)->index();
is_enum_ = false;
}
}
Vertex *
PathVertexRep::vertex(const StaState *sta) const
{
const Graph *graph = sta->graph();
2019-11-11 17:38:25 +01:00
return graph->vertex(vertex_id_);
2018-09-28 17:54:21 +02:00
}
Tag *
PathVertexRep::tag(const StaState *sta) const
{
const Search *search = sta->search();
return search->tag(tag_index_);
}
Arrival
PathVertexRep::arrival(const StaState *sta) const
{
2020-04-20 00:23:16 +02:00
Graph *graph = sta->graph();
2018-09-28 17:54:21 +02:00
const Search *search = sta->search();
Tag *tag = search->tag(tag_index_);
2019-11-11 17:38:25 +01:00
Vertex *vertex = graph->vertex(vertex_id_);
2018-09-28 17:54:21 +02:00
TagGroup *tag_group = search->tagGroup(vertex);
if (tag_group) {
int arrival_index;
bool arrival_exists;
tag_group->arrivalIndex(tag, arrival_index, arrival_exists);
if (!arrival_exists)
sta->report()->critical(1420, "tag group missing tag");
Arrival *arrivals = graph->arrivals(vertex);
if (arrivals)
return arrivals[arrival_index];
else
sta->report()->critical(1421, "missing arrivals");
}
else
sta->report()->error(1422, "missing arrivals.");
return 0.0;
2018-09-28 17:54:21 +02:00
}
void
PathVertexRep::prevPath(const StaState *sta,
// Return values.
PathRef &prev_path,
TimingArc *&prev_arc) const
{
PathVertex path_vertex(this, sta);
path_vertex.prevPath(sta, prev_path, prev_arc);
}
////////////////////////////////////////////////////////////////
bool
PathVertexRep::equal(const PathVertexRep *path1,
const PathVertexRep *path2)
{
2019-11-11 17:38:25 +01:00
return path1->vertex_id_ == path2->vertex_id_
2018-09-28 17:54:21 +02:00
&& path1->tag_index_ == path2->tag_index_;
}
bool
PathVertexRep::equal(const PathVertexRep &path1,
const PathVertexRep &path2)
{
2019-11-11 17:38:25 +01:00
return path1.vertex_id_ == path2.vertex_id_
2018-09-28 17:54:21 +02:00
&& path1.tag_index_ == path2.tag_index_;
}
int
PathVertexRep::cmp(const PathVertexRep *path1,
const PathVertexRep *path2)
{
if (path1 && path2) {
2019-11-11 17:38:25 +01:00
VertexId vertex_id1 = path1->vertexId();
VertexId vertex_id2 = path2->vertexId();
if (vertex_id1 == vertex_id2) {
2018-09-28 17:54:21 +02:00
TagIndex tag_index1 = path1->tagIndex();
TagIndex tag_index2 = path2->tagIndex();
if (tag_index1 == tag_index2)
return 0;
else if (tag_index1 < tag_index2)
return -1;
else
return 1;
}
2019-11-11 17:38:25 +01:00
else if (vertex_id1 < vertex_id2)
2018-09-28 17:54:21 +02:00
return -1;
else
return 1;
}
2019-03-13 01:25:53 +01:00
else if (path1 == nullptr
&& path2 == nullptr)
2018-09-28 17:54:21 +02:00
return 0;
2019-03-13 01:25:53 +01:00
else if (path1 == nullptr)
2018-09-28 17:54:21 +02:00
return -1;
else
return 1;
}
int
PathVertexRep::cmp(const PathVertexRep &path1,
const PathVertexRep &path2)
{
2019-11-11 17:38:25 +01:00
VertexId vertex_id1 = path1.vertexId();
VertexId vertex_id2 = path2.vertexId();
if (vertex_id1 == vertex_id2) {
2018-09-28 17:54:21 +02:00
TagIndex tag_index1 = path1.tagIndex();
TagIndex tag_index2 = path2.tagIndex();
if (tag_index1 == tag_index2)
return 0;
else if (tag_index1 < tag_index2)
return -1;
else
return 1;
}
2019-11-11 17:38:25 +01:00
else if (vertex_id1 < vertex_id2)
2018-09-28 17:54:21 +02:00
return -1;
else
return 1;
}
} // namespace