gen_pb.tcl 7.95 KB
Newer Older
1 2 3 4 5 6
#############################################################################
# This script was written and developed by ABKGroup students at UCSD.
# However, the underlying commands and reports are copyrighted by Cadence. 
# We thank Cadence for granting permission to share our research to help 
# promote and foster the next generation of innovators.
# Author: Sayak Kundu, ABKGroup, UCSD
7 8 9 10
#
# Usage: First source the script in Innovus shell. then use gen_pb_netlist
# command to write out the netlist. The protobuf netlist will be available
# as <design name>.pb.txt.
11 12 13 14 15 16 17 18
#############################################################################

#### Print the design header ####
proc print_header { fp } {
  set design [dbget top.name]
  set user [exec whoami]
  set date [exec date]
  set run_dir [exec pwd]
19 20
  set fp_box_ll [dbget top.fplan.box_ll]
  set fp_box_ur [dbget top.fplan.box_ur]
21 22 23 24

  puts $fp "# User: $user"
  puts $fp "# Date: $date"
  puts $fp "# Run area: $run_dir"
25
  puts $fp "# Block : $design"
26
  puts $fp "# FP bbox: $fp_box_ll $fp_box_ur"
27 28 29 30 31 32
  ## Add dummy Column and Row info ##
  puts $fp "# Columns : 10  Rows : 10"
  ## Add blockage for core to die spacing ##
  foreach box [dbShape -output rect [dbget top.fplan.box] XOR [dbget top.fplan.coreBox]] {
      puts $fp "# Blockage : $box 1"
  }
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
}

#### Print helper ####
proc print_placeholder { fp key value } {
  puts $fp "  attr {"
  puts $fp "    key: \"$key\""
  puts $fp "    value {"
  puts $fp "      placeholder: \"$value\""
  puts $fp "    }"
  puts $fp "  }"
}

proc print_float { fp key value } {
  puts $fp "  attr {"
  puts $fp "    key: \"$key\""
  puts $fp "    value {"
  puts $fp "      f: $value"
  puts $fp "    }"
  puts $fp "  }"
}

### Helper to convert Orientation format ###
proc get_orient { tmp_orient } {
  set orient "N"
  if { $tmp_orient == "R0"} {
    set orient "N"
  } elseif { $tmp_orient == "R180" } {
    set orient "S"
  } elseif { $tmp_orient == "R90" } {
    set orient "W"
  } elseif { $tmp_orient == "R270" } {
    set orient "E"
  } elseif { $tmp_orient == "MY" } {
    set oreint "FN"
  } elseif { $tmp_orient == "MX" } {
    set oreint "FS"
  } elseif { $tmp_orient == "MX90" } {
    set orient "FW" 
  } elseif { $tmp_orient == "MY90" } {
    set orient "FE"
  }

  return $orient
}

#### Procedure to print the sinks ####
proc print_net { net_ptr fp } {
  ### Print Terms ###
  foreach term [dbget [dbget ${net_ptr}.terms.isOutput 1 -p ].name -e] {
    puts $fp "  input: \"${term}\""
  }
  
  ### Print Macro Pins ###
  foreach macro_pin [dbget [dbget [dbget ${net_ptr}.instTerms.isInput 1 -p \
87
                    ].inst.cell.subClass block -p3 ].name -e] {
88 89 90 91 92
    puts $fp "  input: \"${macro_pin}\""
  }
  
  ### Print Stdcells ###
  foreach inst [dbget [dbget [dbget ${net_ptr}.instTerms.isInput 1 -p \
93
                    ].inst.cell.subClass core -p2 ].name -e] {
94 95 96 97 98 99 100 101 102 103
    puts $fp "  input: \"${inst}\""
  }
}

#### Procedure to write Ports ####
proc write_node_port { port_ptr fp } {
  puts $fp "node {"
  
  set name [lindex [dbget ${port_ptr}.name] 0]
  puts $fp "  name: \"${name}\""
104 105 106 107 108
 
  if { [dbget ${port_ptr}.isInput] == 1 } {
    set net_ptr [dbget ${port_ptr}.net]
    print_net $net_ptr $fp
  }
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

  ### Attribute: type ###
  print_placeholder $fp "type" "port"

  ### Attribute: Side ###
  set tmp_side [dbget ${port_ptr}.side]
  set side ""
  if {$tmp_side == "West"} {
    set side "left"
  } elseif {$tmp_side == "East"} {
    set side "right"
  } elseif {$tmp_side == "North"} {
    set side "top"
  } elseif {$tmp_side == "South"} {
    set side "bottom"
  } else {
    puts "Error: Wrong Direction. Port Name: $name"
  }
  print_placeholder $fp "side" $side

  ### Attribute: X ###
  set X1 [lindex [dbget ${port_ptr}.pinShapes.rect] 0 0]
  set X2 [lindex [dbget ${port_ptr}.pinShapes.rect] 0 2]
  set X [expr ($X1 + $X2)/2]
  print_float $fp "x" $X

  ### Attribute: Y ###
  set Y1 [lindex [dbget ${port_ptr}.pinShapes.rect] 0 1]
  set Y2 [lindex [dbget ${port_ptr}.pinShapes.rect] 0 3]
  set Y [expr ($Y1 + $Y2)/2]
  print_float $fp "y" $Y
  
  puts $fp "}"
}

#### Procedure to write Macros ####
proc write_node_macro { macro_ptr fp } {
  puts $fp "node {"

  set name [lindex [dbget ${macro_ptr}.name] 0]
  puts $fp "  name: \"${name}\""

  ### Attribute: ref_name ###
  set ref_name [dbget ${macro_ptr}.cell.name]
  print_placeholder $fp "ref_name" ${ref_name}

  ### Attribute: Width ###
  set width [dbget ${macro_ptr}.box_sizex]
  print_float $fp "width" $width

  ### Attribute: Height ###
  set height [dbget ${macro_ptr}.box_sizey]
  print_float $fp "height" $height

  ### Attribute: type ###
  print_placeholder $fp "type" "macro"

  ### Attribute: X ###
  set X1 [lindex [dbget ${macro_ptr}.box] 0 0]
  set X2 [lindex [dbget ${macro_ptr}.box] 0 2]
  set X [expr ($X1 + $X2)/2]
  print_float $fp "x" $X

  ### Attribute: Y ###
  set Y1 [lindex [dbget ${macro_ptr}.box] 0 1]
  set Y2 [lindex [dbget ${macro_ptr}.box] 0 3]
  set Y [expr ($Y1 + $Y2)/2]
  print_float $fp "y" $Y
  
  ### Attribute: Y ###
  set tmp_orient [dbget ${macro_ptr}.orient]
  set orient [get_orient $tmp_orient]
  print_placeholder $fp "orientation" $orient

  puts $fp "}"
}

#### Procedure to Write Macro Pins ####
proc write_node_macro_pin { macro_pin_ptr fp } {
  puts $fp "node {"

  set name [lindex [dbget ${macro_pin_ptr}.name] 0]
  puts $fp "  name: \"${name}\""

  ### Print all the sinks ###
  if { [dbget ${macro_pin_ptr}.isOutput] == 1} {
    set net_ptr [dbget ${macro_pin_ptr}.net]
    print_net $net_ptr $fp
  }

  ### Attribute: Macro Name ###
  set macro_name [lindex [dbget ${macro_pin_ptr}.inst.name] 0]
  print_placeholder $fp "macro_name" $macro_name

  ### Attribute: type ###
  print_placeholder $fp "type" "macro_pin"
  
  set X [dbget ${macro_pin_ptr}.pt_x]
  set Y [dbget ${macro_pin_ptr}.pt_y]
sakundu committed
208 209 210 211 212 213
  set cell_height [dbget ${macro_pin_ptr}.cellTerm.cell.size_y]
  set cell_width [dbget ${macro_pin_ptr}.cellTerm.cell.size_x]
  set pin_x [dbget ${macro_pin_ptr}.cellTerm.pt_x]
  set pin_y [dbget ${macro_pin_ptr}.cellTerm.pt_y]
  set x_offset [expr $pin_x - $cell_width/2]
  set y_offset [expr $pin_y - $cell_height/2]
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283

  ### Attribute: x_offset ###
  print_float $fp "x_offset" $x_offset
  
  ### Attribute: y_offset ###
  print_float $fp "y_offset" $y_offset

  ### Attribute: X ###
  print_float $fp "x" $X
  
  ### Attribute: Y ###
  print_float $fp "y" $Y
  
  puts $fp "}"
}

#### Procedure to Write Std-cell ###
proc write_node_stdcell { inst_ptr fp } {
  puts $fp "node {"

  set name [lindex [dbget ${inst_ptr}.name] 0]
  puts $fp "  name: \"${name}\""

  ### Print all the sinks ###
  foreach net_ptr [dbget [dbget ${inst_ptr}.instTerms.isOutput 1 -p ].net -e ] {
    print_net $net_ptr $fp
  }

  ### Attribute: ref_name ###
  set ref_name [dbget ${inst_ptr}.cell.name]
  print_placeholder $fp "ref_name" $ref_name

  ### Attribute: Width ###
  set width [dbget ${inst_ptr}.box_sizex]
  print_float $fp "width" $width

  ### Attribute: Height ###
  set height [dbget ${inst_ptr}.box_sizey]
  print_float $fp "height" $height

  ### Attribute: type ###
  print_placeholder $fp "type" "stdcell"

  ### Attribute: X ###
  set X1 [lindex [dbget ${inst_ptr}.box] 0 0]
  set X2 [lindex [dbget ${inst_ptr}.box] 0 2]
  set X [expr ($X1 + $X2)/2]
  print_float $fp "x" $X

  ### Attribute: Y ###
  set Y1 [lindex [dbget ${inst_ptr}.box] 0 1]
  set Y2 [lindex [dbget ${inst_ptr}.box] 0 3]
  set Y [expr ($Y1 + $Y2)/2]
  print_float $fp "y" $Y
  
  puts $fp "}"
}

#### Generate protobuff format netlist ####
proc gen_pb_netlist { } {
  set design [dbget top.name]
  set out_file "${design}.pb.txt"
  set fp [open $out_file w+]

  print_header $fp

  foreach port_ptr [dbget top.terms] {  
    write_node_port $port_ptr $fp
  }

284
  foreach macro_ptr [dbget top.insts.cell.subClass block -p2] {
285 286 287 288 289 290
    write_node_macro $macro_ptr $fp
    foreach macro_pin_ptr [dbget ${macro_ptr}.instTerms] {
      write_node_macro_pin $macro_pin_ptr $fp
    }
  }

291
  foreach inst_ptr [dbget top.insts.cell.subClass core -p2] {
292 293 294 295 296 297
    write_node_stdcell $inst_ptr $fp
  }

  close $fp
  puts "Output netlist: $out_file"
}