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
Creates a new reference with type
concatenating the references of refs
together. def initialize(refs = [])
# 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
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
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
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
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 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
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
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
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
Comparison for hash: structural comparison.
# 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 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
function.
# File lib/HDLRuby/hruby_low.rb, line 5266 def hash return [super,@refs].hash end
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
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
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
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
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
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
# 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
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
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