class SOCMaker::SParameter
A small classes, used to group information and to verify, auto-correct and auto-complete this information: This class represents a static parameter, which is only defined once within a system. Usually, these static parameters are mapped into a vhdl package or verilog include file. The following fields are defined:
-
path
(of the file, which is used as input) -
file_dst
(output file destination) -
parameters
(hash ofSParameterEntry
values)
At the moment, the token within the value of the parameter-hash is used as regular expression to replace this token in the input file by the key of the parameter-hash, and write the result to the destination file.
Attributes
Path of the destination file
Hash of SParameterEntry
, each entry represents a parameter
Path of the file, which is used as input
Public Class Methods
This constructor expects the source file path, the destination file path. The paremters can be passed as optional arguments.
path
-
source file path
file_dst
-
destination file path
# File lib/soc_maker/sparameter.rb, line 79 def initialize( path, file_dst, optional = {} ) init_with( { 'path' => path, 'file_dst' => file_dst }.merge( optional ) ) end
Public Instance Methods
Equality operator
# File lib/soc_maker/sparameter.rb, line 210 def ==(o) o.class == self.class && o.parameters == self.parameters && o.file_dst == self.file_dst && o.path == self.path end
Deployment function. It takes the source file from core_dir, iterates over all parameters and checks, if the parameter is in avaliable in param. If not, the default value is taken. all parameters are added to the source file and the result is saved in dst_dir.
param
-
A parameter hash, like { :name => value }
core_dir:+
The core source directory, where the parameter source file is located
dst_dir
-
The destination directory, where the result is saved. This dir. must exist.
# File lib/soc_maker/sparameter.rb, line 156 def deploy( param, core_dir, dst_dir ) token_val_map = {} @parameters.each do |param_name,sparam_entry| if param != nil and param[ param_name ] != nil # use value defined in soc-spec tmp = param[ param_name ] else # use default value from core-spec tmp = sparam_entry.default end if sparam_entry.type == "enum" token_val_map[ sparam_entry.token ] = sparam_entry.choice[ tmp.to_i ] elsif sparam_entry.type == "bool" if tmp == true token_val_map[ sparam_entry.token ] = sparam_entry.choice else token_val_map[ sparam_entry.token ] = "" end else token_val_map[ sparam_entry.token ] = tmp end end # create file paths src_path = File.join( core_dir, @path ) #dst_dir = CoreDef::get_and_ensure_dst_dir!( dir_name ) dst_path = File.join( dst_dir, @file_dst ) # process each line of input file # and replace tokens by value via # regular expression File.open( dst_path, 'w' ) do |dst_f| File.open( src_path ) do |src_f| SOCMaker::logger.proc( "create #{dst_path} from #{ src_path} " ) while line = src_f.gets token_val_map.each { |token, val| line = line.sub( Regexp.new( token.to_s ), val.to_s ) } dst_f.puts line end end end end
Encoder method (to yaml)
coder
-
An instance of the Psych::Coder to encode this class to a YAML file
# File lib/soc_maker/sparameter.rb, line 89 def encode_with( coder ) init_error_if !coder.is_a?( Psych::Coder ), 'coder is not given as Psych::Coder' %w[ path file_dst parameters ]. each { |v| coder[ v ] = instance_variable_get "@#{v}" } end
Initialization method (from yaml)
coder
-
An instance of the Psych::Coder to init this class from a YAML file
# File lib/soc_maker/sparameter.rb, line 102 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' # path init_error 'no file path specified for static parameter', field: 'path' if coder[ 'path' ] == nil @path = coder[ 'path' ] init_error 'file path specified for static parameter is not of type string', field: 'path' if !@path.is_a?( String ) init_error 'file path specified for static parameter has zero length', field: 'path' if @path.size == 0 # file_dst (file-destination) init_error 'no destination file directory given for static parameter', instance: @path, field: 'file_dst' if coder[ 'file_dst' ] == nil @file_dst = coder[ 'file_dst' ] init_error 'destination file directory given for static parameter is not of type string', instance: @path, field: 'file_dst' if !@file_dst.is_a?( String ) init_error 'file path specified for static parameter has zero length', field: 'path' if @file_dst.size == 0 @parameters = coder[ 'parameters' ] || {} @parameters.each do |name, param| init_error 'Static parameter entry not defined', instance: name if param == nil init_error 'Static parameter entry not SOCMaker::SParameterEntry (use SOCM_SENTRY)', instance: name if !param.is_a?( SOCMaker::SParameterEntry ) end end