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_f ⇒ Object
Convert to an float.
-
#to_i ⇒ Object
Convert to an integer.
-
#to_ruby ⇒ Object
(also: #to_c)
Convert to Ruby code.
-
#to_s ⇒ Object
Convert to a string.
-
#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
#<=, #[], #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+.
3368 3369 3370 3371 3372 3373 3374 3375 3376 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3368 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.
3366 3367 3368 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3366 def dir @dir end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3366 3367 3368 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3366 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3366 3367 3368 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3366 def type @type end |
Instance Method Details
#array? ⇒ Boolean
Tell if the signal is an array.
3389 3390 3391 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3389 def array? return @type.base.is_a?(TypeVector) end |
#global! ⇒ Object
Set the signal to be a global.
3384 3385 3386 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3384 def global! @global = "$" end |
#global? ⇒ Boolean
Tell if the signal is global or not.
3379 3380 3381 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3379 def global? return @global == "$" end |
#to_f ⇒ Object
Convert to an float.
3450 3451 3452 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3450 def to_f return self.value.to_f end |
#to_i ⇒ Object
Convert to an integer.
3445 3446 3447 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3445 def to_i return self.value.to_i end |
#to_ruby ⇒ Object Also known as: to_c
Convert to Ruby code.
3394 3395 3396 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3394 def to_ruby return @global + "__" + self.name.to_s end |
#to_s ⇒ Object
Convert to a string.
3455 3456 3457 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3455 def to_s return self.value.to_s end |
#value ⇒ Object
Gets the value of the signal.
3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3411 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.
3440 3441 3442 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3440 def value=(val) return TOPLEVEL_BINDING.eval("#{self.to_ruby} = #{val}") end |
#value? ⇒ Boolean
Check if a value is defined for the signal.
3402 3403 3404 3405 3406 3407 3408 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3402 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.
3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3427 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 |