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 5

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
  def ports
82
    @ports.each_with_index do |(name, port_def), i|
83
      yield( name.to_s, port_def[ :len ], port_def[ :dir ], i==@ports.size-1 )
84
    end
85
  end
86
 
87
 
88
  def generics
89
    @defn.generics do |name, type, default_value, is_last|
90
      value = @params[ name.to_sym ];
91
      value = value
92
      value = default_value if value == nil
93
      yield( name.to_s, type, value, is_last )
94
    end
95
  end
96
 
97
 
98
  def get_len( ifc_name, port_spec_name )
99
 
100 5 feddischso
    # get the port name, which we are using
101 3 feddischso
 
102
    tmp = @defn.interfaces[ ifc_name.to_sym ].
103
        ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
104
        keys.first.to_s
105 5 feddischso
 
106
    return tmp.size == 0 ? 0 : @ports[ tmp.to_sym ][ :len ]
107 3 feddischso
  end
108
 
109 5 feddischso
 
110
  def implements_port?( ifc_name, port_spec_name )
111
    @defn.implements_port?( ifc_name, port_spec_name )
112
  end
113
 
114 3 feddischso
  def get_port( ifc_name, port_spec_name )
115
    tmp = @defn.interfaces[ ifc_name.to_sym ].
116
        ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
117
        keys.first.to_s
118
    return [ tmp, @ports[ tmp.to_sym ] ]
119
  end
120
 
121
 
122
 
123
  def verify
124
 
125
    @defn = SOCMaker::lib.get_core( @type )
126
 
127
 
128
    # check, if the instance parameters in the core definition
129
    @params.each do |param_name, value|
130
      verr_if(  @defn.inst_parameters[ param_name ] == nil,
131
                "Parameter not found: " + param_name.to_s,
132
        field: 'params' )
133
    end
134
 
135
    ## auto-complete parameters with default values
136
    @defn.inst_parameters.each do |param_name, param|
137
 
138
      # auto-complete to default values
139
      @params[ param_name ] ||= param.default
140
    end
141
 
142
 
143
 
144
 
145
 
146
 
147
 
148
 
149
 
150
#   @_params ||= {}
151
#   if @params != nil
152
#     @params.each do |name, val|
153
#
154
#       param_type = defn.inst_parameters[ name ].type
155
#
156
#       if val.is_a? String
157
#         eval_match = SOCMaker::conf[ :eval_regex ].match( val )
158
#         #TODO error handling
159
#         if eval_match
160
#           #eval_func = eval_match.captures[0]
161
#           @_params[ name ] = { value: eval( eval_str ).to_s, type: param_type }
162
#         else
163
#           @_params[ name ] = { value: val, type: param_type }
164
#         end
165
#       else
166
#         @_params[ name ] = { value: val, type: param_type }
167
#       end
168
#     end
169
#   end
170
 
171
    @ports ||= {}
172
    @defn.ports do |port_name, port_dir, port_len, is_last |
173
      if port_len.is_a?( String )
174
        param_match = SOCMaker::conf[ :length_regex ].match( port_len )
175
 
176
        if param_match and @params[ port_len.to_sym ] != nil
177
          tmp =@params[ port_len.to_sym ]
178
          tmp = tmp.to_i if tmp.is_a?( String )
179
          @ports[ port_name.to_sym ] = { len: tmp, dir: port_dir }
180
        else
181
          SOCMaker::logger.error( "Failed to evaluate #{port_len} for port #{port_name}" )
182
        end
183
      else
184
        @ports[ port_name.to_sym ] = { len: port_len, dir: port_dir }
185
      end
186
    end
187
 
188
    lerr_if( @defn == nil, 'Core not found in lib',
189
      field:    'cores'    )
190
 
191
  end
192
 
193
 
194 5 feddischso
  def to_s
195
    "type:     #{type}\n"   +
196
    "params:   #{params}\n"
197
  end
198 3 feddischso
 
199
  def ==(o)
200
    o.class     == self.class   &&
201
    o.type      == self.type    &&
202
    o.params    == self.params
203
  end
204
 
205
 
206
end # CoreInst
207
end # SOCMaker
208
 
209
 
210
 
211
# 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.