URL
https://opencores.org/ocsvn/soc_maker/soc_maker/trunk
Subversion Repositories soc_maker
[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [lib.rb] - Rev 7
Go to most recent revision | Compare with Previous | Blame | View Log
################################################################# File: spc_lib.rb## Author: Christian Hättich## Project: System-On-Chip Maker## Target: Linux / Windows / Mac## Language: ruby#################################################################### Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org## 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# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <http://www.gnu.org/licenses/>.################################################################### Description:# This class represents the library, which holds all# - cores (core-definitions)# - interfaces (interface-specifications)########################################################################module SOCMakerclass Libinclude ERRdef initialize# will store all cores@cores_lib = {}# will store the versions of all cores { name => { ver1, ver2, ver3 } }@cores_ver = {}# will store all interfaces@ifc_lib = {}# will store the versions of all interfaces { name => { ver1, ver2, ver3 } }@ifc_ver = {}# we remember paths, which we've already processed@path_lut = []enddef clear@cores_lib.clear@cores_ver.clear@ifc_lib.clear@ifc_ver.clear@path_lut.clearend# refreshes the core library:# it useses the global configuration entry cores_search_path,# which defines, where to search for inc_fname (defined in soc_maker_conf.rb) files.# For each directory, we call process_includedef refresh( paths = nil )paths = [ paths ] if paths.is_a?( String )SOCMaker::logger.info "START REFRESHING CORE LIBRARY"# clear the libsclear# use argument if given, otherwise config pathspaths ||= SOCMaker::conf[ :cores_search_path ]paths.each do |dir|process_include direndSOCMaker::logger.info "DONE REFRESHING CORE LIBRARY"enddef process_include( dir )## this prevents the revursive call# from an infinite call#folder_sym = File.expand_path( dir ).to_symlerr_if( @path_lut.include?( folder_sym ),"double-include: infinite resursive search?" )@path_lut << folder_sym# get all yaml files in the directorySOCMaker::logger.info "search for include in: " + dirSOCMaker::from_s( get_all_yaml_in_str( dir ) ) do |o|o.dir = dircase owhen SOCMaker::LibIncadd_include( o, dir )when SOCMaker::CoreDefadd_core( o )when SOCMaker::SOCDefadd_core( o )when SOCMaker::IfcSpcadd_ifc( o )else#TODO add errorendendenddef get_all_yaml_in_str( dir )yaml_str = ""Dir[ File.join( dir, "*.yaml" ) ].sort.each do |yaml_file|SOCMaker::logger.info "reading:" + yaml_fileyaml_str << File.read( yaml_file )endreturn yaml_strend# gets an SOCMaker::LibInc object and iterates# over all folders.# Note: this is moved from process_include to this extra function# to support test capabilitydef add_include( soc_inc_object, dir )soc_inc_object.dirs.each { |d| process_include( File.expand_path( File.join( dir, d ) ) ) }enddef add_core( core )# generate key-string from name and vesioncore_key = core.name + core.version# save core@cores_lib[ core_key ] = core@cores_ver[ core.name.to_sym ] = [] unless @cores_ver.has_key?(core.name.to_sym)@cores_ver[ core.name.to_sym ] << core.versionSOCMaker::logger.info "loaded " +core.name +" version " +core.versionenddef get_core( name, version = "" )core_key = name + versiontmp = @cores_lib[ core_key ]check_nil( tmp, "Core '#{name}' version '#{version}' does not exist" )return tmpenddef rm_core( core )core_key = core.name + core.version@cores_lib.delete( core_key )enddef add_ifc( ifc )ifc_key = ifc.name + ifc.version@ifc_lib[ ifc_key ] = ifc@ifc_ver[ ifc.name.to_sym ] = [] unless @ifc_ver.has_key?(ifc.name.to_sym)@ifc_ver[ ifc.name.to_sym ] << ifc.versionenddef get_ifc( name, version = "" )ifc_key = name + versiontmp = @ifc_lib[ ifc_key ]check_nil( tmp, "Interface '#{name}' version '#{version}' does not exist" )return tmpenddef rm_ifc( ifc )ifc_key = ifc.name + ifc.version@ifc_lib.delete( ifc_key )enddef to_s"IP-Core - lib: \n" +@cores_lib.keys.to_s +"\n\nIP-Core - versions: \n" +@cores_ver.to_s +"\n\nInterface - lib: \n" +@ifc_lib.keys.to_s +"\n\nInterface - versions: \n" +@ifc_ver.to_s + "\n"enddef check_nil( var, error_msg = "")if var == nilSOCMaker::logger.error error_msgraise SOCMaker::ERR::LibError.new( "", error_msg )endend## get all interfaces in a list## TODO untested: do we need this?def get_ifcs( core )ifc_list = [];core.interfaces.values.each do |ifc; ifc_tmp|ifc_tmp = get_ifc( ifc[ :name ], ifc[ :version ] )# error handlingif ifc_tmp == nilSOCMaker::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"end# add interface to listifc_list << ifc_tmpendreturn ifc_listend## TODO add test code#def cores@cores_lib.each do |nameversion,core|yield( nameversion.to_s, core )endendend #class Libend #Module SOCMaker## vim: noai:ts=2:sw=2
Go to most recent revision | Compare with Previous | Blame | View Log
