Class: Origen::SubBlock

Inherits:
Object show all
Includes:
Model
Defined in:
lib/origen/sub_blocks.rb

Overview

A simple class that will be instantiated by default when a sub block is defined without another class name specified

This class includes support for registers, pins, etc.

Instance Method Summary collapse

Methods included from Model

#==, #_initialized?, #_resolve_controller_class, #add_configuration, #add_mode, #attributes, #clock!, #clock_apply, #clock_prepare, #configuration, #configuration=, #configurations, #current_configuration, #current_mode, #current_mode=, #delete_all_modes, #delete_all_specs_and_notes, #find_specs, #has_mode?, #inspect, #ip_name, #is_a_model_and_controller?, #is_an_origen_model?, #is_top_level?, #load_block, #log, #model, #modes, #read_memory, #respond_to?, #respond_to_directly?, #to_json, #with_configuration, #with_each_mode, #with_mode, #wrap_in_controller, #write_memory

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Used to create attribute accessors on the fly.

On first call of a missing method a method is generated to avoid the missing lookup next time, this should be faster for repeated lookups of the same method, e.g. reg



552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'lib/origen/sub_blocks.rb', line 552

def method_missing(method, *args, &block)
  super
rescue NoMethodError
  return regs(method) if self.has_reg?(method)
  return ports(method) if self.has_port?(method)
  if method.to_s =~ /=$/
    define_singleton_method(method) do |val|
      instance_variable_set("@#{method.to_s.sub('=', '')}", val)
    end
  else
    define_singleton_method(method) do
      instance_variable_get("@#{method}")
    end
  end
  send(method, *args, &block)
end

Instance Method Details

#appObject

Since no application defined this sub-block class, consider its parent's app to be the owning application



544
545
546
# File 'lib/origen/sub_blocks.rb', line 544

def app
  parent.app
end