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

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

Methods included from HEnumerable

#hall?, #hany?, #hchain, #hchunk, #hchunk_while, #hcompact, #hcount, #hcycle, #hdrop, #hdrop_while, #heach_cons, #heach_entry, #heach_range, #heach_slice, #heach_with_index, #heach_with_object, #hfind, #hfind_index, #hfirst, #hflat_map, #hgrep, #hgrep_v, #hgroup_by, #hinclude?, #hinject, #hlazy, #hmap, #hmax, #hmax_by, #hmin, #hmin_by, #hminmax, #hminmax_by, #hnone?, #hone?, #hpartition, #hreduce, #hreject, #hreverse_each, #hselect, #hslice_after, #hslice_before, #hslice_when, #hsort, #hsort_by, #hsum, #htake, #htake_while, #htally, #hto_a, #hto_h, #huniq, #hzip

Constructor Details

#initialize(name, type, dir) ⇒ SignalI

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



4320
4321
4322
4323
4324
4325
4326
4327
4328
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4320

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.



4318
4319
4320
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4318

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



4318
4319
4320
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4318

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4318
4319
4320
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4318

def type
  @type
end

Instance Method Details

#array?Boolean

Tell if the signal is an array.

Returns:

  • (Boolean)


4341
4342
4343
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4341

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

#global!Object

Set the signal to be a global.



4336
4337
4338
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4336

def global!
  @global = "$"
end

#global?Boolean

Tell if the signal is global or not.

Returns:

  • (Boolean)


4331
4332
4333
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4331

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

#to_cObject

Convert to C code.



4351
4352
4353
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4351

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

#to_fObject

Convert to an float.



4414
4415
4416
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4414

def to_f
  return self.value.to_f
end

#to_iObject

Convert to an integer.



4409
4410
4411
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4409

def to_i
  return self.value.to_i
end

#to_python(l = "") ⇒ Object

Convert to Python code.



4356
4357
4358
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4356

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

#to_rubyObject

Convert to Ruby code.



4346
4347
4348
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4346

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

#to_sObject

Convert to a string.



4419
4420
4421
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4419

def to_s
  return self.value.to_s
end

#to_tf(l = "") ⇒ Object

Convert to Tensorflow code.



4361
4362
4363
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4361

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

#valueObject

Gets the value of the signal.



4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4375

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.



4404
4405
4406
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4404

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)


4366
4367
4368
4369
4370
4371
4372
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4366

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.



4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4391

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