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_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_high, #to_vhdl, #with_port!, #with_var!

Methods included from Low::Low2Symbol

#to_sym

Methods included from Low::Hparent

#scope

Constructor Details

#initialize(name, systemT) ⇒ SystemI

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



1867
1868
1869
1870
1871
1872
1873
1874
# File 'lib/HDLRuby/hruby_high.rb', line 1867

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.



1962
1963
1964
1965
# File 'lib/HDLRuby/hruby_high.rb', line 1962

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.



1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
# File 'lib/HDLRuby/hruby_high.rb', line 1898

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|
            # 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.get_output(ssig.name)
            # 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+.



1941
1942
1943
# File 'lib/HDLRuby/hruby_high.rb', line 1941

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

#namespaceObject

Gets the private namespace.



1976
1977
1978
1979
# File 'lib/HDLRuby/hruby_high.rb', line 1976

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.



1950
1951
1952
1953
1954
1955
1956
# File 'lib/HDLRuby/hruby_high.rb', line 1950

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.



1971
1972
1973
# File 'lib/HDLRuby/hruby_high.rb', line 1971

def public_namespace
    self.systemT.public_namespace
end

#to_low(name = self.name) ⇒ Object

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



1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
# File 'lib/HDLRuby/hruby_high.rb', line 1983

def to_low(name = self.name)
    # puts "to_low with #{self} (#{self.name}) #{self.systemT}"
    # Converts the system of the instance to HDLRuby::Low
    systemTlow = self.systemT.to_low
    # Creates the resulting HDLRuby::Low instance
    systemIlow = HDLRuby::Low::SystemI.new(High.names_create(name),
                                     systemTlow)
    # Adds the other systemTs.
    self.each_systemT do |systemT|
        systemIlow.add_systemT(systemT.to_low) unless systemT == self.systemT
    end
    return systemIlow
end

#to_refObject

Converts to a new reference.



1882
1883
1884
1885
1886
1887
1888
1889
1890
# File 'lib/HDLRuby/hruby_high.rb', line 1882

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



1877
1878
1879
# File 'lib/HDLRuby/hruby_high.rb', line 1877

def type
    return void
end