Class: SOCMaker::CoreInst
- Inherits:
-
Object
- Object
- SOCMaker::CoreInst
- Includes:
- ERR
- Defined in:
- lib/soc_maker/core_inst.rb
Overview
This class represents a core instantiation within a SOC. It contains a parameter-hash #params, which is used to define, which parameters are set to which values. The type field is used to identify the SOCMaker::CoreDef and the field @defn is initialized as reference to the corresponding CoreDef instance.
Instance Attribute Summary collapse
-
#defn ⇒ Object
The core-definition of this instance Please note: this field is initialized by the method consistence_check.
-
#params ⇒ Object
(HDL) instance parameters.
-
#type ⇒ Object
The type (core-def. id), as symbol.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Equality operator.
-
#consistence_check ⇒ Object
Runs a consistence check and creates an internal hash, which contains all evaluated ports.
-
#encode_with(coder) ⇒ Object
Encoder method (to yaml).
-
#generics ⇒ Object
Iterate over all generics and call the block with - generic-name - generic-type - the value - is-last information.
-
#init_with(coder) ⇒ Object
Initialization method (from yaml).
-
#initialize(type, params = {}) ⇒ CoreInst
constructor
Constructor: there is one mandatory attributes
type
and an optional oneparams
. -
#port(ifc_name, port_ref) ⇒ Object
Returns a port, identified by the interface and port name.
-
#port_length(ifc_name, port_ref, inst = nil) ⇒ Object
Returns the length of a port within an interface.
-
#ports(*args) ⇒ Object
Iterate over all ports and call the block with - port-name - port length - default value - is-last value.
-
#to_s ⇒ Object
Returns a string describing this instance.
Methods included from ERR
#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if
Constructor Details
#initialize(type, params = {}) ⇒ CoreInst
Constructor: there is one mandatory attributes type
and an optional one params
.
type
-
The id of the core-definition, which is instanciated
params
-
Instanciation parameters
71 72 73 74 75 |
# File 'lib/soc_maker/core_inst.rb', line 71 def initialize( type, params = {} ) init_with( 'type' => type, 'params' => params ) end |
Instance Attribute Details
#defn ⇒ Object
The core-definition of this instance Please note: this field is initialized by the method consistence_check
54 55 56 |
# File 'lib/soc_maker/core_inst.rb', line 54 def defn @defn end |
#params ⇒ Object
(HDL) instance parameters
60 61 62 |
# File 'lib/soc_maker/core_inst.rb', line 60 def params @params end |
#type ⇒ Object
The type (core-def. id), as symbol
57 58 59 |
# File 'lib/soc_maker/core_inst.rb', line 57 def type @type end |
Instance Method Details
#==(o) ⇒ Object
Equality operator
288 289 290 291 292 |
# File 'lib/soc_maker/core_inst.rb', line 288 def ==(o) o.class == self.class && o.type == self.type && o.params == self.params end |
#consistence_check ⇒ Object
Runs a consistence check and creates an internal hash, which contains all evaluated ports. Because the core-definition may contain variable port sizes, which depend on the instance, these sizes need to be evaluated. This is also done here and the result is stored in @_ifcs_evaluated.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/soc_maker/core_inst.rb', line 124 def consistence_check begin @defn = SOCMaker::lib.get_core( @type ) rescue ProcessingError => e consistence_error e. end # check, if the instance parameters are in the core definition @params.each do |param_name, value| consistence_error_if( @defn.inst_parameters[ param_name ] == nil, "Parameter not found: " + param_name.to_s, field: 'params', core_type: @defn.name ) end ## auto-complete parameters with default values @defn.inst_parameters.each do |param_name, param| # auto-complete to default values @params[ param_name ] ||= param.default end @_ifcs_evaluated ||= {} @defn.interfaces.keys.each do |ifc_name| @_ifcs_evaluated[ ifc_name ] = {} @defn.ports( ifc_name.to_s ) do |port_name, port_dir, port_len, default, spc_ref, is_last | if port_len.is_a?( String ) param_match = SOCMaker::conf[ :length_regex ].match( port_len ) if param_match and @params[ port_len.to_sym ] != nil tmp =@params[ port_len.to_sym ] tmp = tmp.to_i if tmp.is_a?( String ) @_ifcs_evaluated[ ifc_name ][ port_name.to_sym ] = { len: tmp, dir: port_dir, default: default, ref: spc_ref } else SOCMaker::logger.error( "Failed to evaluate #{port_len} for port #{port_name}" ) end else @_ifcs_evaluated[ ifc_name ][ port_name.to_sym ] = { len: port_len, dir: port_dir, default: default, ref: spc_ref } end end end @defn.consistence_check end |
#encode_with(coder) ⇒ Object
Encoder method (to yaml)
coder
-
An instance of the Psych::Coder to encode this class to a YAML file
82 83 84 85 86 87 |
# File 'lib/soc_maker/core_inst.rb', line 82 def encode_with( coder ) init_error_if !coder.is_a?( Psych::Coder ), 'coder is not given as Psych::Coder' coder[ "params" ] = @params coder[ "type" ] = @type.to_s end |
#generics ⇒ Object
Iterate over all generics and call the block with
-
generic-name
-
generic-type
-
the value
-
is-last information
219 220 221 222 223 224 225 |
# File 'lib/soc_maker/core_inst.rb', line 219 def generics @defn.generics do |name, type, default_value, is_last| value = @params[ name.to_sym ]; value = default_value if value == nil yield( name.to_s, type, value, is_last ) end end |
#init_with(coder) ⇒ Object
Initialization method (from yaml)
coder
-
An instance of the Psych::Coder to init this class from a YAML file
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/soc_maker/core_inst.rb', line 95 def init_with( coder ) init_error_if !( coder.is_a?( Hash ) || coder.is_a?( Psych::Coder ) ), 'coder is not given as Hash neither as Psych::Coder' init_error_if( !( coder[ 'type' ].is_a?( String ) || coder[ 'type' ].is_a?( Symbol ) ), "core-type error: must be defined as String or Symbol", field: type ) @type = coder[ 'type' ].to_sym @params = coder[ 'params' ] || {} init_error_if !@params.is_a?( Hash ), 'Parameters are not given as hash', field: 'params' end |
#port(ifc_name, port_ref) ⇒ Object
Returns a port, identified by the interface and port name
ifc_name
-
name of the interface
port_ref
-
name of the port
239 240 241 242 243 244 |
# File 'lib/soc_maker/core_inst.rb', line 239 def port( ifc_name, port_ref ) tmp = @defn.interfaces[ ifc_name ]. ports.select{ |key,hash| hash.spc_ref == port_ref.to_s }. keys.first return [ tmp.to_s, @_ifcs_evaluated[ ifc_name ][ tmp ] ] end |
#port_length(ifc_name, port_ref, inst = nil) ⇒ Object
Returns the length of a port within an interface. If no instance is given, we know that it is a toplevel interface. Otherwise we check for this and we do a recursive call. If this port is within a interface of a core, we pass the call to the core-definition of this instance, which knows all cores.
ifc_name
-
name of the interface
port_ref
-
name of the port
inst
-
name of the instance (optional), default is nil
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/soc_maker/core_inst.rb', line 259 def port_length( ifc_name, port_ref, inst = nil ) if inst == nil tmp = @defn.interfaces[ ifc_name ]. ports.select{ |key,hash| hash.spc_ref == port_ref.to_s }. keys return 0 if tmp.size == 0 return @_ifcs_evaluated[ ifc_name ][ tmp.first ][ :len ] if tmp.size == 1 # we ensure in SOCMaker::IfcDef that there is only one reference else if inst == @defn.toplevel.to_sym return port_length( ifc_name, port_ref ) else return @defn.port_length( ifc_name, port_ref, inst ) end end end |
#ports(*args) ⇒ Object
Iterate over all ports and call the block with
-
port-name
-
port length
-
default value
-
is-last value
If no argument is given, all ports of this instance are processed. If arguments are given, each argument is supposed to the name of a interface. All specified interfaces with all ports are processed.
args
-
Optional list of interface names
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/soc_maker/core_inst.rb', line 192 def ports( *args ) if args.size == 0 ifc_sel = @_ifcs_evaluated else ifc_sel = @_ifcs_evaluated.select{ |k,v| args.include?( k ) } end ifc_sel.values.each_with_index do |ifc, i_ifc| ifc.each_with_index do |(port_name, port_def), i_port| yield( port_name.to_s, port_def[ :dir ], port_def[ :len ], port_def[ :default ], port_def[ :ref ], i_port==ifc.size-1 && i_ifc == ifc_sel.size-1 ) end end end |
#to_s ⇒ Object
Returns a string describing this instance
280 281 282 283 |
# File 'lib/soc_maker/core_inst.rb', line 280 def to_s "type: #{type}\n" + "params: #{params}\n" end |