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+



4040
4041
4042
4043
4044
4045
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4040

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.



4037
4038
4039
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4037

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4037
4038
4039
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4037

def type
  @type
end

Instance Method Details

#make_return_type(sblock) ⇒ Object

Compute the return type from current sblock +sblock+



4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4048

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.



4065
4066
4067
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4065

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_python(l = "") ⇒ Object

Convert to Python code.



4070
4071
4072
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4070

def to_python(l = "")
  return "#{l}def __#{name}(#{@args.map {|arg| "__" + arg.to_ruby}.join(",")}):\n#{@blk.sequencer.clk_python(l + "  ")}\n#{@blk.to_python(l + "  ")}\n"
end

#to_rubyObject

Convert to Ruby code.



4060
4061
4062
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 4060

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