Skip to content

Commit 5b9d0f3

Browse files
committed
is_object cleanup
Signed-off-by: James Cherry <cherry@parallaxsw.com>
1 parent bfbbe0d commit 5b9d0f3

3 files changed

Lines changed: 165 additions & 154 deletions

File tree

tcl/CmdUtil.tcl

Lines changed: 122 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -191,136 +191,138 @@ proc set_unit_values { unit key suffix key_var } {
191191

192192
################################################################
193193

194-
define_cmd_args "delete_from_list" {list objs}
194+
define_cmd_args "delete_from_list" {list delete}
195195

196-
proc delete_from_list { list objects } {
197-
delete_objects_from_list_cmd $list $objects
196+
proc delete_from_list { list delete } {
197+
delete_objects_from_list_cmd $list $delete
198198
}
199199

200-
proc delete_objects_from_list_cmd { list objects } {
201-
set list0 [lindex $list 0]
202-
set list_is_object [is_object $list0]
203-
set list_type [object_type $list0]
204-
foreach obj $objects {
205-
# If the list is a collection of tcl objects (returned by get_*),
206-
# convert the obj to be removed from a name to an object of the same
207-
# type.
208-
if {$list_is_object && ![is_object $obj]} {
209-
if {$list_type == "Clock"} {
210-
set obj [find_clock $obj]
211-
} elseif {$list_type == "Port"} {
212-
set top_instance [top_instance]
213-
set top_cell [$top_instance cell]
214-
set obj [$top_cell find_port $obj]
215-
} elseif {$list_type == "Pin"} {
216-
set obj [find_pin $obj]
217-
} elseif {$list_type == "Instance"} {
218-
set obj [find_instance $obj]
219-
} elseif {$list_type == "Net"} {
220-
set obj [find_net $obj]
221-
} elseif {$list_type == "LibertyLibrary"} {
222-
set obj [find_liberty $obj]
223-
} elseif {$list_type == "LibertyCell"} {
224-
set obj [find_liberty_cell $obj]
225-
} elseif {$list_type == "LibertyPort"} {
226-
set obj [get_lib_pins $obj]
227-
} else {
228-
sta_error 164 "unsupported object type $list_type."
200+
proc delete_objects_from_list_cmd { list delete } {
201+
if { $list != {} } {
202+
set list0 [lindex $list 0]
203+
set list_is_objects [is_object $list0]
204+
foreach obj $delete {
205+
# If the list is a collection of tcl objects (returned by get_*),
206+
# convert the obj to be removed from a name to an object of the same
207+
# type.
208+
if {$list_is_objects && ![is_object $obj]} {
209+
set list_type [object_type $list0]
210+
if {$list_type == "Clock"} {
211+
set obj [find_clock $obj]
212+
} elseif {$list_type == "Port"} {
213+
set top_instance [top_instance]
214+
set top_cell [$top_instance cell]
215+
set obj [$top_cell find_port $obj]
216+
} elseif {$list_type == "Pin"} {
217+
set obj [find_pin $obj]
218+
} elseif {$list_type == "Instance"} {
219+
set obj [find_instance $obj]
220+
} elseif {$list_type == "Net"} {
221+
set obj [find_net $obj]
222+
} elseif {$list_type == "LibertyLibrary"} {
223+
set obj [find_liberty $obj]
224+
} elseif {$list_type == "LibertyCell"} {
225+
set obj [find_liberty_cell $obj]
226+
} elseif {$list_type == "LibertyPort"} {
227+
set obj [get_lib_pins $obj]
228+
} else {
229+
sta_error 164 "unsupported object type $list_type."
230+
}
231+
}
232+
set index [lsearch $list $obj]
233+
if { $index != -1 } {
234+
set list [lreplace $list $index $index]
229235
}
230-
}
231-
set index [lsearch $list $obj]
232-
if { $index != -1 } {
233-
set list [lreplace $list $index $index]
234236
}
235237
}
236238
return $list
237239
}
238-
239-
################################################################
240-
241-
proc set_cmd_namespace { namespc } {
242-
if { $namespc == "sdc" || $namespc == "sta" } {
243-
set_cmd_namespace_cmd $namespc
244-
} else {
245-
sta_error 165 "unknown namespace $namespc."
240+
241+
################################################################
242+
243+
proc set_cmd_namespace { namespc } {
244+
if { $namespc == "sdc" || $namespc == "sta" } {
245+
set_cmd_namespace_cmd $namespc
246+
} else {
247+
sta_error 165 "unknown namespace $namespc."
248+
}
246249
}
247-
}
248-
249-
################################################################
250-
251-
define_cmd_args "report_object_full_names" {objects}
252-
253-
proc report_object_full_names { objects } {
254-
foreach obj [sort_by_full_name $objects] {
255-
report_line [get_full_name $obj]
250+
251+
################################################################
252+
253+
define_cmd_args "report_object_full_names" {objects}
254+
255+
proc report_object_full_names { objects } {
256+
foreach obj [sort_by_full_name $objects] {
257+
report_line [get_full_name $obj]
258+
}
256259
}
257-
}
258-
259-
define_cmd_args "report_object_names" {objects}
260-
261-
proc report_object_names { objects } {
262-
foreach obj [sort_by_name $objects] {
263-
report_line [get_name $obj]
260+
261+
define_cmd_args "report_object_names" {objects}
262+
263+
proc report_object_names { objects } {
264+
foreach obj [sort_by_name $objects] {
265+
report_line [get_name $obj]
266+
}
264267
}
265-
}
266-
267-
################################################################
268-
269-
define_cmd_args "get_name" {object}
270-
define_cmd_args "get_full_name" {object}
271-
272-
################################################################
273-
274-
proc get_name { object } {
275-
return [get_object_property $object "name"]
276-
}
277-
278-
proc get_full_name { object } {
279-
return [get_object_property $object "full_name"]
280-
}
281-
282-
proc sort_by_name { objects } {
283-
return [lsort -command name_cmp $objects]
284-
}
285-
286-
proc name_cmp { obj1 obj2 } {
287-
return [string compare [get_name $obj1] [get_name $obj2]]
288-
}
289-
290-
proc sort_by_full_name { objects } {
291-
return [lsort -command full_name_cmp $objects]
292-
}
293-
294-
proc full_name_cmp { obj1 obj2 } {
295-
return [string compare [get_full_name $obj1] [get_full_name $obj2]]
296-
}
297-
298-
proc get_object_type { obj } {
299-
set object_type [object_type $obj]
300-
if { $object_type == "Clock" } {
301-
return "clock"
302-
} elseif { $object_type == "LibertyCell" } {
303-
return "lib_cell"
304-
} elseif { $object_type == "LibertyPort" } {
305-
return "lib_pin"
306-
} elseif { $object_type == "Cell" } {
307-
return "cell"
308-
} elseif { $object_type == "Instance" } {
309-
return "instance"
310-
} elseif { $object_type == "Port" } {
311-
return "port"
312-
} elseif { $object_type == "Pin" } {
313-
return "pin"
314-
} elseif { $object_type == "Net" } {
315-
return "net"
316-
} elseif { $object_type == "Edge" } {
317-
return "timing_arc"
318-
} elseif { $object_type == "TimingArcSet" } {
319-
return "timing_arc"
320-
} else {
321-
return "?"
268+
269+
################################################################
270+
271+
define_cmd_args "get_name" {object}
272+
define_cmd_args "get_full_name" {object}
273+
274+
################################################################
275+
276+
proc get_name { object } {
277+
return [get_object_property $object "name"]
322278
}
323-
}
324-
325-
# sta namespace end.
279+
280+
proc get_full_name { object } {
281+
return [get_object_property $object "full_name"]
282+
}
283+
284+
proc sort_by_name { objects } {
285+
return [lsort -command name_cmp $objects]
286+
}
287+
288+
proc name_cmp { obj1 obj2 } {
289+
return [string compare [get_name $obj1] [get_name $obj2]]
290+
}
291+
292+
proc sort_by_full_name { objects } {
293+
return [lsort -command full_name_cmp $objects]
294+
}
295+
296+
proc full_name_cmp { obj1 obj2 } {
297+
return [string compare [get_full_name $obj1] [get_full_name $obj2]]
298+
}
299+
300+
proc get_object_type { obj } {
301+
set object_type [object_type $obj]
302+
if { $object_type == "Clock" } {
303+
return "clock"
304+
} elseif { $object_type == "LibertyCell" } {
305+
return "lib_cell"
306+
} elseif { $object_type == "LibertyPort" } {
307+
return "lib_pin"
308+
} elseif { $object_type == "Cell" } {
309+
return "cell"
310+
} elseif { $object_type == "Instance" } {
311+
return "instance"
312+
} elseif { $object_type == "Port" } {
313+
return "port"
314+
} elseif { $object_type == "Pin" } {
315+
return "pin"
316+
} elseif { $object_type == "Net" } {
317+
return "net"
318+
} elseif { $object_type == "Edge" } {
319+
return "timing_arc"
320+
} elseif { $object_type == "TimingArcSet" } {
321+
return "timing_arc"
322+
} else {
323+
return "?"
324+
}
325+
}
326+
327+
# sta namespace end.
326328
}

tcl/StaTclTypes.i

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
%{
3232

33+
#include <cctype>
34+
#include <string>
35+
3336
#include "Network.hh"
3437
#include "Liberty.hh"
3538
#include "FuncExpr.hh"
@@ -52,7 +55,7 @@ namespace sta {
5255
typedef MinMaxAll MinMaxAllNull;
5356

5457
#if TCL_MAJOR_VERSION < 9
55-
typedef int Tcl_Size;
58+
typedef int Tcl_Size;
5659
#endif
5760

5861
template <class TYPE>
@@ -256,14 +259,51 @@ setPtrTclList(SET_TYPE *set,
256259
Tcl_SetObjResult(interp, list);
257260
}
258261

259-
////////////////////////////////////////////////////////////////
260-
261262
} // namespace sta
262263

263264
using namespace sta;
264265

265266
%}
266267

268+
////////////////////////////////////////////////////////////////
269+
270+
%inline %{
271+
272+
bool
273+
is_object(const char *obj)
274+
{
275+
// _hexaddress_p_type
276+
const std::string s(obj);
277+
if (s.empty() || s[0] != '_')
278+
return false;
279+
const size_t hex_digits = sizeof(void *) * 2;
280+
if (s.size() < 1 + hex_digits + 3)
281+
return false;
282+
for (size_t i = 1; i < 1 + hex_digits; i++) {
283+
if (!std::isxdigit(static_cast<unsigned char>(s[i])))
284+
return false;
285+
}
286+
if (s.compare(1 + hex_digits, 3, "_p_") != 0)
287+
return false;
288+
for (size_t i = 1 + hex_digits + 3; i < s.size(); i++) {
289+
char ch = s[i];
290+
if (!(std::isalnum(ch) || ch == '_'))
291+
return false;
292+
}
293+
return true;
294+
}
295+
296+
// Assumes is_object is true.
297+
const char *
298+
object_type(const char *obj)
299+
{
300+
if (is_object(obj))
301+
return &obj[1 + sizeof(void*) * 2 + 3];
302+
return "";
303+
}
304+
305+
%}
306+
267307
////////////////////////////////////////////////////////////////
268308
//
269309
// SWIG type definitions.

util/Util.i

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -224,37 +224,6 @@ set_debug(const char *what,
224224
Sta::sta()->setDebugLevel(what, level);
225225
}
226226

227-
////////////////////////////////////////////////////////////////
228-
229-
bool
230-
is_object(const char *obj)
231-
{
232-
// _hexaddress_p_type
233-
const char *s = obj;
234-
char ch = *s++;
235-
if (ch != '_')
236-
return false;
237-
while (*s && isxdigit(*s))
238-
s++;
239-
if ((s - obj - 1) == sizeof(void*) * 2
240-
&& *s && *s++ == '_'
241-
&& *s && *s++ == 'p'
242-
&& *s && *s++ == '_') {
243-
while (*s && *s != ' ')
244-
s++;
245-
return *s == '\0';
246-
}
247-
else
248-
return false;
249-
}
250-
251-
// Assumes is_object is true.
252-
const char *
253-
object_type(const char *obj)
254-
{
255-
return &obj[1 + sizeof(void*) * 2 + 3];
256-
}
257-
258227
////////////////////////////////////////////////////////////////
259228
//
260229
// Units

0 commit comments

Comments
 (0)