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.
-
#hdownto(val, &ruby_block) ⇒ Object
HW downto iteration.
-
#htimes(&ruby_block) ⇒ Object
HW times iteration.
-
#hupto(val, &ruby_block) ⇒ Object
HW upto iteration.
-
#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.
5240 5241 5242 |
# File 'lib/HDLRuby/hruby_high.rb', line 5240 def as(typ) return self.to_expr.as(typ) end |
#hdownto(val, &ruby_block) ⇒ Object
HW downto iteration. alias_method :hdownto, :downto
1230 1231 1232 1233 1234 1235 |
# File 'lib/HDLRuby/std/hruby_enum.rb', line 1230 def hdownto(val,&ruby_block) return HEnumeratorWrapper.new(self,:hdownto) unless ruby_block self.downto(val) do |i| ruby_block.call(i) end end |
#htimes(&ruby_block) ⇒ Object
HW times iteration. alias_method :htimes, :times
1212 1213 1214 1215 1216 1217 |
# File 'lib/HDLRuby/std/hruby_enum.rb', line 1212 def htimes(&ruby_block) return HEnumeratorWrapper.new(self,:htimes) unless ruby_block self.times do |i| ruby_block.call(i) end end |
#hupto(val, &ruby_block) ⇒ Object
HW upto iteration. alias_method :hupto, :upto
1221 1222 1223 1224 1225 1226 |
# File 'lib/HDLRuby/std/hruby_enum.rb', line 1221 def hupto(val,&ruby_block) return HEnumeratorWrapper.new(self,:hupto) unless ruby_block self.upto(val) do |i| ruby_block.call(i) end 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.
2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2356 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.
2343 2344 2345 2346 2347 2348 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2343 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.
2351 2352 2353 |
# File 'lib/HDLRuby/std/sequencer.rb', line 2351 def supto(val,&ruby_block) return (self..val).seach(&ruby_block) end |
#to_expr ⇒ Object
Converts to a new high-level expression.
5226 5227 5228 5229 5230 5231 5232 |
# File 'lib/HDLRuby/hruby_high.rb', line 5226 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.
5235 5236 5237 |
# File 'lib/HDLRuby/hruby_high.rb', line 5235 def width return self.bit_length end |