class RgGen::VHDL::Utility::DataObject

Public Class Methods

new(object_type, default_attributes = {}) { |self| ... } click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 9
def initialize(object_type, default_attributes = {})
  @object_type = object_type
  apply_attributes(**default_attributes)
  block_given? && yield(self)
end

Public Instance Methods

declaration() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 22
def declaration
  declaration_snippets
    .compact
    .reject(&:empty?)
    .join(' ')
end
identifier() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 29
def identifier
  Identifier.new(name) do |identifier|
    identifier.__width__(width)
    identifier.__array_size__(array_size)
  end
end

Private Instance Methods

calc_actual_width() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 70
def calc_actual_width
  return width if array_size.nil? || array_size.empty?
  size = [width, *array_size].compact
  size.all? { |s| s.is_a?(Integer) } && size.inject(:*) || size.join('*')
end
calc_msb() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 65
def calc_msb
  width = calc_actual_width
  width && (width.is_a?(Integer) && width - 1 || "#{width}-1")
end
declaration_snippets() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 38
def declaration_snippets
  [
    object_type_keyword,
    "#{name}:",
    direction_keyword,
    type_declaration,
    default_value
  ]
end
default_type() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 80
def default_type
  @object_type == :generic && 'unsigned' || 'std_logic'
end
default_value() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 84
def default_value
  return nil if @object_type != :generic || default.nil?
  ":= #{default}"
end
default_vector_type() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 76
def default_vector_type
  @object_type == :generic && 'unsigned' || 'std_logic_vector'
end
direction_keyword() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 52
def direction_keyword
  @object_type == :port && direction || nil
end
object_type_keyword() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 48
def object_type_keyword
  [:signal].include?(@object_type) && @object_type || nil
end
type_declaration() click to toggle source
# File lib/rggen/vhdl/utility/data_object.rb, line 56
def type_declaration
  if @object_type == :generic && type
    type
  else
    msb = calc_msb
    msb && "#{default_vector_type}(#{msb} downto 0)" || default_type
  end
end