Class: RubyHDL::High::SignalI
- Inherits:
-
Expression
- Object
- Expression
- RubyHDL::High::SignalI
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a signal.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#array? ⇒ Boolean
Tell if the signal is an array.
-
#global! ⇒ Object
Set the signal to be a global.
-
#global? ⇒ Boolean
Tell if the signal is global or not.
-
#initialize(name, type, dir) ⇒ SignalI
constructor
Create a new signal with type +type+ and name +name+.
-
#to_c ⇒ Object
Convert to C code.
-
#to_f ⇒ Object
Convert to an float.
-
#to_i ⇒ Object
Convert to an integer.
-
#to_python(l = "") ⇒ Object
Convert to Python code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
-
#to_s ⇒ Object
Convert to a string.
-
#to_tf(l = "") ⇒ Object
Convert to Tensorflow code.
-
#value ⇒ Object
Gets the value of the signal.
-
#value=(val) ⇒ Object
Sets the value of the signal.
-
#value? ⇒ Boolean
Check if a value is defined for the signal.
-
#value_text ⇒ Object
Generate a Ruby/C string code for accessing the value of the signal with proper bit width and sign.
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
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
4318 4319 4320 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4318 def dir @dir end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4318 4319 4320 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4318 def name @name end |
#type ⇒ Object (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.
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.
4331 4332 4333 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4331 def global? return @global == "$" end |
#to_c ⇒ Object
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_f ⇒ Object
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_i ⇒ Object
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_ruby ⇒ Object
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_s ⇒ Object
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 |
#value ⇒ Object
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.
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_text ⇒ Object
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 |