Class: RubyHDL::High::Expression
- Inherits:
-
Object
- Object
- RubyHDL::High::Expression
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes the software implementation of an expression.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#<=(right) ⇒ Object
The <= operator which can be either a transmit or a comparison.
-
#[](typ, rng = nil) ⇒ Object
Creates an access to elements of range +rng+ of the signal, and set the type of elements as +typ+ if given.
-
#initialize(type) ⇒ Expression
constructor
Create a new expression with +type+ data type.
-
#mux(*choices) ⇒ Object
Converts to a select operator using current expression as condition for one of the +choices+.
-
#sdownto(val, &ruby_block) ⇒ Object
HW downto iteration.
-
#seach(&ruby_block) ⇒ Object
HW iteration on each element.
-
#stimes(&ruby_block) ⇒ Object
HW times iteration.
-
#supto(val, &ruby_block) ⇒ Object
HW upto iteration.
-
#to_c ⇒ Object
Convert to C code.
-
#to_expr ⇒ Object
(also: #to_ref)
Converts to an expression.
-
#to_ruby ⇒ Object
(also: #to_ruby_left)
Convert to Ruby code.
-
#to_value ⇒ Object
Compute the expression (convert it to a value).
Constructor Details
#initialize(type) ⇒ Expression
Create a new expression with +type+ data type.
1636 1637 1638 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1636 def initialize(type) @type = type.to_type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
1634 1635 1636 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1634 def type @type end |
Instance Method Details
#<=(right) ⇒ Object
The <= operator which can be either a transmit or a comparison. By default set to transmit, and converted to comparison if child of operator or condition of sif/swhile statements.
1690 1691 1692 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1690 def <=(right) return Transmit.new(self.to_expr,right.to_expr) end |
#[](typ, rng = nil) ⇒ Object
Creates an access to elements of range +rng+ of the signal, and set the type of elements as +typ+ if given.
NOTE: +rng+ can be a single expression in which case it is an index.
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 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1705 def [](typ,rng=nil) # Treat the number of arguments rng, typ = typ, nil unless rng # Process the range. if rng.is_a?(::Range) then first = rng.first if (first.is_a?(::Integer)) then first = self.type.size+first if first < 0 end last = rng.last if (last.is_a?(::Integer)) then last = self.type.size+last if last < 0 end rng = first..last end if rng.is_a?(::Integer) && rng < 0 then rng = self.type.size+rng end if rng.respond_to?(:to_expr) then # Number range: convert it to an expression. rng = rng.to_expr end if rng.is_a?(Expression) then # Index case if typ then return RefIndex.new(typ,self.to_expr,rng) else return RefIndex.new(self.type.base,self.to_expr,rng) end else # Range case, ensure it is made among expression. first = rng.first.to_expr last = rng.last.to_expr # And create the reference. if typ then return RefRange.new(typ, self.to_expr,first..last) else return RefRange.new(self.type.slice(first..last), self.to_expr,first..last) end end end |
#mux(*choices) ⇒ Object
Converts to a select operator using current expression as condition for one of the +choices+.
NOTE: +choices+ can either be a list of arguments or an array. If +choices+ has only two entries (and it is not a hash), +value+ will be converted to a boolean.
1755 1756 1757 1758 1759 1760 1761 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1755 def mux(*choices) # Process the choices. choices = choices.flatten(1) if choices.size == 1 choices.map! { |choice| choice.to_expr } # Generate the select expression. return Select.new(choices[0].type,self.to_expr,*choices) end |
#sdownto(val, &ruby_block) ⇒ Object
HW downto iteration.
1784 1785 1786 1787 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1784 def sdownto(val,&ruby_block) RubyHDL::High.top_sblock << Siter.new(RubyHDL::High.top_sblock.sequencer,self,"downto",&ruby_block) end |
#seach(&ruby_block) ⇒ Object
HW iteration on each element.
1766 1767 1768 1769 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1766 def seach(&ruby_block) RubyHDL::High.top_sblock << Siter.new(RubyHDL::High.top_sblock.sequencer,self,"each",&ruby_block) end |
#stimes(&ruby_block) ⇒ Object
HW times iteration.
1772 1773 1774 1775 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1772 def stimes(&ruby_block) RubyHDL::High.top_sblock << Siter.new(RubyHDL::High.top_sblock.sequencer,self,"times",&ruby_block) end |
#supto(val, &ruby_block) ⇒ Object
HW upto iteration.
1778 1779 1780 1781 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1778 def supto(val,&ruby_block) RubyHDL::High.top_sblock << Siter.new(RubyHDL::High.top_sblock.sequencer,self,"upto",&ruby_block) end |
#to_c ⇒ Object
Convert to C code.
1658 1659 1660 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1658 def to_c raise "to_c not defined for class: #{self.class}." end |
#to_expr ⇒ Object Also known as: to_ref
Converts to an expression.
1641 1642 1643 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1641 def to_expr self end |
#to_ruby ⇒ Object Also known as: to_ruby_left
Convert to Ruby code.
1653 1654 1655 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1653 def to_ruby raise "to_ruby not defined for class: #{self.class}." end |
#to_value ⇒ Object
Compute the expression (convert it to a value).
1648 1649 1650 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1648 def to_value raise "to_value not defined here." end |