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_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.
-
#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+.
3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 |
# File 'lib/HDLRuby/hruby_low.rb', line 3370 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.
3364 3365 3366 |
# File 'lib/HDLRuby/hruby_low.rb', line 3364 def match @match end |
#statement ⇒ Object (readonly)
The statement to execute in in case of match.
3366 3367 3368 |
# File 'lib/HDLRuby/hruby_low.rb', line 3366 def statement @statement end |
Instance Method Details
#add_blocks_code(res, level) ⇒ Object
Adds the c code of the blocks to +res+ at +level+
1645 1646 1647 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1645 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+.
1650 1651 1652 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1650 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)
3419 3420 3421 |
# File 'lib/HDLRuby/hruby_low.rb', line 3419 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.
886 887 888 889 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 886 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.
3435 3436 3437 3438 3439 3440 3441 |
# File 'lib/HDLRuby/hruby_low.rb', line 3435 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.
3444 3445 3446 3447 3448 3449 3450 |
# File 'lib/HDLRuby/hruby_low.rb', line 3444 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.
3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 |
# File 'lib/HDLRuby/hruby_low.rb', line 3394 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.
3462 3463 3464 3465 3466 3467 3468 3469 |
# File 'lib/HDLRuby/hruby_low.rb', line 3462 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.
3472 3473 3474 3475 3476 3477 3478 3479 3480 |
# File 'lib/HDLRuby/hruby_low.rb', line 3472 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.
3426 3427 3428 3429 3430 3431 3432 |
# File 'lib/HDLRuby/hruby_low.rb', line 3426 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.
3453 3454 3455 3456 3457 3458 3459 |
# File 'lib/HDLRuby/hruby_low.rb', line 3453 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.
3406 3407 3408 3409 3410 3411 |
# File 'lib/HDLRuby/hruby_low.rb', line 3406 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.
3414 3415 3416 |
# File 'lib/HDLRuby/hruby_low.rb', line 3414 def hash return [@match,@statement].hash end |
#map_nodes!(&ruby_block) ⇒ Object
Maps on the children (including the match).
848 849 850 851 852 853 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 848 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.
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 861 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.
823 824 825 826 827 828 829 830 831 832 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 823 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.
835 836 837 838 839 840 841 842 843 844 845 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 835 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 |
#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)
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1617 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
1638 1639 1640 1641 1642 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1638 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.
981 982 983 984 985 986 987 988 989 990 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 981 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.
3483 3484 3485 3486 |
# File 'lib/HDLRuby/hruby_low.rb', line 3483 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.
3490 3491 3492 |
# File 'lib/HDLRuby/hruby_low.rb', line 3490 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 |