###############################################################
|
###############################################################
|
#
|
#
|
# File: ifc_def.rb
|
# File: ifc_def.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:
|
# The class represents an interface definition:
|
# The class represents an interface definition:
|
# - name of the interface (mandatory)
|
# - name of the interface (mandatory)
|
# - a version (mandatory)
|
# - a id (mandatory)
|
# - a direction (mandatry)
|
# - a direction (mandatry)
|
# - ports (hash of type SOCMaker::IfcPort, mandatory)
|
# - ports (hash of type SOCMaker::IfcPort, mandatory)
|
#
|
#
|
# Note: instances of this class are used withing core-definitions.
|
# Note: instances of this class are used withing core-definitions.
|
# Different cores may use the same interface, but with a
|
# Different cores may use the same interface, but with a
|
# different naming of the ports. For this reason, the name+version
|
# different naming of the ports. For this reason, the name+id
|
# is used to identify, which interface specification (SOCMaker::IfcSpc)
|
# is used to identify, which interface specification (SOCMaker::IfcSpc)
|
# is defined. The port-hash makes the relation between the core port-naming
|
# is defined. The port-hash makes the relation between the core port-naming
|
# and the IfcSpc port-naming.
|
# and the IfcSpc port-naming.
|
|
# TODO
|
#
|
#
|
###############################################################
|
###############################################################
|
|
|
module SOCMaker
|
module SOCMaker
|
class IfcDef
|
class IfcDef
|
include ERR
|
include ERR
|
attr_accessor :name
|
attr_accessor :name
|
attr_accessor :dir
|
attr_accessor :dir
|
attr_accessor :version
|
attr_accessor :id
|
attr_accessor :ports
|
attr_accessor :ports
|
|
|
def initialize( name, version, dir, ports )
|
def initialize( name, id, dir, ports )
|
init_with( 'name' => name,
|
init_with( 'name' => name,
|
'dir' => dir,
|
'dir' => dir,
|
'version' => version,
|
'id' => id,
|
'ports' => ports )
|
'ports' => ports )
|
end
|
end
|
def encode_with( coder )
|
def encode_with( coder )
|
%w[ name dir version ports ].
|
%w[ name dir id ports ].
|
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 )
|
|
|
# name
|
# name
|
serr_if( coder[ 'name' ] == nil,
|
serr_if( coder[ 'name' ] == nil,
|
'no name defined for this interface',
|
'no name defined for this interface',
|
field: 'name' )
|
field: 'name' )
|
@name = coder[ 'name' ]
|
@name = coder[ 'name' ]
|
verr_if( !@name.is_a?( String ),
|
verr_if( !@name.is_a?( String ),
|
'Interface name is not defined as string',
|
'Interface name is not defined as string',
|
instance: @name.to_s,
|
instance: @name.to_s,
|
field: 'name' )
|
field: 'name' )
|
verr_if( @name.size == 0,
|
verr_if( @name.size == 0,
|
"Name has zero length",
|
"Name has zero length",
|
field: "name" )
|
field: "name" )
|
|
|
# version
|
# id
|
serr_if( coder[ 'version' ] == nil,
|
serr_if( coder[ 'id' ] == nil,
|
'version is not given for interface',
|
'id is not given for interface',
|
instance: @name,
|
instance: @name,
|
field: 'version' )
|
field: 'id' )
|
@version = coder[ 'version' ]
|
@id = coder[ 'id' ]
|
@version = @version.to_s if @version.is_a?( Numeric )
|
serr_if( !@id.is_a?( String ),
|
serr_if( !@version.is_a?( String ),
|
'Interface id is not defined as string',
|
'Interface version is not defined as string',
|
|
instance: @name,
|
instance: @name,
|
field: 'version' )
|
field: 'id' )
|
verr_if( @version.size == 0,
|
verr_if( @id.size == 0,
|
"Version has zero length",
|
"Version has zero length",
|
field: "name" )
|
field: "name" )
|
|
|
|
|
# ports
|
# ports
|
serr_if( coder[ 'ports' ] == nil,
|
serr_if( coder[ 'ports' ] == nil,
|
"No ports are given for interface definition",
|
"No ports are given for interface definition",
|
field: 'ports' )
|
field: 'ports' )
|
@ports = coder[ 'ports' ]
|
@ports = coder[ 'ports' ]
|
serr_if( !@ports.is_a?( Hash ) ||
|
serr_if( !@ports.is_a?( Hash ) ||
|
@ports.size == 0,
|
@ports.size == 0,
|
'no ports are given for this interface',
|
'no ports are given for this interface',
|
instance: @name,
|
instance: @name,
|
field: 'ports' )
|
field: 'ports' )
|
|
|
@ports.each do |name, port|
|
@ports.each do |name, port|
|
serr_if( port == nil, 'no port definition found',
|
serr_if( port == nil, 'no port definition found',
|
instance: @name + name.to_s,
|
instance: @name + name.to_s,
|
field: 'ports' )
|
field: 'ports' )
|
|
|
serr_if( !port.is_a?( SOCMaker::IfcPort ),
|
serr_if( !port.is_a?( SOCMaker::IfcPort ),
|
'Port is not of type SocMaker::IfcPort (use SOCM_PORT)',
|
'Port is not of type SocMaker::IfcPort (use SOCM_PORT)',
|
instance: @name + name.to_s,
|
instance: @name + name.to_s,
|
field: 'ports' )
|
field: 'ports' )
|
|
|
end
|
end
|
|
|
# direction
|
# direction
|
serr_if( coder[ 'dir' ] == nil,
|
serr_if( coder[ 'dir' ] == nil,
|
'Interface direction is not given',
|
'Interface direction is not given',
|
instance: @name,
|
instance: @name,
|
field: 'dir' )
|
field: 'dir' )
|
@dir = coder[ 'dir' ]
|
@dir = coder[ 'dir' ]
|
verr_if( @dir != 0 && @dir != 1,
|
verr_if( @dir != 0 && @dir != 1,
|
'Interface direction must be 0 or 1',
|
'Interface direction must be 0 or 1',
|
instance: @name,
|
instance: @name,
|
field: 'dir' )
|
field: 'dir' )
|
|
|
|
|
end
|
end
|
|
|
|
|
|
|
def ==(o)
|
def ==(o)
|
o.class == self.class &&
|
o.class == self.class &&
|
o.name == self.name &&
|
o.name == self.name &&
|
o.dir == self.dir &&
|
o.dir == self.dir &&
|
o.version == self.version &&
|
o.id == self.id &&
|
o.ports == self.ports
|
o.ports == self.ports
|
end
|
end
|
|
|
|
|
end # IFCDef
|
end # IFCDef
|
end # SOCMaker
|
end # SOCMaker
|
|
|