Class: HDLRuby::High::Case

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

Overview

Describes a high-level case 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::Case

#default, #value

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from HStatement

#hif

Methods inherited from Low::Case

#add_when, #blocks2seq!, #boolean_in_assign2select!, #casts_without_expression!, #clone, #delete_related!, #delete_unless!, #delete_when!, #each_block, #each_block_deep, #each_deep, #each_node, #each_node_deep, #each_statement, #each_statement_deep, #each_when, #eql?, #explicit_types!, #extract_declares!, #extract_selects!, #hash, #map_nodes!, #map_whens!, #mix?, #par_in_seq2seq!, #replace_expressions!, #replace_names!, #set_default!, #set_value!, #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(value) ⇒ Case

Creates a new case statement with a +value+ that decides which block to execute.



2332
2333
2334
2335
# File 'lib/HDLRuby/hruby_high.rb', line 2332

def initialize(value)
    # Create the yes block.
    super(value.to_expr)
end

Instance Method Details

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

Sets the block executed in +mode+ when there were no match to the block generated by the execution of +ruby_block+.

Can only be used once.



2352
2353
2354
2355
2356
2357
# File 'lib/HDLRuby/hruby_high.rb', line 2352

def helse(mode = nil, &ruby_block)
    # Create the nu block if required
    default_block = High.make_block(mode,&ruby_block)
    # Sets the default block.
    self.default = default_block
end

#hwhen(match, mode = nil, &ruby_block) ⇒ Object

Sets the block executed in +mode+ when the value matches +match+. The block is generated by the execution of +ruby_block+.

Can only be used once for the given +match+.



2341
2342
2343
2344
2345
2346
# File 'lib/HDLRuby/hruby_high.rb', line 2341

def hwhen(match, mode = nil, &ruby_block)
    # Create the nu block if required
    when_block = High.make_block(mode,&ruby_block)
    # Adds the case.
    self.add_when(When.new(match.to_expr,when_block))
end

#to_lowObject

Converts the case to HDLRuby::Low.



2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
# File 'lib/HDLRuby/hruby_high.rb', line 2360

def to_low
    # Create the low level case.
    caseL = HDLRuby::Low::Case.new(@value.to_low)
    # # For debugging: set the source high object 
    # caseL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = caseL
    # Add each when case.
    self.each_when do |w|
        caseL.add_when(w.to_low)
    end
    # Add the default if any.
    if self.default then
        caseL.default = self.default.to_low
    end
    return caseL
end