class HDLRuby::Low::RefConcat

Describes reference concatenation.

Describes concatenation reference.

Extends the RefConcat class with generation of C text.

Extends the RefConcat class with generation of hdr text.

Add the conversion to high.

Extends the RefConcat class with generation of HDLRuby::High text.

Extends the Ref class with functionality for converting booleans in assignments to select operators.

Extends the RefConcat class with functionality for converting booleans in assignments to select operators.

Extends the RefConcat class with fixing of types and constants.

Describes concatenation reference.

Use it when collecting references.

Public Class Methods

new(type, refs = []) click to toggle source

Creates a new reference with type concatenating the references of refs together. def initialize(refs = [])

Calls superclass method
# File lib/HDLRuby/hruby_low.rb, line 5210
def initialize(type, refs = [])
    super(type)
    # Check and set the refs.
    refs.each do |ref|
        # puts "ref.class=#{ref.class}"
        unless ref.is_a?(Ref) then
            raise AnyError,
                  "Invalid class for an reference: #{ref.class}"
        end
    end
    @refs = refs
    # And set their parents.
    refs.each { |ref| ref.parent = self }
end

Public Instance Methods

add_ref(ref) click to toggle source

Adds an ref to concat.

# File lib/HDLRuby/hruby_low.rb, line 5282
def add_ref(ref)
    # Check ref.
    unless ref.is_a?(Ref) then
        raise AnyError,
              "Invalid class for an ref: #{ref.class}"
    end
    # Add it.
    @refs << ref
    # And set its parent.
    ref.parent = self
    ref
end
boolean_in_assign2select() click to toggle source

Converts booleans in assignments to select operators.

# File lib/HDLRuby/hruby_low_bool2select.rb, line 274
def boolean_in_assign2select
    # Recurse on the sub references.
    return RefConcat.new(self.type,self.each_expression.map do |expr|
        expr.boolean_in_assign2select
    end )
end
casts_without_expression() click to toggle source

Extracts the expressions from the casts.

# File lib/HDLRuby/hruby_low_casts_without_expression.rb, line 282
def casts_without_expression
    # Recurse on the sub references.
    return RefConcat.new(self.type,self.each_expression.map do |expr|
        expr.casts_without_expression
    end )
end
clone() click to toggle source

Clones the concatenated references (deeply)

# File lib/HDLRuby/hruby_low.rb, line 5314
def clone
    return RefConcat.new(@type, @refs.map { |ref| ref.clone } )
end
delete_ref!(ref) click to toggle source

Delete a reference.

# File lib/HDLRuby/hruby_low_mutable.rb, line 1718
def delete_ref!(ref)
    if @refs.include?(ref) then
        # The ref is present, delete it.
        @refs.delete(ref)
        # And remove its parent.
        ref.parent = nil
    end
    ref
end
each_deep(&ruby_block) click to toggle source

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 5236
def each_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # Then apply on the type.
    self.type.each_deep(&ruby_block)
    # Then apply on the sub references.
    self.each_ref do |ref|
        ref.each_deep(&ruby_block)
    end
end
each_node(&ruby_block)
Alias for: each_ref
each_node_deep(&ruby_block) click to toggle source

Iterates over the nodes deeply if any.

# File lib/HDLRuby/hruby_low.rb, line 5296
def each_node_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # And recurse on the sub references.
    self.each_ref do |ref|
        ref.each_node_deep(&ruby_block)
    end
end
each_ref(&ruby_block) click to toggle source

Iterates over the concatenated references.

Returns an enumerator if no ruby block is given.

# File lib/HDLRuby/hruby_low.rb, line 5273
def each_ref(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_ref) unless ruby_block
    # A ruby block? Apply it on each children.
    @refs.each(&ruby_block)
end
Also aliased as: each_node
eql?(obj) click to toggle source

Comparison for hash: structural comparison.

Calls superclass method
# File lib/HDLRuby/hruby_low.rb, line 5250
def eql?(obj)
    # General comparison.
    return false unless super(obj)
    # Specific comparison.
    return false unless obj.is_a?(RefConcat)
    idx = 0
    obj.each_ref do |ref|
        return false unless @refs[idx].eql?(ref)
        idx += 1
    end
    return false unless idx == @refs.size
    return false unless @refs.eql?(obj.instance_variable_get(:@refs))
    return true
end
explicit_types(type = nil) click to toggle source

Explicit the types conversions in the concat ref where type is the expected type of the condition if any.

# File lib/HDLRuby/hruby_low_fix_types.rb, line 352
def explicit_types(type = nil)
    # Is there a type to match?
    if type then
        # Yes, update the concat to the type.
        # Is it an array type?
        if type.is_a?(TypeVector) then
            # Yes, update the concat accordingly.
            return RefConcat.new(type,self.each_ref.map do |ref|
                ref.explicit_types(type.base)
            end)
        else
            # No, it should be a tuple.
            return RefConcat.new(type,self.each_ref.map.with_index do
                |ref,i|
                ref.explicit_types(type.get_type(i))
            end)
        end
    else
        # No, recurse on the sub expressions.
        return RefConcat.new(self.type,self.each_ref.map.with_index do
            |ref,i| 
            ref.explicit_types(self.type.get_type(i))
        end)
    end
end
hash() click to toggle source

Hash function.

Calls superclass method
# File lib/HDLRuby/hruby_low.rb, line 5266
def hash
    return [super,@refs].hash
end
immutable?() click to toggle source

Tells if the expression is immutable (cannot be written.)

# File lib/HDLRuby/hruby_low.rb, line 5226
def immutable?
    # Immutable if children are all immutable.
    return self.each_ref.reduce(true) do |r,c|
        r && c.immutable?
    end
end
map_nodes!(&ruby_block)
Alias for: map_refs!
map_refs!(&ruby_block) click to toggle source

Maps on the references.

# File lib/HDLRuby/hruby_low_mutable.rb, line 1707
def map_refs!(&ruby_block)
    @refs.map! do |ref|
        ref = ruby_block.call(ref)
        ref.parent = self unless ref.parent
        ref
    end
end
Also aliased as: map_nodes!
to_c(level = 0, left = false) click to toggle source

Generates the C text of the equivalent HDLRuby code. level is the hierachical level of the object and left tells if it is a left value or not.

# File lib/HDLRuby/hruby_low2c.rb, line 1886
def to_c(level = 0, left = false)
    raise "RefConcat cannot be converted to C directly, please use break_concat_assign!."
    # # The resulting string.
    # res = "ref_concat(#{self.each_ref.to_a.size}"
    # self.each_ref do |ref|
    #     res << ",#{ref.to_c(level,left)}"
    # end
    # res << ")"
    # return res
end
to_c_signal(level = 0) click to toggle source

Generates the C text for reference as left value to a signal. level is the hierarchical level of the object.

# File lib/HDLRuby/hruby_low2c.rb, line 1899
def to_c_signal(level = 0)
    raise "RefConcat cannot be converted to C directly, please use break_concat_assign!."
    # # The resulting string.
    # res = "sig_concat(#{self.each_ref.to_a.size}"
    # self.each_ref do |ref|
    #     res << ",#{ref.to_c_signal(level)}"
    # end
    # res << ")"
    # return res
end
to_hdr(level = 0) click to toggle source

Generates the text of the equivalent hdr text. level is the hierachical level of the object.

# File lib/HDLRuby/hruby_low2hdr.rb, line 664
def to_hdr(level = 0)
    # The resulting string.
    res = ""
    # Generate the header.
    res << "[ "
    # Generate the references.
    res << self.each_ref.map do |ref|
        ref.to_hdr(level+1)
    end.join(", ")
    # Close the select.
    res << " ]"
    # Return the resulting string.
    return res
end
to_high() click to toggle source

Creates a new high concat reference.

# File lib/HDLRuby/hruby_low2high.rb, line 463
def to_high
    return HDLRuby::High::Ref.new(self.type.to_high,
                            self.each_ref.map { |ref| ref.to_high })
end
to_verilog() click to toggle source
# File lib/HDLRuby/hruby_verilog.rb, line 1425
def to_verilog    
    ref = self.each_ref.to_a

    result = "{"
    ref[0..-2].each do |ref|
        result << "#{ref.to_verilog},"
    end
    result << "#{ref.last.to_verilog}}"

    return result
end
to_vhdl(level = 0) click to toggle source

Generates the text of the equivalent HDLRuby::High code. level is the hierachical level of the object.

# File lib/HDLRuby/hruby_low2vhd.rb, line 1423
def to_vhdl(level = 0)
    # The resulting string.
    res = ""
    # Generate the header.
    res << "( "
    # Generate the references.
    res << self.each_ref.map do |ref|
        ref.to_vhdl(level+1)
    end.join(", ")
    # Close the select.
    res << " )"
    # Return the resulting string.
    return res
end
use_name?(*names) click to toggle source

Tell if the expression includes a signal whose name is one of names.

# File lib/HDLRuby/hruby_low.rb, line 5308
def use_name?(*names)
    # Recurse on the references.
    return @refs.any? { |expr| expr.use_name?(*names) }
end