Skip to content

Commit 548b665

Browse files
committed
get_* -filter allow true/false, '.' in glob pattern resolves #416
Signed-off-by: James Cherry <cherry@parallaxsw.com>
1 parent d6e826e commit 548b665

12 files changed

Lines changed: 118 additions & 128 deletions

File tree

include/sta/FilterObjects.hh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,67 +40,56 @@ class Report;
4040
PortSeq
4141
filterPorts(std::string_view filter_expression,
4242
PortSeq *objects,
43-
bool bool_props_as_int,
4443
Sta *sta);
4544

4645
InstanceSeq
4746
filterInstances(std::string_view filter_expression,
4847
InstanceSeq *objects,
49-
bool bool_props_as_int,
5048
Sta *sta);
5149

5250
PinSeq
5351
filterPins(std::string_view filter_expression,
5452
PinSeq *objects,
55-
bool bool_props_as_int,
5653
Sta *sta);
5754

5855
NetSeq
5956
filterNets(std::string_view filter_expression,
6057
NetSeq *objects,
61-
bool bool_props_as_int,
6258
Sta *sta);
6359

6460
ClockSeq
6561
filterClocks(std::string_view filter_expression,
6662
ClockSeq *objects,
67-
bool bool_props_as_int,
6863
Sta *sta);
6964

7065
LibertyCellSeq
7166
filterLibCells(std::string_view filter_expression,
7267
LibertyCellSeq *objects,
73-
bool bool_props_as_int,
7468
Sta *sta);
7569

7670
LibertyPortSeq
7771
filterLibPins(std::string_view filter_expression,
7872
LibertyPortSeq *objects,
79-
bool bool_props_as_int,
8073
Sta *sta);
8174

8275
LibertyLibrarySeq
8376
filterLibertyLibraries(std::string_view filter_expression,
8477
LibertyLibrarySeq *objects,
85-
bool bool_props_as_int,
8678
Sta *sta);
8779

8880
EdgeSeq
8981
filterTimingArcs(std::string_view filter_expression,
9082
EdgeSeq *objects,
91-
bool bool_props_as_int,
9283
Sta *sta);
9384

9485
PathEndSeq
9586
filterPathEnds(std::string_view filter_expression,
9687
PathEndSeq *objects,
97-
bool bool_props_as_int,
9888
Sta *sta);
9989

10090
// For FilterExpr unit tests.
10191
StringSeq
10292
filterExprToPostfix(std::string_view expr,
103-
bool bool_props_as_int,
10493
Report *report);
10594

10695
} // namespace

sdc/FilterObjects.cc

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class FilterExpr
7373
FilterExpr(std::string_view expression,
7474
Report *report);
7575

76-
std::vector<std::unique_ptr<Token>> postfix(bool bool_props_as_int);
76+
std::vector<std::unique_ptr<Token>> postfix();
7777
private:
78-
std::vector<std::unique_ptr<Token>> lex(bool bool_props_as_int);
78+
std::vector<std::unique_ptr<Token>> lex();
7979
std::vector<std::unique_ptr<Token>> shuntingYard(std::vector<std::unique_ptr<Token>> &infix);
8080

8181
std::string raw_;
@@ -106,20 +106,21 @@ FilterExpr::FilterExpr(std::string_view expression,
106106
}
107107

108108
std::vector<std::unique_ptr<FilterExpr::Token>>
109-
FilterExpr::postfix(bool bool_props_as_int)
109+
FilterExpr::postfix()
110110
{
111-
auto infix = lex(bool_props_as_int);
111+
auto infix = lex();
112112
return shuntingYard(infix);
113113
}
114114

115115
std::vector<std::unique_ptr<FilterExpr::Token>>
116-
FilterExpr::lex(bool bool_props_as_int)
116+
FilterExpr::lex()
117117
{
118118
std::vector<std::pair<std::regex, Token::Kind>> token_regexes = {
119119
{std::regex("^\\s+"), Token::Kind::skip},
120120
{std::regex("^defined\\(([a-zA-Z_]+)\\)"), Token::Kind::defined},
121121
{std::regex("^undefined\\(([a-zA-Z_]+)\\)"), Token::Kind::undefined},
122-
{std::regex("^@?([a-zA-Z_]+) *((==|!=|=~|!~) *([0-9a-zA-Z_\\/$\\[\\]*?]+))?"), Token::Kind::predicate},
122+
{std::regex("^@?([a-zA-Z_]+) *((==|!=|=~|!~) *([0-9a-zA-Z_\\/$\\[\\]*?.]+))?"),
123+
Token::Kind::predicate},
123124
{std::regex("^(&&)"), Token::Kind::op_and},
124125
{std::regex("^(\\|\\|)"), Token::Kind::op_or},
125126
{std::regex("^(!)"), Token::Kind::op_inv},
@@ -139,9 +140,9 @@ FilterExpr::lex(bool bool_props_as_int)
139140
std::string property = token_match[1].str();
140141

141142
// The default operation on a predicate if an op and arg are
142-
// omitted is 'arg == 1' / 'arg == true'.
143+
// omitted is 'prop == 1 || true'.
143144
std::string op = "==";
144-
std::string arg = (bool_props_as_int ? "1" : "true");
145+
std::string arg = "1";
145146

146147
if (token_match[2].length() != 0) {
147148
op = token_match[3].str();
@@ -250,13 +251,18 @@ filterObjects(const char *property,
250251
bool not_pattern_match = stringEq(op, "!~");
251252
for (T *object : all) {
252253
PropertyValue value = properties.getProperty(object, property);
253-
std::string prop_str = value.to_string(network);
254-
const char *prop = prop_str.c_str();
255-
if (prop &&
256-
((exact_match && stringEq(prop, pattern))
257-
|| (not_match && !stringEq(prop, pattern))
258-
|| (pattern_match && patternMatch(pattern, prop))
259-
|| (not_pattern_match && !patternMatch(pattern, prop))))
254+
std::string prop = value.to_string(network);
255+
if (value.type() == PropertyValue::Type::bool_) {
256+
// Canonicalize bool true/false to 1/0.
257+
if (stringEqual(pattern, "true"))
258+
pattern = "1";
259+
else if (stringEqual(pattern, "false"))
260+
pattern = "0";
261+
}
262+
if ((exact_match && stringEq(prop.c_str(), pattern))
263+
|| (not_match && !stringEq(prop.c_str(), pattern))
264+
|| (pattern_match && patternMatch(pattern, prop))
265+
|| (not_pattern_match && !patternMatch(pattern, prop)))
260266
filtered_objects.insert(object);
261267
}
262268
return filtered_objects;
@@ -265,7 +271,6 @@ filterObjects(const char *property,
265271
template <typename T> std::vector<T*>
266272
filterObjects(std::string_view filter_expression,
267273
std::vector<T*> *objects,
268-
bool bool_props_as_int,
269274
Sta *sta)
270275
{
271276
Report *report = sta->report();
@@ -278,7 +283,7 @@ filterObjects(std::string_view filter_expression,
278283
all.insert(object);
279284

280285
FilterExpr filter(filter_expression, report);
281-
auto postfix = filter.postfix(bool_props_as_int);
286+
auto postfix = filter.postfix();
282287
std::stack<std::set<T*>> eval_stack;
283288
for (auto &token : postfix) {
284289
if (token->kind == FilterExpr::Token::Kind::op_or) {
@@ -405,100 +410,89 @@ filterObjects(std::string_view filter_expression,
405410
PortSeq
406411
filterPorts(std::string_view filter_expression,
407412
PortSeq *objects,
408-
bool bool_props_as_int,
409413
Sta *sta)
410414
{
411-
return filterObjects<const Port>(filter_expression, objects, bool_props_as_int, sta);
415+
return filterObjects<const Port>(filter_expression, objects, sta);
412416
}
413417

414418
InstanceSeq
415419
filterInstances(std::string_view filter_expression,
416420
InstanceSeq *objects,
417-
bool bool_props_as_int,
418421
Sta *sta)
419422
{
420-
return filterObjects<const Instance>(filter_expression, objects, bool_props_as_int, sta);
423+
return filterObjects<const Instance>(filter_expression, objects, sta);
421424
}
422425

423426
PinSeq
424427
filterPins(std::string_view filter_expression,
425428
PinSeq *objects,
426-
bool bool_props_as_int,
427429
Sta *sta)
428430
{
429-
return filterObjects<const Pin>(filter_expression, objects, bool_props_as_int, sta);
431+
return filterObjects<const Pin>(filter_expression, objects, sta);
430432
}
431433

432434
NetSeq
433435
filterNets(std::string_view filter_expression,
434436
NetSeq *objects,
435-
bool bool_props_as_int,
436437
Sta *sta)
437438
{
438-
return filterObjects<const Net>(filter_expression, objects, bool_props_as_int, sta);
439+
return filterObjects<const Net>(filter_expression, objects, sta);
439440
}
440441

441442
ClockSeq
442443
filterClocks(std::string_view filter_expression,
443444
ClockSeq *objects,
444-
bool bool_props_as_int,
445445
Sta *sta)
446446
{
447-
return filterObjects<Clock>(filter_expression, objects, bool_props_as_int, sta);
447+
return filterObjects<Clock>(filter_expression, objects, sta);
448448
}
449449

450450
LibertyCellSeq
451451
filterLibCells(std::string_view filter_expression,
452452
LibertyCellSeq *objects,
453-
bool bool_props_as_int,
454453
Sta *sta)
455454
{
456-
return filterObjects<LibertyCell>(filter_expression, objects, bool_props_as_int, sta);
455+
return filterObjects<LibertyCell>(filter_expression, objects, sta);
457456
}
458457

459458
LibertyPortSeq
460459
filterLibPins(std::string_view filter_expression,
461460
LibertyPortSeq *objects,
462-
bool bool_props_as_int,
463461
Sta *sta)
464462
{
465-
return filterObjects<LibertyPort>(filter_expression, objects, bool_props_as_int, sta);
463+
return filterObjects<LibertyPort>(filter_expression, objects, sta);
466464
}
467465

468466
LibertyLibrarySeq
469467
filterLibertyLibraries(std::string_view filter_expression,
470468
LibertyLibrarySeq *objects,
471-
bool bool_props_as_int,
472469
Sta *sta)
473470
{
474-
return filterObjects<LibertyLibrary>(filter_expression, objects, bool_props_as_int, sta);
471+
return filterObjects<LibertyLibrary>(filter_expression, objects, sta);
475472
}
476473

477474
EdgeSeq
478475
filterTimingArcs(std::string_view filter_expression,
479476
EdgeSeq *objects,
480-
bool bool_props_as_int,
481477
Sta *sta)
482478
{
483-
return filterObjects<Edge>(filter_expression, objects, bool_props_as_int, sta);
479+
return filterObjects<Edge>(filter_expression, objects, sta);
484480
}
485481

486482
PathEndSeq
487483
filterPathEnds(std::string_view filter_expression,
488484
PathEndSeq *objects,
489-
bool bool_props_as_int,
490485
Sta *sta)
491486
{
492-
return filterObjects<PathEnd>(filter_expression, objects, bool_props_as_int, sta);
487+
return filterObjects<PathEnd>(filter_expression, objects, sta);
493488
}
494489

495490
StringSeq
496491
filterExprToPostfix(std::string_view expr,
497-
bool bool_props_as_int,
498492
Report *report)
499493
{
500494
FilterExpr filter(expr, report);
501-
auto postfix = filter.postfix(bool_props_as_int);
495+
auto postfix = filter.postfix();
502496
StringSeq result;
503497
for (auto &token : postfix)
504498
result.push_back(token->text);

sdc/Sdc.i

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,101 +1493,90 @@ find_register_output_pins(ClockSet *clks,
14931493

14941494
PortSeq
14951495
filter_ports(const char *filter_expression,
1496-
PortSeq *ports,
1497-
bool bool_props_as_int)
1496+
PortSeq *ports)
14981497
{
14991498
sta::Sta *sta = Sta::sta();
1500-
return filterPorts(filter_expression, ports, bool_props_as_int, sta);
1499+
return filterPorts(filter_expression, ports, sta);
15011500
}
15021501

15031502
InstanceSeq
15041503
filter_insts(const char *filter_expression,
1505-
InstanceSeq *insts,
1506-
bool bool_props_as_int)
1504+
InstanceSeq *insts)
15071505
{
15081506
sta::Sta *sta = Sta::sta();
1509-
return filterInstances(filter_expression, insts, bool_props_as_int, sta);
1507+
return filterInstances(filter_expression, insts, sta);
15101508
}
15111509

15121510
PinSeq
15131511
filter_pins(const char *filter_expression,
1514-
PinSeq *pins,
1515-
bool bool_props_as_int)
1512+
PinSeq *pins)
15161513
{
15171514
sta::Sta *sta = Sta::sta();
1518-
return filterPins(filter_expression, pins, bool_props_as_int, sta);
1515+
return filterPins(filter_expression, pins, sta);
15191516
}
15201517

15211518
NetSeq
15221519
filter_nets(const char *filter_expression,
1523-
NetSeq *nets,
1524-
bool bool_props_as_int)
1520+
NetSeq *nets)
15251521
{
15261522
sta::Sta *sta = Sta::sta();
1527-
return filterNets(filter_expression, nets, bool_props_as_int, sta);
1523+
return filterNets(filter_expression, nets, sta);
15281524
}
15291525

15301526
ClockSeq
15311527
filter_clocks(const char *filter_expression,
1532-
ClockSeq *clocks,
1533-
bool bool_props_as_int)
1528+
ClockSeq *clocks)
15341529
{
15351530
sta::Sta *sta = Sta::sta();
1536-
return filterClocks(filter_expression, clocks, bool_props_as_int, sta);
1531+
return filterClocks(filter_expression, clocks, sta);
15371532
}
15381533

15391534
LibertyCellSeq
15401535
filter_lib_cells(const char *filter_expression,
1541-
LibertyCellSeq *cells,
1542-
bool bool_props_as_int)
1536+
LibertyCellSeq *cells)
15431537
{
15441538
sta::Sta *sta = Sta::sta();
1545-
return filterLibCells(filter_expression, cells, bool_props_as_int, sta);
1539+
return filterLibCells(filter_expression, cells, sta);
15461540
}
15471541

15481542
LibertyPortSeq
15491543
filter_lib_pins(const char *filter_expression,
1550-
LibertyPortSeq *pins,
1551-
bool bool_props_as_int)
1544+
LibertyPortSeq *pins)
15521545
{
15531546
sta::Sta *sta = Sta::sta();
1554-
return filterLibPins(filter_expression, pins, bool_props_as_int, sta);
1547+
return filterLibPins(filter_expression, pins, sta);
15551548
}
15561549

15571550
LibertyLibrarySeq
15581551
filter_liberty_libraries(const char *filter_expression,
1559-
LibertyLibrarySeq *libs,
1560-
bool bool_props_as_int)
1552+
LibertyLibrarySeq *libs)
15611553
{
15621554
sta::Sta *sta = Sta::sta();
1563-
return filterLibertyLibraries(filter_expression, libs, bool_props_as_int, sta);
1555+
return filterLibertyLibraries(filter_expression, libs, sta);
15641556
}
15651557

15661558
EdgeSeq
15671559
filter_timing_arcs(const char *filter_expression,
1568-
EdgeSeq *edges,
1569-
bool bool_props_as_int)
1560+
EdgeSeq *edges)
15701561
{
15711562
sta::Sta *sta = Sta::sta();
1572-
return filterTimingArcs(filter_expression, edges, bool_props_as_int, sta);
1563+
return filterTimingArcs(filter_expression, edges, sta);
15731564
}
15741565

15751566
PathEndSeq
15761567
filter_path_ends(const char *filter_expression,
1577-
PathEndSeq *path_ends,
1578-
bool bool_props_as_int)
1568+
PathEndSeq *path_ends)
15791569
{
15801570
sta::Sta *sta = Sta::sta();
1581-
return filterPathEnds(filter_expression, path_ends, bool_props_as_int, sta);
1571+
return filterPathEnds(filter_expression, path_ends, sta);
15821572
}
15831573

15841574
// For FilterExpr unit tests.
15851575
StringSeq
1586-
filter_expr_to_postfix(const char* expr,
1587-
bool bool_props_as_int)
1576+
filter_expr_to_postfix(const char* expr)
15881577
{
15891578
Report *report = Sta::sta()->report();
1590-
return filterExprToPostfix(expr, bool_props_as_int, report);
1579+
return filterExprToPostfix(expr, report);
15911580
}
15921581

15931582
////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)