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



2535
2536
2537
2538
2539
2540
# File 'lib/HDLRuby/hruby_high.rb', line 2535

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.



579
580
581
# File 'lib/HDLRuby/hruby_rcsim.rb', line 579

def rcstatement
  @rcstatement
end

Instance Method Details

#execute(mode) ⇒ Object

Executes the statement.



693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/HDLRuby/hruby_rsim.rb', line 693

def execute(mode)
    # puts "execute hif with mode=#{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

#fullnameObject

Returns the name of the signal with its hierarchy.



886
887
888
# File 'lib/HDLRuby/hruby_rsim.rb', line 886

def fullname
    return self.parent.fullname
end

#get_vars_with_fullname(vars_with_fullname = {}) ⇒ Object

Gets the VCD variables with their long name.



478
479
480
481
482
483
484
485
486
487
488
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 478

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

#get_vars_with_idstr(vars_with_idstr = {}) ⇒ Object

Gets the VCD variables with their id string.



491
492
493
494
495
496
497
498
499
500
501
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 491

def get_vars_with_idstr(vars_with_idstr = {})
    # Recurse on the yes.
    self.yes.get_vars_with_idstr(vars_with_idstr)
    # Recurse on the noifs.
    self.each_noif do |cond,stmnt|
        stmnt.get_vars_with_idstr(vars_with_idstr)
    end
    # Recure on the no if any.
    self.no.get_vars_with_idstr(vars_with_idstr) if self.no
    return vars_with_idstr
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:



2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
# File 'lib/HDLRuby/hruby_high.rb', line 2546

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:



2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
# File 'lib/HDLRuby/hruby_high.rb', line 2562

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



686
687
688
689
690
# File 'lib/HDLRuby/hruby_rsim.rb', line 686

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.



466
467
468
469
470
471
472
473
474
475
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 466

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.



2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
# File 'lib/HDLRuby/hruby_high.rb', line 2574

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.



582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'lib/HDLRuby/hruby_rcsim.rb', line 582

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.
    rcsim_conds = self.each_noif.map {|cond,stmnt| cond.to_rcsim }
    rcsim_stmnts = self.each_noif.map {|cond,stmnt| stmnt.to_rcsim }
    if rcsim_conds.any? then
        RCSim.rcsim_add_hif_noifs(@rcstatement,rcsim_conds,rcsim_stmnts)
    end

    return @rcstatement
end