Class: Array

Inherits:
Object
  • Object
show all
Includes:
HArrow
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Extends the Array class for conversion to a high-level expression.

Direct Known Subclasses

HDLRuby::High::Std::PipelineT::Stage

Instance Method Summary collapse

Instance Method Details

#call(obj = nil, &ruby_block) ⇒ Object

Create an array whose number of elements is given by the content of the current array, filled by +obj+ objects. If +obj+ is nil, +ruby_block+ is used instead for filling the array.



3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
# File 'lib/HDLRuby/hruby_high.rb', line 3807

def call(obj = nil, &ruby_block)
    unless self.size == 1 then
        raise AnyError, "Invalid array for call opertor."
    end
    number = self[0].to_i
    if obj then
        return Array.new(number,obj)
    else
        return Array.new(number,&ruby_block)
    end
end

#constant(hsh) ⇒ Object

Declares high-level inner constants named from +hsh+ with names and corresponding values.



3789
3790
3791
# File 'lib/HDLRuby/hruby_high.rb', line 3789

def constant(hsh)
    High.top_user.make_constants(self.to_type,hsh)
end

#hcase(value, &ruby_block) ⇒ Object

Creates a hcase statement executing +ruby_block+ on the element of the array selected by +value+



3795
3796
3797
3798
3799
3800
# File 'lib/HDLRuby/hruby_high.rb', line 3795

def hcase(value,&ruby_block)
    High.cur_block.hcase(value)
    self.each.with_index do |elem,i|
        High.cur_block.hwhen(i) { ruby_block.call(elem) }
    end
end

#inner(*names) ⇒ Object

Declares high-level inner signals named +names+ of the current type.



3783
3784
3785
# File 'lib/HDLRuby/hruby_high.rb', line 3783

def inner(*names)
    High.top_user.make_inners(self.to_type,*names)
end

#inout(*names) ⇒ Object

Declares high-level untyped inout signals named +names+ of the current type.



3777
3778
3779
# File 'lib/HDLRuby/hruby_high.rb', line 3777

def inout(*names)
    High.top_user.make_inouts(self.to_type,*names)
end

#input(*names) ⇒ Object

Declares high-level input signals named +names+ of the current type.



3765
3766
3767
# File 'lib/HDLRuby/hruby_high.rb', line 3765

def input(*names)
    High.top_user.make_inputs(self.to_type,*names)
end

#make(name, *args) ⇒ Object

Create an array of instances of system +name+, using +args+ as arguments.

NOTE: the array must have a single element that is an integer.



3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
# File 'lib/HDLRuby/hruby_high.rb', line 3823

def make(name,*args)
    # Check the array and get the number of elements.
    size = self[0]
    unless self.size == 1 and size.is_a?(::Integer)
        raise AnyError,
              "Invalid array for declaring a list of instances."
    end
    # Get the system to instantiate.
    systemT = High.space_call(name)
    # Get the name of the instance from the arguments.
    nameI = args.shift.to_s
    # Create the instances.
    instances = size.times.map do |i| 
        systemT.instantiate((nameI + "[#{i}]").to_sym,*args)
    end
    nameI = nameI.to_sym
    # Add them to the top system
    High.space_top.user.add_groupI(nameI,*instances)
    # Register and return the result.
    High.space_reg(nameI) { High.space_top.user.get_groupI(nameI) }
    return High.space_top.user.get_groupI(nameI)
end

#output(*names) ⇒ Object

Declares high-level untyped output signals named +names+ of the current type.



3771
3772
3773
# File 'lib/HDLRuby/hruby_high.rb', line 3771

def output(*names)
    High.top_user.make_outputs(self.to_type,*names)
end

#to_exprObject

Converts to a new high-level expression.



3726
3727
3728
3729
3730
3731
3732
3733
# File 'lib/HDLRuby/hruby_high.rb', line 3726

def to_expr
    # expr = Concat.new
    expr = Concat.new(TypeTuple.new(:"",:little,*self.map do |elem|
        elem.to_expr.type
    end))
    self.each {|elem| expr.add_expression(elem.to_expr) }
    expr
end

#to_refObject

Converts to a new high-level reference.



3736
3737
3738
3739
3740
3741
3742
3743
# File 'lib/HDLRuby/hruby_high.rb', line 3736

def to_ref
    # expr = RefConcat.new
    expr = RefConcat.new(TypeTuple.new(:"",:little,*self.map do |elem|
        elem.to_ref.type
    end))
    self.each {|elem| expr.add_ref(elem.to_ref) }
    expr
end

#to_typeObject

Converts to a new type.



3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
# File 'lib/HDLRuby/hruby_high.rb', line 3746

def to_type
    if self.size == 1 and
       ( self[0].is_a?(Range) or self[0].respond_to?(:to_i) ) then
        # Vector type case
        return bit[*self]
    else
        # Tuple type case.
        return TypeTuple.new(:"",:little,*self)
    end
end

#typedef(name) ⇒ Object

Declares a new type definition with +name+ equivalent to current one.



3758
3759
3760
# File 'lib/HDLRuby/hruby_high.rb', line 3758

def typedef(name)
    return self.to_type.typedef(name)
end