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

Subversion Repositories soc_maker

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

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

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      core_inst.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 a core instantiation within
37
#     a SOC. It contains a params (parameters) hash,
38
#     which defines, which parameters are set to which values.
39
#     The type field is used to identify the SOCMaker::CoreDef
40
#     and the field @defn is initialized as reference to
41
#     the corresponding CoreDef instance.
42
#
43
#
44
###############################################################
45
 
46
 
47
module SOCMaker
48
class CoreInst
49
  include ERR
50
 
51
 
52
 
53
  attr_accessor :defn
54
  attr_accessor :type
55
  attr_accessor :params
56
 
57
  def initialize(  type, params = {} )
58
    init_with(  'type'   => type,
59
                'params' => params  )
60
    verify
61
  end
62
  def encode_with( coder )
63
    %w[ type params ].
64
      each { |v| coder[ v ] = instance_variable_get "@#{v}" }
65
  end
66
 
67
  def init_with( coder )
68
 
69
    serr_if( coder[ 'type' ] == nil,
70
      "no type is provided for a core instance",
71
      field: "type" )
72
 
73
    @type = coder[ 'type' ]
74
 
75
    @params = coder[ 'params' ] || {}
76
    serr_if( !@params.is_a?( Hash ), 'Parameters are not given as hash',
77
      field: 'params' )
78
 
79
  end
80
 
81
  #
82
  # TODO: extract the HDL ports
83
  #
84
  # HDLParam = Struct.new( :value, :type )
85
  # HDLPort  = Struct.new( :len, :dir )
86
  def ports
87
    @ports.each_with_index do |(name, port_def), i|
88
      yield( name.to_s, port_def[ :len ], port_def[ :dir ], i==@ports.size-1 )
89
    end
90
  end
91
 
92
 
93
  def generics
94
    @defn.generics do |name, type, default_value, is_last|
95
      value = @params[ name.to_sym ];
96
      value = value
97
      value = default_value if value == nil
98
      yield( name.to_s, type, value, is_last )
99
    end
100
  end
101
 
102
 
103
  def get_len( ifc_name, port_spec_name )
104
 
105
 
106
    # get the port name, which we are using
107
    tmp = @defn.interfaces[ ifc_name.to_sym ].
108
        ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
109
        keys.first.to_s
110
    return @ports[ tmp.to_sym ][ :len ]
111
  end
112
 
113
  def get_port( ifc_name, port_spec_name )
114
    tmp = @defn.interfaces[ ifc_name.to_sym ].
115
        ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
116
        keys.first.to_s
117
    return [ tmp, @ports[ tmp.to_sym ] ]
118
  end
119
 
120
 
121
 
122
  def verify
123
 
124
    @defn = SOCMaker::lib.get_core( @type )
125
 
126
 
127
    # check, if the instance parameters in the core definition
128
    @params.each do |param_name, value|
129
      verr_if(  @defn.inst_parameters[ param_name ] == nil,
130
                "Parameter not found: " + param_name.to_s,
131
        field: 'params' )
132
    end
133
 
134
    ## auto-complete parameters with default values
135
    @defn.inst_parameters.each do |param_name, param|
136
 
137
      # auto-complete to default values
138
      @params[ param_name ] ||= param.default
139
    end
140
 
141
 
142
 
143
 
144
 
145
 
146
 
147
 
148
 
149
#   @_params ||= {}
150
#   if @params != nil
151
#     @params.each do |name, val|
152
#
153
#       param_type = defn.inst_parameters[ name ].type
154
#
155
#       if val.is_a? String
156
#         eval_match = SOCMaker::conf[ :eval_regex ].match( val )
157
#         #TODO error handling
158
#         if eval_match
159
#           #eval_func = eval_match.captures[0]
160
#           @_params[ name ] = { value: eval( eval_str ).to_s, type: param_type }
161
#         else
162
#           @_params[ name ] = { value: val, type: param_type }
163
#         end
164
#       else
165
#         @_params[ name ] = { value: val, type: param_type }
166
#       end
167
#     end
168
#   end
169
 
170
    @ports ||= {}
171
    @defn.ports do |port_name, port_dir, port_len, is_last |
172
      if port_len.is_a?( String )
173
        param_match = SOCMaker::conf[ :length_regex ].match( port_len )
174
 
175
        if param_match and @params[ port_len.to_sym ] != nil
176
          tmp =@params[ port_len.to_sym ]
177
          tmp = tmp.to_i if tmp.is_a?( String )
178
          @ports[ port_name.to_sym ] = { len: tmp, dir: port_dir }
179
        else
180
          SOCMaker::logger.error( "Failed to evaluate #{port_len} for port #{port_name}" )
181
        end
182
      else
183
        @ports[ port_name.to_sym ] = { len: port_len, dir: port_dir }
184
      end
185
    end
186
 
187
    lerr_if( @defn == nil, 'Core not found in lib',
188
      field:    'cores'    )
189
 
190
  end
191
 
192
 
193
 
194
 
195
  def ==(o)
196
    o.class     == self.class   &&
197
    o.type      == self.type    &&
198
    o.params    == self.params
199
  end
200
 
201
 
202
end # CoreInst
203
end # SOCMaker
204
 
205
 
206
 
207
# 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.