From 117e4094bc38a910653f8bd50bde0ae3b3e8c92c Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Fri, 23 Jan 2026 11:39:56 -0800 Subject: [PATCH] Fix for invalid operator error handling (#366) * Fix for invalid operator error handling * Revisions --- sdc/Sdc.tcl | 25 +++++++++++++++++-------- test/get_filter.ok | 2 ++ test/get_filter.tcl | 5 +++++ test/prima3.ok | 10 ---------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/sdc/Sdc.tcl b/sdc/Sdc.tcl index 112ea504..e22645f2 100644 --- a/sdc/Sdc.tcl +++ b/sdc/Sdc.tcl @@ -306,11 +306,18 @@ proc current_design { {design ""} } { # Generic get_* filter. proc filter_objs { filter objects filter_function object_type } { - set filter_regexp1 {@?([a-zA-Z_]+) *((==|!=|=~|!~) *([0-9a-zA-Z_\*]+))?} - set filter_or_regexp "($filter_regexp1) *\\|\\| *($filter_regexp1)" - set filter_and_regexp "($filter_regexp1) *&& *($filter_regexp1)" + # Regexp for attr op arg (e.g., full_name =~ *blk*) + set filter_regexp_op {@?([a-zA-Z_]+) *(==|!=|=~|!~) *([0-9a-zA-Z_\*]+)} + # Regexp for bool attr (e.g., is_hierarchical) - anchored for standalone use + set filter_regexp_bool {^@?([a-zA-Z_]+)$} + # Regexp for wildcard attr (e.g., full_name *blk*) + set filter_regexp_wild_op {@?([a-zA-Z_]+) *(.+) *([0-9a-zA-Z_\*]+)} + # Regexp for term in compound expression (no anchors) + set filter_regexp_term {@?([a-zA-Z_]+)( *(==|!=|=~|!~) *([0-9a-zA-Z_\*]+))?} + set filter_or_regexp "($filter_regexp_term) *\\|\\| *($filter_regexp_term)" + set filter_and_regexp "($filter_regexp_term) *&& *($filter_regexp_term)" set filtered_objects {} - # Ignore sub-exprs in filter_regexp1 for expr2 match var. + # Ignore sub-exprs in filter_regexp for expr2 match var. if { [regexp $filter_or_regexp $filter ignore expr1 ignore ignore ignore ignore expr2] } { set filtered_objects1 [filter_objs $expr1 $objects $filter_function $object_type] set filtered_objects2 [filter_objs $expr2 $objects $filter_function $object_type] @@ -318,11 +325,13 @@ proc filter_objs { filter objects filter_function object_type } { } elseif { [regexp $filter_and_regexp $filter ignore expr1 ignore ignore ignore ignore expr2] } { set filtered_objects [filter_objs $expr1 $objects $filter_function $object_type] set filtered_objects [filter_objs $expr2 $filtered_objects $filter_function $object_type] - } elseif { [regexp $filter_regexp1 $filter ignore attr_name ignore op arg] } { - # If no op/arg, use ==1 by default. - set op [expr {($op == "") ? "==" : $op}] - set arg [expr {($arg == "") ? "1" : $arg}] + } elseif { [regexp $filter_regexp_op $filter ignore attr_name op arg] } { set filtered_objects [$filter_function $attr_name $op $arg $objects] + } elseif { [regexp $filter_regexp_bool $filter ignore attr_name] } { + # Bool property: use ==1 by default. + set filtered_objects [$filter_function $attr_name "==" "1" $objects] + } elseif { [regexp $filter_regexp_wild_op $filter ignore attr_name op arg] } { + sta_error 336 "unknown filter operand." } else { sta_error 350 "unsupported $object_type -filter expression." } diff --git a/test/get_filter.ok b/test/get_filter.ok index 8e98cdba..deaa54f3 100644 --- a/test/get_filter.ok +++ b/test/get_filter.ok @@ -52,3 +52,5 @@ in1 in2 [get_ports -filter direction==output *] out +[get_cells -filter {name ~= *r1*} *] +Error: get_filter.tcl line 48, unknown filter operand. diff --git a/test/get_filter.tcl b/test/get_filter.tcl index ea17f599..7263811e 100644 --- a/test/get_filter.tcl +++ b/test/get_filter.tcl @@ -42,3 +42,8 @@ puts {[get_ports -filter direction==input *]} report_object_full_names [get_ports -filter direction==input *] puts {[get_ports -filter direction==output *]} report_object_full_names [get_ports -filter direction==output *] + +# Test invalid operator ~= (should be =~) +puts {[get_cells -filter {name ~= *r1*} *]} +catch {get_cells -filter {name ~= *r1*} *} result +puts $result diff --git a/test/prima3.ok b/test/prima3.ok index 98c9c3cd..a4ac1d9c 100644 --- a/test/prima3.ok +++ b/test/prima3.ok @@ -1,13 +1,3 @@ -Warning: asap7_simple.lib.gz line 71029, timing group from output port. -Warning: asap7_simple.lib.gz line 71505, timing group from output port. -Warning: asap7_simple.lib.gz line 71981, timing group from output port. -Warning: asap7_simple.lib.gz line 72457, timing group from output port. -Warning: asap7_simple.lib.gz line 72933, timing group from output port. -Warning: asap7_simple.lib.gz line 73409, timing group from output port. -Warning: asap7_simple.lib.gz line 73885, timing group from output port. -Warning: asap7_simple.lib.gz line 81795, timing group from output port. -Warning: asap7_simple.lib.gz line 82271, timing group from output port. -Warning: asap7_simple.lib.gz line 82747, timing group from output port. Startpoint: r2 (rising edge-triggered flip-flop clocked by clk) Endpoint: r3 (rising edge-triggered flip-flop clocked by clk) Path Group: clk