Class: HDLRuby::High::If
- Inherits:
-
Low::If
- Object
- Low::Statement
- Low::If
- HDLRuby::High::If
- 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
Describes an if statement.
Constant Summary collapse
Constants included from Low::Low2Symbol
Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#rcstatement ⇒ Object
readonly
Extends the If class for hybrid Ruby-C simulation.
Attributes inherited from Low::If
Attributes included from Low::Hparent
Instance Method Summary collapse
-
#execute(mode) ⇒ Object
Executes the statement.
-
#fullname ⇒ Object
Returns the name of the signal with its hierarchy.
-
#get_vars_with_fullname(vars_with_fullname = {}) ⇒ Object
Gets the VCD variables with their long name.
-
#get_vars_with_idstr(vars_with_idstr = {}) ⇒ Object
Gets the VCD variables with their id string.
-
#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+.
-
#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+.
-
#init_sim(systemT) ⇒ Object
Initialize the simulation for system +systemT+.
-
#initialize(condition, mode = nil, &ruby_block) ⇒ If
constructor
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+.
-
#show_hierarchy(vcdout) ⇒ Object
Enhance the if class with VCD support.
-
#to_low ⇒ Object
Converts the if to HDLRuby::Low.
-
#to_rcsim ⇒ Object
Generate the C description of the hardware if.
Methods included from HStatement
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!, #fix_scope_refnames!, #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!, #fix_scope_refnames!, #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
Methods included from Low::Hparent
#absolute_ref, #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+.
2577 2578 2579 2580 2581 2582 |
# File 'lib/HDLRuby/hruby_high.rb', line 2577 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
#rcstatement ⇒ Object (readonly)
Extends the If class for hybrid Ruby-C simulation.
593 594 595 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 593 def rcstatement @rcstatement end |
Instance Method Details
#execute(mode) ⇒ Object
Executes the statement.
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 741 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 |
#fullname ⇒ Object
Returns the name of the signal with its hierarchy.
934 935 936 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 934 def fullname return self.parent.fullname end |
#get_vars_with_fullname(vars_with_fullname = {}) ⇒ Object
Gets the VCD variables with their long name.
480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 480 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.
493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 493 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.
2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 |
# File 'lib/HDLRuby/hruby_high.rb', line 2588 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.
2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 |
# File 'lib/HDLRuby/hruby_high.rb', line 2604 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+.
730 731 732 733 734 735 736 737 738 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 730 def init_sim(systemT) self.yes.init_sim(systemT) # self.each_noif { |cond,stmnt| stmnt.init_sim(systemT) } self.each_noif do |cond,stmnt| cond.init_sim(systemT) stmnt.init_sim(systemT) end self.no.init_sim(systemT) if self.no end |
#show_hierarchy(vcdout) ⇒ Object
Enhance the if class with VCD support. Shows the hierarchy of the variables.
468 469 470 471 472 473 474 475 476 477 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 468 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_low ⇒ Object
Converts the if to HDLRuby::Low.
2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 |
# File 'lib/HDLRuby/hruby_high.rb', line 2616 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_rcsim ⇒ Object
Generate the C description of the hardware if.
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 596 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 |