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+



3682
3683
3684
3685
3686
3687
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3682

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.



3679
3680
3681
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3679

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3679
3680
3681
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3679

def type
  @type
end

Instance Method Details

#make_return_type(sblock) ⇒ Object

Compute the return type from current sblock +sblock+



3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3690

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.



3707
3708
3709
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3707

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.



3702
3703
3704
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 3702

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