Class: SOCMaker::Lib

Inherits:
Object
  • Object
show all
Includes:
ERR
Defined in:
lib/soc_maker/lib.rb

Overview

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.

Instance Method Summary collapse

Methods included from ERR

#consistence_error, #consistence_error_if, #init_error, #init_error_if, #processing_error, #processing_error_if

Constructor Details

#initializeLib

The constructor creates two empty hashes #cores_lib and #ifc_lib, and an empty list #path_lut.



54
55
56
57
58
59
60
61
62
63
64
65
# 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

Instance Method Details

#add_core(core) ⇒ Object

Method to add an IP-Core object (SOCMaker::CoreDef) to this library



188
189
190
191
192
193
# 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

#add_ifc(ifc) ⇒ Object

Method to add an IP-Core interface (SOCMaker::IfcSpc) to this library



228
229
230
# File 'lib/soc_maker/lib.rb', line 228

def add_ifc( ifc )
  @ifc_lib[ ifc.id ] = ifc
end

#clearObject

This method clears all three attributes of this class.



71
72
73
74
75
# File 'lib/soc_maker/lib.rb', line 71

def clear
  @cores_lib.clear
  @ifc_lib.clear
  @path_lut.clear
end

#coresObject

Iterates over all cores and yields the block with the id (as string) and the core.



276
277
278
279
280
# File 'lib/soc_maker/lib.rb', line 276

def cores
  @cores_lib.each do |id,core|
    yield( id.to_s, core )
  end
end

#get_core(id) ⇒ Object

Method to access IP-Core objects (SOCMaker::CoreDef) of this library



198
199
200
201
202
# 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

#get_ifc(id) ⇒ Object

Method to access an IP-Core interface (SOCMaker::IfcSpc) of this library



235
236
237
238
239
# 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

#process_include(dir) ⇒ Object

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



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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

#refresh(paths = nil) ⇒ Object

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)



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 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

#rm_core(arg) ⇒ Object

Method to remove IP-Core objects (SOCMaker::CoreDef) from this library



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# 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

#rm_ifc(arg) ⇒ Object

Method to remove an IP-Core interface (SOCMaker::IfcSpc) from this library



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# 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

#to_sObject

Function to represent this library as string: A list of IP-cores and interfaces is returned as string



264
265
266
267
268
269
# 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