class TdlSpace::ArrayChain

Attributes

belong_to_module[R]
chain[R]
end_slice[R]
obj[R]

Public Class Methods

create(obj: "tmp",lchain: [],end_slice: false,belong_to_module: nil) click to toggle source
# File lib/tdl/elements/originclass.rb, line 35
def self.create(obj: "tmp",lchain: [],end_slice: false,belong_to_module: nil)
    ArrayChain.new(obj, lchain, end_slice, belong_to_module)
end
new(obj="tmp",lchain=[],end_slice=false,belong_to_module=nil) click to toggle source
# File lib/tdl/elements/originclass.rb, line 12
def initialize(obj="tmp",lchain=[],end_slice=false,belong_to_module=nil)
    @belong_to_module=belong_to_module
    @obj = obj
    if !end_slice
        if lchain.is_a? Array
            @chain = lchain
            @end_slice = end_slice
        else 
            @chain = [lchain]
            @end_slice = end_slice
        end
    elsif lchain 
        @chain = []
        @end_slice = [lchain,end_slice]
    else
        raise TdlError.new("数组下标类型出错")
    end

    unless @belong_to_module
        raise TdlError.new "ArrayChain<#{obj.to_s}> 必须添加 belong_to_module"
    end
end

Public Instance Methods

[](a,b=false) click to toggle source
# File lib/tdl/class_hdl/hdl_redefine_opertor.rb, line 633
def [](a,b=false)
    if a.is_a? Range
        b = a.last 
        a = a.first
    end 

    if a.is_a? ClassHDL::OpertorChain
        a.slaver = true
    end
    
    if b.is_a? ClassHDL::OpertorChain
        b.slaver = true
    end

    if @end_slice
        raise TdlError.new("数组下标已经被用片选[#{@end_slice[0]},#{@end_slice[1]}]终结")
    end
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
        unless b 
            ArrayChain.create(obj: obj,lchain: chain+[a],belong_to_module: belong_to_module)
        else 
            @end_slice = [a,b]
            self
        end
    end
end
inspect() click to toggle source
# File lib/tdl/elements/originclass.rb, line 43
def inspect
    self.to_s
end
method_missing(method,arg=nil) click to toggle source
Calls superclass method
# File lib/tdl/elements/originclass.rb, line 51
def method_missing(method,arg=nil)
    if arg 
        raise TdlError.new("ArrayChain 末尾调用方法[#{method}]不能带参数")
    end

    if @end_slice
        raise TdlError.new("ArrayChain 末尾slice不能再调用方法 #{method} #{arg.to_s}")
    end
    ## 判断 obj是否响应方法
    if @obj.respond_to?(method) && !method.to_s.eql?("inst_name")
        ArrayChain.create(obj: @obj,lchain:@chain.dup.concat([ArrayChainSignalMethod.new(method)]) ,belong_to_module: belong_to_module)
    else 
    
        # raise TdlError.new("ArrayChain 没有末尾方法 #{method} #{arg}")
        super
    end
end
root_ref(&block) click to toggle source
# File lib/tdl/elements/originclass.rb, line 39
def root_ref(&block)
    "#{belong_to_module.root_ref(&block)}.#{to_s}".to_nq
end
signal() click to toggle source
# File lib/tdl/elements/originclass.rb, line 47
def signal
    self.to_s.to_nq
end
to_s() click to toggle source
# File lib/tdl/class_hdl/hdl_redefine_opertor.rb, line 660
def to_s
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
        str = ""
        xstr = false
        chain.each do |e|
            unless e.is_a? ArrayChainSignalMethod
                str += "[#{e.to_s}]"
            else 
                if (e.name.to_s == "vld_rdy" || e.name.to_s == "vld_rdy_last") && ( obj.is_a?(AxiStream) || obj.is_a?(DataInf_C) )
                    xstr = obj.public_send("array_chain_#{e.name.to_s}_inst",obj.to_s + chain[0, chain.size-1].map{|x| "[#{x}]"}.join(''))                            
                else 
                    str += ".#{e.name.to_s}"
                end
            end
        end
        if @end_slice
            str += "[#{@end_slice[0]}:#{@end_slice[1]}]"
        end

        xstr || "#{obj.to_s}#{str}"

    end
end
~() click to toggle source
# File lib/tdl/class_hdl/hdl_redefine_opertor.rb, line 684
def ~
    ArrayChain.create(obj: "~#{self.to_s}", belong_to_module: belong_to_module)
end