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



4049
4050
4051
# File 'lib/HDLRuby/hruby_high.rb', line 4049

def namespace
  @namespace
end

#return_valueObject (readonly)

The return value when building the scope.



4052
4053
4054
# File 'lib/HDLRuby/hruby_high.rb', line 4052

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+.



4083
4084
4085
4086
4087
4088
4089
4090
# File 'lib/HDLRuby/hruby_high.rb', line 4083

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+.



4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
# File 'lib/HDLRuby/hruby_high.rb', line 4055

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.



4137
4138
4139
# File 'lib/HDLRuby/hruby_high.rb', line 4137

def cur_behavior
    return HDLRuby::High.cur_behavior
end

#cur_blockObject

Gets the current block.



4127
4128
4129
# File 'lib/HDLRuby/hruby_high.rb', line 4127

def cur_block
    return HDLRuby::High.cur_block
end

#cur_scopeObject

Gets the current scope.



4142
4143
4144
# File 'lib/HDLRuby/hruby_high.rb', line 4142

def cur_scope
    return HDLRuby::High.cur_scope
end

#cur_systemObject

Gets the current system.



4147
4148
4149
# File 'lib/HDLRuby/hruby_high.rb', line 4147

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.



4209
4210
4211
4212
# File 'lib/HDLRuby/hruby_high.rb', line 4209

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.



4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
# File 'lib/HDLRuby/hruby_high.rb', line 4173

def helse(mode = nil, &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # 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+.



4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
# File 'lib/HDLRuby/hruby_high.rb', line 4189

def helsif(condition, mode = nil, &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # 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 = self.mode, &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. def hif(condition, mode = nil, &ruby_block)



4162
4163
4164
4165
4166
4167
# File 'lib/HDLRuby/hruby_high.rb', line 4162

def hif(condition, mode = self.mode, &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # Creates the if statement.
    self.add_statement(If.new(condition,mode,&ruby_block))
end

#hprint(*args) ⇒ Object

Prints.



4234
4235
4236
# File 'lib/HDLRuby/hruby_high.rb', line 4234

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.



4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
# File 'lib/HDLRuby/hruby_high.rb', line 4218

def hwhen(match, mode = nil, &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # 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+.



4094
4095
4096
4097
# File 'lib/HDLRuby/hruby_high.rb', line 4094

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+.



4101
4102
4103
4104
# File 'lib/HDLRuby/hruby_high.rb', line 4101

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+.



4108
4109
4110
4111
4112
# File 'lib/HDLRuby/hruby_high.rb', line 4108

def sub(name = :"", &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    self.add_block(self.mode,name,&ruby_block)
end

#terminateObject

Terminate the simulation.



4239
4240
4241
# File 'lib/HDLRuby/hruby_high.rb', line 4239

def terminate
    self.add_statement(TimeTerminate.new)
end

#to_refObject

Converts to a new reference.



4075
4076
4077
# File 'lib/HDLRuby/hruby_high.rb', line 4075

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

#top_blockObject

Gets the top block of the current behavior.



4132
4133
4134
# File 'lib/HDLRuby/hruby_high.rb', line 4132

def top_block
    return HDLRuby::High.top_block
end

#unshift(&ruby_block) ⇒ Object

Adds statements at the top of the block.



4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
# File 'lib/HDLRuby/hruby_high.rb', line 4115

def unshift(&ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # 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