Class: Array
- Inherits:
-
Object
- Object
- Array
- Includes:
- HArrow
- Defined in:
- lib/HDLRuby/hruby_high.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
-
#call(obj = nil, &ruby_block) ⇒ Object
Create an array whose number of elements is given by the content of the current array, filled by +obj+ objects.
-
#constant(hsh) ⇒ Object
Declares high-level inner constants named from +hsh+ with names and corresponding values.
-
#hcase(value, &ruby_block) ⇒ Object
Creates a hcase statement executing +ruby_block+ on the element of the array selected by +value+.
-
#inner(*names) ⇒ Object
Declares high-level inner signals named +names+ of the current type.
-
#inout(*names) ⇒ Object
Declares high-level untyped inout signals named +names+ of the current type.
-
#input(*names) ⇒ Object
Declares high-level input signals named +names+ of the current type.
-
#make(name, *args) ⇒ Object
Create an array of instances of system +name+, using +args+ as arguments.
-
#output(*names) ⇒ Object
Declares high-level untyped output signals named +names+ of the current type.
-
#shared(*names) ⇒ Object
Create new shared signals from +args+.
-
#to_expr ⇒ Object
Converts to a new high-level expression.
-
#to_ref ⇒ Object
Converts to a new high-level reference.
-
#to_type ⇒ Object
Converts to a new type.
-
#typedef(name) ⇒ Object
Declares a new type definition with +name+ equivalent to current one.
Instance Method Details
#call(obj = nil, &ruby_block) ⇒ Object
Create an array whose number of elements is given by the content of the current array, filled by +obj+ objects. If +obj+ is nil, +ruby_block+ is used instead for filling the array.
5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 |
# File 'lib/HDLRuby/hruby_high.rb', line 5106 def call(obj = nil, &ruby_block) unless self.size == 1 then raise AnyError, "Invalid array for call opertor." end number = self[0].to_i if obj then return Array.new(number,obj) else return Array.new(number,&ruby_block) end end |
#constant(hsh) ⇒ Object
Declares high-level inner constants named from +hsh+ with names and corresponding values.
5080 5081 5082 |
# File 'lib/HDLRuby/hruby_high.rb', line 5080 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+
5086 5087 5088 5089 5090 5091 5092 5093 |
# File 'lib/HDLRuby/hruby_high.rb', line 5086 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 |
#inner(*names) ⇒ Object
Declares high-level inner signals named +names+ of the current type.
5074 5075 5076 |
# File 'lib/HDLRuby/hruby_high.rb', line 5074 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.
5068 5069 5070 |
# File 'lib/HDLRuby/hruby_high.rb', line 5068 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.
5056 5057 5058 |
# File 'lib/HDLRuby/hruby_high.rb', line 5056 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.
5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 |
# File 'lib/HDLRuby/hruby_high.rb', line 5122 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.
5062 5063 5064 |
# File 'lib/HDLRuby/hruby_high.rb', line 5062 def output(*names) High.top_user.make_outputs(self.to_type,*names) 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_expr ⇒ Object
Converts to a new high-level expression.
5018 5019 5020 5021 5022 5023 5024 5025 |
# File 'lib/HDLRuby/hruby_high.rb', line 5018 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.
5028 5029 5030 5031 5032 5033 5034 |
# File 'lib/HDLRuby/hruby_high.rb', line 5028 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_type ⇒ Object
Converts to a new type.
5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 |
# File 'lib/HDLRuby/hruby_high.rb', line 5037 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 |
#typedef(name) ⇒ Object
Declares a new type definition with +name+ equivalent to current one.
5049 5050 5051 |
# File 'lib/HDLRuby/hruby_high.rb', line 5049 def typedef(name) return self.to_type.typedef(name) end |