Class: HDLRuby::High::Behavior

Inherits:
Low::Behavior show all
Includes:
RCSimBehavior
Defined in:
lib/HDLRuby/hruby_high.rb,
lib/HDLRuby/hruby_rsim.rb,
lib/HDLRuby/hruby_rcsim.rb,
lib/HDLRuby/hruby_high_fullname.rb

Overview

Extends the Behavior class for hybrid Ruby-C simulation.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

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

Instance Attribute Summary

Attributes included from RCSimBehavior

#rcbehavior

Attributes inherited from Low::Behavior

#block

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from RCSimBehavior

#to_rcsim

Methods inherited from Low::Behavior

#add_event, #blocks2seq!, #delete_event!, #each_block, #each_block_deep, #each_deep, #each_event, #each_node_deep, #each_statement, #eql?, #explicit_types!, #extract_declares!, #get_by_name, #has_event?, #hash, #last_statement, #map_events!, #mixblocks2seq!, #on_edge?, #on_event?, #parent_system, #replace_names!, #reverse_each_statement, #set_block!, #to_c, #to_ch, #to_hdr, #to_high, #to_upper_space!, #to_vhdl, #top_scope, #with_boolean!, #with_var!

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#hierarchy, #no_parent!, #scope

Constructor Details

#initialize(mode, *events, &ruby_block) ⇒ Behavior

Creates a new behavior executing +block+ activated on a list of +events+, and built by executing +ruby_block+. +mode+ can be either :seq or :par for respectively sequential or parallel.



4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
# File 'lib/HDLRuby/hruby_high.rb', line 4318

def initialize(mode,*events,&ruby_block)
    # Initialize the behavior with it.
    super(nil)
    # # Save the Location for debugging information
    # @location = caller_locations
    # Sets the current behavior
    @@cur_behavior = self
    # Add the events.
    events.each { |event| self.add_event(event) }
    # Create and add the block.
    self.block = High.make_block(mode,&ruby_block)
    # Unset the current behavior
    @@cur_behavior = nil
end

Instance Method Details

#execute(mode) ⇒ Object

Execute the expression.



275
276
277
# File 'lib/HDLRuby/hruby_rsim.rb', line 275

def execute(mode)
    return self.block.execute(mode)
end

#fullnameObject

Returns the name of the signal with its hierarchy.



322
323
324
# File 'lib/HDLRuby/hruby_rsim.rb', line 322

def fullname
    return self.parent.fullname
end

#init_sim(systemT) ⇒ Object

Initialize the simulation for system +systemT+.



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/HDLRuby/hruby_rsim.rb', line 280

def init_sim(systemT)
    # Process the sensitivity list.
    # Is it a clocked behavior?
    events = self.each_event.to_a
    if events.empty? then
        # No events, this is not a clock behavior.
        # And it is not a time behavior neigther.
        # Generate the events list from the right values.
        # First get the references.
        refs = self.block.each_node_deep.select do |node|
            node.is_a?(RefObject) && !node.leftvalue? && 
                !node.parent.is_a?(RefObject) 
        end.to_a
        # Keep only one ref per signal.
        refs.uniq! { |node| node.fullname }
        # Remove the inner signals from the list.
        self.block.each_inner do |inner|
            refs.delete_if {|r| r.name == inner.name }
        end
        # Generate the event.
        events = refs.map {|ref| Event.new(:anyedge,ref.clone) }
        # Add them to the behavior for further processing.
        events.each {|event| self.add_event(event) }
    end
    # Now process the events: add the behavior to the corresponding
    # activation list of the signals of the events.
    self.each_event do |event|
        sig = event.ref.object
        case event.type
        when :posedge
            sig.add_posedge(self)
        when :negedge
            sig.add_negedge(self)
        else
            sig.add_anyedge(self)
        end
    end
    # Now process the block.
    self.block.init_sim(systemT)
end

#to_lowObject

Converts the time behavior to HDLRuby::Low.



4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
# File 'lib/HDLRuby/hruby_high.rb', line 4338

def to_low
    # Create the low level block.
    blockL = self.block.to_low
    # Create the low level events.
    eventLs = self.each_event.map { |event| event.to_low }
    # Create and return the resulting low level behavior.
    behaviorL = HDLRuby::Low::Behavior.new(blockL)
    # # For debugging: set the source high object 
    # behaviorL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = behaviorL
    eventLs.each(&behaviorL.method(:add_event))
    return behaviorL
end