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+



3669
3670
3671
3672
3673
3674
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3669

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.



3666
3667
3668
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3666

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3666
3667
3668
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3666

def type
  @type
end

Instance Method Details

#make_return_type(sblock) ⇒ Object

Compute the return type from current sblock +sblock+



3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3677

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.



3694
3695
3696
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3694

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.



3689
3690
3691
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3689

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