Class: HDLRuby::Low::Event
- Inherits:
-
Base::Event
- Object
- Base::Event
- HDLRuby::Low::Event
- Includes:
- Hparent, Low2Symbol
- Defined in:
- lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2hdr.rb,
lib/HDLRuby/hruby_low2sym.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb
Overview
Describes an event.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#ref ⇒ Object
readonly
The reference of the event.
-
#type ⇒ Object
readonly
The type of event.
Attributes included from Hparent
Instance Method Summary collapse
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#hash ⇒ Object
Hash function.
-
#initialize(type, ref) ⇒ Event
constructor
Creates a new +type+ sort of event on signal refered by +ref+.
-
#on_edge? ⇒ Boolean
Tells if there is a positive or negative edge event.
-
#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.
-
#set_ref!(ref) ⇒ Object
Sets the reference to +ref+.
-
#set_type!(type) ⇒ Object
Sets the type.
-
#to_c(res, level = 0) ⇒ Object
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 event.
Methods included from Low2Symbol
Methods included from Hparent
#hierarchy, #no_parent!, #scope
Constructor Details
#initialize(type, ref) ⇒ Event
Creates a new +type+ sort of event on signal refered by +ref+.
2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 |
# File 'lib/HDLRuby/hruby_low.rb', line 2424 def initialize(type,ref) # Check and set the type. @type = type.to_sym # Check and set the reference. unless ref.is_a?(Ref) raise AnyError, "Invalid class for a reference: #{ref.class}" end @ref = ref # And set the parent of ref. ref.parent = self end |
Instance Attribute Details
#ref ⇒ Object (readonly)
The reference of the event.
2421 2422 2423 |
# File 'lib/HDLRuby/hruby_low.rb', line 2421 def ref @ref end |
#type ⇒ Object (readonly)
The type of event.
2418 2419 2420 |
# File 'lib/HDLRuby/hruby_low.rb', line 2418 def type @type end |
Instance Method Details
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 |
# File 'lib/HDLRuby/hruby_low.rb', line 2462 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 reference. self.ref.each_deep(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
2440 2441 2442 2443 2444 2445 |
# File 'lib/HDLRuby/hruby_low.rb', line 2440 def eql?(obj) return false unless obj.is_a?(Event) return false unless @type.eql?(obj.type) return false unless @ref.eql?(obj.ref) return true end |
#hash ⇒ Object
Hash function.
2448 2449 2450 |
# File 'lib/HDLRuby/hruby_low.rb', line 2448 def hash return [@type,@ref].hash end |
#on_edge? ⇒ Boolean
Tells if there is a positive or negative edge event.
NOTE: checks if the event type is :posedge or :negedge
2455 2456 2457 |
# File 'lib/HDLRuby/hruby_low.rb', line 2455 def on_edge? return (@type == :posedge or @type == :negedge) 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.
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 456 def reassign_expressions!(node2reassign) # Build the replacement table. node2rep = node2reassign.map {|n,r| [n,r[0]] }.to_h # Performs the replacement. node2rep_done = {} # The performed replacements. # Replace on the sons of the reference. node2rep_done.merge!(self.ref.replace_expressions!(node2rep)) # Shall we replace the ref? rep = node2rep[self.ref] if rep then # Yes, do it. rep = rep.clone node = self.ref # node.set_parent!(nil) self.set_ref!(rep) node2rep_done[node] = rep end # Assign the replaced nodes. node2rep_done.each do |node,rep| reassign = node2reassign[node][1].clone self.parent.parent. add_connection(Connection.new(reassign,node.clone)) end end |
#set_ref!(ref) ⇒ Object
Sets the reference to +ref+.
443 444 445 446 447 448 449 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 443 def set_ref!(ref) # Check and set the reference. unless ref.is_a?(Ref) raise AnyError, "Invalid class for a reference: #{ref.class}" end @ref = ref end |
#set_type!(type) ⇒ Object
Sets the type.
437 438 439 440 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 437 def set_type!(type) # Check and set the type. @type = type.to_sym end |
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)
861 862 863 864 865 866 867 868 869 870 871 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 861 def to_c(res,level = 0) edge = "ANYEDGE" edge = "POSEDGE" if self.type == :posedge edge = "NEGEDGE" if self.type == :negedge # return "make_event(#{edge}," + # "#{self.ref.resolve.to_c_signal(level+1)})" res << "make_event(#{edge}," self.ref.resolve.to_c_signal(res,level+1) res << ")" return res end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.
293 294 295 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 293 def to_hdr(level = 0) return self.ref.to_hdr(level) + ".#{self.type}" end |