Class: Array

Inherits:
Object
  • Object
show all
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

HDLRuby::High::Std::PipelineT::Stage

Instance Method Summary collapse

Instance Method Details

#constant(hsh) ⇒ Object

Declares high-level inner constants named from +hsh+ with names and corresponding values.



5427
5428
5429
# File 'lib/HDLRuby/hruby_high.rb', line 5427

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+



5433
5434
5435
5436
5437
5438
5439
5440
# File 'lib/HDLRuby/hruby_high.rb', line 5433

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

#heach(&ruby_block) ⇒ Object

Enhance the Array class with extra arguments in interation.

include HEnumArg



1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'lib/HDLRuby/std/hruby_enum.rb', line 1099

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) } }
  self.each do |e|
    HDLRuby::High.top_user.sub do
      # HDLRuby::High.top_user.instance_exec(e,&ruby_block)
      ruby_block.call(e)
    end
  end
end

#inner(*names) ⇒ Object

Declares high-level inner signals named +names+ of the current type.



5421
5422
5423
# File 'lib/HDLRuby/hruby_high.rb', line 5421

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.



5415
5416
5417
# File 'lib/HDLRuby/hruby_high.rb', line 5415

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.



5403
5404
5405
# File 'lib/HDLRuby/hruby_high.rb', line 5403

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.



5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
# File 'lib/HDLRuby/hruby_high.rb', line 5469

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.



5409
5410
5411
# File 'lib/HDLRuby/hruby_high.rb', line 5409

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_exprObject

Converts to a new high-level expression.



5365
5366
5367
5368
5369
5370
5371
5372
# File 'lib/HDLRuby/hruby_high.rb', line 5365

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_refObject

Converts to a new high-level reference.



5375
5376
5377
5378
5379
5380
5381
# File 'lib/HDLRuby/hruby_high.rb', line 5375

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_typeObject

Converts to a new type.



5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
# File 'lib/HDLRuby/hruby_high.rb', line 5384

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.



5396
5397
5398
# File 'lib/HDLRuby/hruby_high.rb', line 5396

def typedef(name)
    return self.to_type.typedef(name)
end