class SdlInst
Attributes
belong_to_module[RW]
inner_port_hash[RW]
inst_param_hash[RW]
inst_port_hash[RW]
name[RW]
origin[R]
Public Class Methods
new(origin:nil,name:'inst')
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 13 def initialize(origin:nil,name:'inst') @origin = origin @inner_port_hash = Hash.new @inst_port_hash = Hash.new @inst_param_hash = Hash.new @name = name Tdl.add_to_all_file_paths(@origin.module_name.to_s,@origin.real_sv_path) if @origin.real_sv_path end
Private Class Methods
add_inst_t0_method(mf)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 253 def self.add_inst_t0_method(mf) @@_inst_t0_methods ||= [] @@_inst_t0_methods << mf end
Public Instance Methods
Parameter(key)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 34 def Parameter(key) read_hash_value(inst_param_hash,key) end
Ports(key)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 38 def Ports(key) read_hash_value(inst_port_hash,key) end
[](key)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 42 def [](key) key = key.to_s if inst_param_hash.key? key # inst_param_hash[key] Parameter(key) elsif inst_port_hash.key? key # inst_port_hash[key] Ports(key) else printf_keys raise TdlError.new("#{@origin.module_name} dont have port [#{key} :CLASS #{key.class}]") end end
[]=(key,value)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 56 def []=(key,value) key = key.to_s if inst_param_hash.key? key inst_param_hash[key] = value elsif inst_port_hash.key? key ## 判断 接口类型是否一样 # if @origin.send(key).is_a?(InfElm) && value.is_a?(InfElm) if @origin.send(key).is_a?(TdlSpace::TdlBaseInterface) && value.is_a?(TdlSpace::TdlBaseInterface) if @origin.send(key).class != value.class raise TdlError.new("#{@origin.module_name} port type<#{@origin.send(key).class}> isnot same as #{value.name} <#{value.class}>") else # raise TdlError.new("#{@origin.module_name} port type isnot same as #{value.module_name}") if value.modport_type if @origin.send(key).modport_type.to_s != value.modport_type.to_s # raise TdlError.new("[#{@origin.module_name}] port[#{key}][#{@origin.send(key).port}] type isnot same as [#{value}][#{value.port}]") # puts "[#{@origin.module_name}] port[#{key}][#{@origin.send(key).port}] type isnot same as [#{value}][#{value.port}]" inst_port_hash[key] = VCSCompatable::auto_vcs_cpt_connect(@origin.send(key) ,value) else inst_port_hash[key] = value end else inst_port_hash[key] = value end end else inst_port_hash[key] = value end else printf_keys raise TdlError.new("#{@origin.module_name} dont have port [#{key} :CLASS #{key.class}]") end end
_last_hier_signal(key)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 116 def _last_hier_signal(key) @_name_collect ||= hier_name_collect if key.is_a? BaseElm key_str = key.signal elsif key.is_a? String key_str = key elsif key.is_a? Symbol key_str = key.to_s else raise TdlError.new("#{@origin.module_name} hier signal key type error") end if @_name_collect.include? key_str "#{inst_name}.#{key_str}" else raise TdlError.new("#{@origin.module_name} INST #{inst_name} dont have #{key_str}") end end
hier_inst_collect()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 310 def hier_inst_collect ois = @origin.instance_variable_get("@sub_instanced") end
hier_signal(*keys)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 89 def hier_signal(*keys) RedefOpertor.with_normal_operators do if keys.size == 1 _last_hier_signal(keys[0]) else @_inst_collect ||= hier_inst_collect cl = @_inst_collect.find do |e| if keys[0].is_a? SdlInst keys[0].inst_name == e.inst_name elsif keys[0].is_a?(String) || keys[0].is_a?(Symbol) kstr = keys[0].to_s kstr == e.inst_name else raise TdlError.new("#{@origin.module_name} hier signal key type error") end end unless cl raise TdlError.new("#{@origin.module_name} INST #{inst_name} dont have #{keys[0].to_s}") end "#{cl.inst_name}."+hier_signal(*keys[1,keys.size]) end end end
inst_draw()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 137 def inst_draw "#{@origin.module_name} #{inst_param}#{inst_name}( #{inst_port} );" end
inst_name()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 143 def inst_name @name.to_s end
output(*args)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 381 def output(*args) return SdlInstSimplePortSugar.new(self) end
port(*args)
click to toggle source
添加语法糖
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 370 def port(*args) return SdlInstPortSugar.new(self) end
Private Instance Methods
hier_name_collect()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 284 def hier_name_collect oss = [] ops = @origin.instance_variable_get("@ports").map { |k,v| v.signal } (SignalElm.subclass | InfElm.subclass).each do |e| # puts "@#{e.to_s}_collect" oss |= @origin.instance_variable_get("@#{e.to_s}_collect").map { |se| se.signal } # oss |= @origin.method("#{e.to_s}_collect").map { |se| se.signal } end ops + oss end
inst_param()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 149 def inst_param "<T0> .xxxx <T1> (.....)" t0 = [] t1 = [] inst_param_hash.each do |key,value| t0 << " .#{key.to_s}" if value raise TdlError.new("Instance ERROR module[#{@origin.module_name}] Inst_name[#{name}] Parameter [#{key}]") if value.is_a? Array t1 << inst_t2(value) else t1 << nil end end max_len_t0 = t0.map { |e| e.length }.max max_len_t1 = t1.map do |e| if e e.length else 0 end end.max tt = [] t0.each_index do |index| if t1[index] t0_str = t0[index]+" "*(max_len_t0+1-t0[index].length) t1_str = "("+t1[index]+" "*(max_len_t1-t1[index].length)+" )" tt << t0_str + t1_str end end if tt.empty? tt_str = "" else tt_str = "#(\n"+tt.join(",\n")+"\n)" end end
inst_port()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 190 def inst_port "<T0> /* ..... */ <T1> .xxxx <T2> (....)" t0 = [] t1 = [] t2 = [] inner_port_hash.each do |key,value| raise TdlError.new("Instance ERROR module[#{@origin.module_name}] Inst_name[#{name}] Port [#{key}] Port cant be array") if inst_port_hash[key].is_a? Array t0 << inst_t0(value) t1 << inst_t1(value) t2 << inst_t2(inst_port_hash[key]) end max_len_t0 = t0.map { |e| e.length }.max max_len_t1 = t1.map { |e| e.length }.max max_len_t2 = t2.map { |e| e.length }.max ttt = [] t0.each_index do |index| t0_str = "/* " + t0[index] + " "*(max_len_t0-t0[index].length) + " */" t1_str = t1[index] + " "*(max_len_t1+1-t1[index].length) t2_str = "(" + t2[index] + " "*(max_len_t2-t2[index].length) + " )" ttt << t0_str + t1_str + t2_str end ttt.join(",\n") end
inst_t0(ele)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 221 def inst_t0(ele) case when ele.class == Clock then "#{ele.port} clock" when ele.class == Reset then "#{ele.port} reset" when ele.class == Logic then "#{ele.port}" # when ele.class == AxiStream then # "axi_stream_inf.#{ele.port}" # when ele.class == DataInf then # "data_inf.#{ele.port}" # when ele.class == DataInf_C then # "data_inf_c.#{ele.port}" # when ele.class == AxiLite then # "axi_lite_inf.#{ele.port}" # when ele.class == Axi4 then # "axi_inf.#{ele.port}" # when ele.class == VideoInf then # "video_native_inf.#{ele.port}" when TdlSpace::TdlBaseInterface.subclass.include?(ele.class) then "#{ele.class.get_class_var('hdl_name')}.#{ele.modport_type}" else rel_str = inst_t0_methods(ele) unless rel_str raise TdlError.new("When instance ports of module, but it can parse this #{ele.to_s} class [#{ele.class}]") else rel_str end end end
inst_t0_methods(ele)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 258 def inst_t0_methods(ele) @@_inst_t0_methods ||= [] rel = nil @@_inst_t0_methods.each do |m| rel = m.call(ele) if rel break end end rel end
inst_t1(ele)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 270 def inst_t1(ele) ".#{ele.name.to_s}" end
inst_t2(value)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 274 def inst_t2(value) with_new_align(0) do if value.is_a? DefaultProc # It mean the port not be used,so leave it empty "#{align_signal('/*unused */',q_mark=false)}" else "#{align_signal(value)}" end end end
method_missing(method_id,*argvs,&block)
click to toggle source
Calls superclass method
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 316 def method_missing(method_id,*argvs,&block) methods_pool = @origin.instance_variable_get("@_add_to_new_module_vars") method_str = method_id.to_s # if methods_pool.include?(method_str) # if argvs.empty? # if inst_port_hash.key?(method_str) # inst_port_hash[method_str] # elsif inst_param_hash.key?(method_str) # inst_param_hash[method_str] # else # @origin.public_send(method_id,*argvs,&block) # end # else # ## 带参数,及函数带连接 # self[method_id] = argvs[0] # end # else # super # # raise TdlError.new("SDL Instance dont have method `#{method_id}`") # end if inst_port_hash.key? method_str if argvs.empty? inst_port_hash[method_str] else self[method_id] = argvs[0] end elsif inst_param_hash.key? method_str if argvs.empty? inst_param_hash[method_str] else self[method_id] = argvs[0] end else super end # if argvs.empty? # if inst_port_hash.key?(method_str) # inst_port_hash[method_str] # elsif inst_param_hash.key?(method_str) # inst_param_hash[method_str] # else # @origin.public_send(method_id,*argvs,&block) # end # else # ## 带参数,及函数带连接 # self[method_id] = argvs[0] # end end
printf_keys()
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 297 def printf_keys puts pagination("PARAMETERS KEY") inst_param_hash.keys.each do |e| puts "CLASS[#{e.class}] VALUE[#{e}]" end puts pagination("PORTS KEY") inst_port_hash.keys.each do |e| puts "CLASS[#{e.class}] VALUE[#{e}]" end end
read_hash_value(hash,key)
click to toggle source
# File lib/tdl/sdlmodule/sdlmodule_instance.rb, line 23 def read_hash_value(hash,key) value = hash[key] if value.is_a? DefaultProc hash[key] = value.call(key) else value end end