Class: HDLRuby::High::If

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

Overview

Enhance the if class with VCD support.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

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

Instance Attribute Summary collapse

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, #no_parent!, #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+.



2500
2501
2502
2503
2504
2505
# File 'lib/HDLRuby/hruby_high.rb', line 2500

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 Attribute Details

#rcstatementObject (readonly)

Returns the value of attribute rcstatement.



564
565
566
# File 'lib/HDLRuby/hruby_rcsim.rb', line 564

def rcstatement
  @rcstatement
end

Instance Method Details

#execute(mode) ⇒ Object

Executes the statement.



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/HDLRuby/hruby_rsim.rb', line 574

def execute(mode)
    # Check the main condition.
    if !(self.condition.execute(mode).zero?) then
        self.yes.execute(mode)
    else
        # Check the other conditions (elsif)
        success = false
        self.each_noif do |cond,stmnt|
            if !(cond.execute(mode).zero?) then
                stmnt.execute(mode)
                success = true
                break
            end
        end
        self.no.execute(mode) if self.no && !success
    end
end

#get_vars_with_fullname(vars_with_fullname = {}) ⇒ Object

Gets the VCD variables with their long name.



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 284

def get_vars_with_fullname(vars_with_fullname = {})
    # Recurse on the yes.
    self.yes.get_vars_with_fullname(vars_with_fullname)
    # Recurse on the noifs.
    self.each_noif do |cond,stmnt|
        stmnt.get_vars_with_fullname(vars_with_fullname)
    end
    # Recure on the no if any.
    self.no.get_vars_with_fullname(vars_with_fullname) if self.no
    return vars_with_fullname
end

#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:



2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
# File 'lib/HDLRuby/hruby_high.rb', line 2511

def helse(mode = nil, &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # 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:



2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
# File 'lib/HDLRuby/hruby_high.rb', line 2527

def helsif(next_cond, mode = nil, &ruby_block)
    # Ensure there is a block.
    ruby_block = proc {} unless block_given?
    # 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

#init_sim(systemT) ⇒ Object

Initialize the simulation for system +systemT+.



567
568
569
570
571
# File 'lib/HDLRuby/hruby_rsim.rb', line 567

def init_sim(systemT)
    self.yes.init_sim(systemT)
    self.each_noif { |cond,stmnt| stmnt.init_sim(systemT) } 
    self.no.init_sim(systemT) if self.no
end

#show_hierarchy(vcdout) ⇒ Object

Shows the hierarchy of the variables.



272
273
274
275
276
277
278
279
280
281
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 272

def show_hierarchy(vcdout)
    # Recurse on the yes.
    self.yes.show_hierarchy(vcdout)
    # Recurse on the noifs.
    self.each_noif do |cond,stmnt|
        stmnt.show_hierarchy(vcdout)
    end
    # Recure on the no if any.
    self.no.show_hierarchy(vcdout) if self.no
end

#to_lowObject

Converts the if to HDLRuby::Low.



2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
# File 'lib/HDLRuby/hruby_high.rb', line 2539

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

#to_rcsimObject

Generate the C description of the hardware if.



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/HDLRuby/hruby_rcsim.rb', line 567

def to_rcsim
    # Create the hardware if C object.
    @rcstatement = RCSim.rcsim_make_hif(self.condition.to_rcsim,
                                  self.yes.to_rcsim, 
                                  self.no ? self.no.to_rcsim : nil)

    # Add the alternate ifs if any.
    # self.each_noif do |cond,stmnt|
    #     RCSim.rcsim_add_hif_noif(@rcstatement,cond.to_rcsim,stmnt.to_rcsim)
    # end
    rcsim_conds = self.each_noif.map {|cond,stmnt| cond.to_rcsim }
    rcsim_stmnts = self.each_noif.map {|cond,stmnt| stmnt.to_rcsim }
    RCSim.rcsim_add_hif_noifs(@rcstatement,rcsim_conds,rcsim_stmnts)

    return @rcstatement
end