Class: VHDL_Parser::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/vhdl_parser/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Entity

Returns a new instance of Entity.



16
17
18
19
20
# File 'lib/vhdl_parser/entity.rb', line 16

def initialize(name)
  @name = name
  @ports = Array.new
  @generics = Array.new
end

Instance Attribute Details

#genericsArray<Generic> (readonly)

An array of all the Generics.

Returns:

  • (Array<Generic>)

    An array of all the Generics on this entity.



10
11
12
# File 'lib/vhdl_parser/entity.rb', line 10

def generics
  @generics
end

#nameString (readonly)

The name of the Entity.

Returns:

  • (String)

    The name of the Entity



14
15
16
# File 'lib/vhdl_parser/entity.rb', line 14

def name
  @name
end

#portsArray<Port> (readonly)

An array of all the Ports.

Returns:

  • (Array<Port>)

    An array of all the Ports on this entity.



6
7
8
# File 'lib/vhdl_parser/entity.rb', line 6

def ports
  @ports
end

Instance Method Details

#merge_package(package) ⇒ nil

Applies constants from a package to the entity. For example, if the Entity has an input whose size is defined with a constant, like “std_logic_vector(MY_SIZE-1 downto 0)”, and “MY_SIZE” is defined in the package, this method will evaluate the size to a real number.

Parameters:

  • Package (package)

    The package instance to merge.

Returns:

  • (nil)

    Nothing



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
# File 'lib/vhdl_parser/entity.rb', line 39

def merge_package(package)
  # TODO: do some type checking
  @generics.each do |g|
    package.constants.each do |k,v|
      unless g.value.nil?
        g.value = Utility.sub_constants(g.value, k, v)
      end

      unless g.left.nil?
        g.left = Utility.sub_constants(g.left, k, v)
      end

      unless g.right.nil?
        g.right = Utility.sub_constants(g.right, k, v)
      end
    end
    nil
  end

  @ports.each do |p|
    package.constants.each do |k,v|
      unless p.left.nil?
        p.left = Utility.sub_constants(p.left, k, v)
      end

      unless p.right.nil?
        p.right = Utility.sub_constants(p.right, k, v)
      end
    end
  end
end

#to_sObject



23
24
25
26
27
28
29
# File 'lib/vhdl_parser/entity.rb', line 23

def to_s
  out = name + "\n"
  @generics.each { |p| out += "\t" + p.to_s}
  out += "\n\n"
  @ports.each { |p| out += "\t" + p.to_s}
  out
end