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+.



3472
3473
3474
3475
3476
3477
3478
3479
3480
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3472

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.



3470
3471
3472
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3470

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



3470
3471
3472
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3470

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3470
3471
3472
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3470

def type
  @type
end

Instance Method Details

#array?Boolean

Tell if the signal is an array.

Returns:

  • (Boolean)


3493
3494
3495
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3493

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

#global!Object

Set the signal to be a global.



3488
3489
3490
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3488

def global!
  @global = "$"
end

#global?Boolean

Tell if the signal is global or not.

Returns:

  • (Boolean)


3483
3484
3485
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3483

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

#to_cObject

Convert to C code.



3503
3504
3505
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3503

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

#to_fObject

Convert to an float.



3556
3557
3558
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3556

def to_f
  return self.value.to_f
end

#to_iObject

Convert to an integer.



3551
3552
3553
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3551

def to_i
  return self.value.to_i
end

#to_rubyObject

Convert to Ruby code.



3498
3499
3500
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3498

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

#to_sObject

Convert to a string.



3561
3562
3563
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3561

def to_s
  return self.value.to_s
end

#valueObject

Gets the value of the signal.



3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3517

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.



3546
3547
3548
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3546

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)


3508
3509
3510
3511
3512
3513
3514
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3508

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.



3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3533

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