Class: HDLRuby::Low::Statement
- Inherits:
-
Object
- Object
- HDLRuby::Low::Statement
- 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_fix_types.rb,
lib/HDLRuby/hruby_low_with_bool.rb,
lib/HDLRuby/hruby_low_without_parinseq.rb,
lib/HDLRuby/hruby_low_without_namespace.rb
Overview
Describes a statement.
NOTE: this is an abstract class which is not to be used directly.
Direct Known Subclasses
Block, Case, Configure, If, Print, TimeRepeat, TimeTerminate, TimeWait, Transmit
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary
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+.
-
#behavior ⇒ Object
Gets the behavior the statement is in.
-
#block ⇒ Object
Get the block of the statement.
-
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
-
#break_types!(types) ⇒ Object
Breaks the hierarchical types into sequences of type definitions.
-
#clone ⇒ Object
Clones (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_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#each_statement(&ruby_block) ⇒ Object
Iterates over each sub statement if any.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types! ⇒ Object
Explicit the types conversions in the statement.
-
#extract_declares! ⇒ Object
Extract the declares from the scope and returns them into an array.
-
#hash ⇒ Object
Hash function.
-
#mix?(mode = nil) ⇒ Boolean
Tell if there is a mix block.
-
#par_in_seq2seq! ⇒ Object
Converts par blocks within seq blocks to seq blocks.
-
#parent_system ⇒ Object
Gets the parent system, i.e., the parent of the top scope.
-
#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.
-
#scope ⇒ Object
Get the scope of 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 statement.
-
#to_seq! ⇒ Object
Convert the block to seq.
-
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
-
#to_vhdl(vars, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#top_block ⇒ Object
Gets the top block, i.e.
-
#top_scope ⇒ Object
Gets the top scope, i.e.
-
#use_name?(*names) ⇒ Boolean
Tell if the statement includes a signal whose name is one of +names+.
-
#with_boolean! ⇒ Object
Converts to a variable-compatible system.
Methods included from Low2Symbol
Methods included from Hparent
Instance Method Details
#add_blocks_code(res, level) ⇒ Object
Adds the c code of the blocks to +res+ at +level+
1348 1349 1350 1351 1352 1353 1354 1355 1356 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1348 def add_blocks_code(res,level) if self.respond_to?(:each_node) then self.each_node do |node| if node.respond_to?(:add_blocks_code) then node.add_blocks_code(res,level) end end end end |
#add_make_block(res, level) ⇒ Object
Adds the creation of the blocks to +res+ at +level+.
1359 1360 1361 1362 1363 1364 1365 1366 1367 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1359 def add_make_block(res,level) if self.respond_to?(:each_node) then self.each_node do |node| if node.respond_to?(:add_blocks_code) then node.add_make_block(res,level) end end end end |
#behavior ⇒ Object
Gets the behavior the statement is in.
3125 3126 3127 3128 3129 3130 3131 |
# File 'lib/HDLRuby/hruby_low.rb', line 3125 def behavior if self.parent.is_a?(Behavior) then return self.parent else return self.parent.behavior end end |
#block ⇒ Object
Get the block of the statement.
3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 |
# File 'lib/HDLRuby/hruby_low.rb', line 3102 def block if self.is_a?(Block) return self elsif self.parent.is_a?(Scope) # No block return nil else return self.parent.block end end |
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
85 86 87 88 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 85 def blocks2seq! # By default, nothing to do. 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.
496 497 498 499 500 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 496 def break_types!(types) self.each_node do |node| node.break_types!(types) end end |
#clone ⇒ Object
Clones (deeply)
3067 3068 3069 3070 |
# File 'lib/HDLRuby/hruby_low.rb', line 3067 def clone raise AnyError, "Internal error: clone is not defined for class: #{self.class}" 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.
537 538 539 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 537 def (*names) # Nothing to do by default. end |
#delete_unless!(keep) ⇒ Object
Removes the signals and corresponding assignments whose name is not in +keep+.
116 117 118 |
# File 'lib/HDLRuby/hruby_low_cleanup.rb', line 116 def delete_unless!(keep) # By default nothing to do. end |
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
3075 3076 3077 3078 |
# File 'lib/HDLRuby/hruby_low.rb', line 3075 def each_deep(&ruby_block) raise AnyError, "Internal error: each_deep is not defined for class: #{self.class}" end |
#each_statement(&ruby_block) ⇒ Object
Iterates over each sub statement if any.
Returns an enumerator if no ruby block is given.
3095 3096 3097 3098 3099 |
# File 'lib/HDLRuby/hruby_low.rb', line 3095 def each_statement(&ruby_block) # No ruby statement? Return an enumerator. return to_enum(:each_statement) unless ruby_block # By default: nothing to do. end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
3081 3082 3083 3084 |
# File 'lib/HDLRuby/hruby_low.rb', line 3081 def eql?(obj) raise AnyError, "Internal error: eql? is not defined for class: #{self.class}" end |
#explicit_types! ⇒ Object
Explicit the types conversions in the statement.
78 79 80 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 78 def explicit_types! raise "Should implement explicit_types! for class #{self.class}." 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!
478 479 480 481 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 478 def extract_declares! # By default, nothing to do. return [] end |
#hash ⇒ Object
Hash function.
3087 3088 3089 3090 |
# File 'lib/HDLRuby/hruby_low.rb', line 3087 def hash raise AnyError, "Internal error: hash is not defined for class: #{self.class}" end |
#mix?(mode = nil) ⇒ Boolean
Tell if there is a mix block. +mode+ is the mode of the upper block.
92 93 94 95 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 92 def mix?(mode = nil) # By default, no mix block. return false end |
#par_in_seq2seq! ⇒ Object
Converts par blocks within seq blocks to seq blocks.
48 49 50 51 |
# File 'lib/HDLRuby/hruby_low_without_parinseq.rb', line 48 def par_in_seq2seq! # By default nothing to do. return self end |
#parent_system ⇒ Object
Gets the parent system, i.e., the parent of the top scope.
3144 3145 3146 |
# File 'lib/HDLRuby/hruby_low.rb', line 3144 def parent_system return self.top_scope.parent 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.
528 529 530 531 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 528 def replace_expressions!(node2rep) # By default: nothing to do. return {} end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
484 485 486 487 488 489 490 491 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 484 def replace_names!(former,nname) # By default: try to replace the name recursively. self.each_node_deep do |node| if node.respond_to?(:name) && node.name == former then node.set_name!(nname) end end end |
#scope ⇒ Object
Get the scope of the statement.
3114 3115 3116 3117 3118 3119 3120 3121 3122 |
# File 'lib/HDLRuby/hruby_low.rb', line 3114 def scope if self.parent.is_a?(Scope) then return self.parent elsif self.parent.is_a?(Behavior) then return self.parent.parent else return self.parent.scope end 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)
1334 1335 1336 1337 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1334 def to_c(res,level = 0) # Should never be here. raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}" end |
#to_ch(res) ⇒ Object
Generates the content of the h file. def to_ch
1341 1342 1343 1344 1345 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1341 def to_ch(res) # By default nothing to generate. # return "" return res end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.
332 333 334 335 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 332 def to_hdr(level = 0) # Should never be here. raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}" end |
#to_high ⇒ Object
Creates a new high statement.
250 251 252 253 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 250 def to_high raise AnyError, "Internal error: to_high is not defined for class: #{self.class}" end |
#to_seq! ⇒ Object
Convert the block to seq.
54 55 56 57 |
# File 'lib/HDLRuby/hruby_low_without_parinseq.rb', line 54 def to_seq! # By default nothing to do. return self end |
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
471 472 473 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 471 def to_upper_space! # By default, nothing to do. end |
#to_vhdl(vars, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +vars+ is the list of the variables and +level+ is the hierachical level of the object.
901 902 903 904 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 901 def to_vhdl(vars, level = 0) # Should never be here. raise AnyError, "Internal error: to_vhdl should be implemented in class :#{self.class}" end |
#top_block ⇒ Object
Gets the top block, i.e. the first block of the current behavior.
3134 3135 3136 |
# File 'lib/HDLRuby/hruby_low.rb', line 3134 def top_block return self.parent.is_a?(Behavior) ? self : self.parent.top_block end |
#top_scope ⇒ Object
Gets the top scope, i.e. the first scope of the current system.
3139 3140 3141 |
# File 'lib/HDLRuby/hruby_low.rb', line 3139 def top_scope return self.scope.top_scope end |
#use_name?(*names) ⇒ Boolean
Tell if the statement includes a signal whose name is one of +names+.
3149 3150 3151 |
# File 'lib/HDLRuby/hruby_low.rb', line 3149 def use_name?(*names) # By default, nothing to do. end |
#with_boolean! ⇒ Object
Converts to a variable-compatible system.
NOTE: the result is the same Behaviour.
94 95 96 97 98 99 100 |
# File 'lib/HDLRuby/hruby_low_with_bool.rb', line 94 def with_boolean! self.each_node do |node| if node.is_a?(Expression) && node.boolean? then node.set_type!(HDLRuby::Low::Boolean) end end end |