Class: HDLRuby::High::If

Inherits:
Low::If show all
Includes:
HStatement
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Describes a high-level if statement.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable

Instance Attribute Summary

Attributes inherited from Low::If

#condition, #no, #yes

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from HStatement

#hif

Methods inherited from Low::If

#add_noif, #blocks2seq!, #boolean_in_assign2select!, #clone, #delete_noif!, #delete_unless!, #each_block, #each_block_deep, #each_node, #each_node_deep, #each_noif, #each_statement_deep, #eql?, #explicit_types!, #extract_declares!, #extract_selects!, #hash, #map_nodes!, #map_noifs!, #mix?, #replace_expressions!, #replace_names!, #set_condition!, #set_no!, #set_yes!, #to_c, #to_high, #to_upper_space!, #to_verilog, #to_vhdl, #with_var

Methods inherited from Low::Statement

#add_blocks_code, #block, #blocks2seq!, #break_types!, #clone, #delete_unless!, #eql?, #explicit_types!, #extract_declares!, #hash, #mix?, #replace_expressions!, #replace_names!, #to_c, #to_high, #to_upper_space!, #to_vhdl, #top_block, #top_scope, #with_boolean!

Methods included from Low::Low2Symbol

#to_sym

Constructor Details

#initialize(condition, mode = nil, &ruby_block) ⇒ If

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+.



2001
2002
2003
2004
2005
2006
# File 'lib/HDLRuby/hruby_high.rb', line 2001

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

Instance Method Details

#helse(mode = nil, &ruby_block) ⇒ Object

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.

Raises:



2012
2013
2014
2015
2016
2017
2018
2019
# File 'lib/HDLRuby/hruby_high.rb', line 2012

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) ⇒ Object

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.

Raises:



2026
2027
2028
2029
2030
2031
2032
2033
# File 'lib/HDLRuby/hruby_high.rb', line 2026

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_lowObject

Converts the if to HDLRuby::Low.



2036
2037
2038
2039
2040
2041
2042
2043
2044
# File 'lib/HDLRuby/hruby_high.rb', line 2036

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.
    low = HDLRuby::Low::If.new(self.condition.to_low,
                               self.yes.to_low,noL)
    self.each_noif {|cond,block| low.add_noif(cond.to_low,block.to_low)}
    return low
end