Class: RubyHDL::High::Sif

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of a if statement.

Instance Method Summary collapse

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.



2144
2145
2146
2147
2148
2149
2150
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2144

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.



2158
2159
2160
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2158

def selse(&ruby_block)
  @else_blk = Sblock.new(@sequencer,&ruby_block)
end

#selsif(cond, &ruby_block) ⇒ Object

Add a selsif case.



2153
2154
2155
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2153

def selsif(cond,&ruby_block)
  @elsifs << [cond,Sblock.new(@sequencer,&ruby_block)]
end

#to_cObject

Convert to C code.



2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2175

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_rubyObject

Convert to Ruby code.



2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 2163

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