Class: SdlTopImplement

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/sdlimplement/sdl_impl_module.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top_name, out_sv_path, need_modules, tbs, implparams, pins_yaml) ⇒ SdlTopImplement

Returns a new instance of SdlTopImplement.



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 189

def initialize(top_name,out_sv_path,need_modules,tbs,implparams,pins_yaml)
    @pins_yaml = TopModule.load_ppins(pins_yaml) if pins_yaml
    @tbs = tbs || []
    @implparams = implparams
    @out_sv_path = out_sv_path

    @top_module = TopModule.new(name: top_name,out_sv_path: out_sv_path)


    @_sure_array_ = []
    need_modules.each do |m|
        inspect_dependent(m)
        rel = SdlImplModule.modules_hash(m)
        @_sure_array_ << rel.dependent(sure:true) if rel
    end

    @_sure_array_ = @_sure_array_.flatten

    @module_pool = []

    need_modules.each do |m|
        rel = SdlImplModule.modules_hash(m)
        @module_pool << rel
        @module_pool << rel.dependent(sure:false,pool: @_sure_array_) if rel
    end

    @module_pool.flatten!
    @module_pool = @module_pool.uniq
    ## implement
    need_modules.each do |m|
        instance_itgt_module SdlImplModule.modules_hash(m)
    end

    # @top_module.gen_sv_module
    inspect_pool
end

Instance Attribute Details

#top_moduleObject (readonly)

Returns the value of attribute top_module.



187
188
189
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 187

def top_module
  @top_module
end

Class Method Details

.build(top_name, resource_yaml) ⇒ Object

class methods



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 362

def self.build(top_name,resource_yaml)
    hash = YAML::load(File.open(resource_yaml))
    pm = SdlImplParam.new(hash['params'])

    hash.each do |k,v|
        SdlImplModule.new(k,v)  if(k != 'params') && (k != 'implement')
    end

    if TopModule.sim && hash['implement']['tb_modules']
        imlp_top = SdlTopImplement.new(top_name,File.dirname(resource_yaml),hash['implement']['tb_modules'],hash['implement']['tb'],pm,hash['params']['yaml']['pins'])
    else
        imlp_top = SdlTopImplement.new(top_name,File.dirname(resource_yaml),hash['implement']['modules'],hash['implement']['tb'],pm,hash['params']['yaml']['pins'])
    end

    # hash['implement']['ex_up_code']
    imlp_top.top_module.ex_up_code  = (hash['implement']['ex_up_code'].join("\n")+"\n") if hash['implement']['ex_up_code']

    imlp_top.top_module.gen_sv_module

    if(hash['implement']['constraints'])
        hash['implement']['constraints'].each do |e|
            Constraints.add_const e
        end
    end

    imlp_top.top_module.create_xdc  if hash['implement']['xdc']

end

Instance Method Details

#inspect_dependent(impl_module_str) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 233

def inspect_dependent(impl_module_str)
    md = SdlImplModule.modules_hash(impl_module_str)
    sure_array = md.dependent(sure:true)

    use_array = md.dependent(sure:false,pool: sure_array.flatten )

    dep_array = SdlImplModule.inspect_dependent_verb(0,use_array)

    Dir.mkdir(File.join(@out_sv_path,"/inspect/")) unless File.exist? File.join(@out_sv_path,"/inspect/")
    Dir.mkdir(File.join(@out_sv_path,"/inspect/dependent/")) unless File.exist? File.join(@out_sv_path,"/inspect/dependent/")
    File.open(File.join(@out_sv_path,"/inspect/dependent/","#{md.class_name}.txt"),'w') do |f|
        f.puts dep_array
    end
end

#inspect_poolObject



226
227
228
229
230
231
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 226

def inspect_pool
    Dir.mkdir(File.join(@out_sv_path,"/inspect/")) unless File.exist? File.join(@out_sv_path,"/inspect/")
    File.open(File.join(@out_sv_path,"/inspect/","#{@top_module.module_name}_include.txt"),'w') do |f|
        f.puts @module_pool.map { |e|  e.key_name }.join("\n")
    end
end

#inspect_sdl(target_class, argv_hash) ⇒ Object



330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 330

def inspect_sdl(target_class,argv_hash)
    Dir.mkdir(File.join(@out_sv_path,"/inspect/")) unless File.exist? File.join(@out_sv_path,"/inspect/")
    Dir.mkdir(File.join(@out_sv_path,"/inspect/sdl_example/")) unless File.exist? File.join(@out_sv_path,"/inspect/sdl_example/")
    str = ""
    argv_hash.each do |k,v|
        if k.to_s == "pins_map"
            vv = v.dup
            v.keys.select { |e|  e.is_a? String }.each do |kk|
                vv.delete kk
            end

            hash_str = ""
            vv.each do |vvk,vvv|
                hash_str    += "        #{vvk}: #{vvv},\n"
            end
            str += "    #{k.to_s}:{\n#{hash_str}\n    }\n"
        else
            str += "    #{k.to_s}:#{v.to_s.gsub('#',"")},\n"
        end
    end

    File.open(File.join(@out_sv_path,"/inspect/sdl_example/","#{target_class.to_s}_example.rb"),'w') do |f|
        # f.puts dep_array
        f.puts "#{target_class.to_s}.new("
        f.puts str
        f.puts ")"

    end
end

#instance_itgt_module(impl_module) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 259

def instance_itgt_module(impl_module)
    ## check define
    if impl_module.nickname
        str = "itgt_#{impl_module.class_name}_#{impl_module.nickname}"
    else
        str = "itgt_#{impl_module.class_name}"
    end

    if respond_to?(str)
        return send(str)
    end

    unless File.exist? impl_module.path
        raise TdlError.new("Implemet Module[#{impl_module.key_name}] Path[#{impl_module.path}] dont exist !!!")
    end
    require_relative(impl_module.path)


    argv_hash = {}

    impl_module.common_argvs.each do |ca|
        rel = impl_module.send(ca)
        if (ca.to_sym == :pins_map) && rel
            argv_hash[ca.to_sym] = @pins_yaml[rel]
        elsif rel
            argv_hash[ca.to_sym] = rel
        end
    end

    impl_module.real_require.each do |k,rel|
        if @module_pool.include? rel
            argv_hash[k.to_sym] = instance_itgt_module(rel)
        else
            TdlError.new("#{rel.key_name} is not in module_pool !!!")
        end
    end

    argv_hash[:top_module]  = @top_module

    if @tbs.include?(impl_module.key_name)
        argv_hash[:tb]          = true
    end

    ## other attr
    other_rep0 = /params-yaml-(?<name>.+)/
    other_rep1 = /params-var-(?<name>.+)/

    impl_module.other.keys.each do |k|
        rel = impl_module.other.send(k)
        if other_rep0.match(rel.to_s) || other_rep1.match(rel.to_s)
            argv_hash[k.to_sym] =  @implparams.send($~[:name])
        else
            argv_hash[k.to_sym] = rel
        end
    end


    ## define itgt methods
    target_class = eval("#{impl_module.class_name}")
    inspect_sdl(target_class,argv_hash)

    _inst_ = target_class.send(:new,argv_hash)

    define_singleton_method(str) do
        _inst_
    end

    return _inst_

end

#pool_hash(name_str, nickname = nil) ⇒ Object



248
249
250
251
252
253
254
255
256
# File 'lib/tdl/sdlimplement/sdl_impl_module.rb', line 248

def pool_hash(name_str,nickname=nil)
    @module_pool.select do |e|
        if nickname
            e.classname == name_str && e.nickname == nickname
        else
            e.classname == name_str
        end
    end[0]
end