Class: HDLRuby::High::If
- Inherits:
-
Low::If
- Object
- Base::Statement
- Low::Statement
- Low::If
- HDLRuby::High::If
- 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
Constants included from Low::Low2Symbol
Low::Low2Symbol::Low2SymbolPrefix, Low::Low2Symbol::Low2SymbolTable, Low::Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#rcstatement ⇒ Object
readonly
Returns the value of attribute rcstatement.
Attributes inherited from Low::If
Attributes included from Low::Hparent
Instance Method Summary collapse
-
#execute(mode) ⇒ Object
Executes the statement.
-
#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
Shows the hierarchy of the variables.
-
#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!, #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
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
#rcstatement ⇒ Object (readonly)
Returns the value of attribute rcstatement.
580 581 582 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 580 def rcstatement @rcstatement end |
Instance Method Details
#execute(mode) ⇒ Object
Executes the statement.
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 672 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.
406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 406 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.
419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 419 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.
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.
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+.
665 666 667 668 669 |
# File 'lib/HDLRuby/hruby_rsim.rb', line 665 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.
394 395 396 397 398 399 400 401 402 403 |
# File 'lib/HDLRuby/hruby_rsim_vcd.rb', line 394 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.
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_rcsim ⇒ Object
Generate the C description of the hardware if.
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 |
# File 'lib/HDLRuby/hruby_rcsim.rb', line 583 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 } if rcsim_conds.any? then RCSim.rcsim_add_hif_noifs(@rcstatement,rcsim_conds,rcsim_stmnts) end return @rcstatement end |