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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [lib.rb] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      spc_lib.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#     This class represents the library, which holds all
37
#       - cores (core-definitions)
38
#       - interfaces (interface-specifications)
39
#
40
#
41
####
42
#
43
#
44
#
45
###############################################################
46
 
47
module SOCMaker
48
class Lib
49 7 feddischso
  include ERR
50 3 feddischso
 
51
  def initialize
52
 
53
    # will store all cores
54
    @cores_lib      = {}
55
 
56
    # will store all interfaces
57
    @ifc_lib      = {}
58
 
59
    # we remember paths, which we've already processed
60
    @path_lut = []
61
 
62
  end
63
 
64
 
65
  def clear
66
    @cores_lib.clear
67
    @ifc_lib.clear
68
    @path_lut.clear
69
  end
70
 
71
 
72
  # refreshes the core library:
73
  # it useses the global configuration entry cores_search_path,
74
  # which defines, where to search for inc_fname (defined in soc_maker_conf.rb) files.
75
  # For each directory, we call process_include
76
  def refresh( paths = nil )
77
 
78
    paths = [ paths ] if paths.is_a?( String )
79
 
80
 
81
    SOCMaker::logger.info  "START REFRESHING CORE LIBRARY"
82
 
83
    # clear the libs
84
    clear
85
 
86
    # use argument if given, otherwise config paths
87
    paths ||= SOCMaker::conf[ :cores_search_path ]
88
 
89
 
90
    paths.each do |dir|
91
      process_include dir
92
    end
93
    SOCMaker::logger.info  "DONE REFRESHING CORE LIBRARY"
94
 
95
  end
96
 
97
 
98
 
99
  def process_include( dir )
100
 
101
    #
102
    # this prevents the revursive call
103
    # from an infinite call
104
    #
105
    folder_sym = File.expand_path( dir ).to_sym
106 7 feddischso
    lerr_if( @path_lut.include?( folder_sym ),
107
        "double-include: infinite resursive search?" )
108
    @path_lut << folder_sym
109 3 feddischso
 
110
    # get all yaml files in the directory
111
    SOCMaker::logger.info  "search for include in: " + dir
112
 
113
 
114
    SOCMaker::from_s( get_all_yaml_in_str( dir ) ) do |o|
115
      o.dir = dir
116
      case o
117
      when SOCMaker::LibInc
118
        add_include( o, dir )
119
      when SOCMaker::CoreDef
120
        add_core( o )
121
      when SOCMaker::SOCDef
122
        add_core( o )
123
      when SOCMaker::IfcSpc
124
        add_ifc( o )
125
      else
126
        #TODO add error
127
      end
128
    end
129
 
130
  end
131
 
132
 
133
 
134
  def get_all_yaml_in_str( dir )
135
    yaml_str = ""
136
    Dir[ File.join( dir, "*.yaml" ) ].sort.each do |yaml_file|
137
      SOCMaker::logger.info "reading:" + yaml_file
138
      yaml_str << File.read( yaml_file )
139
    end
140
    return yaml_str
141
  end
142
 
143
 
144
 
145
  # gets an SOCMaker::LibInc object and iterates
146
  # over all folders.
147
  # Note: this is moved from process_include to this extra function
148
  # to support test capability
149
  def add_include( soc_inc_object, dir )
150
    soc_inc_object.dirs.each { |d| process_include( File.expand_path( File.join( dir, d ) ) ) }
151
  end
152
 
153
  def add_core( core )
154
    # save core
155 10 feddischso
    @cores_lib[ core.id ] = core
156 3 feddischso
 
157
    SOCMaker::logger.info  "loaded "     +
158
                            core.name     +
159 10 feddischso
                            ", id =  "   +
160
                            core.id
161 3 feddischso
  end
162 10 feddischso
 
163
  def get_core( id )
164
    tmp = @cores_lib[ id ]
165
    check_nil( tmp, "Core with id '#{id}' does not exist" )
166 3 feddischso
    return tmp
167
  end
168 10 feddischso
 
169
  def rm_core( arg )
170
 
171
    if arg.is_a?( String )
172
      check_nil( @cores_lib[ arg ], "Core with id '#{arg}' does not exist" )
173
      @cores_lib.delete( arg )
174
 
175
    elsif arg.is_a?( SOCMaker::CoreDef )
176
      check_nil( @cores_lib[ arg.id ], "Core with id '#{arg.id}' does not exist" )
177
      @cores_lib.delete( arg.id )
178
 
179
    else
180
      raise SOCMaker::ERR::LibError.new( "", "FATAL: Can't remove interface" )
181
    end
182 3 feddischso
  end
183
 
184
 
185 10 feddischso
 
186
 
187 3 feddischso
  def add_ifc( ifc )
188 10 feddischso
    @ifc_lib[ ifc.id ] = ifc
189 3 feddischso
  end
190 10 feddischso
 
191
  def get_ifc( id )
192
    tmp = @ifc_lib[ id ]
193
    check_nil( tmp, "Interface with id '#{id}' does not exist" )
194 3 feddischso
    return tmp
195
  end
196 10 feddischso
 
197
  def rm_ifc( arg )
198
 
199
    if arg.is_a?( String )
200
      check_nil( @ifc_lib[ arg ],
201
            "Interface with id '#{arg}' does not exist" )
202
      @ifc_lib.delete( arg )
203
 
204
    elsif arg.is_a?( SOCMaker::IfcSpc )
205
      check_nil( @ifc_lib[ arg.id ],
206
            "Interface with id '#{arg.id}' does not exist" )
207
      @ifc_lib.delete( arg.id )
208
 
209
    else
210
      raise SOCMaker::ERR::LibError.new( "", "FATAL: Can't remove interface" )
211
    end
212
 
213 3 feddischso
  end
214
 
215
  def to_s
216
      "IP-Core - lib: \n"             +
217
      @cores_lib.keys.to_s            +
218 10 feddischso
      "\n\nIP-Interfaces - lib: \n"    +
219
      @ifc_lib.keys.to_s
220 3 feddischso
  end
221
 
222
 
223
 
224
  def check_nil( var, error_msg = "")
225
    if var == nil
226
      SOCMaker::logger.error error_msg
227
      raise SOCMaker::ERR::LibError.new( "", error_msg )
228
    end
229
  end
230
 
231
 
232
 
233
  #
234
  # get all interfaces in a list
235
  #
236
  # TODO untested: do we need this?
237 10 feddischso
# def get_ifcs( core )
238
#   ifc_list = [];
239
#   core.interfaces.values.each do |ifc; ifc_tmp|
240
#     ifc_tmp = get_ifc( ifc[ :name ], ifc[ :version ] )
241
#
242
#     # error handling
243
#     if ifc_tmp == nil
244
#       SOCMaker::logger.error  "Can't find #{ifc[ :name ]} version #{ifc[ :version ]} in SOC library"
245
#       raise NameError, "Can't find #{ifc[ :name ]} version #{ifc[ :version ]} in SOC library"
246
#     end
247
#
248
#     # add interface to list
249
#     ifc_list << ifc_tmp
250
#   end
251
#   return ifc_list
252
# end
253 3 feddischso
 
254
 
255 5 feddischso
  #
256
  # TODO add test code
257
  #
258
  def cores
259 10 feddischso
    @cores_lib.each do |id,core|
260
      yield( id.to_s, core )
261 5 feddischso
    end
262
  end
263 3 feddischso
 
264
 
265
end #class Lib
266
end #Module SOCMaker
267
 
268
#
269
# vim: noai:ts=2:sw=2

powered by: WebSVN 2.1.0

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