Class: IPXACT::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/ipxact/component.rb

Overview

Component is what an Platform is essentially made of. This class defines 6 attributes: (#instance_name}, #cpus, #subcomponents, #interconnections, #hierconnections and #ports. While interconnections, hierconnections and ports are mostly used by the GraphPathFinder class, the subcomponents are what most users will be querying. Subcomponents may be terminal or non-terminal, i.e. composed of other subcomponents. Finally, #cpus simply corresponds to the list of cpus the component is doted with.

Author:

  • Guillaume Godet-Bar

Direct Known Subclasses

Platform

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_name, id_args) ⇒ Component

Creates a new IPXACT::Component instance

Parameters:

  • instance_name (String)

    The name that will be used for identifying this specific component instance component.

  • id_args

    The component’s identifier. Can be either a Hash or an Identifier



58
59
60
61
62
63
64
65
# File 'lib/ipxact/component.rb', line 58

def initialize(instance_name, id_args)
  @subcomponents = {}
  @interconnections = {}
  @hierconnections = {}
  @ports = []
  @ipxact_id = id_args.is_a?(Hash) ? IPXACT::Identifier.new(id_args) : id_args
  @instance_name = instance_name
end

Instance Attribute Details

#cpusArray<Hash>

Returns the list of cpus.

Returns:

  • (Array<Hash>)

    the list of cpus



43
44
45
# File 'lib/ipxact/component.rb', line 43

def cpus
  @cpus
end

#hierconnectionsArray<Hash>

Returns the list of hierconnections.

Returns:

  • (Array<Hash>)

    the list of hierconnections



37
38
39
# File 'lib/ipxact/component.rb', line 37

def hierconnections
  @hierconnections
end

#instance_nameString (readonly)

Returns The component’s instance name.

Returns:

  • (String)

    The component’s instance name



49
50
51
# File 'lib/ipxact/component.rb', line 49

def instance_name
  @instance_name
end

#interconnectionsArray<Hash>

Returns the list of interconnections.

Returns:

  • (Array<Hash>)

    the list of interconnections



34
35
36
# File 'lib/ipxact/component.rb', line 34

def interconnections
  @interconnections
end

#ipxact_idIPXACT::Identifier (readonly)

Returns the component’s IPXACT identifier.

Returns:



46
47
48
# File 'lib/ipxact/component.rb', line 46

def ipxact_id
  @ipxact_id
end

#portsArray<Hash>

Returns the list of ports.

Returns:

  • (Array<Hash>)

    the list of ports



40
41
42
# File 'lib/ipxact/component.rb', line 40

def ports
  @ports
end

#subcomponentsArray<Component>

Returns the list of subcomponents.

Returns:

  • (Array<Component>)

    the list of subcomponents



31
32
33
# File 'lib/ipxact/component.rb', line 31

def subcomponents
  @subcomponents
end

Instance Method Details

#has_cpu?Boolean

Returns true if the component has one or more cpus

Returns:

  • (Boolean)


71
72
73
# File 'lib/ipxact/component.rb', line 71

def has_cpu?
  !(self.cpus.nil? || self.cpus.empty?)
end

#port(port_name) ⇒ Hash

Returns the port that matches the given name, if any.

Parameters:

  • port_name (String)

    The name of the port to search for

Returns:

  • (Hash)

    nil if no port could be found, or else a Hash that with the port’s data.



103
104
105
# File 'lib/ipxact/component.rb', line 103

def port(port_name)
  ports.detect{|p| p[:name] == port_name}
end

#rec_get_subcomponent(instance_name) ⇒ Component

Commodity method for getting a component instance called instance_name, either from the direct subcomponents of the component, or from the subcomponents hierarchy.

Parameters:

  • instance_name (String)

    the name of the subcomponent instance.

Returns:

  • (Component)

    the subcomponent instance or nil if none could be found.



115
116
117
118
119
120
121
122
123
124
# File 'lib/ipxact/component.rb', line 115

def rec_get_subcomponent(instance_name)
  if subcomponents.has_key?(instance_name)
    subcomponents[instance_name]
  elsif subcomponents.empty?
    nil
  else
    subcomponents.collect{|sub_name, sub| sub.rec_get_subcomponent(instance_name)} \
                 .compact.first
  end
end

#rec_get_subcomponents(current_list = []) ⇒ Array<Component>

Commodity method for recursively getting all the subcomponents of the current component (except complex components, i.e. components that themselves have subcomponents).

Returns:

  • (Array<Component>)

    the current component’s subcomponents



132
133
134
135
136
137
138
139
140
141
# File 'lib/ipxact/component.rb', line 132

def rec_get_subcomponents(current_list = [])
  subcomponents.each do |s|
    if s[1].subcomponents.empty?
      current_list << s
    else
      s[1].rec_get_subcomponents(current_list)
    end
  end
  current_list
end

#register_mapArray

Get the component’s register map, if any.

Returns:

  • (Array)

    nil if no register map could be found, or else an Array of registers (Hash) structured as follows: :name the register’s name; :offset the register’s offset (from the memory map’s base address, expressed as a hex String value); :size the register’s size (in bits, expressed as a String); :access the register’s access (read-write, read-only, write-only etc.), expressed as a String.



87
88
89
90
91
92
93
94
# File 'lib/ipxact/component.rb', line 87

def register_map
  return nil \
    unless ports.any?{|port| port[:type] == :slave} ||
           ports.any?{|port| port[:port_data][:registers]}

    ports.select{|port| port[:type] == :slave && port[:port_data][:registers]} \
         .first[:port_data][:registers]
end