Class: HDLRuby::Low::RefRange
- Inherits:
-
Ref
- Object
- Base::Expression
- Expression
- Ref
- HDLRuby::Low::RefRange
- Defined in:
- lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_resolve.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_bool2select.rb
Overview
Extends the RefRange class with functionality for converting booleans in assignments to select operators.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
The access range.
-
#ref ⇒ Object
readonly
The accessed reference.
Attributes inherited from Expression
Attributes included from Hparent
Instance Method Summary collapse
-
#boolean_in_assign2select ⇒ Object
Converts booleans in assignments to select operators.
-
#clone ⇒ Object
Clones the range references (deeply).
-
#each_node(&ruby_block) ⇒ Object
(also: #each_expression)
Iterates over the reference children if any.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the range ref where +type+ is the expected type of the condition if any.
-
#from_systemI? ⇒ Boolean
Tells if it is a reference to a systemI signal.
-
#hash ⇒ Object
Hash function.
-
#initialize(type, ref, range) ⇒ RefRange
constructor
Create a new range reference with +type+ accessing +ref+ at +range+.
-
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children.
-
#path_each(&ruby_block) ⇒ Object
Iterates over the names of the path indicated by the reference.
-
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement.
-
#set_range!(range) ⇒ Object
Sets the range.
-
#set_ref!(ref) ⇒ Object
Sets the base reference.
-
#to_c(level = 0, left = false) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code.
-
#to_c_signal(level = 0) ⇒ Object
Generates the C text for reference as left value to a signal.
-
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#to_verilog(unknown = false) ⇒ Object
Converts the system to Verilog code.
-
#to_vhdl(level = 0, std_logic = false) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
Methods inherited from Expression
#boolean?, #break_types!, #each_ref_deep, #extract_selects_to!, #leftvalue?, #replace_names!, #rightvalue?, #set_type!, #statement
Methods included from Low2Symbol
Constructor Details
#initialize(type, ref, range) ⇒ RefRange
Create a new range reference with +type+ accessing +ref+ at +range+. def initialize(ref,range)
4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 |
# File 'lib/HDLRuby/hruby_low.rb', line 4544 def initialize(type,ref,range) super(type) # Check and set the refered object. # unless ref.is_a?(Ref) then unless ref.is_a?(Expression) then raise AnyError, "Invalid class for a reference: #{ref.class}." end @ref = ref # And set its parent. ref.parent = self # Check and set the range. first = range.first unless first.is_a?(Expression) then raise AnyError, "Invalid class for a range first: #{first.class}." end last = range.last unless last.is_a?(Expression) then raise AnyError, "Invalid class for a range last: #{last.class}." end @range = first..last # And set their parents. first.parent = last.parent = self end |
Instance Attribute Details
#range ⇒ Object (readonly)
The access range.
4540 4541 4542 |
# File 'lib/HDLRuby/hruby_low.rb', line 4540 def range @range end |
#ref ⇒ Object (readonly)
The accessed reference.
4537 4538 4539 |
# File 'lib/HDLRuby/hruby_low.rb', line 4537 def ref @ref end |
Instance Method Details
#boolean_in_assign2select ⇒ Object
Converts booleans in assignments to select operators.
263 264 265 266 267 268 269 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 263 def boolean_in_assign2select # Recurse on the sub references. return RefRange.new(self.type, self.ref.boolean_in_assign2select, self.range.first.boolean_in_assign2select .. self.range.last.boolean_in_assign2select) end |
#clone ⇒ Object
Clones the range references (deeply)
4622 4623 4624 4625 |
# File 'lib/HDLRuby/hruby_low.rb', line 4622 def clone return RefRange.new(@type, @ref.clone, (@range.first.clone)..(@range.last.clone) ) end |
#each_node(&ruby_block) ⇒ Object Also known as: each_expression
Iterates over the reference children if any.
4598 4599 4600 4601 4602 4603 4604 4605 |
# File 'lib/HDLRuby/hruby_low.rb', line 4598 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 ranfe and the ref. ruby_block.call(@range.first) ruby_block.call(@range.last) ruby_block.call(@ref) end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 |
# File 'lib/HDLRuby/hruby_low.rb', line 4610 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. @range.first.each_node_deep(&ruby_block) @range.last.each_node_deep(&ruby_block) @ref.each_node_deep(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
NOTE: ranges are assumed to be flattened (a range of range is a range of same level).
4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 |
# File 'lib/HDLRuby/hruby_low.rb', line 4573 def eql?(obj) # General comparison. return false unless super(obj) # Specific comparison. return false unless obj.is_a?(RefRange) return false unless @range.first.eql?(obj.range.first) return false unless @range.last.eql?(obj.range.last) return false unless @ref.eql?(obj.ref) return true end |
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the range ref where +type+ is the expected type of the condition if any.
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 387 def explicit_types(type = nil) # Is there a type to match ? if type then # Regenerate the reference and cast it. return Cast.new(type, RefRange.new(self.type,self.ref.explicit_types, self.range.first.explicit_types .. self.range.last.explicit_types)) else # No, recurse with the type of the current range ref. return RefRange.new(self.type, self.ref.explicit_types, self.range.first.explicit_types .. self.range.last.explicit_types) end end |
#from_systemI? ⇒ Boolean
Tells if it is a reference to a systemI signal.
104 105 106 |
# File 'lib/HDLRuby/hruby_low_resolve.rb', line 104 def from_systemI? return self.ref.from_systemI end |
#hash ⇒ Object
Hash function.
4585 4586 4587 |
# File 'lib/HDLRuby/hruby_low.rb', line 4585 def hash return [super,@range,@ref].hash end |
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children.
1680 1681 1682 1683 1684 1685 1686 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1680 def map_nodes!(&ruby_block) @range = ruby_block.call(@range.first)..ruby_block.call(@range.last) @range.first.parent = self unless @range.first.parent @range.last.parent = self unless @range.last.parent @ref = ruby_block.call(@ref) @ref.parent = self unless @ref.parent end |
#path_each(&ruby_block) ⇒ Object
Iterates over the names of the path indicated by the reference.
Returns an enumerator if no ruby block is given.
4592 4593 4594 4595 |
# File 'lib/HDLRuby/hruby_low.rb', line 4592 def path_each(&ruby_block) # Recurse on the base reference. return ref.path_each(&ruby_block) end |
#replace_expressions!(node2rep) ⇒ Object
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.
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1694 def replace_expressions!(node2rep) # First recurse on the ref. res = self.ref.replace_expressions!(node2rep) # And and the range. res = self.range.first.replace_expressions!(node2rep) res = self.range.last.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 range first? range = self.range rep = node2rep[range.first] if rep then # Yes, do it. rep = rep.clone node = range.first # node.set_parent!(nil) range.first = rep # And register the replacement. res[node] = rep end rep = node2rep[range.last] if rep then # Yes, do it. rep = rep.clone node = range.last # node.set_parent!(nil) range.last = rep # And register the replacement. res[node] = rep end self.set_range!(range) return res end |
#set_range!(range) ⇒ Object
Sets the range.
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1663 def set_range!(range) # Check and set the range. first = range.first unless first.is_a?(Expression) then raise AnyError, "Invalid class for a range first: #{first.class}." end last = range.last unless last.is_a?(Expression) then raise AnyError, "Invalid class for a range last: #{last.class}." end @range = first..last # And set their parents. first.parent = last.parent = self end |
#set_ref!(ref) ⇒ Object
Sets the base reference.
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1651 def set_ref!(ref) # Check and set the refered object. # unless ref.is_a?(Ref) then unless ref.is_a?(Expression) then raise AnyError, "Invalid class for a reference: #{ref.class}." end @ref = ref # And set its parent. ref.parent = self end |
#to_c(level = 0, left = false) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object and +left+ tells if it is a left value or not.
1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1891 def to_c(level = 0, left = false) # if left then # res = "write_range(#{self.ref.to_c(level,left)}," # else # res = "read_range(#{self.ref.to_c(level,left)}," # end # res << "read64(#{self.range.first.to_c(level)})," + # "read64(#{self.range.last.to_c(level)})," + # "#{self.type.base.to_c(level)})" # return res # Decide if it is a read or a write command = left ? "write" : "read" res = "({\n" # Overrides the upper ref and dst... # 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 first,last;\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 range. res << (" " * ((level+1)*3)) # res << "first = read64(#{self.range.first.to_c(level+2)});\n" res << "first = value2integer(#{self.range.first.to_c(level+2)});\n" res << (" " * ((level+1)*3)) # res << "last = read64(#{self.range.last.to_c(level+2)});\n" res << "last = value2integer(#{self.range.last.to_c(level+2)});\n" # Make the access. res << (" " * ((level+1)*3)) res << "dst = #{command}_range(ref,first,last,#{self.ref.type.base.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 |
#to_c_signal(level = 0) ⇒ Object
Generates the C text for reference as left value to a signal. +level+ is the hierarchical level of the object.
1936 1937 1938 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1936 def to_c_signal(level = 0) return to_c(level,true) end |
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
695 696 697 698 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 695 def to_high(level = 0) return self.ref.to_high(level) + "[(#{self.range.first.to_high(level)})..(#{self.range.last.to_high(level)})]" end |
#to_verilog(unknown = false) ⇒ Object
Converts the system to Verilog code.
1294 1295 1296 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1294 def to_verilog(unknown = false) return "#{self.ref.to_verilog}[#{self.range.first.to_getrange}:#{self.range.last.to_getrange}]" end |
#to_vhdl(level = 0, std_logic = false) ⇒ Object
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.
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1374 def to_vhdl(level = 0, std_logic = false) # Generates the direction. first = self.range.first first = first.content if first.is_a?(Value) last = self.range.last last = last.content if last.is_a?(Value) direction = first >= last ? "downto " : " to " # Generate the reference. # Forced std_logic case. if std_logic then if first == last then # No range, single bit access for forcing std_logic. return self.ref.to_vhdl(level) + "(#{self.range.first.to_vhdl(level)})" else return self.ref.to_vhdl(level) + "((#{self.range.first.to_vhdl(level)}) " + direction + "(#{self.range.last.to_vhdl(level)}))(0)" end else return self.ref.to_vhdl(level) + "((#{self.range.first.to_vhdl(level)}) " + direction + "(#{self.range.last.to_vhdl(level)}))" end end |