class HDLRuby::High::If

Describes a high-level if statement.

Constants

High

High-level libraries for describing digital hardware.

Public Class Methods

new(condition, mode = nil, &ruby_block) click to toggle source

Creates a new if statement with a condition that when met lead to the execution of the block in mode generated by the execution of ruby_block.

Calls superclass method HDLRuby::Low::If::new
# File lib/HDLRuby/hruby_high.rb, line 2208
def initialize(condition, mode = nil, &ruby_block)
    # Create the yes block.
    yes_block = High.make_block(mode,&ruby_block)
    # Creates the if statement.
    super(condition.to_expr,yes_block)
end

Public Instance Methods

helse(mode = nil, &ruby_block) click to toggle source

Sets the block executed in mode when the condition is not met to the block generated by the execution of ruby_block.

Can only be used once.

# File lib/HDLRuby/hruby_high.rb, line 2219
def helse(mode = nil, &ruby_block)
    # If there is a no block, it is an error.
    raise AnyError, "Cannot have two helse for a single if statement." if self.no
    # Create the no block if required
    no_block = High.make_block(mode,&ruby_block)
    # Sets the no block.
    self.no = no_block
end
helsif(next_cond, mode = nil, &ruby_block) click to toggle source

Sets the block executed in mode when the condition is not met but next_cond is met to the block generated by the execution of ruby_block.

Can only be used if the no-block is not set yet.

# File lib/HDLRuby/hruby_high.rb, line 2233
def helsif(next_cond, mode = nil, &ruby_block)
    # If there is a no block, it is an error.
    raise AnyError, "Cannot have an helsif after an helse." if self.no
    # Create the noif block if required
    noif_block = High.make_block(mode,&ruby_block)
    # Adds the noif block.
    self.add_noif(next_cond.to_expr,noif_block)
end
to_low() click to toggle source

Converts the if to HDLRuby::Low.

# File lib/HDLRuby/hruby_high.rb, line 2243
def to_low
    # no may be nil, so treat it appart
    noL = self.no ? self.no.to_low : nil
    # Now generate the low-level if.
    ifL = HDLRuby::Low::If.new(self.condition.to_low,
                               self.yes.to_low,noL)
    self.each_noif {|cond,block| ifL.add_noif(cond.to_low,block.to_low)}
    # For debugging: set the source high object
    ifL.properties[:low2high] = self.hdr_id
    self.properties[:high2low] = ifL
    return ifL
end