Identify Pins with a Regular Expression

This script shows how to identify a flipflop's input, output, and clock pins using a regular expression.

# Given a register pattern, find the nets connected to the register's pins
set reg_pattern "o11\[*\]~FF"
set reg_cells [ get_cells ${reg_pattern} ]
puts $reg_cells

# get all the pins from cells with the pattern "|*"
foreach reg $reg_cells {
    set pin_pattern "${reg}|*"
    set reg_pins [ get_pins $pin_pattern ]
    
    foreach p $reg_pins {
        set is_clock_pin 0
        set is_in_pin 0
        set is_out_pin 0

        # For flipflops, the pin type can be identified by specific pin name
        if {[regexp {\|CLK$} $p]} {
            set is_clock_pin 1
        } elseif {[regexp {\|Q$} $p]} {
            set is_out_pin 1
        } else {
            set is_in_pin 1
        }
        
        set net_on_pin [get_nets $p]
        puts "PIN $p is_clock=${is_clock_pin} is_in_pin=${is_in_pin} / 
            is_out_pin=${is_out_pin} NET: $net_on_pin"
}