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
Extends the When class with functionality for extracting expressions from cast.
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+
1714 1715 1716 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1714 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+.
1719 1720 1721 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1719 def add_make_block(res,level) self.statement.add_make_block(res,level) end |
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
135 136 137 138 139 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 135 def blocks2seq! # Convert the statement. self.statement.blocks2seq! return self end |
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
119 120 121 122 123 124 125 126 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 119 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.
601 602 603 604 605 606 607 608 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 601 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.
889 890 891 892 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 889 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.
149 150 151 152 153 154 155 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 149 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!
585 586 587 588 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 585 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.
210 211 212 213 214 |
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 210 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).
851 852 853 854 855 856 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 851 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.
143 144 145 146 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 143 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.
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 864 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.
591 592 593 594 595 596 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 591 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.
826 827 828 829 830 831 832 833 834 835 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 826 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.
838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 838 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.
182 183 184 185 186 187 188 |
# File 'lib/HDLRuby/hruby_low_without_subsignals.rb', line 182 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)
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1686 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
1707 1708 1709 1710 1711 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1707 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.
381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 381 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.
275 276 277 278 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 275 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.
577 578 579 580 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 577 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.
982 983 984 985 986 987 988 989 990 991 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 982 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.
299 300 301 |
# File 'lib/HDLRuby/hruby_low_with_var.rb', line 299 def with_var(upper = nil) return When.new(self.match.clone,self.statement.with_var(upper)) end |