Class: RubyHDL::High::SfunctionT

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of a sequencer function.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, sblock, *args) ⇒ SfunctionT

Create a new named +name+ with arguments +args+ and executing the content of block +sblock+



3791
3792
3793
3794
3795
3796
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3791

def initialize(name,sblock,*args)
  @name = name.to_sym
  @args  = args
  @blk = sblock
  @type = self.make_return_type(@blk)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3788
3789
3790
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3788

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3788
3789
3790
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3788

def type
  @type
end

Instance Method Details

#make_return_type(sblock) ⇒ Object

Compute the return type from current sblock +sblock+



3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3799

def make_return_type(sblock)
  # Locate a return statement.
  sblock.each_statement_deep do |statement|
    if statement.is_a?(RubyHDL::High::Sreturn) then
      return statement.value.type
    end
  end
  # No return, so void type.
  return RubyHDL::High::Void
end

#to_cObject

Convert to C code.



3816
3817
3818
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3816

def to_c
  return "unsigned long long __#{name}(#{@args.map {|arg| "unsigned long long __" + arg.to_c}.join(",")}) {\n#{@blk.sequencer.clk_up_c}\n#{@blk.to_c}\n}\n"
end

#to_rubyObject

Convert to Ruby code.



3811
3812
3813
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3811

def to_ruby
  return "def __#{name}(#{@args.map {|arg| "__" + arg.to_ruby}.join(",")})\n#{@blk.sequencer.clk_up}\n#{@blk.to_ruby}\nend\n"
end