Class: HDLRuby::High::SystemI

Inherits:
Low::SystemI show all
Includes:
SingletonExtend
Defined in:
lib/HDLRuby/hruby_high.rb

Overview

Describes a high-level system instance.

Constant Summary collapse

High =
HDLRuby::High

Constants included from Low::Low2Symbol

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

Instance Attribute Summary

Attributes inherited from Low::SystemI

#name, #systemT

Attributes included from Low::Hparent

#parent

Instance Method Summary collapse

Methods included from SingletonExtend

#eigen_extend

Methods inherited from Low::SystemI

#add_systemT, #each_arrow_deep, #each_behavior, #each_behavior_deep, #each_block_deep, #each_connection, #each_connection_deep, #each_deep, #each_inner, #each_inout, #each_input, #each_output, #each_sensitive_deep, #each_signal, #each_signal_deep, #each_statement_deep, #each_systemI, #each_systemT, #eql?, #get_by_name, #get_inner, #get_inout, #get_input, #get_output, #get_signal, #get_systemI, #hash, #replace_names!, #set_name!, #set_systemT, #to_c, #to_ch, #to_hdr, #to_high, #to_vhdl, #with_port!, #with_var!

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#hierarchy, #scope

Constructor Details

#initialize(name, systemT) ⇒ SystemI

Creates a new system instance of system type +systemT+ named +name+.



1995
1996
1997
1998
1999
2000
2001
2002
# File 'lib/HDLRuby/hruby_high.rb', line 1995

def initialize(name, systemT)
    # Initialize the system instance structure.
    super(name,systemT)

    # Sets the hdl-like access to the system instance.
    obj = self # For using the right self within the proc
    High.space_reg(name) { obj }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &ruby_block) ⇒ Object

Missing methods are looked for in the public namespace of the system type.



2092
2093
2094
2095
# File 'lib/HDLRuby/hruby_high.rb', line 2092

def method_missing(m, *args, &ruby_block)
    # print "method_missing in class=#{self.class} with m=#{m}\n"
    self.public_namespace.send(m,*args,&ruby_block)
end

Instance Method Details

#call(*connects) ⇒ Object

Connects signals of the system instance according to +connects+.

NOTE: +connects+ can be a hash table where each entry gives the correspondance between a system's signal name and an external signal to connect to, or a list of signals that will be connected in the order of declaration.



2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
# File 'lib/HDLRuby/hruby_high.rb', line 2026

def call(*connects)
    # Checks if it is a connection through is a hash.
    if connects.size == 1 and connects[0].respond_to?(:to_h) and
        !connects[0].is_a?(HRef) then
        # Yes, perform a connection by name
        connects = connects[0].to_h
        # Performs the connections.
        connects.each do |key,value|
            # Gets the signal corresponding to connect.
            signal = self.get_signal(key)
            # Check if it is an output.
            isout = self.get_output(key)
            # Convert it to a reference.
            ref = RefObject.new(self.to_ref,signal)
            # Make the connection.
            if isout then
                value <= ref
            else
                ref <= value
            end
        end
    else
        # No, perform a connection is order of declaration
        connects.each.with_index do |csig,i|
            csig = csig.to_expr
            # puts "csig=#{csig} i=#{i}"
            # puts "systemT inputs=#{systemT.each_input.to_a.size}"
            # Gets i-est signal to connect
            ssig = self.systemT.get_interface_with_included(i)
            # Check if it is an output.
            isout = self.systemT.get_output_with_included(ssig.name)
            # puts "ssig=#{ssig.name} isout=#{isout}"
            # Convert it to a reference.
            ssig = RefObject.new(self.to_ref,ssig)
            # Make the connection.
            if isout then
                csig <= ssig
            else
                ssig <= csig
            end
        end
    end
end

#get_export(name) ⇒ Object

Gets an exported element (signal or system instance) by +name+.



2071
2072
2073
# File 'lib/HDLRuby/hruby_high.rb', line 2071

def get_export(name)
    return @systemT.get_export(name)
end

#namespaceObject

Gets the private namespace.



2106
2107
2108
2109
# File 'lib/HDLRuby/hruby_high.rb', line 2106

def namespace
    # self.systemT.scope.namespace
    self.systemT.namespace
end

#open(&ruby_block) ⇒ Object

Opens for extension.

NOTE: actually executes +ruby_block+ in the context of the systemT.



2080
2081
2082
2083
2084
2085
2086
# File 'lib/HDLRuby/hruby_high.rb', line 2080

def open(&ruby_block)
    # Extend the eigen system.
    @systemT.run(&ruby_block)
    # Update the methods.
    @systemT.eigenize(self)
    self.eigen_extend(@systemT.public_namespace)
end

#public_namespaceObject

Gets the public namespace.



2101
2102
2103
# File 'lib/HDLRuby/hruby_high.rb', line 2101

def public_namespace
    self.systemT.public_namespace
end

#to_low(name = self.name) ⇒ Object

Converts the instance to HDLRuby::Low and set its +name+.



2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
# File 'lib/HDLRuby/hruby_high.rb', line 2113

def to_low(name = self.name)
    # puts "to_low with #{self} (#{self.name}) #{self.systemT}"
    # Converts the system of the instance to HDLRuby::Low
    systemTL = self.systemT.to_low
    # Creates the resulting HDLRuby::Low instance
    systemIL = HDLRuby::Low::SystemI.new(High.names_create(name),
                                     systemTL)
    # # For debugging: set the source high object 
    # systemIL.properties[:low2high] = self.hdr_id
    # self.properties[:high2low] = systemIL
    # Adds the other systemTs.
    self.each_systemT do |systemT|
        systemIL.add_systemT(systemT.to_low) unless systemT == self.systemT
    end
    return systemIL
end

#to_refObject

Converts to a new reference.



2010
2011
2012
2013
2014
2015
2016
2017
2018
# File 'lib/HDLRuby/hruby_high.rb', line 2010

def to_ref
    if self.name.empty? then
        # No name, happens if inside the systemI so use this.
        return this
    else
        # A name.
        return RefObject.new(this,self)
    end
end

#typeObject

The type of a systemI: for now Void (may change in the future).



2005
2006
2007
# File 'lib/HDLRuby/hruby_high.rb', line 2005

def type
    return void
end