Skip to content

Commit 4c8d04b

Browse files
Cleaned Up Changes
1 parent 6f4f1d9 commit 4c8d04b

4 files changed

Lines changed: 42 additions & 44 deletions

File tree

src/sdc_timing_object.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ struct ObjectId {
8080
return value < rhs.value;
8181
}
8282

83+
bool is_valid() const {
84+
return *this != INVALID();
85+
}
86+
8387
explicit constexpr operator std::size_t() const { return value; }
8488

8589
// This is used by the std hash function which uses the private members.
8690
friend std::hash<ObjectId>;
8791

88-
// private:
92+
private:
8993
/// @brief The internal integer that is used by this ID.
9094
size_t value;
9195
};

src/sdc_timing_object_database.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ std::vector<ObjectId> TimingObjectDatabase::query_pattern_match(const std::vecto
6666
std::vector<ObjectId> matches;
6767

6868
// Lambda to check an object against all patterns
69-
auto check_object = [&matches, &regex_patterns](const ObjectId& object_id, const std::string& object_name) {
69+
auto check_object = [&matches, &regex_patterns](ObjectId object_id, const std::string& object_name) {
7070
for (const std::regex& pattern : regex_patterns) {
7171
if (std::regex_match(object_name, pattern)) {
7272
matches.push_back(object_id);
@@ -78,27 +78,27 @@ std::vector<ObjectId> TimingObjectDatabase::query_pattern_match(const std::vecto
7878
for (ObjectType target_object_type : object_types) {
7979
switch (target_object_type) {
8080
case ObjectType::Cell:
81-
for (const ObjectId& cell_object_id : cell_objects) {
81+
for (ObjectId cell_object_id : cell_objects) {
8282
check_object(cell_object_id, get_object_name(cell_object_id));
8383
}
8484
break;
8585
case ObjectType::Clock:
86-
for (const ObjectId& clock_object_id : clock_objects) {
86+
for (ObjectId clock_object_id : clock_objects) {
8787
check_object(clock_object_id, get_object_name(clock_object_id));
8888
}
8989
break;
9090
case ObjectType::Net:
91-
for (const ObjectId& net_object_id : net_objects) {
91+
for (ObjectId net_object_id : net_objects) {
9292
check_object(net_object_id, get_object_name(net_object_id));
9393
}
9494
break;
9595
case ObjectType::Port:
96-
for (const ObjectId& port_object_id : port_objects) {
96+
for (ObjectId port_object_id : port_objects) {
9797
check_object(port_object_id, get_object_name(port_object_id));
9898
}
9999
break;
100100
case ObjectType::Pin:
101-
for (const ObjectId& pin_object_id : pin_objects) {
101+
for (ObjectId pin_object_id : pin_objects) {
102102
check_object(pin_object_id, get_object_name(pin_object_id));
103103
}
104104
break;

src/sdc_timing_object_database.h

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ inline PortDirection from_string_to_port_dir(const std::string& port_type) {
4949
class TimingObjectDatabase {
5050
private:
5151
/// @brief A mapping between an object ID and its name.
52-
std::unordered_map<ObjectId, std::string> object_name_;
52+
std::vector<std::string> object_name_;
5353
/// @brief A mapping between an object ID and its type.
54-
std::unordered_map<ObjectId, ObjectType> object_type_;
54+
std::vector<ObjectType> object_type_;
5555
/// @brief A mapping between a port object and its direction.
5656
std::unordered_map<ObjectId, PortDirection> port_direction_;
5757
/// @brief A collection of all clock driver objects.
5858
std::vector<ObjectId> clock_driver_objects_;
5959

60+
/// @brief A collection of all objects that have been created.
61+
/// This is used to create the IDs.
6062
std::vector<ObjectId> all_objects_;
6163

6264
/// @brief A collection of all cell objects.
@@ -86,10 +88,8 @@ class TimingObjectDatabase {
8688
inline ObjectId create_cell_object(const std::string& cell_name) {
8789
ObjectId cell_object_id = ObjectId(all_objects_.size());
8890
all_objects_.push_back(cell_object_id);
89-
assert(object_name_.count(cell_object_id) == 0);
90-
object_name_[cell_object_id] = cell_name;
91-
assert(object_type_.count(cell_object_id) == 0);
92-
object_type_[cell_object_id] = ObjectType::Cell;
91+
object_name_.push_back(cell_name);
92+
object_type_.push_back(ObjectType::Cell);
9393
cell_objects.push_back(cell_object_id);
9494
return cell_object_id;
9595
}
@@ -105,10 +105,8 @@ class TimingObjectDatabase {
105105
inline ObjectId create_clock_object(const std::string& clock_name) {
106106
ObjectId clock_object_id = ObjectId(all_objects_.size());
107107
all_objects_.push_back(clock_object_id);
108-
assert(object_name_.count(clock_object_id) == 0);
109-
object_name_[clock_object_id] = clock_name;
110-
assert(object_type_.count(clock_object_id) == 0);
111-
object_type_[clock_object_id] = ObjectType::Clock;
108+
object_name_.push_back(clock_name);
109+
object_type_.push_back(ObjectType::Clock);
112110
clock_objects.push_back(clock_object_id);
113111
return clock_object_id;
114112
}
@@ -126,15 +124,13 @@ class TimingObjectDatabase {
126124
* @return The ID of the created object.
127125
*/
128126
inline ObjectId create_port_object(const std::string& port_name,
129-
PortDirection port_direction,
130-
bool is_clock_driver) {
127+
PortDirection port_direction,
128+
bool is_clock_driver) {
131129
assert(port_direction != PortDirection::UNKNOWN);
132130
ObjectId port_object_id = ObjectId(all_objects_.size());
133131
all_objects_.push_back(port_object_id);
134-
assert(object_name_.count(port_object_id) == 0);
135-
object_name_[port_object_id] = port_name;
136-
assert(object_type_.count(port_object_id) == 0);
137-
object_type_[port_object_id] = ObjectType::Port;
132+
object_name_.push_back(port_name);
133+
object_type_.push_back(ObjectType::Port);
138134
port_direction_[port_object_id] = port_direction;
139135
port_objects.push_back(port_object_id);
140136
if (port_direction == PortDirection::INPUT || port_direction == PortDirection::INOUT)
@@ -160,13 +156,11 @@ class TimingObjectDatabase {
160156
* @return The ID of the created object.
161157
*/
162158
inline ObjectId create_pin_object(const std::string& pin_name,
163-
bool is_clock_driver) {
159+
bool is_clock_driver) {
164160
ObjectId pin_object_id = ObjectId(all_objects_.size());
165161
all_objects_.push_back(pin_object_id);
166-
assert(object_name_.count(pin_object_id) == 0);
167-
object_name_[pin_object_id] = pin_name;
168-
assert(object_type_.count(pin_object_id) == 0);
169-
object_type_[pin_object_id] = ObjectType::Pin;
162+
object_name_.push_back(pin_name);
163+
object_type_.push_back(ObjectType::Pin);
170164
pin_objects.push_back(pin_object_id);
171165

172166
if (is_clock_driver) {
@@ -187,10 +181,8 @@ class TimingObjectDatabase {
187181
inline ObjectId create_net_object(const std::string& net_name) {
188182
ObjectId net_object_id = ObjectId(all_objects_.size());
189183
all_objects_.push_back(net_object_id);
190-
assert(object_name_.count(net_object_id) == 0);
191-
object_name_[net_object_id] = net_name;
192-
assert(object_type_.count(net_object_id) == 0);
193-
object_type_[net_object_id] = ObjectType::Net;
184+
object_name_.push_back(net_name);
185+
object_type_.push_back(ObjectType::Net);
194186
net_objects.push_back(net_object_id);
195187

196188
return net_object_id;
@@ -199,20 +191,22 @@ class TimingObjectDatabase {
199191
/**
200192
* @brief Get the type of the given object ID.
201193
*/
202-
inline ObjectType get_object_type(const ObjectId& object_id) {
203-
auto it = object_type_.find(object_id);
204-
if (it != object_type_.end())
205-
return it->second;
206-
return ObjectType::Unknown;
194+
inline ObjectType get_object_type(ObjectId object_id) {
195+
if (!object_id.is_valid())
196+
return ObjectType::Unknown;
197+
size_t id_val = static_cast<size_t>(object_id);
198+
if (id_val >= object_type_.size())
199+
return ObjectType::Unknown;
200+
return object_type_[id_val];
207201
}
208202

209203
/**
210204
* @brief Get the name of the given object.
211205
*/
212-
const std::string& get_object_name(const ObjectId& object_id) const {
213-
auto it = object_name_.find(object_id);
214-
assert(it != object_name_.end());
215-
return it->second;
206+
const std::string& get_object_name(ObjectId object_id) const {
207+
size_t id_val = static_cast<size_t>(object_id);
208+
assert(object_id.is_valid() && id_val < object_name_.size());
209+
return object_name_[id_val];
216210
}
217211

218212
/**

src/tcl/sdc_commands.i

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
%fragment("ObjectIdHelpers", "header") {
2727
// Convert ObjectId to TCL Handle
2828
static Tcl_Obj* ObjectId_To_Tcl(Tcl_Interp */*interp*/, const sdcparse::ObjectId& id) {
29-
return Tcl_ObjPrintf("__vtr_obj_%lld", static_cast<Tcl_WideInt>(id.value));
29+
return Tcl_ObjPrintf("__vtr_obj_%lld", static_cast<Tcl_WideInt>((size_t)id));
3030
}
3131

3232
// Convert TCL Handle to ObjectId
@@ -37,7 +37,7 @@
3737
Tcl_SetObjResult(interp, Tcl_ObjPrintf("Invalid ObjectId handle: %s", str));
3838
return TCL_ERROR;
3939
}
40-
out->value = static_cast<size_t>(val);
40+
*out = sdcparse::ObjectId(static_cast<size_t>(val));
4141
return TCL_OK;
4242
}
4343
}
@@ -63,7 +63,7 @@
6363
temp.push_back(id);
6464
}
6565
std::vector<sdcparse::ObjectId>* temp_ptr = &temp;
66-
66+
6767
$1 = temp_ptr;
6868
}
6969

0 commit comments

Comments
 (0)