Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_tools.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/std/sequencer.rb,
lib/HDLRuby/std/hruby_enum.rb
Overview
Extends the Integer class for computing the bit width.
Instance Method Summary collapse
-
#as(typ) ⇒ Object
Cast.
-
#pow2? ⇒ Boolean
Tells if the value is a power of 2.
-
#sdownto(val, &ruby_block) ⇒ Object
HW downto iteration.
-
#stimes(&ruby_block) ⇒ Object
HW times iteration.
-
#supto(val, &ruby_block) ⇒ Object
HW upto iteration.
-
#to_expr ⇒ Object
Converts to a new high-level expression.
-
#to_verilog ⇒ Object
Extends the Integer class with generation of verilog text.
-
#width ⇒ Object
Gets the bit width NOTE: returns infinity if the number is negative.
Instance Method Details
#as(typ) ⇒ Object
Cast.
5212 5213 5214 |
# File 'lib/HDLRuby/hruby_high.rb', line 5212 def as(typ) return self.to_expr.as(typ) end |
#pow2? ⇒ Boolean
Tells if the value is a power of 2.
44 45 46 |
# File 'lib/HDLRuby/hruby_tools.rb', line 44 def pow2? return self > 0 && (self & (self - 1) == 0) end |
#sdownto(val, &ruby_block) ⇒ Object
HW downto iteration.
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2342 def sdownto(val,&ruby_block) # Create the hardware iterator. range = val..self hw_enum = SEnumeratorBase.new(signed[32],range.size) do |idx| range.last - idx end # Is there a ruby block? if(ruby_block) then # Yes, apply it. return hw_enum.seach(&ruby_block) else # No, return the resulting enumerator. return hw_enum end end |
#stimes(&ruby_block) ⇒ Object
HW times iteration.
2329 2330 2331 2332 2333 2334 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2329 def stimes(&ruby_block) # Ensures there is a ruby block. This allows to use empty while # statement. ruby_block = proc { } unless ruby_block return (0..self-1).seach(&ruby_block) end |
#supto(val, &ruby_block) ⇒ Object
HW upto iteration.
2337 2338 2339 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2337 def supto(val,&ruby_block) return (self..val).seach(&ruby_block) end |
#to_expr ⇒ Object
Converts to a new high-level expression.
5198 5199 5200 5201 5202 5203 5204 |
# File 'lib/HDLRuby/hruby_high.rb', line 5198 def to_expr if (self.bit_length <= 63) then return Value.new(Integer,self) else return Value.new(TypeSigned.new(:"",self.bit_length..0),self) end end |
#to_verilog ⇒ Object
Extends the Integer class with generation of verilog text.
43 44 45 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 43 def to_verilog to_s end |
#width ⇒ Object
Gets the bit width NOTE: returns infinity if the number is negative.
5207 5208 5209 |
# File 'lib/HDLRuby/hruby_high.rb', line 5207 def width return self.bit_length end |