Class: RubyHDL::High::Sif
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a sif statement.
Direct Known Subclasses
Instance Method Summary collapse
-
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
-
#initialize(sequencer, cond, &ruby_block) ⇒ Sif
constructor
Create a new if statement in sequencer +sequencer+ with +cond+ condition and +ruby_block+ for generating the block that is taken if the condition is met.
-
#selse(&ruby_block) ⇒ Object
Sets the else block.
-
#selsif(cond, &ruby_block) ⇒ Object
Add a selsif case.
-
#to_c ⇒ Object
Convert to C code.
-
#to_ruby ⇒ Object
Convert to Ruby code.
Constructor Details
#initialize(sequencer, cond, &ruby_block) ⇒ Sif
Create a new if statement in sequencer +sequencer+ with +cond+ condition and +ruby_block+ for generating the block that is taken if the condition is met.
2295 2296 2297 2298 2299 2300 2301 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2295 def initialize(sequencer,cond, &ruby_block) @sequencer = sequencer @condition = cond.to_expr @yes_blk = Sblock.new(@sequencer,&ruby_block) @elsifs = [] @else_blk = nil end |
Instance Method Details
#each_statement(&ruby_block) ⇒ Object
Iterate on the statements.
2314 2315 2316 2317 2318 2319 2320 2321 2322 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2314 def each_statement(&ruby_block) return to_enum(:each_statement) unless ruby_block # Apply ruby_block on the yes block. ruby_block.call(@yes_blk) # On the elsifs. @elsifs.each { |cond,statement| ruby_block.call(statement) } # On the else if any. ruby_block.call(@else_blk) if @else_blk end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterate deeply on the statements.
2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2325 def each_statement_deep(&ruby_block) return to_enum(:each_statement_deep) unless ruby_block # Recurse on the yes block. @yes_blk.each_statement_deep # On the elsifs. @elsifs.each { |cond,statement| statement.each_statement_deep } # On the else if any. @else_blk.each_statement_deep if @else_blk # And apply ruby_block on self. ruby_block.call(self) end |
#selse(&ruby_block) ⇒ Object
Sets the else block.
2309 2310 2311 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2309 def selse(&ruby_block) @else_blk = Sblock.new(@sequencer,&ruby_block) end |
#selsif(cond, &ruby_block) ⇒ Object
Add a selsif case.
2304 2305 2306 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2304 def selsif(cond,&ruby_block) @elsifs << [cond,Sblock.new(@sequencer,&ruby_block)] end |
#to_c ⇒ Object
Convert to C code.
2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2350 def to_c res = @sequencer.clk_up_c + "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}" @elsifs.each do |(cond,blk)| res << "\nelse if(#{cond.to_c}) {\n#{blk.to_c}\n}" end if @else_blk then res << "\nelse {\n#{@else_blk.to_c}\n}" end return res + @sequencer.clk_up_c end |
#to_ruby ⇒ Object
Convert to Ruby code.
2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2338 def to_ruby res = @sequencer.clk_up + "\nif((#{@condition.to_ruby}) != 0)\n#{@yes_blk.to_ruby}\n" @elsifs.each do |(cond,blk)| res << "elsif((#{cond.to_ruby}) != 0)\n#{blk.to_ruby}\n" end if @else_blk then res << "else\n#{@else_blk.to_ruby}\n" end return res + "end\n" + @sequencer.clk_up end |