###############################################################
|
###############################################################
|
#
|
#
|
# File: sparameter.rb
|
# File: sparameter.rb
|
#
|
#
|
# Author: Christian Hättich
|
# Author: Christian Hättich
|
#
|
#
|
# Project: System-On-Chip Maker
|
# Project: System-On-Chip Maker
|
#
|
#
|
# Target: Linux / Windows / Mac
|
# Target: Linux / Windows / Mac
|
#
|
#
|
# Language: ruby
|
# Language: ruby
|
#
|
#
|
#
|
#
|
###############################################################
|
###############################################################
|
#
|
#
|
#
|
#
|
# Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
|
# Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
|
#
|
#
|
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with this program. If not, see .
|
# along with this program. If not, see .
|
#
|
#
|
#
|
#
|
###############################################################
|
###############################################################
|
#
|
#
|
# Description:
|
# Description:
|
#
|
#
|
# A small classes, used to group information
|
# A small classes, used to group information
|
# and to verify, auto-correct and auto-complete
|
# and to verify, auto-correct and auto-complete
|
# this information:
|
# this information:
|
# This class represents a static parameter, which is
|
# This class represents a static parameter, which is
|
# only defined once within a system. Usually, these
|
# only defined once within a system. Usually, these
|
# static parameters are mapped into a vhdl package or
|
# static parameters are mapped into a vhdl package or
|
# verilog include file.
|
# verilog include file.
|
# The following fields are defined:
|
# The following fields are defined:
|
# - path (of the file, which is used as input)
|
# - path (of the file, which is used as input)
|
# - file_dst (output file destination)
|
# - file_dst (output file destination)
|
# - parameters (hash of SParameterEntry values)
|
# - parameters (hash of SParameterEntry values)
|
# At the moment, the token within the value of the parameter-hash
|
# At the moment, the token within the value of the parameter-hash
|
# is used as regular expression to replace this token
|
# is used as regular expression to replace this token
|
# in the input file by the key of the parameter-hash, and
|
# in the input file by the key of the parameter-hash, and
|
# write the result to the destination file.
|
# write the result to the destination file.
|
#
|
#
|
###############################################################
|
###############################################################
|
|
|
|
|
module SOCMaker
|
module SOCMaker
|
class SParameter
|
class SParameter
|
include ERR
|
include ERR
|
attr_accessor :path
|
attr_accessor :path
|
attr_accessor :file_dst
|
attr_accessor :file_dst
|
attr_accessor :parameters
|
attr_accessor :parameters
|
|
|
def initialize( path, file_dst, options = {} )
|
def initialize( path, file_dst, optional = {} )
|
init_with( { 'path' => path,
|
init_with( { 'path' => path,
|
'file_dst' => file_dst }.merge( options ) )
|
'file_dst' => file_dst }.merge( optional ) )
|
end
|
end
|
def encode_with( coder )
|
def encode_with( coder )
|
%w[ path file_dst parameters ].
|
%w[ path file_dst parameters ].
|
each { |v| coder[ v ] = instance_variable_get "@#{v}" }
|
each { |v| coder[ v ] = instance_variable_get "@#{v}" }
|
end
|
end
|
def init_with( coder )
|
def init_with( coder )
|
|
|
# path
|
# path
|
serr_if( coder[ 'path' ] == nil,
|
serr_if( coder[ 'path' ] == nil,
|
'no file path specified for static parameter',
|
'no file path specified for static parameter',
|
field: 'path' )
|
field: 'path' )
|
@path = coder[ 'path' ]
|
@path = coder[ 'path' ]
|
verr_if( !@path.is_a?( String ),
|
verr_if( !@path.is_a?( String ),
|
'file path specified for static parameter is not of type string',
|
'file path specified for static parameter is not of type string',
|
field: 'path' )
|
field: 'path' )
|
verr_if( @path.size == 0,
|
verr_if( @path.size == 0,
|
'file path specified for static parameter has zero length',
|
'file path specified for static parameter has zero length',
|
field: 'path' )
|
field: 'path' )
|
|
|
|
|
# file_dst (file-destination)
|
# file_dst (file-destination)
|
serr_if( coder[ 'file_dst' ] == nil,
|
serr_if( coder[ 'file_dst' ] == nil,
|
'no destination file directory given for static parameter',
|
'no destination file directory given for static parameter',
|
instance: @path,
|
instance: @path,
|
field: 'file_dst' )
|
field: 'file_dst' )
|
@file_dst = coder[ 'file_dst' ]
|
@file_dst = coder[ 'file_dst' ]
|
verr_if( !@file_dst.is_a?( String ),
|
verr_if( !@file_dst.is_a?( String ),
|
'destination file directory given for static parameter is not of type string',
|
'destination file directory given for static parameter is not of type string',
|
instance: @path,
|
instance: @path,
|
field: 'file_dst' )
|
field: 'file_dst' )
|
verr_if( @file_dst.size == 0,
|
verr_if( @file_dst.size == 0,
|
'file path specified for static parameter has zero length',
|
'file path specified for static parameter has zero length',
|
field: 'path' )
|
field: 'path' )
|
|
|
|
|
@parameters = coder[ 'parameters' ] || {}
|
@parameters = coder[ 'parameters' ] || {}
|
@parameters.each do |name, param|
|
@parameters.each do |name, param|
|
serr_if( param == nil,
|
serr_if( param == nil,
|
'Static parameter entry not defined',
|
'Static parameter entry not defined',
|
instance: name.to_s )
|
instance: name.to_s )
|
|
|
serr_if( !param.is_a?( SOCMaker::SParameterEntry ),
|
serr_if( !param.is_a?( SOCMaker::SParameterEntry ),
|
'Static parameter entry not SOCMaker::SParameterEntry (use SOCM_SENTRY)',
|
'Static parameter entry not SOCMaker::SParameterEntry (use SOCM_SENTRY)',
|
instance: name.to_s )
|
instance: name.to_s )
|
end
|
end
|
|
|
end
|
end
|
|
|
|
|
|
|
def ==(o)
|
def ==(o)
|
o.class == self.class &&
|
o.class == self.class &&
|
o.parameters == self.parameters &&
|
o.parameters == self.parameters &&
|
o.file_dst == self.file_dst &&
|
o.file_dst == self.file_dst &&
|
o.path == self.path
|
o.path == self.path
|
end
|
end
|
|
|
|
|
|
|
end
|
end
|
class SParameterEntry < Parameter
|
class SParameterEntry < Parameter
|
attr_accessor :token
|
attr_accessor :token
|
|
|
def initialize( type, token, options = {} )
|
def initialize( type, token, optional = {} )
|
init_with( { 'type' => type,
|
init_with( { 'type' => type,
|
'token' => token }.merge( options ) )
|
'token' => token }.merge( optional ) )
|
|
|
end
|
end
|
def encode_with( coder )
|
def encode_with( coder )
|
super coder
|
super coder
|
coder[ 'token' ] = @token
|
coder[ 'token' ] = @token
|
end
|
end
|
def init_with( coder )
|
def init_with( coder )
|
super coder
|
super coder
|
|
|
serr_if( coder[ 'token' ] == nil,
|
serr_if( coder[ 'token' ] == nil,
|
'no token specified',
|
'no token specified',
|
field: token)
|
field: token)
|
@token = coder[ 'token' ]
|
@token = coder[ 'token' ]
|
verr_if( !@token.is_a?( String ), 'token is not a string' )
|
verr_if( !@token.is_a?( String ), 'token is not a string' )
|
verr_if( @token.size == 0, 'token has zero size' )
|
verr_if( @token.size == 0, 'token has zero size' )
|
end
|
end
|
|
|
def ==(o)
|
def ==(o)
|
o.class == self.class &&
|
o.class == self.class &&
|
o.token == self.token &&
|
o.token == self.token &&
|
super( o )
|
super( o )
|
end
|
end
|
|
|
|
|
end
|
end
|
end
|
end
|
|
|
|
|
# vim: noai:ts=2:sw=2
|
# vim: noai:ts=2:sw=2
|
|
|