Class: Array
- Inherits:
-
Object
- Object
- Array
- Includes:
- HArrow, HEnumerable
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/std/hruby_enum.rb,
lib/HDLRuby/std/sequencer_sync.rb
Overview
Extends the Array class for conversion to a high-level expression.
Direct Known Subclasses
Instance Method Summary collapse
-
#as(typ) ⇒ Object
Casts to
typ. -
#constant(hsh) ⇒ Object
Declares high-level inner constants named from
hshwith names and corresponding values. -
#hcase(value, &ruby_block) ⇒ Object
Creates a hcase statement executing
ruby_blockon the element of the array selected byvalue. -
#hcasez(value, &ruby_block) ⇒ Object
Creates a hcase statement taking z as wildcard executing
ruby_blockon the element of the array selected byvalue. -
#heach(&ruby_block) ⇒ Object
Enhance the Array class with extra arguments in interation.
-
#inner(*names) ⇒ Object
Declares high-level inner signals named
namesof the current type. -
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named
namesof the current type. -
#input(*names) ⇒ Object
Declares high-level input signals named
namesof the current type. -
#make(name, *args) ⇒ Object
Create an array of instances of system
name, usingargsas arguments. -
#output(*names) ⇒ Object
Declares high-level untyped output signals named
namesof the current type. -
#sext(n) ⇒ Object
Extends on the left to
nbits preserving the signe. -
#shared(*names) ⇒ Object
Create new shared signals from
args. -
#to_bit ⇒ Object
Converts to a bit vector.
-
#to_expr ⇒ Object
Converts to a new high-level expression.
-
#to_ref ⇒ Object
Converts to a new high-level reference.
-
#to_signed ⇒ Object
Casts to a signed bit vector type.
-
#to_type ⇒ Object
Converts to a new type.
-
#to_unsigned ⇒ Object
Casts to an unsigned bit vector type.
-
#typedef(name) ⇒ Object
Declares a new type definition with
nameequivalent to current one. -
#zext(n) ⇒ Object
Extends on the left to
nbits filling with 0.
Instance Method Details
#as(typ) ⇒ Object
Casts to typ.
5564 5565 5566 |
# File 'lib/HDLRuby/hruby_high.rb', line 5564 def as(typ) return self.to_expr.as(typ) end |
#constant(hsh) ⇒ Object
Declares high-level inner constants named from hsh with names
and corresponding values.
5648 5649 5650 |
# File 'lib/HDLRuby/hruby_high.rb', line 5648 def constant(hsh) High.top_user.make_constants(self.to_type,hsh) end |
#hcase(value, &ruby_block) ⇒ Object
Creates a hcase statement executing ruby_block on the element of
the array selected by value
5654 5655 5656 5657 5658 5659 5660 5661 |
# File 'lib/HDLRuby/hruby_high.rb', line 5654 def hcase(value,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? High.cur_block.hcase(value) self.each.with_index do |elem,i| High.cur_block.hwhen(i) { ruby_block.call(elem) } end end |
#hcasez(value, &ruby_block) ⇒ Object
Creates a hcase statement taking z as wildcard executing ruby_block on the element of
the array selected by value
5665 5666 5667 5668 5669 5670 5671 5672 |
# File 'lib/HDLRuby/hruby_high.rb', line 5665 def hcasez(value,&ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? High.cur_block.hcasez(value) self.each.with_index do |elem,i| High.cur_block.hwhen(i) { ruby_block.call(elem) } end end |
#heach(&ruby_block) ⇒ Object
Enhance the Array class with extra arguments in interation.
include HEnumArg
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 |
# File 'lib/HDLRuby/std/hruby_enum.rb', line 1113 def heach(&ruby_block) if !ruby_block then return HEnumeratorWrapper.new(self) end # self.each { |e| HDLRuby::High.top_user.sub { ruby_block.call(e) } } catch(:HDLRubyThrow) do caught = false self.each do |e| HDLRuby::High.top_user.sub do caught = true catch(:HDLRubyThrow) do # HDLRuby::High.top_user.instance_exec(e,&ruby_block) ruby_block.call(e) caught = false end end throw(:HDLRubyThrow) if caught end end end |
#inner(*names) ⇒ Object
Declares high-level inner signals named names of the
current type.
5642 5643 5644 |
# File 'lib/HDLRuby/hruby_high.rb', line 5642 def inner(*names) High.top_user.make_inners(self.to_type,*names) end |
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named names of the
current type.
5636 5637 5638 |
# File 'lib/HDLRuby/hruby_high.rb', line 5636 def inout(*names) High.top_user.make_inouts(self.to_type,*names) end |
#input(*names) ⇒ Object
Declares high-level input signals named names of the current type.
5624 5625 5626 |
# File 'lib/HDLRuby/hruby_high.rb', line 5624 def input(*names) High.top_user.make_inputs(self.to_type,*names) end |
#make(name, *args) ⇒ Object
Create an array of instances of system name, using args as
arguments.
NOTE: the array must have a single element that is an integer.
5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 |
# File 'lib/HDLRuby/hruby_high.rb', line 5701 def make(name,*args) # Check the array and get the number of elements. size = self[0] unless self.size == 1 and size.is_a?(::Integer) raise AnyError, "Invalid array for declaring a list of instances." end # Get the system to instantiate. systemT = High.space_call(name) # Get the name of the instance from the arguments. nameI = args.shift.to_s # Create the instances. instances = size.times.map do |i| systemT.instantiate((nameI + "[#{i}]").to_sym,*args) end nameI = nameI.to_sym # Add them to the top system High.space_top.user.add_groupI(nameI,*instances) # Register and return the result. High.space_reg(nameI) { High.space_top.user.get_groupI(nameI) } return High.space_top.user.get_groupI(nameI) end |
#output(*names) ⇒ Object
Declares high-level untyped output signals named names of the
current type.
5630 5631 5632 |
# File 'lib/HDLRuby/hruby_high.rb', line 5630 def output(*names) High.top_user.make_outputs(self.to_type,*names) end |
#sext(n) ⇒ Object
Extends on the left to n bits preserving the signe.
5589 5590 5591 |
# File 'lib/HDLRuby/hruby_high.rb', line 5589 def sext(n) return self.to_bit.sext(n) end |
#shared(*names) ⇒ Object
Create new shared signals from args.
382 383 384 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 382 def shared(*names) return self.to_type.shared(*names) end |
#to_bit ⇒ Object
Converts to a bit vector.
5569 5570 5571 |
# File 'lib/HDLRuby/hruby_high.rb', line 5569 def to_bit return self.to_expr.to_bit end |
#to_expr ⇒ Object
Converts to a new high-level expression.
5554 5555 5556 5557 5558 5559 5560 5561 |
# File 'lib/HDLRuby/hruby_high.rb', line 5554 def to_expr elems = self.map {|elem| elem.to_expr } typ= TypeTuple.new(:"",:little) elems.each {|elem| typ.add_type(elem.type) } expr = Concat.new(typ) elems.each {|elem| expr.add_expression(elem) } expr end |
#to_ref ⇒ Object
Converts to a new high-level reference.
5596 5597 5598 5599 5600 5601 5602 |
# File 'lib/HDLRuby/hruby_high.rb', line 5596 def to_ref expr = RefConcat.new(TypeTuple.new(:"",:little,*self.map do |elem| elem.to_ref.type end)) self.each {|elem| expr.add_ref(elem.to_ref) } expr end |
#to_signed ⇒ Object
Casts to a signed bit vector type.
5579 5580 5581 |
# File 'lib/HDLRuby/hruby_high.rb', line 5579 def to_signed return self.to_bit_to_signed end |
#to_type ⇒ Object
Converts to a new type.
5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 |
# File 'lib/HDLRuby/hruby_high.rb', line 5605 def to_type if self.size == 1 and ( self[0].is_a?(Range) or self[0].respond_to?(:to_i) ) then # Vector type case return bit[*self] else # Tuple type case. return TypeTuple.new(:"",:little,*self) end end |
#to_unsigned ⇒ Object
Casts to an unsigned bit vector type.
5574 5575 5576 |
# File 'lib/HDLRuby/hruby_high.rb', line 5574 def to_unsigned return self.to_bit.to_unsigned end |
#typedef(name) ⇒ Object
Declares a new type definition with name equivalent to current one.
5617 5618 5619 |
# File 'lib/HDLRuby/hruby_high.rb', line 5617 def typedef(name) return self.to_type.typedef(name) end |
#zext(n) ⇒ Object
Extends on the left to n bits filling with 0.
5584 5585 5586 |
# File 'lib/HDLRuby/hruby_high.rb', line 5584 def zext(n) return self.to_bit.zext(n) end |