class HDLRuby::Low::RefIndex
Describes an index reference.
Describes a index reference.
Extends the RefIndex
class with generation of C text.
Extends the RefIndex
class with generation of hdr text.
Add the conversion to high.
Extends the RefIndex
class with generation of HDLRuby::High
text.
Extends the RefIndex
class with functionality for converting booleans in assignments to select operators.
Extends the RefIndex
class with functionality for converting booleans in assignments to select operators.
Extends the RefIndex
class with fixing of types and constants.
Describes a index reference.
Extends RefIndex
with the capability of finding the object it refered to.
Used to convert an array. Enhance RefIndex
with generation of verilog code.
Attributes
The access index.
The accessed reference.
Public Class Methods
Create a new index reference with type
accessing ref
at index
. def initialize(ref,index)
# File lib/HDLRuby/hruby_low.rb, line 5331 def initialize(type,ref,index) super(type) # Check and set the accessed reference. unless ref.is_a?(Ref) then raise AnyError, "Invalid class for a reference: #{ref.class}." end @ref = ref # And set its parent. ref.parent = self # Check and set the index. unless index.is_a?(Expression) then raise AnyError, "Invalid class for an index reference: #{index.class}." end @index = index # And set its parent. index.parent = self end
Public Instance Methods
Converts booleans in assignments to select operators.
# File lib/HDLRuby/hruby_low_bool2select.rb, line 287 def boolean_in_assign2select # Recurse on the sub references. return RefIndex.new(self.type, self.ref.boolean_in_assign2select, self.index.boolean_in_assign2select) end
Extracts the expressions from the casts.
# File lib/HDLRuby/hruby_low_casts_without_expression.rb, line 295 def casts_without_expression # Recurse on the sub references. return RefIndex.new(self.type, self.ref.casts_without_expression, self.index.casts_without_expression) end
Clones the indexed references (deeply)
# File lib/HDLRuby/hruby_low.rb, line 5427 def clone return RefIndex.new(@type, @ref.clone, @index.clone) end
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
# File lib/HDLRuby/hruby_low.rb, line 5359 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 reference. self.ref.each_deep(&ruby_block) # Then apply on the index if possible. if self.index.respond_to?(:each_deep) then self.index.each_deep(&ruby_block) end end
Iterates over the reference children if any.
# File lib/HDLRuby/hruby_low.rb, line 5399 def each_node(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node) unless ruby_block # A ruby block? Apply it on the index and the ref. ruby_block.call(@index) ruby_block.call(@ref) end
Iterates over the nodes deeply if any.
# File lib/HDLRuby/hruby_low.rb, line 5410 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 children. @index.each_node_deep(&ruby_block) @ref.each_node_deep(&ruby_block) end
Comparison for hash: structural comparison.
# File lib/HDLRuby/hruby_low.rb, line 5375 def eql?(obj) # General comparison. return false unless super(obj) # Specific comparison. return false unless obj.is_a?(RefIndex) return false unless @index.eql?(obj.index) return false unless @ref.eql?(obj.ref) return true end
Explicit the types conversions in the index ref where type
is the expected type of the condition if any.
# File lib/HDLRuby/hruby_low_fix_types.rb, line 384 def explicit_types(type = nil) # Is there a type to match ? if type then # Regenerate the reference and cast it return Cast.new(type, RefIndex.new(self.type,self.ref.explicit_types, self.index.explicit_types)) else # No, recurse with the type of the current index ref. return RefIndex.new(self.type, self.ref.explicit_types, self.index.explicit_types) end end
Tells if it is a reference to a systemI signal.
# File lib/HDLRuby/hruby_low_resolve.rb, line 107 def from_systemI? return self.ref.from_systemI? end
Hash
function.
# File lib/HDLRuby/hruby_low.rb, line 5386 def hash return [super,@index,@ref].hash end
Tells if the expression is immutable (cannot be written.)
# File lib/HDLRuby/hruby_low.rb, line 5351 def immutable? # Immutable if the ref is immutable. return self.ref.immutable? end
Maps on the children.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1759 def map_nodes!(&ruby_block) @index = ruby_block.call(@index) @index.parent = self unless @index.parent @ref = ruby_block.call(@ref) @ref.parent = self unless @ref.parent end
Iterates over the names of the path indicated by the reference.
Returns an enumerator if no ruby block is given.
# File lib/HDLRuby/hruby_low.rb, line 5393 def path_each(&ruby_block) # Recurse on the base reference. return ref.path_each(&ruby_block) end
Replaces sub expressions using node2rep
table indicating the node to replace and the corresponding replacement. Returns the actually replaced nodes and their corresponding replacement.
NOTE: the replacement is duplicated.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1772 def replace_expressions!(node2rep) # First recurse on the ref. res = self.ref.replace_expressions!(node2rep) # And and the index. res = self.index.replace_expressions!(node2rep) # Is there a replacement to on the ref? rep = node2rep[self.ref] if rep then # Yes, do it. rep = rep.clone node = self.ref # node.set_parent!(nil) self.set_ref!(rep) # And register the replacement. res[node] = rep end # Is there a replacement to on the index? rep = node2rep[self.index] if rep then # Yes, do it. rep = rep.clone node = self.index # node.set_parent!(nil) self.set_index!(rep) # And register the replacement. res[node] = rep end return res end
Resolves the name of the reference (if any) and return the corresponding object. NOTE: return nil if could not resolve.
# File lib/HDLRuby/hruby_low_resolve.rb, line 114 def resolve return self.ref.resolve end
Sets the index.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1747 def set_index!(ref) # Check and set the index. unless index.is_a?(Expression) then raise AnyError, "Invalid class for an index reference: #{index.class}." end @index = index # And set its parent. index.parent = self end
Sets the base reference.
# File lib/HDLRuby/hruby_low_mutable.rb, line 1736 def set_ref!(ref) # Check and set the accessed reference. unless ref.is_a?(Ref) then raise AnyError, "Invalid class for a reference: #{ref.class}." end @ref = ref # And set its parent. ref.parent = self end
Generates the C text of the equivalent HDLRuby
code. level
is thehierachical level of the object and left
tells if it is a left value or not.
# File lib/HDLRuby/hruby_low2c.rb, line 1918 def to_c(level = 0, left = false) res = "({\n" # And allocates a new value for dst. res << (" " * ((level+1)*3)) res << "Value ref,dst = get_value();\n" res << (" " * ((level+1)*3)) res << "unsigned long long idx;\n" # Save the state of the value pool. res << (" " * ((level+1)*3)) res << "unsigned int pool_state = get_value_pos();\n" # Compute the reference. res << (" " * ((level+1)*3)) res << "ref = #{self.ref.to_c(level+2)};\n" # Compute the index. res << (" " * ((level+1)*3)) # res << "idx = read64(#{self.index.to_c(level+2)});\n" res << "idx = value2integer(#{self.index.to_c(level+2)});\n" # Make the access. res << (" " * ((level+1)*3)) # res << "dst = read_range(ref,idx,idx,#{self.ref.type.base.to_c(level)},dst);\n" res << "dst = read_range(ref,idx,idx,#{self.type.to_c(level)},dst);\n" # Restore the state of the value pool. res << (" " * ((level+1)*3)) res << "set_value_pos(pool_state);\n" # Close the computation. res << (" " * (level*3)) res << "dst; })" 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 1949 def to_c_signal(level = 0) return "make_ref_rangeS(#{self.ref.to_c_signal(level)}," + "value2integer(#{self.index.to_c(level)}),value2integer(#{self.index.to_c(level)}))" end
Generates the text of the equivalent hdr text. level
is the hierachical level of the object.
# File lib/HDLRuby/hruby_low2hdr.rb, line 685 def to_hdr(level = 0) return self.ref.to_hdr(level) + "[#{self.index.to_hdr(level)}]" end
Creates a new high index reference.
# File lib/HDLRuby/hruby_low2high.rb, line 473 def to_high return HDLRuby::High::RefIndex.new(self.type.to_high, self.ref.to_high, self.index.to_high) end
Converts the system to Verilog
code.
# File lib/HDLRuby/hruby_verilog.rb, line 1396 def to_verilog return "#{self.ref.to_verilog}[#{self.index.to_verilog}]" end
Generates the text of the equivalent HDLRuby::High
code. level
is the hierachical level of the object. std_logic
tells if std_logic computation is to be done.
# File lib/HDLRuby/hruby_low2vhd.rb, line 1445 def to_vhdl(level = 0, std_logic = false) if self.index.is_a?(Value) then return self.ref.to_vhdl(level,std_logic) + "(#{self.index.to_vhdl(level)})" else return self.ref.to_vhdl(level,std_logic) + "(to_integer(unsigned(#{self.index.to_vhdl(level)})))" end end
Tell if the expression includes a signal whose name is one of names
.
# File lib/HDLRuby/hruby_low.rb, line 5421 def use_name?(*names) # Recurse on the index and the reference. return @index.use_name?(names) || @ref.use_name?(*names) end