Module: HDLRuby::High::HBlock

Includes:
HScope_missing, Hmux
Included in:
Block, TimeBlock
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Module giving the properties of a high-level block.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Hmissing

HDLRuby::High::Hmissing::NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hmux

#mux

Methods included from HScope_missing

#h_missing, #method_missing

Methods included from Hmissing

#method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HDLRuby::High::HScope_missing

Instance Attribute Details

#namespaceObject (readonly)

The namespace



3737
3738
3739
# File 'lib/HDLRuby/hruby_high.rb', line 3737

def namespace
  @namespace
end

#return_valueObject (readonly)

The return value when building the scope.



3740
3741
3742
# File 'lib/HDLRuby/hruby_high.rb', line 3740

def return_value
  @return_value
end

Instance Method Details

#add_block(mode = nil, name = :"", &ruby_block) ⇒ Object

Creates and adds a new block executed in +mode+, with possible +name+ and built by executing +ruby_block+.



3771
3772
3773
3774
3775
3776
3777
3778
# File 'lib/HDLRuby/hruby_high.rb', line 3771

def add_block(mode = nil, name = :"", &ruby_block)
    # Creates the block.
    block = High.make_block(mode,name,&ruby_block)
    # Adds it as a statement.
    self.add_statement(block)
    # Use its return value.
    return block.return_value
end

#build(&ruby_block) ⇒ Object Also known as: open

Build the block by executing +ruby_block+.



3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
# File 'lib/HDLRuby/hruby_high.rb', line 3743

def build(&ruby_block)
    High.space_push(@namespace)
    @return_value = High.top_user.instance_eval(&ruby_block)
    High.space_pop
    # if @return_value.is_a?(HExpression) then
    #     res = @return_value
    #     High.space_push(@namespace)
    #     @return_value = res.type.inner(HDLRuby.uniq_name)
    #     puts "@return_value name=#{@return_value.name}"
    #     @return_value <= res
    #     High.space_pop
    #     @return_value = RefObject.new(self,@return_value)
    # end
    @return_value
end

#cur_behaviorObject

Gets the current behavior.



3821
3822
3823
# File 'lib/HDLRuby/hruby_high.rb', line 3821

def cur_behavior
    return HDLRuby::High.cur_behavior
end

#cur_blockObject

Gets the current block.



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

def cur_block
    return HDLRuby::High.cur_block
end

#cur_scopeObject

Gets the current scope.



3826
3827
3828
# File 'lib/HDLRuby/hruby_high.rb', line 3826

def cur_scope
    return HDLRuby::High.cur_scope
end

#cur_systemObject

Gets the current system.



3831
3832
3833
# File 'lib/HDLRuby/hruby_high.rb', line 3831

def cur_system
    return HDLRuby::High.cur_system
end

#hcase(value) ⇒ Object

Creates a new case statement with a +value+ used for deciding which block to execute.

NOTE: the when part is defined through the hwhen method.



3886
3887
3888
3889
# File 'lib/HDLRuby/hruby_high.rb', line 3886

def hcase(value)
    # Creates the case statement.
    self.add_statement(Case.new(value))
end

#helse(mode = nil, &ruby_block) ⇒ Object

Sets the block executed when the condition is not met to the block in +mode+ generated by the execution of +ruby_block+.

Can only be used once.



3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
# File 'lib/HDLRuby/hruby_high.rb', line 3854

def helse(mode = nil, &ruby_block)
    # There is a ruby_block: the helse is assumed to be with
    # the hif in the same block.
    # Completes the hif or the hcase statement.
    statement = @statements.last
    unless statement.is_a?(If) or statement.is_a?(Case) then
        raise AnyError, "Error: helse statement without hif nor hcase (#{statement.class})."
    end
    statement.helse(mode, &ruby_block)
end

#helsif(condition, mode = nil, &ruby_block) ⇒ Object

Sets the condition check when the condition is not met to the block, with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.



3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
# File 'lib/HDLRuby/hruby_high.rb', line 3868

def helsif(condition, mode = nil, &ruby_block)
    # There is a ruby_block: the helse is assumed to be with
    # the hif in the same block.
    # Completes the hif statement.
    statement = @statements.last
    unless statement.is_a?(If) then
        raise AnyError,
             "Error: helsif statement without hif (#{statement.class})."
    end
    statement.helsif(condition, mode, &ruby_block)
end

#hif(condition, mode = nil, &ruby_block) ⇒ Object

Creates a new if statement with a +condition+ that when met lead to the execution of the block in +mode+ generated by the +ruby_block+.

NOTE: the else part is defined through the helse method.



3845
3846
3847
3848
# File 'lib/HDLRuby/hruby_high.rb', line 3845

def hif(condition, mode = nil, &ruby_block)
    # Creates the if statement.
    self.add_statement(If.new(condition,mode,&ruby_block))
end

#hprint(*args) ⇒ Object

Prints.



3909
3910
3911
# File 'lib/HDLRuby/hruby_high.rb', line 3909

def hprint(*args)
    self.add_statement(Print.new(*args))
end

#hwhen(match, mode = nil, &ruby_block) ⇒ Object

Sets the block of a case structure executed when the +match+ is met to the block in +mode+ generated by the execution of +ruby_block+.

Can only be used once.



3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
# File 'lib/HDLRuby/hruby_high.rb', line 3895

def hwhen(match, mode = nil, &ruby_block)
    # There is a ruby_block: the helse is assumed to be with
    # the hif in the same block.
    # Completes the hcase statement.
    statement = @statements.last
    unless statement.is_a?(Case) then
        raise AnyError,
            "Error: hwhen statement without hcase (#{statement.class})."
    end
    statement.hwhen(match, mode, &ruby_block)
end

#par(name = :"", &ruby_block) ⇒ Object

Creates a new parallel block with possible +name+ and built from +ruby_block+.



3782
3783
3784
3785
# File 'lib/HDLRuby/hruby_high.rb', line 3782

def par(name = :"", &ruby_block)
    return :par unless ruby_block
    self.add_block(:par,name,&ruby_block)
end

#seq(name = :"", &ruby_block) ⇒ Object

Creates a new sequential block with possible +name+ and built from +ruby_block+.



3789
3790
3791
3792
# File 'lib/HDLRuby/hruby_high.rb', line 3789

def seq(name = :"", &ruby_block)
    return :seq unless ruby_block
    self.add_block(:seq,name,&ruby_block)
end

#sub(name = :"", &ruby_block) ⇒ Object

Creates a new block with the current mode with possible +name+ and built from +ruby_block+.



3796
3797
3798
# File 'lib/HDLRuby/hruby_high.rb', line 3796

def sub(name = :"", &ruby_block)
    self.add_block(self.mode,name,&ruby_block)
end

#terminateObject

Terminate the simulation.



3914
3915
3916
# File 'lib/HDLRuby/hruby_high.rb', line 3914

def terminate
    self.add_statement(TimeTerminate.new)
end

#to_refObject

Converts to a new reference.



3763
3764
3765
# File 'lib/HDLRuby/hruby_high.rb', line 3763

def to_ref
    return RefObject.new(this,self)
end

#top_blockObject

Gets the top block of the current behavior.



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

def top_block
    return HDLRuby::High.top_block
end

#unshift(&ruby_block) ⇒ Object

Adds statements at the top of the block.



3801
3802
3803
3804
3805
3806
3807
3808
# File 'lib/HDLRuby/hruby_high.rb', line 3801

def unshift(&ruby_block)
    # Create a sub block for the statements.
    block = High.make_block(self.mode,:"",&ruby_block)
    # Unshifts it.
    self.unshift_statement(block)
    # Use its return value.
    return block.return_value
end