Class: RubyHDL::High::Sif
- Inherits:
-
Object
- Object
- RubyHDL::High::Sif
- Defined in:
- lib/HDLRuby/std/sequencer_sw.rb
Overview
Describes a SW implementation of a if statement.
Instance Method Summary collapse
-
#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.
2197 2198 2199 2200 2201 2202 2203 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2197 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
#selse(&ruby_block) ⇒ Object
Sets the else block.
2211 2212 2213 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2211 def selse(&ruby_block) @else_blk = Sblock.new(@sequencer,&ruby_block) end |
#selsif(cond, &ruby_block) ⇒ Object
Add a selsif case.
2206 2207 2208 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2206 def selsif(cond,&ruby_block) @elsifs << [cond,Sblock.new(@sequencer,&ruby_block)] end |
#to_c ⇒ Object
Convert to C code.
2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2228 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.
2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 |
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2216 def to_ruby res = @sequencer.clk_up + "\nif(#{@condition.to_ruby})\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 |