OpenCores
URL https://opencores.org/ocsvn/soc_maker/soc_maker/trunk

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [lib.rb] - Diff between revs 7 and 10

Show entire file | Details | Blame | View Log

Rev 7 Rev 10
Line 51... Line 51...
  def initialize
  def initialize
 
 
    # will store all cores
    # will store all cores
    @cores_lib      = {}
    @cores_lib      = {}
 
 
    # will store the versions of all cores { name => { ver1, ver2, ver3 } }
 
    @cores_ver  = {}
 
 
 
    # will store all interfaces
    # will store all interfaces
    @ifc_lib      = {}
    @ifc_lib      = {}
 
 
    # will store the versions of all interfaces { name => { ver1, ver2, ver3 } }
 
    @ifc_ver  = {}
 
 
 
 
 
    # we remember paths, which we've already processed
    # we remember paths, which we've already processed
    @path_lut = []
    @path_lut = []
 
 
  end
  end
 
 
 
 
  def clear
  def clear
    @cores_lib.clear
    @cores_lib.clear
    @cores_ver.clear
 
    @ifc_lib.clear
    @ifc_lib.clear
    @ifc_ver.clear
 
    @path_lut.clear
    @path_lut.clear
  end
  end
 
 
 
 
  # refreshes the core library:
  # refreshes the core library:
Line 158... Line 149...
  def add_include( soc_inc_object, dir )
  def add_include( soc_inc_object, dir )
    soc_inc_object.dirs.each { |d| process_include( File.expand_path( File.join( dir, d ) ) ) }
    soc_inc_object.dirs.each { |d| process_include( File.expand_path( File.join( dir, d ) ) ) }
  end
  end
 
 
  def add_core( core )
  def add_core( core )
    # generate key-string from name and vesion
 
    core_key = core.name + core.version
 
 
 
    # save core
    # save core
    @cores_lib[ core_key ] = core
    @cores_lib[ core.id ] = core
    @cores_ver[ core.name.to_sym ] = [] unless @cores_ver.has_key?(core.name.to_sym)
 
    @cores_ver[ core.name.to_sym ] << core.version
 
 
 
    SOCMaker::logger.info  "loaded "     +
    SOCMaker::logger.info  "loaded "     +
                            core.name     +
                            core.name     +
                            " version "   +
                            ", id =  "   +
                            core.version
                            core.id
  end
  end
  def get_core( name, version = "" )
 
    core_key = name + version
  def get_core( id )
    tmp = @cores_lib[ core_key ]
    tmp = @cores_lib[ id ]
    check_nil( tmp, "Core '#{name}' version '#{version}' does not exist" )
    check_nil( tmp, "Core with id '#{id}' does not exist" )
    return tmp
    return tmp
  end
  end
  def rm_core( core )
 
    core_key = core.name + core.version
  def rm_core( arg )
    @cores_lib.delete( core_key )
 
 
    if arg.is_a?( String )
 
      check_nil( @cores_lib[ arg ], "Core with id '#{arg}' does not exist" )
 
      @cores_lib.delete( arg )
 
 
 
    elsif arg.is_a?( SOCMaker::CoreDef )
 
      check_nil( @cores_lib[ arg.id ], "Core with id '#{arg.id}' does not exist" )
 
      @cores_lib.delete( arg.id )
 
 
 
    else
 
      raise SOCMaker::ERR::LibError.new( "", "FATAL: Can't remove interface" )
 
    end
  end
  end
 
 
 
 
 
 
 
 
  def add_ifc( ifc )
  def add_ifc( ifc )
    ifc_key = ifc.name + ifc.version
    @ifc_lib[ ifc.id ] = ifc
    @ifc_lib[ ifc_key         ] = ifc
  end
    @ifc_ver[ ifc.name.to_sym ] = [] unless @ifc_ver.has_key?(ifc.name.to_sym)
 
    @ifc_ver[ ifc.name.to_sym ] << ifc.version
  def get_ifc( id )
  end
    tmp = @ifc_lib[ id ]
  def get_ifc( name, version = "" )
    check_nil( tmp, "Interface with id '#{id}' does not exist" )
    ifc_key = name + version
 
    tmp = @ifc_lib[ ifc_key ]
 
    check_nil( tmp, "Interface '#{name}' version '#{version}' does not exist" )
 
    return tmp
    return tmp
  end
  end
  def rm_ifc( ifc )
 
    ifc_key = ifc.name + ifc.version
  def rm_ifc( arg )
    @ifc_lib.delete( ifc_key )
 
 
    if arg.is_a?( String )
 
      check_nil( @ifc_lib[ arg ],
 
            "Interface with id '#{arg}' does not exist" )
 
      @ifc_lib.delete( arg )
 
 
 
    elsif arg.is_a?( SOCMaker::IfcSpc )
 
      check_nil( @ifc_lib[ arg.id ],
 
            "Interface with id '#{arg.id}' does not exist" )
 
      @ifc_lib.delete( arg.id )
 
 
 
    else
 
      raise SOCMaker::ERR::LibError.new( "", "FATAL: Can't remove interface" )
 
    end
 
 
  end
  end
 
 
  def to_s
  def to_s
      "IP-Core - lib: \n"             +
      "IP-Core - lib: \n"             +
      @cores_lib.keys.to_s            +
      @cores_lib.keys.to_s            +
      "\n\nIP-Core - versions: \n"    +
      "\n\nIP-Interfaces - lib: \n"    +
      @cores_ver.to_s                 +
      @ifc_lib.keys.to_s
      "\n\nInterface - lib: \n"       +
 
      @ifc_lib.keys.to_s              +
 
      "\n\nInterface - versions: \n"  +
 
      @ifc_ver.to_s  + "\n"
 
  end
  end
 
 
 
 
 
 
  def check_nil( var, error_msg = "")
  def check_nil( var, error_msg = "")
Line 226... Line 232...
 
 
  #
  #
  # get all interfaces in a list
  # get all interfaces in a list
  #
  #
  # TODO untested: do we need this?
  # TODO untested: do we need this?
  def get_ifcs( core )
# def get_ifcs( core )
    ifc_list = [];
#   ifc_list = [];
    core.interfaces.values.each do |ifc; ifc_tmp|
#   core.interfaces.values.each do |ifc; ifc_tmp|
      ifc_tmp = get_ifc( ifc[ :name ], ifc[ :version ] )
#     ifc_tmp = get_ifc( ifc[ :name ], ifc[ :version ] )
 
#
      # error handling
#     # error handling
      if ifc_tmp == nil
#     if ifc_tmp == nil
        SOCMaker::logger.error  "Can't find #{ifc[ :name ]} version #{ifc[ :version ]} in SOC library"
#       SOCMaker::logger.error  "Can't find #{ifc[ :name ]} version #{ifc[ :version ]} in SOC library"
        raise NameError, "Can't find #{ifc[ :name ]} version #{ifc[ :version ]} in SOC library"
#       raise NameError, "Can't find #{ifc[ :name ]} version #{ifc[ :version ]} in SOC library"
      end
#     end
 
#
      # add interface to list
#     # add interface to list
      ifc_list << ifc_tmp
#     ifc_list << ifc_tmp
    end
#   end
    return ifc_list
#   return ifc_list
  end
# end
 
 
 
 
  #
  #
  # TODO add test code
  # TODO add test code
  #
  #
  def cores
  def cores
    @cores_lib.each do |nameversion,core|
    @cores_lib.each do |id,core|
      yield( nameversion.to_s, core )
      yield( id.to_s, core )
    end
    end
  end
  end
 
 
 
 
end #class Lib
end #class Lib

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.