Class: HDLRuby::Low::When
- Inherits:
-
Object
- Object
- HDLRuby::Low::When
- Includes:
- Hparent, Low2Symbol
- Defined in:
- lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2hdr.rb,
lib/HDLRuby/hruby_low2seq.rb,
lib/HDLRuby/hruby_low2sym.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_cleanup.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_with_var.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_bool2select.rb,
lib/HDLRuby/hruby_low_without_select.rb,
lib/HDLRuby/hruby_low_without_namespace.rb,
lib/HDLRuby/hruby_low_without_subsignals.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb
Overview
Describes a when for a case statement.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
The value to match.
-
#statement ⇒ Object
readonly
The statement to execute in in case of match.
Attributes included from Hparent
Instance Method Summary collapse
-
#add_blocks_code(res, level) ⇒ Object
Adds the c code of the blocks to +res+ at +level+.
-
#add_make_block(res, level) ⇒ Object
Adds the creation of the blocks to +res+ at +level+.
-
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
-
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
-
#break_types!(types) ⇒ Object
Breaks the hierarchical types into sequences of type definitions.
-
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
-
#clone ⇒ Object
Clones the When (deeply).
-
#delete_related!(*names) ⇒ Object
Deletes the elements related to one of +names+: either they have one of the names or they use an element with these names.
-
#delete_unless!(keep) ⇒ Object
Removes the signals and corresponding assignments whose name is not in +keep+.
-
#each_block(&ruby_block) ⇒ Object
Iterates over the sub blocks.
-
#each_block_deep(&ruby_block) ⇒ Object
Iterates over all the blocks contained in the current block.
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#each_node(&ruby_block) ⇒ Object
Interates over the children.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
-
#each_statement(&ruby_block) ⇒ Object
Iterates over each sub statement if any.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the stamements of the block and its sub blocks.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types!(type) ⇒ Object
Explicit the types conversions in the when where +type+ is the type of the selecting value.
-
#extract_declares! ⇒ Object
Extract the declares from the scope and returns them into an array.
-
#extract_selects! ⇒ Object
Extract the Select expressions.
-
#hash ⇒ Object
Hash function.
-
#initialize(match, statement) ⇒ When
constructor
Creates a new when for a casde statement that executes +statement+ on +match+.
-
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children (including the match).
-
#mix?(mode = nil) ⇒ Boolean
Tell if there is a mix block.
-
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement.
-
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
-
#set_match!(match) ⇒ Object
Sets the match.
-
#set_statement!(statement) ⇒ Object
Sets the statement.
-
#signal2subs! ⇒ Object
Decompose the hierarchical signals in the statements.
-
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code.
-
#to_ch(res) ⇒ Object
Generates the content of the h file.
-
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high when.
-
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
-
#to_vhdl(vars, type, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code ensuring the match is of +type+.
-
#top_block ⇒ Object
Gets the top block, i.e.
-
#use_name?(*names) ⇒ Boolean
Tell if the statement includes a signal whose name is one of +names+.
-
#with_var(upper = nil) ⇒ Object
Converts to a variable-compatible case where +upper+ is the upper block if any.
Methods included from Low2Symbol
Methods included from Hparent
#hierarchy, #no_parent!, #scope
Constructor Details
#initialize(match, statement) ⇒ When
Creates a new when for a casde statement that executes +statement+ on +match+.
3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 |
# File 'lib/HDLRuby/hruby_low.rb', line 3534 def initialize(match,statement) # Checks the match. unless match.is_a?(Expression) raise AnyError, "Invalid class for a case match: #{match.class}" end # Checks statement. unless statement.is_a?(Statement) raise AnyError, "Invalid class for a statement: #{statement.class}" end # Set the match. @match = match # Set the statement. @statement = statement # And set their parents. match.parent = statement.parent = self end |
Instance Attribute Details
#match ⇒ Object (readonly)
The value to match.
3528 3529 3530 |
# File 'lib/HDLRuby/hruby_low.rb', line 3528 def match @match end |
#statement ⇒ Object (readonly)
The statement to execute in in case of match.
3530 3531 3532 |
# File 'lib/HDLRuby/hruby_low.rb', line 3530 def statement @statement end |
Instance Method Details
#add_blocks_code(res, level) ⇒ Object
Adds the c code of the blocks to +res+ at +level+
1721 1722 1723 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1721 def add_blocks_code(res,level) self.statement.add_blocks_code(res,level) end |
#add_make_block(res, level) ⇒ Object
Adds the creation of the blocks to +res+ at +level+.
1726 1727 1728 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1726 def add_make_block(res,level) self.statement.add_make_block(res,level) end |
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
139 140 141 142 143 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 139 def blocks2seq! # Convert the statement. self.statement.blocks2seq! return self end |
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
120 121 122 123 124 125 126 127 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 120 def boolean_in_assign2select! # No need to apply on the match! # # Apply on the match. # self.set_match!(self.match.boolean_in_assign2select) # Apply on the statement. self.statement.boolean_in_assign2select! return self end |
#break_types!(types) ⇒ Object
Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before. +types+ include the resulting types.
613 614 615 616 617 618 619 620 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 613 def break_types!(types) self.each_node do |node| # Need to break only in the case of a cast. if node.is_a?(Cast) then node.type.break_types!(types) end end end |
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
105 106 107 108 109 110 111 |
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 105 def casts_without_expression! # Apply on the match. self.set_match!(self.match.casts_without_expression!) # Apply on the statement. self.statement.casts_without_expression! return self end |
#clone ⇒ Object
Clones the When (deeply)
3583 3584 3585 |
# File 'lib/HDLRuby/hruby_low.rb', line 3583 def clone return When.new(@match.clone,@statement.clone) end |
#delete_related!(*names) ⇒ Object
Deletes the elements related to one of +names+: either they have one of the names or they use an element with these names. NOTE: only delete actual instantiated elements, types or systemTs are left as is.
862 863 864 865 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 862 def (*names) # Recurse on the statement. @statement.(*names) end |
#delete_unless!(keep) ⇒ Object
Removes the signals and corresponding assignments whose name is not in +keep+.
145 146 147 148 |
# File 'lib/HDLRuby/hruby_low_cleanup.rb', line 145 def delete_unless!(keep) # Recurse on the statement. self.statement.delete_unless!(keep) end |
#each_block(&ruby_block) ⇒ Object
Iterates over the sub blocks.
3599 3600 3601 3602 3603 3604 3605 |
# File 'lib/HDLRuby/hruby_low.rb', line 3599 def each_block(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_block) unless ruby_block # A ruby block? # Apply it on the statement if it is a block. ruby_block.call(@statement) if @statement.is_a?(Block) end |
#each_block_deep(&ruby_block) ⇒ Object
Iterates over all the blocks contained in the current block.
3608 3609 3610 3611 3612 3613 3614 |
# File 'lib/HDLRuby/hruby_low.rb', line 3608 def each_block_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_block_deep) unless ruby_block # A ruby block? # Recurse on the statement. @statement.each_block_deep(&ruby_block) end |
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 |
# File 'lib/HDLRuby/hruby_low.rb', line 3558 def each_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # Then apply on the match. self.match.each_deep(&ruby_block) # Then apply on the statement. self.statement.each_deep(&ruby_block) end |
#each_node(&ruby_block) ⇒ Object
Interates over the children.
3626 3627 3628 3629 3630 3631 3632 3633 |
# File 'lib/HDLRuby/hruby_low.rb', line 3626 def each_node(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node) unless ruby_block # A ruby block? # Appy it on the children. ruby_block.call(@match) ruby_block.call(@statement) end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
3636 3637 3638 3639 3640 3641 3642 3643 3644 |
# File 'lib/HDLRuby/hruby_low.rb', line 3636 def each_node_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # And recurse on the children @match.each_node_deep(&ruby_block) @statement.each_node_deep(&ruby_block) end |
#each_statement(&ruby_block) ⇒ Object
Iterates over each sub statement if any.
Returns an enumerator if no ruby block is given.
3590 3591 3592 3593 3594 3595 3596 |
# File 'lib/HDLRuby/hruby_low.rb', line 3590 def each_statement(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_statement) unless ruby_block # A ruby block? # Appy it on the statement child. ruby_block.call(@statement) end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the stamements of the block and its sub blocks.
3617 3618 3619 3620 3621 3622 3623 |
# File 'lib/HDLRuby/hruby_low.rb', line 3617 def each_statement_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_statement_deep) unless ruby_block # A ruby block? # Recurse on the statement. @statement.each_statement_deep(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
3570 3571 3572 3573 3574 3575 |
# File 'lib/HDLRuby/hruby_low.rb', line 3570 def eql?(obj) return false unless obj.is_a?(When) return false unless @match.eql?(obj.match) return false unless @statement.eql?(obj.statement) return true end |
#explicit_types!(type) ⇒ Object
Explicit the types conversions in the when where +type+ is the type of the selecting value.
160 161 162 163 164 165 166 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 160 def explicit_types!(type) # Recurse on the match, it must be of type. self.set_match!(self.match.explicit_types(type)) # Recurse on the statement. self.statement.explicit_types! return self end |
#extract_declares! ⇒ Object
Extract the declares from the scope and returns them into an array.
NOTE: do not recurse into the sub scopes or behaviors!
597 598 599 600 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 597 def extract_declares! # Recurse on the statement. return self.statement.extract_declares! end |
#extract_selects! ⇒ Object
Extract the Select expressions.
NOTE: work on the match only.
221 222 223 224 225 |
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 221 def extract_selects! selects = [] self.set_match!(self.match.extract_selects_to!(selects)) return selects end |
#hash ⇒ Object
Hash function.
3578 3579 3580 |
# File 'lib/HDLRuby/hruby_low.rb', line 3578 def hash return [@match,@statement].hash end |
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children (including the match).
824 825 826 827 828 829 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 824 def map_nodes!(&ruby_block) @match = ruby_block.call(@match) @match.parent = self unless @match.parent @statement = ruby_block.call(@statement) @statement.parent = self unless @statement.parent end |
#mix?(mode = nil) ⇒ Boolean
Tell if there is a mix block. +mode+ is the mode of the upper block.
147 148 149 150 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 147 def mix?(mode = nil) # Check the statement. return statement.mix?(mode) end |
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement. Returns the actually replaced nodes and their corresponding replacement.
NOTE: the replacement is duplicated.
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 837 def replace_expressions!(node2rep) # First recurse on the children. res = {} self.each_node do |node| res.merge!(node.replace_expressions!(node2rep)) end # Is there a replacement to do on the value? rep = node2rep[self.match] if rep then # Yes, do it. rep = rep.clone node = self.match # node.set_parent!(nil) self.set_match!(rep) # And register the replacement. res[node] = rep end return res end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
603 604 605 606 607 608 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 603 def replace_names!(former,nname) # Recurse on the match. self.match.replace_names!(former,nname) # Recurse on the statement. self.statement.replace_names!(former,nname) end |
#set_match!(match) ⇒ Object
Sets the match.
799 800 801 802 803 804 805 806 807 808 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 799 def set_match!(match) # Checks the match. unless match.is_a?(Expression) raise AnyError, "Invalid class for a case match: #{match.class}" end # Set the match. @match = match # And set their parents. match.parent = self end |
#set_statement!(statement) ⇒ Object
Sets the statement.
811 812 813 814 815 816 817 818 819 820 821 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 811 def set_statement!(statement) # Checks statement. unless statement.is_a?(Statement) raise AnyError, "Invalid class for a statement: #{statement.class}" end # Set the statement. @statement = statement # And set their parents. statement.parent = self end |
#signal2subs! ⇒ Object
Decompose the hierarchical signals in the statements.
183 184 185 186 187 188 189 |
# File 'lib/HDLRuby/hruby_low_without_subsignals.rb', line 183 def signal2subs! # Recurse on the match. self.set_match!(self.match.signal2subs!) # Recurse on the statement. self.set_statement!(self.statement.signal2subs!) return self end |
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1693 def to_c(res,level = 0) # The result string. # res = " " * level*3 res << " " * level*3 # Generate the match. # res << "case " << self.match.to_c(level+1) << ": {\n" res << "case " self.match.to_c(res,level+1) res << ": {\n" # Generate the statement. # res << self.statement.to_c(level+1) self.statement.to_c(res,level+1) # Adds a break res << " " * (level+1)*3 << "break;\n" res << " " * level*3 << "}\n" # Returns the result. return res end |
#to_ch(res) ⇒ Object
Generates the content of the h file. def to_ch
1714 1715 1716 1717 1718 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1714 def to_ch(res) # return self.statement.to_ch self.statement.to_ch(res) return res end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.
389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 389 def to_hdr(level = 0) # The result string. res = " " * (level*3) # Generate the match. res << "hwhen " << self.match.to_hdr(level+1) << " do\n" # Generate the statement. res << self.statement.to_hdr(level+1) # Close the when. res << " " * (level*3) << "end\n" # Returns the result. return res end |
#to_high ⇒ Object
Creates a new high when.
296 297 298 299 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 296 def to_high return HDLRuby::High::When.new(self.match.to_high, self.statement.to_high) end |
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
589 590 591 592 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 589 def to_upper_space! # Recurse on the statement. self.statement.to_upper_space! end |
#to_vhdl(vars, type, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code ensuring the match is of +type+. +vars+ is the list of the variables and +level+ is the hierachical level of the object.
996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 996 def to_vhdl(vars,type,level = 0) # The result string. res = " " * (level*3) # Generate the match. res << "when " << Low2VHDL.to_type(type,self.match) << " =>\n" # Generate the statement. res << self.statement.to_vhdl(vars,level+1) # Returns the result. return res end |
#top_block ⇒ Object
Gets the top block, i.e. the first block of the current behavior.
3647 3648 3649 3650 |
# File 'lib/HDLRuby/hruby_low.rb', line 3647 def top_block # return self.parent.is_a?(Behavior) ? self : self.parent.top_block return self.parent.top_block end |
#use_name?(*names) ⇒ Boolean
Tell if the statement includes a signal whose name is one of +names+. NOTE: for the when check only the match.
3654 3655 3656 |
# File 'lib/HDLRuby/hruby_low.rb', line 3654 def use_name?(*names) return @match.use_name?(*name) end |
#with_var(upper = nil) ⇒ Object
Converts to a variable-compatible case where +upper+ is the upper block if any.
NOTE: the result is a new case.
312 313 314 |
# File 'lib/HDLRuby/hruby_low_with_var.rb', line 312 def with_var(upper = nil) return When.new(self.match.clone,self.statement.with_var(upper)) end |