Class: RubyHDL::High::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes the software implementation of an expression.

Direct Known Subclasses

Binary, Ref, Ruby, Scall, Select, SignalI, Unary, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Expression

Create a new expression with +type+ data type.



1796
1797
1798
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1796

def initialize(type)
  @type = type.to_type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



1794
1795
1796
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1794

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.



1855
1856
1857
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1855

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.



1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1870

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.



1920
1921
1922
1923
1924
1925
1926
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1920

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.



1949
1950
1951
1952
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1949

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.



1931
1932
1933
1934
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1931

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.



1937
1938
1939
1940
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1937

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.



1943
1944
1945
1946
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1943

def supto(val,&ruby_block)
  RubyHDL::High.top_sblock <<
  Siter.new(RubyHDL::High.top_sblock.sequencer,self,"upto",&ruby_block)
end

#to_cObject

Convert to C code.



1818
1819
1820
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1818

def to_c
  raise "to_c not defined for class: #{self.class}."
end

#to_exprObject Also known as: to_ref

Converts to an expression.



1801
1802
1803
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1801

def to_expr
  self
end

#to_python(l = "") ⇒ Object

Convert to Python code.



1823
1824
1825
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1823

def to_python(l = "")
  raise "to_python not defined for class: #{self.class}."
end

#to_rubyObject Also known as: to_ruby_left

Convert to Ruby code.



1813
1814
1815
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1813

def to_ruby
  raise "to_ruby not defined for class: #{self.class}."
end

#to_valueObject

Compute the expression (convert it to a value).



1808
1809
1810
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 1808

def to_value
  raise "to_value not defined here."
end