File size: 3,565 Bytes
784ee2c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 | #!/usr/bin/env ruby
require 'digest'
require 'json'
require_relative 'LEFNamedObject'
#
# Class to store LEF via information
#
class LEFVia < LEFNamedObject
#
# Container class that store information about the and shapes that are part
# of the via that exist on the specified layer. Only RECTs are supported.
#
class LEFViaLayer
#
# Initializer
#
# layer is a ref to a LEFLayer
# shape_list is the list of shapes for the via on the specified layer
#
def initialize(layer)
# make sure this is a LEFLayer
if !layer.is_a?(LEFLayer)
raise ArgumentError, sprintf("LEFViaLayer initialize expects LEFLayer, got %s", layer.class.name)
end
@layer = layer
@shape_list = []
end
#
# Adds a shape to the shape list
#
def add_shape(shape)
@shape_list << shape
end
#
# Returns the LEF layer for the shapes
#
def get_layer()
return @layer
end
#
# Returns the shape list
#
def get_shape_list()
return @shape_list
end
#
# Computes and returns the sha256 for the container
#
def sha256()
layer_sha = get_layer().sha256()
serialized_shapes = JSON.generate(get_shape_list)
shape_list_sha = Digest::SHA256.hexdigest(serialized_shapes)
return Digest::SHA256.hexdigest(layer_sha + shape_list_sha)
end
#
# Writes the LEF snippet for the container
#
def write_lef(outfh)
outfh.puts sprintf(" LAYER %s ;", get_layer().get_name())
get_shape_list.each do | rect |
outfh.puts sprintf(" RECT %5.3f %5.3f %5.3f %5.3f ;", rect[0],
rect[1], rect[2], rect[3])
end
end
end
#
# Initializer
#
# layer_list is a list of LEFViaLayers, which is unsorted. That way whoever
# is creating the via can just add LEFViaLayers without regard for the
# layer stacking order.
#
def initialize(name, is_default=false)
super(name)
@is_default = is_default
# List of LEFViaLayers - unsorted
@layer_list = []
end
#
# Computes and returns the sha256 for the via
#
def sha256()
layer_stack = get_layer_list()
hashes = get_layer_list.map { |layer| layer.sha256 }
concat_hashes = hashes.join
return Digest::SHA256.hexdigest(concat_hashes)
end
#
# Returns the LEFViaLayer list for the via
#
# default is to sort the layers, by the layer number. That way it's returned
# bottom layer to top layer
#
def get_layer_list(sorted=true)
if sorted
return @layer_list.sort_by { |layer| layer.get_layer().get_number }
end
return @layer_list
end
#
# Adds a layer to the layer list
#
def add_layer(layer)
@layer_list << layer
end
#
# Writes the LEF snippet
#
def write_lef(outfh)
via_name = get_name()
if @is_default
default_str = " DEFAULT"
else
default_str = ""
end
outfh.puts sprintf("VIA %s%s", via_name, default_str)
get_layer_list().each do | layer |
layer.write_lef(outfh)
end
outfh.puts sprintf("END %s", via_name)
outfh.puts
end
end
|