Class: RubyHDL::High::SignalI

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

Overview

Describes a SW implementation of a signal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#<=, #[], #mux, #sdownto, #seach, #stimes, #supto, #to_expr, #to_value

Constructor Details

#initialize(name, type, dir) ⇒ SignalI

Create a new signal with type +type+ and name +name+.



3704
3705
3706
3707
3708
3709
3710
3711
3712
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3704

def initialize(name,type,dir)
  @name = name.to_sym
  @type = type.to_type
  @dir = dir.to_sym
  # Compute the mask for adjusting the value to the type.
  @mask = (2 ** @type.width)-1
  @sign = 2 ** (@type.width-1)
  @global = "" # The global indicator: empty or '$'
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



3702
3703
3704
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3702

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



3702
3703
3704
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3702

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3702
3703
3704
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3702

def type
  @type
end

Instance Method Details

#array?Boolean

Tell if the signal is an array.

Returns:

  • (Boolean)


3725
3726
3727
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3725

def array?
  return @type.base.is_a?(TypeVector)
end

#global!Object

Set the signal to be a global.



3720
3721
3722
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3720

def global!
  @global = "$"
end

#global?Boolean

Tell if the signal is global or not.

Returns:

  • (Boolean)


3715
3716
3717
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3715

def global?
  return @global == "$"
end

#to_cObject

Convert to C code.



3735
3736
3737
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3735

def to_c
  return "__" + self.name.to_s
end

#to_fObject

Convert to an float.



3793
3794
3795
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3793

def to_f
  return self.value.to_f
end

#to_iObject

Convert to an integer.



3788
3789
3790
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3788

def to_i
  return self.value.to_i
end

#to_python(l = "") ⇒ Object

Convert to Python code.



3740
3741
3742
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3740

def to_python(l = "")
  return "__" + self.name.to_s
end

#to_rubyObject

Convert to Ruby code.



3730
3731
3732
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3730

def to_ruby
  return @global + "__" + self.name.to_s
end

#to_sObject

Convert to a string.



3798
3799
3800
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3798

def to_s
  return self.value.to_s
end

#valueObject

Gets the value of the signal.



3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3754

def value
  # return TOPLEVEL_BINDING.eval(self.to_ruby)
  res = TOPLEVEL_BINDING.eval(self.to_ruby)
  if res.is_a?(Integer) then
    res = res & @mask
    if @type.signed? then
      if res & @sign != 0 then
        return res - (@mask+1)
      end
    end
  end
  return res
end

#value=(val) ⇒ Object

Sets the value of the signal.



3783
3784
3785
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3783

def value=(val)
  return TOPLEVEL_BINDING.eval("#{self.to_ruby} = #{val}")
end

#value?Boolean

Check if a value is defined for the signal.

Returns:

  • (Boolean)


3745
3746
3747
3748
3749
3750
3751
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3745

def value?
  if global? then
    return global_variables.include?(self.to_ruby)
  else
    return TOPLEVEL_BINDING.local_variable_defined?(self.to_ruby)
  end
end

#value_textObject

Generate a Ruby/C string code for accessing the value of the signal with proper bit width and sign.



3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3770

def value_text
  unless self.array? then
    if @type.signed? then
      return "(#{self.to_ruby} & #{@sign} != 0 ? #{self.to_ruby} & #{@mask} - #{@mask+1} : #{self.to_ruby} & #{@mask})"
    else
      return "(#{self.to_ruby} & #{@mask})"
    end
  else
    return self.to_ruby
  end
end