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
-
#name ⇒ Object
readonly
, :content.
-
#type ⇒ Object
readonly
, :content.
Instance Method Summary collapse
-
#array? ⇒ Boolean
Tell if the signal is an array.
-
#initialize(type, name) ⇒ 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(type, name) ⇒ SignalI
Create a new signal with type +type+ and name +name+.
3163 3164 3165 3166 3167 3168 3169 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3163 def initialize(type,name) @type = type.to_type @name = name.to_sym # Compute the mask for adjusting the value to the type. @mask = (2 ** @type.width)-1 @sign = 2 ** (@type.width-1) end |
Instance Attribute Details
#name ⇒ Object (readonly)
, :content
3161 3162 3163 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3161 def name @name end |
#type ⇒ Object (readonly)
, :content
3161 3162 3163 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3161 def type @type end |
Instance Method Details
#array? ⇒ Boolean
Tell if the signal is an array.
3172 3173 3174 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3172 def array? return @type.base.is_a?(TypeVector) end |
#to_f ⇒ Object
Convert to an float.
3229 3230 3231 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3229 def to_f return self.value.to_f end |
#to_i ⇒ Object
Convert to an integer.
3224 3225 3226 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3224 def to_i return self.value.to_i end |
#to_ruby ⇒ Object Also known as: to_c
Convert to Ruby code.
3177 3178 3179 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3177 def to_ruby return "__" + self.name.to_s end |
#to_s ⇒ Object
Convert to a string.
3234 3235 3236 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3234 def to_s return self.value.to_s end |
#value ⇒ Object
Gets the value of the signal.
3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3190 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.
3219 3220 3221 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3219 def value=(val) return TOPLEVEL_BINDING.eval("#{self.to_ruby} = #{val}") end |
#value? ⇒ Boolean
Check if a value is defined for the signal.
3185 3186 3187 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3185 def value? return TOPLEVEL_BINDING.local_variable_defined?(self.to_ruby) end |
#value_text ⇒ Object
Generate a Ruby/C string code for accessing the value of the signal with proper bit width and sign.
3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3206 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 |