Module: HDLRuby::High::HBlock
- Includes:
- HScope_missing, Hmux
- Defined in:
- lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/std/hruby_enum.rb
Overview
Module giving the properties of a high-level block.
Constant Summary collapse
Constants included from Hmissing
HDLRuby::High::Hmissing::NAMES
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
The namespace.
-
#return_value ⇒ Object
readonly
The return value when building the scope.
Instance Method Summary collapse
-
#add_block(mode = nil, name = :"", &ruby_block) ⇒ Object
Creates and adds a new block executed in
mode, with possiblenameand built by executingruby_block. -
#build(&ruby_block) ⇒ Object
(also: #open)
Build the block by executing
ruby_block. -
#cur_behavior ⇒ Object
Gets the current behavior.
-
#cur_block ⇒ Object
Gets the current block.
-
#cur_scope ⇒ Object
Gets the current scope.
-
#cur_system ⇒ Object
Gets the current system.
-
#hcase(value) ⇒ Object
Creates a new case statement with a
valueused for deciding which block to execute. -
#hcasez(value) ⇒ Object
Creates a new case statement taking z as wildcard with a
valueused for deciding which block to execute. -
#helse(mode = nil, &ruby_block) ⇒ Object
Sets the block executed when the condition is not met to the block in
modegenerated by the execution ofruby_block. -
#helsif(condition, mode = nil, &ruby_block) ⇒ Object
Sets the condition check when the condition is not met to the block, with a
conditionthat when met lead to the execution of the block inmodegenerated by theruby_block. -
#hif(condition, mode = self.mode, other = nil, &ruby_block) ⇒ Object
Creates a new if statement with a
conditionthat when met lead to the execution of the block inmodegenerated by theruby_block. -
#hprint(*args) ⇒ Object
Prints.
-
#hwhen(match, mode = nil, &ruby_block) ⇒ Object
Sets the block of a case structure executed when the
matchis met to the block inmodegenerated by the execution ofruby_block. -
#par(name = :"", &ruby_block) ⇒ Object
Creates a new parallel block with possible
nameand built fromruby_block. -
#seq(name = :"", &ruby_block) ⇒ Object
Creates a new sequential block with possible
nameand built fromruby_block. -
#sub(name = HDLRuby.uniq_name, &ruby_block) ⇒ Object
Creates a new block with the current mode with possible
nameand built fromruby_block. -
#terminate ⇒ Object
Terminate the simulation.
-
#to_ref ⇒ Object
Converts to a new reference.
-
#top_block ⇒ Object
Gets the top block of the current behavior.
-
#unshift(&ruby_block) ⇒ Object
Adds statements at the top of the block.
Methods included from Hmux
Methods included from HScope_missing
Methods included from Hmissing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HDLRuby::High::HScope_missing
Instance Attribute Details
#namespace ⇒ Object (readonly)
The namespace
4585 4586 4587 |
# File 'lib/HDLRuby/hruby_high.rb', line 4585 def namespace @namespace end |
#return_value ⇒ Object (readonly)
The return value when building the scope.
4588 4589 4590 |
# File 'lib/HDLRuby/hruby_high.rb', line 4588 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.
4619 4620 4621 4622 4623 4624 4625 4626 |
# File 'lib/HDLRuby/hruby_high.rb', line 4619 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.
4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 |
# File 'lib/HDLRuby/hruby_high.rb', line 4591 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_behavior ⇒ Object
Gets the current behavior.
4682 4683 4684 |
# File 'lib/HDLRuby/hruby_high.rb', line 4682 def cur_behavior return HDLRuby::High.cur_behavior end |
#cur_block ⇒ Object
Gets the current block.
4672 4673 4674 |
# File 'lib/HDLRuby/hruby_high.rb', line 4672 def cur_block return HDLRuby::High.cur_block end |
#cur_scope ⇒ Object
Gets the current scope.
4687 4688 4689 |
# File 'lib/HDLRuby/hruby_high.rb', line 4687 def cur_scope return HDLRuby::High.cur_scope end |
#cur_system ⇒ Object
Gets the current system.
4692 4693 4694 |
# File 'lib/HDLRuby/hruby_high.rb', line 4692 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.
4776 4777 4778 4779 4780 |
# File 'lib/HDLRuby/hruby_high.rb', line 4776 def hcase(value) return if self.(value) # Creates the case statement. self.add_statement(Case.new(value)) end |
#hcasez(value) ⇒ Object
Creates a new case statement taking z as wildcard with a value used for deciding which
block to execute.
NOTE: the when part is defined through the hwhen method.
4786 4787 4788 4789 4790 |
# File 'lib/HDLRuby/hruby_high.rb', line 4786 def hcasez(value) return if self.(value) # Creates the case statement. self.add_statement(Case.new(value, :casez)) 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.
4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 |
# File 'lib/HDLRuby/hruby_high.rb', line 4732 def helse(mode = nil, &ruby_block) return if self.(&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.
4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 |
# File 'lib/HDLRuby/hruby_high.rb', line 4749 def helsif(condition, mode = nil, &ruby_block) = self.(condition,&ruby_block) if == :toif then # Must be converted to hif. return self.hif(condition,mode, &ruby_block) elsif then return end # 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, other = 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. def hif(condition, mode = nil, &ruby_block)
4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 |
# File 'lib/HDLRuby/hruby_high.rb', line 4712 def hif(condition, mode = self.mode, other = nil, &ruby_block) if mode and !mode.is_a?(Symbol) then if ruby_block then raise AnyError, "Error: expression hif with a block." end # Expression hif case: 'mode' is interpreted as the # expression of the condition is true, 'other'if it is false. return EIfMaker.new(condition,mode,other) end return if self.(condition,&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.
4813 4814 4815 |
# File 'lib/HDLRuby/hruby_high.rb', line 4813 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.
4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 |
# File 'lib/HDLRuby/hruby_high.rb', line 4796 def hwhen(match, mode = nil, &ruby_block) return if self.(match,&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.
4630 4631 4632 4633 4634 4635 4636 4637 |
# File 'lib/HDLRuby/hruby_high.rb', line 4630 def par(name = :"", &ruby_block) return :par unless ruby_block unless name.is_a?(::Symbol) or name.is_a?(::String) then raise AnyError, "Events can only be used at top level seq blocks." end 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.
4641 4642 4643 4644 4645 4646 4647 4648 |
# File 'lib/HDLRuby/hruby_high.rb', line 4641 def seq(name = :"", &ruby_block) return :seq unless ruby_block unless name.is_a?(::Symbol) or name.is_a?(::String) then raise AnyError, "Events can only be used at top level seq blocks." end self.add_block(:seq,name,&ruby_block) end |
#sub(name = HDLRuby.uniq_name, &ruby_block) ⇒ Object
Creates a new block with the current mode with possible name and
built from ruby_block.
def sub(name = :"", &ruby_block)
4653 4654 4655 4656 4657 |
# File 'lib/HDLRuby/hruby_high.rb', line 4653 def sub(name = HDLRuby.uniq_name, &ruby_block) # Ensure there is a block. ruby_block = proc {} unless block_given? self.add_block(self.mode,name,&ruby_block) end |
#terminate ⇒ Object
Terminate the simulation.
4818 4819 4820 |
# File 'lib/HDLRuby/hruby_high.rb', line 4818 def terminate self.add_statement(TimeTerminate.new) end |
#to_ref ⇒ Object
Converts to a new reference.
4611 4612 4613 |
# File 'lib/HDLRuby/hruby_high.rb', line 4611 def to_ref return RefObject.new(this,self) end |
#top_block ⇒ Object
Gets the top block of the current behavior.
4677 4678 4679 |
# File 'lib/HDLRuby/hruby_high.rb', line 4677 def top_block return HDLRuby::High.top_block end |
#unshift(&ruby_block) ⇒ Object
Adds statements at the top of the block.
4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 |
# File 'lib/HDLRuby/hruby_high.rb', line 4660 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 |