class HDLRuby::High::Std::TaskI

Describes a high-level task instance.

Attributes

name[R]

The name of the task instance.

namespace[R]

The namespace associated with the current execution when building a task.

scope[R]

The scope the task has been created in.

Public Class Methods

new(name,&ruby_block) click to toggle source

Creates a new task instance with name built from ruby_block.

# File lib/HDLRuby/std/task.rb, line 327
def initialize(name,&ruby_block)
    # Check and set the name of the task.
    @name = name.to_sym
    # Generate a name for the scope containing the signals of
    # the task.
    @scope_name = HDLRuby.uniq_name

    # # Sets the scope.
    # @scope = HDLRuby::High.cur_scope

    # Keep access to self.
    obj = self

      
    # The runner input ports by name.
    @runner_inputs = {}
    # The runner output ports by name.
    @runner_outputs = {}
    # The runner inout ports by name.
    @runner_inouts = {}
      
    # # The stopper input ports by name.
    # @stopper_inputs = {}
    # # The stopper output ports by name.
    # @stopper_outputs = {}
    # # The stopper inout ports by name.
    # @stopper_inouts = {}
      
    # The finisher input ports by name.
    @finisher_inputs = {}
    # The finisher output ports by name.
    @finisher_outputs = {}
    # The finisher inout ports by name.
    @finisher_inouts = {}

    # Create the namespaces for building the task, its readers
    # its writers and its accessers.

    # Creates the namespace of the task.
    @namespace = Namespace.new(self)
    # Make it give access to the internal of the class.
    @namespace.add_method(:runner_input,   &method(:runner_input))
    @namespace.add_method(:runner_output,  &method(:runner_output))
    @namespace.add_method(:runner_inout,   &method(:runner_inout))
    # @namespace.add_method(:stopper_input,   &method(:stopper_input))
    # @namespace.add_method(:stopper_output,  &method(:stopper_output))
    # @namespace.add_method(:stopper_inout,   &method(:stopper_inout))
    @namespace.add_method(:finisher_input,     &method(:finisher_input))
    @namespace.add_method(:finisher_output,    &method(:finisher_output))
    @namespace.add_method(:finisher_inout,     &method(:finisher_inout))
    @namespace.add_method(:runner,         &method(:runner))
    # @namespace.add_method(:stopper,         &method(:stopper))
    @namespace.add_method(:finisher,           &method(:finisher))

    # Creates the namespace of the runner.
    @runner_namespace = Namespace.new(self)
    # # Creates the namespace of the stopper.
    # @stopper_namespace = Namespace.new(self)
    # Creates the namespace of the finisher.
    @finisher_namespace = Namespace.new(self)
    @controller_namespace = Namespace.new(self)

    # Builds the task within a new scope.
    HDLRuby::High.space_push(@namespace)
    # puts "top_user=#{HDLRuby::High.top_user}"
    scope_name = @scope_name
    scope = nil
    HDLRuby::High.top_user.instance_eval do 
        sub(scope_name) do
            # Generate the task code.
            ruby_block.call
        end
    end
    HDLRuby::High.space_pop

    # Keep access to the scope containing the code of the task.
    @scope = @namespace.send(scope_name)
    # puts "@scope=#{@scope}"
    # Adds the name space of the scope to the namespace of the
    # task
    @namespace.concat_namespace(@scope.namespace)

    # Gives access to the task by registering its name.
    obj = self
    # HDLRuby::High.space_reg(@name) { self }
    HDLRuby::High.space_reg(@name) { obj }
end

Public Instance Methods

finish(*args,&ruby_block) click to toggle source

Performs a wait from the end of the computation of the task using args and ruby_block as arguments.

# File lib/HDLRuby/std/task.rb, line 780
def finish(*args,&ruby_block)
    # Gain access to the finisher as local variable.
    finisher_proc = @finisher_proc
    # # The context is the one of the finisher.
    # Execute the code generating the finisher in context.
    HDLRuby::High.space_push(@namespace)
    HDLRuby::High.cur_block.open do
        instance_exec(ruby_block,*args,&finisher_proc)
    end
    HDLRuby::High.space_pop
end
finisher(&ruby_block) click to toggle source

Sets the finisher procedure to be ruby_block.

# File lib/HDLRuby/std/task.rb, line 558
def finisher(&ruby_block)
    @finisher_proc = ruby_block
end
finisher_inout(*keys) click to toggle source

Sets the signals accessible through key to be finisher inout port.

# File lib/HDLRuby/std/task.rb, line 535
def finisher_inout(*keys)
    # Registers each signal as finisher port
    keys.each do |key|
        # Ensure the key is a symbol.
        key = key.to_sym
        # Register it with the corresponding signal.
        name = HDLRuby.uniq_name # The name of the signal is uniq.
        @finisher_inouts[name] = send(key)
    end
end
finisher_input(*keys) click to toggle source

Sets the signals accessible through key to be finisher input port.

# File lib/HDLRuby/std/task.rb, line 511
def finisher_input(*keys)
    # Registers each signal as finisher port
    keys.each do |key|
        # Ensure the key is a symbol.
        key = key.to_sym
        # Register it with the corresponding signal.
        name = HDLRuby.uniq_name # The name of the signal is uniq.
        @finisher_inputs[name] = send(key)
    end
end
finisher_output(*keys) click to toggle source

Sets the signals accessible through key to be finisher output port.

# File lib/HDLRuby/std/task.rb, line 523
def finisher_output(*keys)
    # Registers each signal as finisher port
    keys.each do |key|
        # Ensure the key is a symbol.
        key = key.to_sym
        # Register it with the corresponding signal.
        name = HDLRuby.uniq_name # The name of the signal is uniq.
        @finisher_outputs[name] = send(key)
    end
end
finisher_signals() click to toggle source

Gets the list of the signals of the task to be connected to the finisher.

# File lib/HDLRuby/std/task.rb, line 587
def finisher_signals
    return @finisher_inputs.values + @finisher_outputs.values +
           @finisher_inouts.values
end
inner(name) click to toggle source

Declares the ports for accessing the task as an inner component and assigned them to name.

# File lib/HDLRuby/std/task.rb, line 715
def inner(name)
    # Ensure name is a symbol.
    name = name.to_sym
    # Access the ports
    loc_inputs  = @runner_inputs.merge(@finisher_inputs)
    loc_outputs = @runner_outputs.merge(@finisher_outputs)
    loc_inouts  = @runner_inouts.merge(@finisher_inouts)
    locs = loc_inputs.merge(loc_outputs).merge(loc_inouts)
    # The generated port with corresponding task port pairs.
    port_pairs = []
    # Add them to the current system.
    HDLRuby::High.cur_system.open do
        locs.each  do |name,sig|
            port_pairs << [sig, sig.type.inner(name)]
        end
    end
    obj = self
    # Make the inner connection
    port_pairs.each do |sig, port|
        sig.parent.open do
            port.to_ref <= sig
        end
    end

    # Set ups the controller's namespace
    loc_inputs.each do |name,sig|
        @controller_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end
    loc_outputs.each do |name,sig|
        @controller_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end
    loc_inouts.each do |name,sig|
        @controller_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end

    # Give access to the ports through name.
    # NOTE: for now, simply associate the task to name.
    tp = TaskPortSA.new(@controller_namespace,@runner_proc,@finisher_proc,@reseter_proc)
    HDLRuby::High.space_reg(name) { chp }
    return tp
end
input(name) click to toggle source

Declares the ports for the runner and assigned them to name.

# File lib/HDLRuby/std/task.rb, line 594
def input(name)
    # Ensure name is a symbol.
    name = name.to_sym
    # Access the ports
    loc_inputs  = @runner_inputs
    loc_outputs = @runner_outputs
    loc_inouts  = @runner_inouts
    # The generated port with corresponding task port pairs.
    port_pairs = []
    # Add them to the current system.
    HDLRuby::High.cur_system.open do
        # The inputs
        loc_inputs.each  do |name,sig|
            # puts "name=#{name} sig.name=#{sig.name}"
            port_pairs << [sig, sig.type.input(name)]
        end
        # The outputs
        loc_outputs.each do |name,sig| 
            port_pairs << [sig, sig.type.output(name)]
        end
        # The inouts
        loc_inouts.each  do |name,sig| 
            port_pairs << [sig, sig.type.inout(name)]
        end
    end
    obj = self
    # Make the connection of the instance.
    HDLRuby::High.cur_system.on_instance do |inst|
        obj.scope.open do
            port_pairs.each do |sig, port|
                RefObject.new(inst,port.to_ref) <= sig
            end
        end
    end

    # Fill the runner namespace with the access to the runner signals.
    @runner_inputs.each do |name,sig|
        @runner_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end
    @runner_outputs.each do |name,sig|
        @runner_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end
    @runner_inouts.each do |name,sig|
        @runner_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end

    # Give access to the ports through name.
    # NOTE: for now, simply associate the task to name.
    tp = TaskPortS.new(@runner_namespace,@runner_proc,@reseter_proc)
    HDLRuby::High.space_reg(name) { tp }
    return tp
end
output(name) click to toggle source

Declares the ports for the finisher and assigned them to name.

# File lib/HDLRuby/std/task.rb, line 654
def output(name)
    # Ensure name is a symbol.
    name = name.to_sym
    # Access the ports
    loc_inputs  = @finisher_inputs
    loc_outputs = @finisher_outputs
    loc_inouts  = @finisher_inouts
    # The generated port with corresponding task port pairs.
    port_pairs = []
    # Add them to the current system.
    HDLRuby::High.cur_system.open do
        # The inputs
        loc_inputs.each  do |name,sig|
            port_pairs << [sig, sig.type.input(name)]
        end
        # The outputs
        loc_outputs.each do |name,sig| 
            port_pairs << [sig, sig.type.output(name)]
        end
        # The inouts
        loc_inouts.each  do |name,sig| 
            port_pairs << [sig, sig.type.inout(name)]
        end
    end
    obj = self
    # Make the connection of the instance.
    HDLRuby::High.cur_system.on_instance do |inst|
        obj.scope.open do
            port_pairs.each do |sig, port|
                RefObject.new(inst,port.to_ref) <= sig
            end
        end
    end

    # Fill the finisher namespace with the access to the finisher signals.
    @finisher_inputs.each do |name,sig|
        @finisher_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end
    @finisher_outputs.each do |name,sig|
        @finisher_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end
    @finisher_inouts.each do |name,sig|
        @finisher_namespace.add_method(sig.name) do
            HDLRuby::High.top_user.send(name)
        end
    end

    # Give access to the ports through name.
    # NOTE: for now, simply associate the task to name.
    chp = TaskPortA.new(@finisher_namespace,@finisher_proc,@output_reseter_proc)
    HDLRuby::High.space_reg(name) { chp }
    return chp
end
reset(*args,&ruby_block) click to toggle source

Performs a reset on the task using args and ruby_block as arguments.

# File lib/HDLRuby/std/task.rb, line 794
def reset(*args,&ruby_block)
    # Gain access to the writer as local variable.
    reseter_proc = @inout_reseter_proc
    # # The context is the one of the writer.
    # Execute the code generating the writer in context.
    HDLRuby::High.space_push(@namespace)
    HDLRuby::High.cur_block.open do
        instance_exec(ruby_block,*args,&reseter_proc)
    end
    HDLRuby::High.space_pop
end
reseter(&ruby_block) click to toggle source

Sets the reset to be ruby_block.

# File lib/HDLRuby/std/task.rb, line 563
def reseter(&ruby_block)
    @reseter_proc = ruby_block
end
run(*args,&ruby_block) click to toggle source

Runs the task using args and ruby_block as arguments.

# File lib/HDLRuby/std/task.rb, line 766
def run(*args,&ruby_block)
    # Gain access to the runner as local variable.
    runner_proc = @runner_proc
    # # The context is the one of the reader.
    # Execute the code generating the reader in context.
    HDLRuby::High.space_push(@namespace)
    HDLRuby::High.cur_block.open do
        instance_exec(ruby_block,*args,&runner_proc)
    end
    HDLRuby::High.space_pop
end
runner(&ruby_block) click to toggle source

Sets the read procedure to be ruby_block.

# File lib/HDLRuby/std/task.rb, line 548
def runner(&ruby_block)
    @runner_proc = ruby_block
end
runner_inout(*keys) click to toggle source

Sets the signals accessible through key to be run inout port.

# File lib/HDLRuby/std/task.rb, line 463
def runner_inout(*keys)
    # Registers each signal as run port
    keys.each do |key|
        # Ensure the key is a symbol.
        key = key.to_sym
        # Register it with the corresponding signal.
        name = HDLRuby.uniq_name # The name of the signal is uniq.
        @runner_inouts[name] = send(key)
    end
end
runner_input(*keys) click to toggle source

Sets the signals accessible through key to be run input port.

# File lib/HDLRuby/std/task.rb, line 439
def runner_input(*keys)
    # Registers each signal as run port
    keys.each do |key|
        # Ensure the key is a symbol.
        key = key.to_sym
        # Register it with the corresponding signal.
        name = HDLRuby.uniq_name # The name of the signal is uniq.
        @runner_inputs[name] = send(key)
    end
end
runner_output(*keys) click to toggle source

Sets the signals accessible through key to be run output port.

# File lib/HDLRuby/std/task.rb, line 451
def runner_output(*keys)
    # Registers each signal as run port
    keys.each do |key|
        # Ensure the key is a symbol.
        key = key.to_sym
        # Register it with the corresponding signal.
        name = HDLRuby.uniq_name # The name of the signal is uniq.
        @runner_outputs[name] = send(key)
    end
end
runner_signals() click to toggle source

Gets the list of the signals of the task to be connected to the runner.

# File lib/HDLRuby/std/task.rb, line 573
def runner_signals
    return @runner_inputs.values + @runner_outputs.values +
           @runner_inouts.values
end