class Object

Constants

ADDR_STEP
PutsEnable

Public Instance Methods

Logic(name,dsize:1,dimension:[],assign:nil) click to toggle source
# File lib/tdl/elements/logic.rb, line 7
def Logic(name,dsize:1,dimension:[],assign:nil)
    a = Logic.new(name:name,dsize:dsize,dimension:dimension)
    $__tdl_cur_self__.send(:define_method,name) { a }
    if assign
        Assign { a <= assign }
    end
    nil
end
__require_hdl__(hdl_path,current_sdlm=nil,encoding='utf-8') click to toggle source
# File lib/tdl/auto_script/import_hdl.rb, line 2
def __require_hdl__(hdl_path,current_sdlm=nil,encoding='utf-8')
    basename = File.basename(hdl_path,".*")
    unless SdlModule.exist_module? basename
        ## 检测是不是全路径, 或当前路径查得到
        if File.exist? hdl_path
            AutoGenSdl.new(hdl_path,File.join(__dir__,"tmp")).auto_rb
        else 
            if hdl_path !~ /[\/|\\]/
                rel = find_first_hdl_path(hdl_path)
                unless rel 
                    raise TdlError.new("Cant find <#{hdl_path}> in tdl paths !!!")    
                end

                AutoGenSdl.new(rel,File.join(__dir__,"tmp"),encoding=encoding).auto_rb

                ## 如果是 在非 sdlmodule 内引用需要添加contain_hdl
                # if !(current_sdlm.is_a?(SdlModule))
                #     if TopModule.current
                #         TopModule.current.contain_hdl(rel)
                #     else
                #         unless  $__contain_hdl__.include? rel
                #             $__contain_hdl__ << rel
                #         end
                #     end
                # end
                if current_sdlm 
                    current_sdlm.contain_hdl(rel)
                else 
                    unless  $__contain_hdl__.include? rel
                        $__contain_hdl__ << rel
                    end
                end
                
            else 
                raise TdlError.new("path<#{hdl_path}> error!!!")
            end
        end
        require_relative File.join(__dir__,"tmp","#{basename}_sdl.rb")
    end
end
add_to_tdl_paths(full_path) click to toggle source
# File lib/tdl/global_scan.rb, line 124
def add_to_tdl_paths(full_path)
    if File.exist? full_path
        unless File.directory? full_path
            raise "<#{full_path}> is not a directory!!!"
        else 
            $__tdl_paths__ << full_path unless $__tdl_paths__.include?(full_path)
        end
    else 
        raise "Dont exist #{full_path}"
    end
end
align_signal(obj,q_mark=true) { |tdl_name_large_len,sl| ... } click to toggle source
# File lib/tdl/basefunc.rb, line 127
def align_signal(obj,q_mark=true)
    raise TdlError.new("align_signal OBJECT CANT BE ARRAY LEN[#{obj.size}] [#{obj}]") if obj.is_a? Array
    if obj.is_a? NqString
        new_obj = obj
    elsif obj.is_a? Proc
        new_obj = obj.call
    elsif obj.instance_of? String
        if obj.match(/\d*'(d|h|b|sd|sh|sb)(\d|z|x)+/i) || obj.match(/'(0|1|z|x)/ || obj.match(/^\d+$/))
            new_obj = obj
        else
            if q_mark
                new_obj = '"'+obj+'"'
            else
                new_obj = obj
            end
        end
    # elsif obj.is_a? BaseElm
    #     new_obj = obj.signal
    else
        new_obj = obj
    end
    sl = new_obj.to_s.length

    if block_given?
        yield(tdl_name_large_len,sl)
    end

    if tdl_name_large_len>=sl
        ll = tdl_name_large_len-sl
    else
        ll=0
    end

    rel = new_obj.to_s + " "*ll
    # if rel =~ /\(.+\)/
    #     puts rel
    #     puts new_obj.class
    #     puts new_obj.to_s
    #     raise TdlError.new("====STOP======")
    # end
    rel
end
axis_gen_big_field(mode:"MASTER",value:"32'h00000",enable:"1'b1",dsize:8,clock:nil,reset:nil,copy_axis:nil) click to toggle source
# File lib/tdl/basefunc.rb, line 22
def axis_gen_big_field(mode:"MASTER",value:"32'h00000",enable:"1'b1",dsize:8,clock:nil,reset:nil,copy_axis:nil)
    if copy_axis.is_a? AxiStream
        new_axis = AxiStream.new(name:"orign_axis",clock:copy_axis.clock,reset:copy_axis.reset,dsize:copy_axis.dsize)
    else
        new_axis = AxiStream.new(name:"orign_axis",clock:clock,reset:reset,dsize:dsize)
    end
    new_axis.gen_big_field(mode:mode,value:value,enable:enable)
end
check_same_name_method(name) click to toggle source
# File lib/tdl/Logic/logic_main.rb, line 3
def check_same_name_method(name)
    raise TdlError.new("\n 'Method' Name Error ,#{name} Can't be defined,because it has same name\n") if self.methods.include? name.to_sym
end
compact_signal(obj,q_mark=false) click to toggle source
# File lib/tdl/basefunc.rb, line 180
def compact_signal(obj,q_mark=false)
    if obj.is_a? String
        if obj.match(/\d*'(d|h|b|sd|sh|sb)(\d|z|x)+/i) || obj.match(/'(0|1|z|x)/ || obj.match(/^\d+$/))
            new_obj = obj
        else
            if q_mark
                new_obj = '"'+obj+'"'
            else
                new_obj = obj
            end
        end
    else
        new_obj = obj
    end

    new_obj.to_s
end
define_main_func(name,&block) click to toggle source
# File lib/tdl/basefunc.rb, line 275
def define_main_func(name,&block)
    raise TdlError.new("\n In define main Function: function name <<#{name}>> must Symbol\n") unless name.is_a? Symbol
    raise TdlError.new("\n Function <<#{name}>>has already be defined in MAIN  \n") if $__main__.methods.include?(name)
    $__main__.send(:define_method,name,&block)
end
exist_same_name_sdl(e) click to toggle source
# File lib/tdl/auto_script/test_autogensdl.rb, line 20
def exist_same_name_sdl(e)
    sdl_file = e.sub(/\.sv$/,".rb")
    File.exist? sdl_file
end
find_first_hdl_path(basename) click to toggle source
# File lib/tdl/auto_script/import_hdl.rb, line 59
def find_first_hdl_path(basename)
    $__tdl_paths__.each do |e|
        if File.exist? File.join(e,basename)
            return File.expand_path(File.join(e,basename))
        end
    end
    return nil
end
freeze_tdl_name_large_len() click to toggle source
# File lib/tdl/basefunc.rb, line 14
def freeze_tdl_name_large_len
    $__tdl_name_large_len_freeze_en = true
end
globle_random_name_flag(flag='R') click to toggle source
# File lib/tdl/basefunc.rb, line 335
def globle_random_name_flag(flag='R')
    rel = $__name_random_index__[$__name_random_index_ii__]
    $__name_random_index_ii__ += 1
    "#{flag}#{rel}"
end
large_name_len(*c) click to toggle source

def String.align_signal()

# File lib/tdl/basefunc.rb, line 32
def large_name_len(*c)
    update_tdl_name_large_len(0)
    c.each do |e|
        begin
            if e.to_s.length > tdl_name_large_len
                update_tdl_name_large_len(e.to_s.length)
            end
        # rescue Exception => er
        #     p e
        #     raise er
        end
    end
    return tdl_name_large_len
end
look_for_v(path) click to toggle source
# File lib/public_atom_module/altera_xilinx_always_block_sw.rb, line 28
def look_for_v(path)
    paths = Dir::entries(path) - %w{. ..}

    paths.each do |pf|
        full_name = File.join(path,pf)
        if(File.directory? full_name)
            look_for_v(full_name)
        elsif(File.file? full_name)
            if(/\.v$/i =~ pf || /\.sv$/i =~ pf)
                sw_always($mode,full_name)
            end
        end
    end
end
mark_files(file_list) click to toggle source
# File lib/tdl/global_scan.rb, line 25
def mark_files(file_list)
    file_hash = Hash.new
    file_list.each do |e|
        f_str = File.open(e,'r').read.force_encoding('utf-8')
        mth = f_str.match(/\(\*\s+(?<inf>axi_stream|axi4|data_inf|axi_lite)\s*=\s*"true"\s+\*\)/)
        next unless (mth)
        sub_hash = Hash.new
        hash_name = File::basename(e,".*")
        sub_hash[:name] = File::basename(e,".*")
        sub_hash[:path] = e
        sub_hash[:mtime]= File::mtime(e)
        sub_hash[:inf]  = mth[:inf]

        file_hash[hash_name] = sub_hash
    end
    return file_hash
end
page(tag:"TAG EXP",body:"") click to toggle source
# File lib/tdl/basefunc.rb, line 56
def page(tag:"TAG EXP",body:"")
    return "" if body.empty?
    end_str =
    "\n//====>>>> #{tag} <<<<#{"="*(60-tag.length)}\n"
    head_str =
    "//----<<<< #{tag} >>>>#{"-"*(60-tag.length)}\n"
    return head_str + body.strip + end_str
end
pagination(tag="") click to toggle source
# File lib/tdl/basefunc.rb, line 65
def pagination(tag="")
    return "" if tag.empty?
    head_str = "\n//==============#{"="*(60-0)}"
    end_str  = "\n//-------- #{tag} ----#{"-"*(60-tag.length)}\n"
    head_str.concat end_str
end
path_scan(path,rep=/.sv/i) click to toggle source

require_relative “./autogenaxis” require_relative “./autogentdl”

# File lib/tdl/global_scan.rb, line 4
def path_scan(path,rep=/.sv/i)
    root_path = path
    dir_list = Dir::entries(path) - %w{. ..}
    dir_list.select! {|d| d !~ /^\./}
    dir_list.map! {|d| File::join(root_path,d)}

    file_list = dir_list.select do |d|
            (File::file? d) && (d =~ rep)
        end

    dir_list = dir_list - file_list

    dir_list.select! {|d| File.directory? d}

    dir_cel = dir_list.map do |e|
        path_scan(e,rep)
    end

    return file_list + dir_cel.flatten
end
replace_methods(class_obj,methods_hash) click to toggle source
# File lib/tdl/basefunc.rb, line 303
def replace_methods(class_obj,methods_hash)
    
    methods_hash.each do |key,proc|
        ## 判断是否class_obj是否有方法
        if class_obj.instance_methods.include?(key.to_s.to_sym)
            # class_obj.defind_method("replace__m_old_#{key.to_s}")
            # class_obj.class_exec(key) do |key|
            #     alias_method "replace__m_old_#{key.to_s}",key
            # end
            class_obj.alias_method "replace__m_old_#{key.to_s}",key.to_s
        end

        class_obj.define_method(key,&proc)
    end
end
require_axi4path(a) click to toggle source
# File lib/tdl/tdl.rb, line 163
def require_axi4path(a)
    require_relative File.join(Tdl.Axi4Path,a)
end
require_hdl(hdl_path,encoding='utf-8') click to toggle source
# File lib/tdl/auto_script/import_hdl.rb, line 68
def require_hdl(hdl_path,encoding='utf-8')
    __require_hdl__(hdl_path,nil,encoding)
end
require_path(path) click to toggle source

def gen_auto_files(file_hash)

axi_stream_path = "./axi_stream"

file_hash.each do |key,value|
    auto_axi_stream(filename=value[:path],out_file_path=axi_stream_path)
end

end

# File lib/tdl/global_scan.rb, line 51
def require_path(path)
    curr_path = File.expand_path(path)

    file_list = path_scan(curr_path,/\.rb$/)
    ## ------------
    mark_list = file_list.map { |e|  e.sub(/\.rb$/,"_auto.rb") }

    mark_list = mark_list.select { |e|  e !~ /_auto_auto/}
    ## -----------
    mark_sdl  = file_list.map { |e|  e.sub(/\.rb$/,"_sdl.rb") }

    mark_sdl  = mark_sdl.select { |e|  e !~ /_sdl_sdl/}
    ## -----------
    mark_bak  = file_list.select { |e| e =~ /\Wbak\W/i}

    file_list = file_list - mark_list - mark_bak - mark_sdl

    file_list = file_list - mark_list.select { |e| e.sub(/^_+/,"") }

    file_list = file_list.select { |e|  e !~ /^test/i}

    file_list.each do |e|
        # puts e
        require_relative (''+e.sub(/\.rb/,'')+'')
    end

    return file_list
end
require_path_and_ignore(path,*ignores) click to toggle source
# File lib/tdl/global_scan.rb, line 80
def require_path_and_ignore(path,*ignores)
    curr_path = File.expand_path(path)

    file_list = path_scan(curr_path,/\.rb$/)

    mark_list = file_list.map { |e|  e.sub(/\.rb$/,"_auto.rb") }

    mark_list = mark_list.select { |e|  e !~ /_auto_auto/}

    file_list = file_list - mark_list

    file_list = file_list - mark_list.select { |e| e.sub(/^_+/,"") }

    file_list = file_list.select { |e|  e !~ /^test/i}

    file_list = file_list.select do |e|
        get_l = true
        ignores.each do |ig|
            if e.include? ig
                get_l   = false
            end
        end
        get_l
    end

    file_list.each do |e|
        # puts e
        require_relative (''+e.sub(/\.rb/,'')+'')
    end
end
require_relative_path(relative=File.expand_path(__dir__),path) click to toggle source

mark_files(path_scan('E:workAXIAXI_stream')).each {|e| puts e} unless ARGV.empty?

gen_auto_files(mark_files(path_scan('E:\work\AXI\AXI_stream')))

end

# File lib/tdl/global_scan.rb, line 117
def require_relative_path(relative=File.expand_path(__dir__),path)
    require_path(File.expand_path(File.join(relative,path)))
end
require_sdl(sdl_path) click to toggle source

添加 引入 sdl module

# File lib/tdl/auto_script/import_sdl.rb, line 3
def require_sdl(sdl_path)
    basename = File.basename(sdl_path,".rb")
    unless SdlModule.exist_module? basename
        ## 检测是不是全路径, 或当前路径查得到
        if File.exist? sdl_path
            # AutoGenSdl.new(hdl_path,File.join(__dir__,"tmp")).auto_rb
            # puts File.expand_path sdl_path
            require_relative File.expand_path(sdl_path)
        else 
            if sdl_path !~ /[\/|\\]/
                rel = find_first_hdl_path(sdl_path)
                unless rel 
                    raise TdlError.new("Can find <#{sdl_path}> in tdl paths !!!")    
                end

                # AutoGenSdl.new(rel,File.join(__dir__,"tmp")).auto_rb
                require_relative rel
            else 
                raise TdlError.new("path<#{sdl_path}> error!!!")
            end
        end
        # require_relative File.join(__dir__,"tmp","#{basename}_sdl.rb")
    end
end
rollback_methods(class_obj,*methods_nams) click to toggle source
# File lib/tdl/basefunc.rb, line 319
def rollback_methods(class_obj,*methods_nams)
    methods_nams.each do |key|
        if class_obj.instance_methods.include?("replace__m_old_#{key.to_s}".to_sym)
            class_obj.class_exec(key) do |key|
                alias_method key.to_s,"replace__m_old_#{key.to_s}"
            end
        else 
            class_obj.undef_method(key.to_s)
        end
    end
end
stand(path) click to toggle source
# File lib/axi/macro/bak/standard_tcl.rb, line 11
def stand(path)
    all_str = File.open(path,'r'){ |f| f.read }
    all_str.gsub!(/\\\s*$/,'>>>>')
    all_str.gsub!("\n","[NNNNN]")
    all_str.gsub!("\r","[RRRRR]")
    all_str.gsub!("\\","/")
    all_str.gsub!('>>>>',"\\")
    all_str.gsub!(/\\\s*$/,"\n")
    all_str.gsub!("[NNNNN]","\n")
    all_str.gsub!("[RRRRR]","\r")
    return all_str
end
sw_always(to="xilinx",file_name) click to toggle source
# File lib/public_atom_module/altera_xilinx_always_block_sw.rb, line 4
def sw_always(to="xilinx",file_name)
    all_str = File.open(file_name).read
    altera_rep_0 = /always\s*@\s*\(\s*posedge\s+(?<clock_name>\w*(?i:clock|clk)\w*)\s*(?:,|or)\s*negedge\s+(?<rst_name>\w*(?:rst|reset)\w*)\s*\)/
    xilinx_rep   = /always\s*@\s*\(posedge\s+(?<clock_name>\w*(?i:clock|clk)\w*)\s*\/\*.+\*\/\s*\)/
    # altera_rep_0 = /always\s*@\s*\(\s*posedge\s+(?<clock_name>\s*(?i:clock|clk)\s*)\t*(?:,|or)\s*/
    if(to.downcase=="xilinx")
        all_str.gsub!(altera_rep_0) do |s|
            "always@(posedge #{$~["clock_name"]}/*,negedge #{$~["rst_name"]}*/)"
        end
    elsif to.downcase=="altera"
        all_str.gsub!(xilinx_rep) do |s|
            s.sub('/*','').sub('*/','')
        end
    end

    # if xilinx_rep.match("always@(posedge clk/*,negedge rst_n*/)")
    #     puts "rep OK"
    #     puts $~["clock_name"]
    # else
    #     puts "rep ERR"
    # end
    File.open(file_name,"w"){|f| f.print(all_str)}
end
tdl_name_large_len() click to toggle source
# File lib/tdl/basefunc.rb, line 5
def tdl_name_large_len
    $__tdl_name_large_len
end
test0() click to toggle source
# File lib/tdl/rebuild_ele/ele_base.rb, line 806
def test0
    as = TestAxiStream.new
    as.modport_type = 'master'
    as.dimension = [9,4]
    as.inst_name = "dt_inf"

    puts as.instance
end
test_inner_inst() click to toggle source
# File lib/tdl/rebuild_ele/ele_base.rb, line 815
def test_inner_inst
    as = TestAxiStream.new
    # as.modport_type = 'master'
    as.dsize = 12
    as.clock = 'clock_90M'
    as.reset = "rst_n"
    as.dimension = [9,4]
    as.inst_name = "dt_inf"

    puts as.instance
end
undefine_main_func(name) click to toggle source
# File lib/tdl/basefunc.rb, line 281
def undefine_main_func(name)
    # $__main__.send(:undef_method,name)
    # $__main__.send(:remove_method,name)
    eval("undef #{name}")
    # $__main__.undef_method(name)
end
unfreeze_tdl_name_large_len() click to toggle source
# File lib/tdl/basefunc.rb, line 18
def unfreeze_tdl_name_large_len
    $__tdl_name_large_len_freeze_en = false
end
update_tdl_name_large_len(a) click to toggle source
# File lib/tdl/basefunc.rb, line 9
def update_tdl_name_large_len(a)
    raise TdlError.new("\n Cant assign $__tdl_name_large_len_freeze\n") if $__tdl_name_large_len_freeze_en
    $__tdl_name_large_len = a
end
with_main_funcs(func_hash) { || ... } click to toggle source
# File lib/tdl/basefunc.rb, line 288
def with_main_funcs(func_hash,&block)
    func_hash.each do |key,value|
        define_main_func(key,&value)
    end
    yr = yield

    func_hash.each do |key,value|
        undefine_main_func(key)
    end

    return yr
end
with_new_align(num=0,&block) click to toggle source
# File lib/tdl/basefunc.rb, line 47
def with_new_align(num=0,&block)
    tmp = tdl_name_large_len
    update_tdl_name_large_len(num)
    rel = block.call
    update_tdl_name_large_len(tmp)
    rel
end