Class: IPXACT::Component
- Inherits:
-
Object
- Object
- IPXACT::Component
- 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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cpus ⇒ Array<Hash>
The list of cpus.
-
#hierconnections ⇒ Array<Hash>
The list of hierconnections.
-
#instance_name ⇒ String
readonly
The component’s instance name.
-
#interconnections ⇒ Array<Hash>
The list of interconnections.
-
#ipxact_id ⇒ IPXACT::Identifier
readonly
The component’s IPXACT identifier.
-
#ports ⇒ Array<Hash>
The list of ports.
-
#subcomponents ⇒ Array<Component>
The list of subcomponents.
Instance Method Summary collapse
-
#has_cpu? ⇒ Boolean
Returns true if the component has one or more cpus.
-
#initialize(instance_name, id_args) ⇒ Component
constructor
Creates a new Component instance.
-
#port(port_name) ⇒ Hash
Returns the port that matches the given name, if any.
-
#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. -
#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).
-
#rec_prepare_pathfinder_connections(current_nodes, current_interconnections) ⇒ Array<Array,Array<Hash>>
Prepares the connection structure for the GraphPathFinder class.
-
#reformat_connector(connector) ⇒ Hash
Executes the actual replacement of an hierarchical component’s outside port with the attached subcomponent port.
-
#register_map ⇒ Array
Get the component’s register map, if any.
-
#resolve_base_address(data_path, initial_value = 0) ⇒ Object
Computes a the base address of the last component instance mentionned in the
data_path
. -
#resolve_data_path(subcomponent_start, subcomponent_end) ⇒ Array<Array<Hash>>
Calculates an optimal path in the subcomponent graph between
subcomponent_start
andsubcomponent_end
.
Constructor Details
#initialize(instance_name, id_args) ⇒ Component
Creates a new IPXACT::Component instance
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
#cpus ⇒ Array<Hash>
Returns the list of cpus.
43 44 45 |
# File 'lib/ipxact/component.rb', line 43 def cpus @cpus end |
#hierconnections ⇒ Array<Hash>
Returns the list of hierconnections.
37 38 39 |
# File 'lib/ipxact/component.rb', line 37 def hierconnections @hierconnections end |
#instance_name ⇒ String (readonly)
Returns The component’s instance name.
49 50 51 |
# File 'lib/ipxact/component.rb', line 49 def instance_name @instance_name end |
#interconnections ⇒ Array<Hash>
Returns the list of interconnections.
34 35 36 |
# File 'lib/ipxact/component.rb', line 34 def interconnections @interconnections end |
#ipxact_id ⇒ IPXACT::Identifier (readonly)
Returns the component’s IPXACT identifier.
46 47 48 |
# File 'lib/ipxact/component.rb', line 46 def ipxact_id @ipxact_id end |
#ports ⇒ Array<Hash>
Returns the list of ports.
40 41 42 |
# File 'lib/ipxact/component.rb', line 40 def ports @ports end |
#subcomponents ⇒ Array<Component>
Returns 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
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.
190 191 192 |
# File 'lib/ipxact/component.rb', line 190 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.
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/ipxact/component.rb', line 202 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).
219 220 221 222 223 224 225 226 227 228 |
# File 'lib/ipxact/component.rb', line 219 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 |
#rec_prepare_pathfinder_connections(current_nodes, current_interconnections) ⇒ Array<Array,Array<Hash>>
Prepares the connection structure for the GraphPathFinder class. Traverses the hierarchy of subcomponents in order to create a flattened representation of the subcomponents graph. In particular, the method considers hierconnections, and replaces the wrapper’s interface port with the subcomponent’s port that it is attached to.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/ipxact/component.rb', line 241 def rec_prepare_pathfinder_connections(current_nodes, current_interconnections) if subcomponents.empty? [current_nodes << self.instance_name, current_interconnections] else subcomponents.each do |sub_name, subcomponent| formatted_interconnections = interconnections.values.collect do |interconnect| [reformat_connector(interconnect[0]), reformat_connector(interconnect[1])] end current_nodes, current_interconnections = \ subcomponent.rec_prepare_pathfinder_connections(current_nodes, current_interconnections + formatted_interconnections) end [current_nodes, current_interconnections] end end |
#reformat_connector(connector) ⇒ Hash
Executes the actual replacement of an hierarchical component’s outside port with the attached subcomponent port.
265 266 267 268 269 270 271 272 273 274 |
# File 'lib/ipxact/component.rb', line 265 def reformat_connector(connector) instance = subcomponents[connector[:component_instance]] if instance.subcomponents.empty? new_connector = connector else port = connector[:port_name] new_connector = instance.hierconnections[port] end new_connector end |
#register_map ⇒ Array
Get the component’s register map, if any.
174 175 176 177 178 179 180 181 |
# File 'lib/ipxact/component.rb', line 174 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 |
#resolve_base_address(data_path, initial_value = 0) ⇒ Object
Computes a the base address of the last component instance mentionned in the data_path
. The latter should be calculated using the #resolve_data_path method. Additionally, this method takes into account all subcomponents from the data_path
, and basically adds up mirrored slave ports’ remap addresses.
Returns the base address of the target component, as an Integer.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ipxact/component.rb', line 147 def resolve_base_address(data_path, initial_value = 0) base_address = initial_value data_path.each do |connection| connection.each do |connection_step| subcomponent = rec_get_subcomponent(connection_step[:component_instance]) port = subcomponent.ports \ .select{|port| port[:name] == connection_step[:port_name]} \ .first if port[:type] == :mirrored_slave && !port[:port_data].nil? base_address += port[:port_data][:remap][:address].to_i(16) end end end base_address end |
#resolve_data_path(subcomponent_start, subcomponent_end) ⇒ Array<Array<Hash>>
Calculates an optimal path in the subcomponent graph between subcomponent_start
and subcomponent_end
. This computation takes into account hierarchical subcomponents, and identifies optimal sub-paths in these elements as well, using hierconnections. This method is in fact the facade for the GraphPathFinder class. It handles the creation of the connection Hash, and translates the result in a IPXACT-specific format.
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 |
# File 'lib/ipxact/component.rb', line 101 def resolve_data_path(subcomponent_start, subcomponent_end) nodes, connections = rec_prepare_pathfinder_connections([], []) pathfinder_connections = connections.collect do |connection| { :link => [nodes.index(connection[0][:component_instance]), nodes.index(connection[1][:component_instance])], :ports => [connection[0][:port_name], connection[1][:port_name]] } end pathfinder_interconnect = {:nodes => nodes, :connections => pathfinder_connections} pathfinder = IPXACT::GraphPathFinder.new(pathfinder_interconnect) finder_result = pathfinder.resolve(subcomponent_start, subcomponent_end) formatted_result = finder_result.collect do |res| pathfinder_interconnect[:connections][res] end.collect do |connection| [ { :component_instance => pathfinder_interconnect[:nodes][connection[:link][0]], :port_name => connection[:ports][0] }, { :component_instance => pathfinder_interconnect[:nodes][connection[:link][1]], :port_name => connection[:ports][1] } ] end end |