class SOCMaker::Lib
This class represents the IP core library, which holds all
-
cores (core-definitions and SoC definitions)
-
interfaces (interface-specifications)
The cores are stored in cores_lib and the interfaces in ifc_lib. Furthermore, a path_lut is used to remmeber, which folder-path has been processed. This is necessary to avoid circular search during loading.
Public Class Methods
The constructor creates two empty hashes cores_lib and ifc_lib, and an empty list path_lut.
# File lib/soc_maker/lib.rb, line 54 def initialize # will store all cores @cores_lib = {} # will store all interfaces @ifc_lib = {} # we remember paths, which we've already processed @path_lut = [] end
Public Instance Methods
Method to add an IP-Core object (SOCMaker::CoreDef
) to this library
# File lib/soc_maker/lib.rb, line 188 def add_core( core ) # save core @cores_lib[ core.id ] = core SOCMaker::logger.info "loaded #{core.name}, id: #{core.id}" end
Method to add an IP-Core interface (SOCMaker::IfcSpc
) to this library
# File lib/soc_maker/lib.rb, line 228 def add_ifc( ifc ) @ifc_lib[ ifc.id ] = ifc end
This method clears all three attributes of this class.
# File lib/soc_maker/lib.rb, line 71 def clear @cores_lib.clear @ifc_lib.clear @path_lut.clear end
Iterates over all cores and yields the block with the id (as string) and the core.
# File lib/soc_maker/lib.rb, line 276 def cores @cores_lib.each do |id,core| yield( id.to_s, core ) end end
Method to access IP-Core objects (SOCMaker::CoreDef
) of this library
# File lib/soc_maker/lib.rb, line 198 def get_core( id ) tmp = @cores_lib[ id ] processing_error "Core with id '#{id}' does not exist" if !tmp return tmp end
Method to access an IP-Core interface (SOCMaker::IfcSpc
) of this library
# File lib/soc_maker/lib.rb, line 235 def get_ifc( id ) tmp = @ifc_lib[ id ] processing_error "Interface with id '#{id}' does not exist" if !tmp return tmp end
This method processes a directory, which needs to be included into the search: It uses the method get_all_yaml_in_str
to read all *.yaml files and processes each yaml-object. If there is a SOCMaker::LibInc
object, all entries of this object are further processed with this method (recursively, see add_include
).
dir
-
the directory path, which is processed
# File lib/soc_maker/lib.rb, line 126 def process_include( dir ) # # this prevents the revursive call # from an infinite call # folder_sym = File.expand_path( dir ).to_sym init_error_if @path_lut.include?( folder_sym ), "double-include: infinite resursive search?" @path_lut << folder_sym # get all yaml files in the directory SOCMaker::logger.info "search for include in: " + dir SOCMaker::from_s( get_all_yaml_in_str( dir ) ) do |o| o.src_dir = dir case o when SOCMaker::LibInc add_include( o, dir ) when SOCMaker::SOCDef add_core( o ) when SOCMaker::CoreDef add_core( o ) when SOCMaker::IfcSpc add_ifc( o ) else raise SOCMaker::ERR::InitError.new( "Can't load object", object: o ) end end end
Method to refresh / load the core library: it useses the global configuration entry cores_search_path, which defines, where to search for inc_fname (defined in SOCMaker::Conf
) files.
Before start searching, clear is called to clear the library.
For each directory, we call process_include. The method process_include
takes care of proessing everything else recursively.
paths
-
eiter a single path (as String) or multiple paths (as Array of strings)
# File lib/soc_maker/lib.rb, line 91 def refresh( paths = nil ) paths = [ paths ] if paths.is_a?( String ) SOCMaker::logger.info "START REFRESHING CORE LIBRARY" # clear the libs clear # use argument if given, otherwise config paths paths ||= SOCMaker::conf[ :cores_search_path ] paths.each do |dir| process_include dir end SOCMaker::logger.info "DONE REFRESHING CORE LIBRARY" end
Method to remove IP-Core objects (SOCMaker::CoreDef
) from this library
# File lib/soc_maker/lib.rb, line 207 def rm_core( arg ) if arg.is_a?( Symbol ) processing_error "Core with id '#{arg}' does not exist" if !@cores_lib[ arg ] @cores_lib.delete( arg ) elsif arg.is_a?( SOCMaker::CoreDef ) processing_error "Core with id '#{arg.id}' does not exist" if !@cores_lib[ arg.id ] @cores_lib.delete( arg.id ) else raise SOCMaker::ERR::ProcessingError.new( "", "Can't remove core" ) end end
Method to remove an IP-Core interface (SOCMaker::IfcSpc
) from this library
# File lib/soc_maker/lib.rb, line 244 def rm_ifc( arg ) if arg.is_a?( Symbol ) processing_error "Interface with id '#{arg}' does not exist" if !@ifc_lib[ arg ] @ifc_lib.delete( arg ) elsif arg.is_a?( SOCMaker::IfcSpc ) processing_error "Interface with id '#{arg.id}' does not exist" if !@ifc_lib[ arg.id ] @ifc_lib.delete( arg.id ) else raise SOCMaker::ERR::ProcessingError.new( "", "Can't remove interface" ) end end
Function to represent this library as string: A list of IP-cores and interfaces is returned as string
# File lib/soc_maker/lib.rb, line 264 def to_s "IP-Core - lib: \n" + @cores_lib.keys.to_s + "\n\nIP-Interfaces - lib: \n" + @ifc_lib.keys.to_s end
Private Instance Methods
gets an SOCMaker::LibInc
object and iterates over all folders. Note: this is moved from process_include
to this extra function to support test capability
# File lib/soc_maker/lib.rb, line 180 def add_include( soc_inc_object, dir ) soc_inc_object.dirs.each { |d| process_include( File.expand_path( File.join( dir, d ) ) ) } end
Search for all *.yaml files and concatenate them.
result
-
the resulting string
# File lib/soc_maker/lib.rb, line 165 def get_all_yaml_in_str( dir ) yaml_str = "" Dir[ File.join( dir, "*.yaml" ) ].sort.each do |yaml_file| SOCMaker::logger.info "reading:" + yaml_file yaml_str << File.read( yaml_file ) end return yaml_str end