Class: HDLRuby::Low::Connection
- Defined in:
- lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb
Overview
Extends the Connection class with fixing of types and constants.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary
Attributes inherited from Transmit
Attributes included from Hparent
Instance Method Summary collapse
-
#array_connection(left, right) ⇒ Object
Method used for array.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#hash ⇒ Object
Hash function.
-
#reassign_expressions!(node2reassign) ⇒ Object
Replace node by corresponding replacement from +node2reassign+ that is a table whose entries are: +node+ the node to replace +rep+ the replacement of the node +ref+ the reference where to reassign the node.
- #to_verilog ⇒ Object
Methods inherited from Transmit
#boolean_in_assign2select!, #break_concat_assigns, #clone, #each_block, #each_block_deep, #each_node, #each_node_deep, #each_statement_deep, #explicit_types!, #extract_selects!, #initialize, #map_nodes!, #replace_expressions!, #set_left!, #set_right!, #to_c, #to_high, #to_vhdl
Methods inherited from Statement
#add_blocks_code, #block, #blocks2seq!, #break_types!, #clone, #delete_unless!, #explicit_types!, #extract_declares!, #mix?, #replace_expressions!, #replace_names!, #to_c, #to_high, #to_upper_space!, #to_vhdl, #top_block, #top_scope, #with_boolean!
Methods included from Low2Symbol
Constructor Details
This class inherits a constructor from HDLRuby::Low::Transmit
Instance Method Details
#array_connection(left, right) ⇒ Object
Method used for array.
1443 1444 1445 1446 1447 1448 1449 1450 1451 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1443 def array_connection(left,right) expression = right.each_expression.to_a result = "" expression[0..-2].each do |expression| result << " assign #{left.to_verilog}[#{expression.content.to_s}] = #{expression.to_verilog};\n" end result << " assign #{left.to_verilog}[#{expression.last.content.to_s}] = #{expression.last.to_verilog};\n" return result end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
3638 3639 3640 3641 |
# File 'lib/HDLRuby/hruby_low.rb', line 3638 def eql?(obj) return false unless obj.is_a?(Connection) return super(obj) end |
#hash ⇒ Object
Hash function.
3644 3645 3646 |
# File 'lib/HDLRuby/hruby_low.rb', line 3644 def hash return super end |
#reassign_expressions!(node2reassign) ⇒ Object
Replace node by corresponding replacement from +node2reassign+ that is a table whose entries are: +node+ the node to replace +rep+ the replacement of the node +ref+ the reference where to reassign the node.
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1135 def reassign_expressions!(node2reassign) # Build the replacement table. node2rep = node2reassign.map {|n,r| [n,r[0]] }.to_h # Performs the replacements. node2rep_done = {} # The performed replacements. # Replace on the sons of the left. node2rep_done.merge!(self.left.replace_expressions!(node2rep)) # Replace on the sons of the left. node2rep_done.merge!(self.right.replace_expressions!(node2rep)) # Shall we replace the right? rep = node2rep[self.right] if rep then # Yes, do it. rep = rep.clone node = self.right # node.set_parent!(nil) self.set_right!(rep) node2rep_done[node] = rep end # Assign the replaced nodes. node2rep_done.each do |node,rep| reassign = node2reassign[node][1].clone self.parent.add_connection( Connection.new(reassign,node.clone)) end end |
#to_verilog ⇒ Object
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1453 def to_verilog # Decide whether to assign to array by if. # NOTICE: Now array assignment is done trough constant initialization, will be treated later. # if self.right.respond_to? (:each_expression) # array_connection(self.left,self.right); # else cnt = 0 # Use count. bit = -2 # Used to determine the bit width. Since there are 0 and default, -2. # Measure the number of choices on the right side (case statement if it is 3 or more). if self.right.respond_to? (:each_choice) choice = self.right.each_choice.to_a choice.each do |choice| bit += 1 end end # Three or more choices. if (bit > 2) # The bit width is obtained by converting the bit into a binary number and obtaining the size. bit = bit.to_s(2).size # Create a case statement. result = " begin\n" result << " case(#{self.right.select.to_verilog})\n" # Output other than the last one in order. choice[0..-2].each do |choice| result << " #{bit}'#{cnt}: #{self.left.to_verilog} = #{choice.to_verilog}\n" cnt += 1 end # At the end, it becomes default because it needs default. result << " default: #{self.left.to_verilog} = #{choice.last.to_verilog}\n" result << " endcase\n" result << " end\n" return result end # It is not a case so call it normally. return " assign #{self.left.to_verilog} = #{self.right.to_verilog};\n" # end end |