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

Subversion Repositories soc_maker

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      component.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 an abstract component.
37
#     It is one of the central classes and holds data,
38
#     which is used to describe and instanciate a core or SOC.
39
#
40
#     The following fields are defined and used
41
#     by CoreDef and SOCDef
42
#         - name               : name of the core  (mandatory)
43
#         - version            : version of the core  (mandatory)
44
#         - toplevel           : toplevel name (mandatory)
45
#         - description        : description of this core
46
#         - date               : creation date
47
#         - license            : license of this core
48
#         - licensefile        : location of the license file
49
#         - author             : author of this core
50
#         - authormail         : author-mail of this core
51
#         - vccmd              : a version control command, which is used
52
#                                to download the files
53
#         - interfaces         : interfaces which are implemented
54
#                                see SOCMaker::IfcSpc
55
#         - inst_parameters    : hash of instantiation parameters
56
#                                see SOCMaker::Parameter
57
#         - static_parameters  : hash of static parameters
58
#                                see SOCMaker::SParameter
59
########
60
#
61
# TODO
62
#
63
#
64
###############################################################
65
 
66
 
67
module SOCMaker
68
class Component
69
  include ERR
70
  include YAML_EXT
71
 
72
  attr_accessor :name
73
  attr_accessor :version
74
  attr_accessor :toplevel
75
  attr_accessor :description
76
  attr_accessor :date
77
  attr_accessor :license
78
  attr_accessor :licensefile
79
  attr_accessor :author
80
  attr_accessor :authormail
81
  attr_accessor :vccmd
82
  attr_accessor :interfaces
83
  attr_accessor :functions
84
  attr_accessor :inst_parameters
85
  attr_accessor :static_parameters
86
  def initialize( name, version, toplevel, options = {} )
87
    init_with( { 'name'      => name,
88
                 'version'   => version,
89
                 'toplevel'  => toplevel }.merge( options ) )
90
  end
91
  def encode_with( coder )
92
    %w[ name version description date license licensefile
93
        author authormail vccmd toplevel interfaces
94
        functions inst_parameters static_parameters ].
95
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
96
  end
97
  def init_with( coder )
98
 
99
    serr_if( coder[ 'name' ] == nil,
100
      'Name not defined',
101
      field:    'name'    )
102
    @name = coder[ 'name' ]
103
    verr_if( !@name.is_a?( String ),
104
      'The name must be of type string',
105
      field:    'name'         )
106
    serr_if( @name.size  == 0,
107
      'Name not defined (size == 0)',
108
      field:    'name'    )
109
    verr_if( !!SOCMaker::conf[ :name_regex ].match( @name ) == false,
110
         'The core name is invalid',
111
        instance: @name,
112
        field:    'name' )
113
 
114
    serr_if( coder[ 'version' ] == nil,
115
      'Version not defined',
116
      instance: @name,
117
      field:    'version' )
118
    @version = coder[ 'version' ]
119
    serr_if( @version.size == 0,
120
      'Version not defined (size == 0)',
121
      instance: @name,
122
      field:    'version' )
123
 
124
    # cast from numeric to string, if not given as string
125
    @version = @version.to_s if @version.is_a? ( Numeric )
126
    verr_if( !@version.is_a?( String ),
127
      'The name must be of type string or numeric',
128
      field:    'name'         )
129
 
130
 
131
 
132
    serr_if( coder[ 'toplevel' ] == nil,
133
      'Toplevel not defined',
134
      instance: @name,
135
      field:    'toplevel' )
136
    @toplevel = coder[ 'toplevel' ]
137
    verr_if( !@toplevel.is_a?( String ),
138
      "toplevel must be of type string",
139
      instance: @name,
140
      field:    "toplevel" )
141
    serr_if( @toplevel.size  == 0,
142
      'Toplevel not defined (size == 0 )',
143
      instance: @name,
144
      field:    'toplevel' )
145
 
146
 
147
 
148
 
149
    # set non-nil values
150
    #  -> we don't need to check for nil in the rest of the
151
    #     processing
152
    @description       = coder[ 'description'       ] || ""
153
    @date              = coder[ 'date'              ] || ""
154
    @license           = coder[ 'license'           ] || ""
155
    @licensefile       = coder[ 'licensefile'       ] || ""
156
    @author            = coder[ 'author'            ] || ""
157
    @authormail        = coder[ 'authormail'        ] || ""
158
    @vccmd             = coder[ 'vccmd'             ] || ""
159
    @interfaces        = coder[ 'interfaces'        ] || {}
160
    @functions         = coder[ 'functions'         ] || {}
161
    @inst_parameters   = coder[ 'inst_parameters'   ] || {}
162
    @static_parameters = coder[ 'static_parameters' ] || {}
163
 
164
 
165
    # ensure, that these fields are of type String
166
    %w[ description date license licensefile
167
        author authormail vccmd ].each do |n|
168
      verr_if( !instance_variable_get( '@'+n ).is_a?( String ),
169
        "#{n} must be of type String",
170
        instance: @name,
171
        field:    n )
172
    end
173
 
174
    # ensure, that these fields are of type Hash
175
    %w[ interfaces inst_parameters
176
        functions  static_parameters ].each do |n|
177
      verr_if( !instance_variable_get( '@'+n ).is_a?( Hash ),
178
        "#{n} must be of type Hash",
179
        instance: @name,
180
        field:    n )
181
    end
182
 
183
 
184
 
185
    # check interfaces
186
    @interfaces.each do |ifc_name, ifc|
187
      serr_if( ifc == nil,
188
            'Interface not defined',
189
            instance:   @name+":"+ifc_name.to_s )
190
 
191
      serr_if( !ifc.is_a?( SOCMaker::IfcDef ),
192
            'Interface definition is not SOCMaker::IfcDef (use SOCM_IFC)',
193
            instance: @name+":"+ifc_name.to_s )
194
    end
195
 
196
    # check instance parameters
197
    @inst_parameters.each do |name, param |
198
      serr_if( param == nil,
199
            'Instance parameter not defined',
200
            instance:   @name+":"+name.to_s )
201
 
202
      serr_if( !param.is_a?( SOCMaker::Parameter ),
203
            'Instance parameter not SOCMaker::Parameter (use SOCM_PARAM)',
204
            instance: @name+":"+name.to_s )
205
    end
206
 
207
    # check instance parameters
208
    @static_parameters.each do |name, sparam |
209
      serr_if( sparam == nil,
210
            'Static parameter not defined',
211
            instance:   @name+":"+name.to_s )
212
 
213
      serr_if( !sparam.is_a?( SOCMaker::SParameter ),
214
            'Static parameter not SOCMaker::Parameter (use SOCM_SPARAM)',
215
            instance: @name+":"+name.to_s )
216
    end
217
 
218
 
219
 
220
 
221
  end
222
 
223
 
224
  def get_files
225
    unless self.vccmd.nil? or self.vccmd == 0
226
      system( self.vccmd )
227
    end
228
  end
229
 
230
 
231
 
232
 
233
  def generics
234
    @inst_parameters.each_with_index do |(name, val), i|
235
      yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
236
    end
237
  end
238
 
239
 
240
  #
241
  # Iterates over interface list.
242
  # For each interface, all ports are processed.
243
  # For each port within each interface, we lookup the port defn
244
  # and yield the call block with
245
  #   - port-name
246
  #   - port-definition
247
  #   - info if last
248
  # as argument
249
  #
250
  #
251
  #
252
  def ports( *args )
253
 
254
    if args.size == 0
255
      @interfaces.values.each_with_index do | ifc, i_ifc; ifc_def|
256
 
257
        # get interface definition
258
        ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
259
 
260
        # loop over ports in this interface
261
        ifc.ports.each_with_index do |(port_name, port_def), i_port; port_dir|
262
 
263
          # the reference to the port in the definition
264
          defn_ref = port_def.defn
265
          port_dir = ifc_def.ports[ defn_ref.to_sym ]
266
          perr_if( port_dir == nil,
267
                "Can't find #{defn_ref} in interface " +
268
                "definition #{ifc_def.name} version "  +
269
                ifc_def.version + "==>>" + ifc_def.to_yaml )
270
 
271
          # An xor mechanism between port_dir and ifc=>dir is used
272
          # to determine the direction of a port, for example:
273
          #  If the interface is declared as input (1) and a port is declared as input (1)
274
          #  the resulting direction will be an output 1^1 = 0.
275
          #  But if the overall interface direction is an output (0) and a port is declared
276
          #  as input, the resulting direction will an input 0^1 = 1.
277
          # This allows to define a port-direction in the interface definition,
278
          # and toggle the directions on core-definition level.
279
 
280
          #  (name, direction, length, is_last)
281
          yield(  port_name.to_s,
282
                  port_dir ^ ifc.dir,
283
                  port_def.len,
284
                  ( (i_port == ifc.ports.size-1 ) and (i_ifc == @interfaces.size-1 ) ) )
285
        end
286
      end
287
 
288
    elsif args.size == 1
289
 
290
      # get interface (input is the name as string  )
291
      ifc = @interfaces[ args.first.to_sym  ]
292
 
293
      ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
294
      ifc.ports.each do |port_name, port_def; port_dir|
295
        port_def = port_def.defn
296
        port_dir = ifc_def.ports[ port_def.to_sym ]
297
        if port_dir == nil
298
          perr_if( port_dir==nil,
299
              "Can't find #{port_def} in" +
300
              "interface definition #{ifc_def.name} " +
301
              "version #{ifc_def.version}" )
302
        end
303
        yield(  port_def.to_s,
304
                port_name.to_s,
305
                port_dir ^ ifc.dir )
306
      end
307
 
308
    else
309
 
310
    end
311
 
312
  end
313
 
314
 
315
 
316
 
317
  def param_ok?( param_name, param_value )
318
    param = inst_parameters[ param_name.to_sym ]
319
    param = static_parameters[ param_name.to_sym ] if param == nil
320
    return false if param == nil
321
  end
322
 
323
 
324
 
325
  def verify( is_soc = false )
326
 
327
    # check interfaces
328
    @interfaces.each do |ifc_name, ifc|
329
      ifc.verify
330
    end
331
 
332
    # check instance parameters
333
    @inst_parameters.each do |name, param |
334
      param.verify
335
    end
336
 
337
    # check instance parameters
338
    @static_parameters.each do |name, sparam |
339
      sparam.verify
340
    end
341
 
342
  end
343
 
344
  def ==(o)
345
 
346
    tmp    = ( o.class   == self.class )
347
    return tmp if !tmp
348
 
349
    %w[ name version description date license licensefile
350
        author authormail vccmd toplevel interfaces
351
        functions inst_parameters static_parameters ].
352
          each do |v|
353
      return false if instance_variable_get( "@#{v}" ) != o.instance_variable_get( "@#{v}" )
354
    end
355
    return true
356
  end
357
 
358
end # class CoreDef
359
end # module SOCMaker
360
 
361
 
362
# vim: noai:ts=2:sw=2
363
 

powered by: WebSVN 2.1.0

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