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!, #casts_without_expression!, #clone, #delete_noif!, #delete_related!, #delete_unless!, #each_block, #each_block_deep, #each_deep, #each_node, #each_node_deep, #each_noif, #each_statement, #each_statement_deep, #eql?, #explicit_types!, #extract_declares!, #extract_selects!, #hash, #map_nodes!, #map_noifs!, #mix?, #par_in_seq2seq!, #replace_expressions!, #replace_names!, #set_condition!, #set_no!, #set_yes!, #to_c, #to_ch, #to_hdr, #to_high, #to_seq!, #to_upper_space!, #to_verilog, #to_vhdl, #use_name?, #with_var

Methods inherited from Low::Statement

#add_blocks_code, #add_make_block, #behavior, #block, #blocks2seq!, #break_types!, #clone, #delete_related!, #delete_unless!, #each_deep, #each_statement, #eql?, #explicit_types!, #extract_declares!, #hash, #mix?, #par_in_seq2seq!, #parent_system, #replace_expressions!, #replace_names!, #scope, #to_c, #to_ch, #to_hdr, #to_high, #to_seq!, #to_upper_space!, #to_vhdl, #top_block, #top_scope, #use_name?, #with_boolean!

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#hierarchy, #scope

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



2248
2249
2250
2251
2252
2253
# File 'lib/HDLRuby/hruby_high.rb', line 2248

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:



2259
2260
2261
2262
2263
2264
2265
2266
# File 'lib/HDLRuby/hruby_high.rb', line 2259

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:



2273
2274
2275
2276
2277
2278
2279
2280
# File 'lib/HDLRuby/hruby_high.rb', line 2273

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.



2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
# File 'lib/HDLRuby/hruby_high.rb', line 2283

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