Class: HDLRuby::Low::Event

Inherits:
Base::Event
  • Object
show all
Includes:
Hparent, Low2Symbol
Defined in:
lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.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

High::Event

Constant Summary

Constants included from Low2Symbol

Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable

Instance Attribute Summary collapse

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#scope

Constructor Details

#initialize(type, ref) ⇒ Event

Creates a new +type+ sort of event on signal refered by +ref+.



2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
# File 'lib/HDLRuby/hruby_low.rb', line 2192

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

#refObject (readonly)

The reference of the event.



2189
2190
2191
# File 'lib/HDLRuby/hruby_low.rb', line 2189

def ref
  @ref
end

#typeObject (readonly)

The type of event.



2186
2187
2188
# File 'lib/HDLRuby/hruby_low.rb', line 2186

def type
  @type
end

Instance Method Details

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


2205
2206
2207
2208
2209
2210
# File 'lib/HDLRuby/hruby_low.rb', line 2205

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

#hashObject

Hash function.



2213
2214
2215
# File 'lib/HDLRuby/hruby_low.rb', line 2213

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

Returns:

  • (Boolean)


2220
2221
2222
# File 'lib/HDLRuby/hruby_low.rb', line 2220

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.



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 417

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+.



404
405
406
407
408
409
410
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 404

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.



398
399
400
401
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 398

def set_type!(type)
    # Check and set the type.
    @type = type.to_sym
end

#to_c(level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



722
723
724
725
726
727
728
# File 'lib/HDLRuby/hruby_low2c.rb', line 722

def to_c(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)})"
end

#to_high(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



293
294
295
# File 'lib/HDLRuby/hruby_low2high.rb', line 293

def to_high(level = 0)
    return self.ref.to_high(level) + ".#{self.type}"
end