Class: HDLRuby::Low::Unary
- Inherits:
-
Operation
- Object
- Expression
- Operation
- HDLRuby::Low::Unary
- Includes:
- OneChildMutable
- Defined in:
- lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2hdr.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,
lib/HDLRuby/hruby_low_with_bool.rb,
lib/HDLRuby/hruby_low_bool2select.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb
Overview
Describes an unary operation.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#child ⇒ Object
readonly
The child.
Attributes inherited from Operation
Attributes inherited from Expression
Attributes included from Hparent
Instance Method Summary collapse
-
#boolean? ⇒ Boolean
Tells if the expression is boolean.
-
#boolean_in_assign2select ⇒ Object
Converts booleans in assignments to select operators.
-
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
-
#clone ⇒ Object
Clones the unary operator (deeply).
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#each_node(&ruby_block) ⇒ Object
(also: #each_expression)
Iterates over the expression children if any.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
-
#each_ref_deep(&ruby_block) ⇒ Object
Iterates over all the references encountered in the expression.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the unary operation where +type+ is the expected type of the condition if any.
-
#hash ⇒ Object
Hash function.
-
#immutable? ⇒ Boolean
Tells if the expression is immutable (cannot be written.).
-
#initialize(type, operator, child) ⇒ Unary
constructor
Creates a new unary expression with +type+ applying +operator+ on +child+ expression.
-
#to_c(res, level = 0) ⇒ Object
return res end Generates the C text of the equivalent HDLRuby code.
-
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high unary expression.
-
#to_verilog ⇒ Object
Converts the system to Verilog code.
-
#to_vhdl(level = 0, std_logic = false) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#use_name?(*names) ⇒ Boolean
Tell if the expression includes a signal whose name is one of +names+.
Methods included from OneChildMutable
#map_nodes!, #replace_expressions!, #set_child!
Methods inherited from Operation
Methods inherited from Expression
#break_types!, #extract_selects_to!, #fix_scope_refnames!, #leftvalue?, #map_nodes!, #replace_expressions!, #replace_names!, #rightvalue?, #set_type!, #signal2subs!, #statement, #to_c_expr, #to_viz_names
Methods included from Low2Symbol
Methods included from Hparent
#absolute_ref, #hierarchy, #no_parent!, #scope
Constructor Details
#initialize(type, operator, child) ⇒ Unary
Creates a new unary expression with +type+ applying +operator+ on +child+ expression. def initialize(operator,child)
5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 |
# File 'lib/HDLRuby/hruby_low.rb', line 5289 def initialize(type,operator,child) # Initialize as a general operation. super(type,operator) # Check and set the child. unless child.is_a?(Expression) raise AnyError, "Invalid class for an expression: #{child.class}" end @child = child # And set its parent. child.parent = self end |
Instance Attribute Details
#child ⇒ Object (readonly)
The child.
5284 5285 5286 |
# File 'lib/HDLRuby/hruby_low.rb', line 5284 def child @child end |
Instance Method Details
#boolean? ⇒ Boolean
Tells if the expression is boolean.
120 121 122 |
# File 'lib/HDLRuby/hruby_low_with_bool.rb', line 120 def boolean? return self.child.boolean? end |
#boolean_in_assign2select ⇒ Object
Converts booleans in assignments to select operators.
217 218 219 220 221 222 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 217 def boolean_in_assign2select # Recurse on the sub node. return Unary.new(self.type,self.operator, self.child.boolean_in_assign2select) return self end |
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
232 233 234 235 236 237 238 |
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 232 def casts_without_expression! # # Recurse on the sub node. # return Unary.new(self.type,self.operator, # self.child.casts_without_expression) self.set_child!(self.child.casts_without_expression!) return self end |
#clone ⇒ Object
Clones the unary operator (deeply)
5376 5377 5378 |
# File 'lib/HDLRuby/hruby_low.rb', line 5376 def clone return Unary.new(@type,self.operator,@child.clone) end |
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 |
# File 'lib/HDLRuby/hruby_low.rb', line 5311 def each_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # Then apply on the type. self.type.each_deep(&ruby_block) # Then apply on the child. self.child.each_deep(&ruby_block) end |
#each_node(&ruby_block) ⇒ Object Also known as: each_expression
Iterates over the expression children if any.
5338 5339 5340 5341 5342 5343 |
# File 'lib/HDLRuby/hruby_low.rb', line 5338 def each_node(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node) unless ruby_block # A ruby block? Apply it on the child. ruby_block.call(@child) end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over the nodes deeply if any.
5348 5349 5350 5351 5352 5353 5354 5355 |
# File 'lib/HDLRuby/hruby_low.rb', line 5348 def each_node_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node_deep) unless ruby_block # A ruby block? First apply it to current. ruby_block.call(self) # And recurse on the child. @child.each_node_deep(&ruby_block) end |
#each_ref_deep(&ruby_block) ⇒ Object
Iterates over all the references encountered in the expression.
NOTE: do not iterate inside the references.
5360 5361 5362 5363 5364 5365 5366 5367 |
# File 'lib/HDLRuby/hruby_low.rb', line 5360 def each_ref_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_ref_deep) unless ruby_block # puts "each_ref_deep for Unary" # A ruby block? # Recurse on the child. @child.each_ref_deep(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
5323 5324 5325 5326 5327 5328 5329 5330 |
# File 'lib/HDLRuby/hruby_low.rb', line 5323 def eql?(obj) # General comparison. return false unless super(obj) # Specific comparison. return false unless obj.is_a?(Unary) return false unless @child.eql?(obj.child) return true end |
#explicit_types(type = nil) ⇒ Object
Explicit the types conversions in the unary operation where +type+ is the expected type of the condition if any.
290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 290 def explicit_types(type = nil) # Recurse on the child (no type to specify here, unary operations # preserve the type of their child). op = Unary.new(self.type,self.operator,self.child.explicit_types) # Does the type match the operation? if type && !self.type.eql?(type) then # No create a cast. return Cast.new(type,op) else # Yes, return the operation as is. return op end end |
#hash ⇒ Object
Hash function.
5333 5334 5335 |
# File 'lib/HDLRuby/hruby_low.rb', line 5333 def hash return [super,@child].hash end |
#immutable? ⇒ Boolean
Tells if the expression is immutable (cannot be written.)
5303 5304 5305 5306 |
# File 'lib/HDLRuby/hruby_low.rb', line 5303 def immutable? # Immutable if the child is immutable. return child.immutable? end |
#to_c(res, level = 0) ⇒ Object
return res end Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)
2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 2427 def to_c(res,level = 0) if (self.operator == :+@) then # No computation required. self.child.to_c(res,level) return res end # Some computation required. # Save the value pool state. res << (" " * (level*3)) << "PV;\n" # Generate the child. self.child.to_c(res,level) res << (" " * (level*3)) res << "unary(" # Adds the operation case self.operator when :~ then res << "¬_value" when :-@ then res << "&neg_value" else raise "Invalid unary operator: #{self.operator}." end res << ");\n" # Restore the value pool state. res << (" " * (level*3)) << "RV;\n" return res end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.
606 607 608 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 606 def to_hdr(level = 0) return "(#{self.operator.to_s[0]}" + self.child.to_hdr(level) + ")" end |
#to_high ⇒ Object
Creates a new high unary expression.
449 450 451 452 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 449 def to_high return HDLRuby::High::Unary.new(self.type.to_high,self.operator, self.child.to_high) end |
#to_verilog ⇒ Object
Converts the system to Verilog code.
1846 1847 1848 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1846 def to_verilog return "#{self.operator[0]}#{self.child.to_verilog}" end |
#to_vhdl(level = 0, std_logic = false) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object. +std_logic+ tells if std_logic computation is to be done.
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1287 def to_vhdl(level = 0, std_logic = false) # Generate the operator string. operator = self.operator == :~ ? "not " : self.operator.to_s[0] # Is the operator arithmetic? if [:+@, :-@].include?(self.operator) then # Yes, type conversion my be required by VHDL standard. res = "#{Low2VHDL.unarith_cast(self)}(#{operator}" + Low2VHDL.to_arith(self.child) + ")" res += "(0)" if std_logic return res else # No, generate simply the unary operation. # (The other unary operator is logic, no need to force # std_logic.) return "(#{operator}" + self.child.to_vhdl(level,std_logic) + ")" end end |
#use_name?(*names) ⇒ Boolean
Tell if the expression includes a signal whose name is one of +names+.
5370 5371 5372 5373 |
# File 'lib/HDLRuby/hruby_low.rb', line 5370 def use_name?(*names) # Recurse on the child. return @child.use_name?(*names) end |