Class: HDLRuby::Low::TimeRepeat
- 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_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.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 timed loop statement: not synthesizable!
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
The delay until the loop is repeated attr_reader :delay The number of interrations.
-
#statement ⇒ Object
readonly
The statement to execute.
Attributes included from Hparent
Instance Method Summary collapse
-
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
-
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
-
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
-
#clone ⇒ Object
Clones the TimeRepeat (deeply).
-
#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
Iterates over the expression children if any.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the statements contained in the current block.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types! ⇒ Object
Explicit the types conversions in the time repeat.
-
#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(number, statement) ⇒ TimeRepeat
constructor
Creates a new timed loop statement execute in a loop +statement+ until # +delay+ has passed.
-
#map_nodes!(&ruby_block) ⇒ Object
Maps on the child.
-
#mix?(mode = nil) ⇒ Boolean
Tell if there is a mix block.
-
#process_to_vhdl(vars, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code as a new process.
-
#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_delay!(delay) ⇒ Object
Sets the delay.
-
#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_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high repreat statement.
-
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
-
#to_verilog(spc = 3) ⇒ Object
Enhances TimeRepeat with generation of verilog code.
-
#to_vhdl(vars, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
Methods inherited from Statement
#add_blocks_code, #add_make_block, #behavior, #block, #break_types!, #delete_related!, #delete_unless!, #each_statement, #par_in_seq2seq!, #parent_system, #scope, #to_ch, #to_seq!, #top_block, #top_scope, #use_name?, #with_boolean!
Methods included from Low2Symbol
Methods included from Hparent
#hierarchy, #no_parent!, #scope
Constructor Details
#initialize(number, statement) ⇒ TimeRepeat
Creates a new timed loop statement execute in a loop +statement+ until
+delay+ has passed.
def initialize(statement,delay) Creates a new timed loop statement execute in a loop +statement+ +number+ times (negative means inifinity).
4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 |
# File 'lib/HDLRuby/hruby_low.rb', line 4222 def initialize(number,statement) # Check and set the statement. unless statement.is_a?(Statement) raise AnyError, "Invalid class for a statement: #{statement.class}." end super() @statement = statement # And set its parent. statement.parent = self # # Check and set the delay. # unless delay.is_a?(Delay) # raise AnyError, "Invalid class for a delay: #{delay.class}." # end # @delay = delay # Check and set the number. @number = number.to_i # # And set its parent. # delay.parent = self end |
Instance Attribute Details
#number ⇒ Object (readonly)
The delay until the loop is repeated
attr_reader :delay The number of interrations.
4212 4213 4214 |
# File 'lib/HDLRuby/hruby_low.rb', line 4212 def number @number end |
#statement ⇒ Object (readonly)
The statement to execute.
4215 4216 4217 |
# File 'lib/HDLRuby/hruby_low.rb', line 4215 def statement @statement end |
Instance Method Details
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
185 186 187 188 189 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 185 def blocks2seq! # Converts the statement. self.statement.blocks2seq! return self end |
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
166 167 168 169 170 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 166 def boolean_in_assign2select! # Simply recurse on the stamtement. self.statement.boolean_in_assign2select! return self end |
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
150 151 152 153 154 |
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 150 def casts_without_expression! # Simply recurse on the stamtement. self.statement.casts_without_expression! return self end |
#clone ⇒ Object
Clones the TimeRepeat (deeply)
4274 4275 4276 4277 |
# File 'lib/HDLRuby/hruby_low.rb', line 4274 def clone # return TimeRepeat.new(@statement.clone,@delay.clone) return TimeRepeat.new(@statement.clone,@number) end |
#each_block(&ruby_block) ⇒ Object
Iterates over the sub blocks.
4298 4299 4300 4301 4302 4303 4304 |
# File 'lib/HDLRuby/hruby_low.rb', line 4298 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.
4307 4308 4309 4310 4311 4312 4313 |
# File 'lib/HDLRuby/hruby_low.rb', line 4307 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.
4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 |
# File 'lib/HDLRuby/hruby_low.rb', line 4247 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 statement. self.statement.each_deep(&ruby_block) # # Then apply on the delay. # self.delay.each_deep(&ruby_block) end |
#each_node(&ruby_block) ⇒ Object
Iterates over the expression children if any.
4280 4281 4282 4283 4284 4285 |
# File 'lib/HDLRuby/hruby_low.rb', line 4280 def each_node(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node) unless ruby_block # A ruby block? Apply it on the child. ruby_block.call(@statement) end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
4288 4289 4290 4291 4292 4293 4294 4295 |
# File 'lib/HDLRuby/hruby_low.rb', line 4288 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 child @statement.each_node_deep(&ruby_block) end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the statements contained in the current block.
4316 4317 4318 4319 4320 4321 4322 4323 4324 |
# File 'lib/HDLRuby/hruby_low.rb', line 4316 def each_statement_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_statement_deep) unless ruby_block # A ruby block? # Apply it on self. ruby_block.call(self) # Recurse on the statement. @statement.each_statement_deep(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
4259 4260 4261 4262 4263 4264 4265 |
# File 'lib/HDLRuby/hruby_low.rb', line 4259 def eql?(obj) return false unless obj.is_a?(TimeRepeat) # return false unless @delay.eql?(obj.delay) return false unless @number.eql?(obj.number) return false unless @statement.eql?(obj.statement) return true end |
#explicit_types! ⇒ Object
Explicit the types conversions in the time repeat.
200 201 202 203 204 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 200 def explicit_types! # 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!
674 675 676 677 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 674 def extract_declares! # Recurse on the statement. return self.statement.extract_declares! end |
#extract_selects! ⇒ Object
Extract the Select expressions.
119 120 121 122 123 124 125 126 |
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 119 def extract_selects! # Simply recruse on the statement. if self.statement.is_a?(Block) then return [] else return self.statement.extract_selects! end end |
#hash ⇒ Object
Hash function.
4268 4269 4270 4271 |
# File 'lib/HDLRuby/hruby_low.rb', line 4268 def hash # return [@delay,@statement].hash return [@number,@statement].hash end |
#map_nodes!(&ruby_block) ⇒ Object
Maps on the child.
1052 1053 1054 1055 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1052 def map_nodes!(&ruby_block) @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.
193 194 195 196 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 193 def mix?(mode = nil) # Check the statement. return self.statement.mix?(mode) end |
#process_to_vhdl(vars, level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code as a new process. +vars+ is the list of the variables and +level+ is the hierachical level of the object.
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1088 def process_to_vhdl(vars,level = 0) # Generate a separate process for the repeated statement with # a wait. # The resulting string. res = " " * (level*3) # Generate the header. unless self.block.name.empty? then res << Low2VHDL.vhdl_name(self.block.name) << ": " end res << "process \n" # Generate the content. res << " " * (level*3) res << "begin\n" # Adds the wait. res << " " * ((level+1)*3) res << "wait for " << self.delay.to_vhdl(level) << ";\n" # Generate the remaining of the body. res << self.statement.to_vhdl(vars,level+1) # Close the process. res << " " * (level*3) res << "end process;\n\n" # Return the result. return res 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.
1063 1064 1065 1066 1067 1068 1069 1070 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1063 def replace_expressions!(node2rep) res = {} # Recurse on the children. self.each_node do |node| res.merge!(node.replace_expressions!(node2rep)) end return res end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
680 681 682 683 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 680 def replace_names!(former,nname) # Recurse on the statement. self.statement.replace_names!(former,nname) end |
#set_delay!(delay) ⇒ Object
Sets the delay.
1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1041 def set_delay!(delay) # Check and set the delay. unless delay.is_a?(Delay) raise AnyError, "Invalid class for a delay: #{delay.class}." end @delay = delay # And set its parent. delay.parent = self end |
#set_statement!(statement) ⇒ Object
Sets the statement.
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1029 def set_statement!(statement) # Check and set the statement. unless statement.is_a?(Statement) raise AnyError, "Invalid class for a statement: #{statement.class}." end @statement = statement # And set its parent. statement.parent = self end |
#signal2subs! ⇒ Object
Decompose the hierarchical signals in the statements.
110 111 112 113 114 |
# File 'lib/HDLRuby/hruby_low_without_subsignals.rb', line 110 def 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)
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1928 def to_c(res,level = 0) # The resulting string. res << " " * level*3 if (self.number < 0) then # Generate an infinite loop executing the block and waiting. res << "for(;;) {\n" else # Generate a finite loop. res << "for(long long i = 0; i<#{self.number}; ++i) {\n" end self.statement.to_c(res,level+1) res << " " * level*3 << "}\n" # Return the resulting string. return res end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.
464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 464 def to_hdr(level = 0) # The resulting string. res = " " * (level*3) # Generate the header. res << "repeat " << self.delay.to_hdr(level) << " do\n" # Generate the statement to repeat. res << self.statement.to_hdr(level+1) # Close the repeat. res << " " * (level*3) << "end\n" # Return the resulting string. return res end |
#to_high ⇒ Object
Creates a new high repreat statement.
354 355 356 357 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 354 def to_high return HDLRuby::High::TimeReapeat.new(self.delay.to_high, self.statement.to_high) end |
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
666 667 668 669 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 666 def to_upper_space! # Recurse on the statement. self.statement.to_upper_space! end |
#to_verilog(spc = 3) ⇒ Object
Enhances TimeRepeat with generation of verilog code.
1886 1887 1888 1889 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1886 def to_verilog(spc = 3) result = (" " * spc) + "repeat(#{self.number})" + "\n" result << self.statement.to_verilog(spc+3) 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.
1079 1080 1081 1082 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1079 def to_vhdl(vars,level = 0) # Nothing to do, see process_to_vhdl return "" end |