Class: RubyHDL::High::Sif
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a if statement.
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.
2268 2269 2270 2271 2272 2273 2274 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2268 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.
2287 2288 2289 2290 2291 2292 2293 2294 2295 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2287 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.
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2298 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.
2282 2283 2284 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2282 def selse(&ruby_block) @else_blk = Sblock.new(@sequencer,&ruby_block) end |
#selsif(cond, &ruby_block) ⇒ Object
Add a selsif case.
2277 2278 2279 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2277 def selsif(cond,&ruby_block) @elsifs << [cond,Sblock.new(@sequencer,&ruby_block)] end |
#to_c ⇒ Object
Convert to C code.
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2323 def to_c res = @sequencer.clk_up + "\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.
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2311 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})\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 |