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



2037
2038
2039
2040
2041
2042
2043
2044
# File 'lib/HDLRuby/hruby_high.rb', line 2037

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.



2197
2198
2199
2200
# File 'lib/HDLRuby/hruby_high.rb', line 2197

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.



2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
# File 'lib/HDLRuby/hruby_high.rb', line 2068

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)
            unless signal then
                # Look into the included systems.
                self.systemT.scope.each_included do |included|
                    signal = included.get_signal(key)
                    break if signal
                end
            end
            # Check if it is an output.
            isout = self.get_output(key)
            unless isout then
                # Look into the inlucded systems.
                self.systemT.scope.each_included do |included|
                    isout = included.get_output(key)
                    break if isout
                end
            end
            # Convert it to a reference.
            ref = RefObject.new(self.to_ref,signal)
            # puts "key=#{key} value=#{value} signal=#{signal} ref=#{ref}"
            # 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

#choice(configuration = {}) ⇒ Object

Adds alternative system +systemT+



2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
# File 'lib/HDLRuby/hruby_high.rb', line 2146

def choice(configuration = {})
    # Process the argument.
    configuration.each do |k,v|
        k = k.to_sym
        unless v.is_a?(SystemT) then
            raise "Invalid class for a system type: #{v.class}"
        end
        # Create an eigen system.
        eigen = v.instantiate(HDLRuby.uniq_name(self.name)).systemT
        # Ensure its interface corresponds.
        my_signals = self.each_signal.to_a
        if (eigen.each_signal.with_index.find { |sig,i|
            !sig.eql?(my_signals[i])
        }) then
        raise "Invalid system for configuration: #{systemT.name}." 
        end
        # Add it.
        # At the HDLRuby::High level
        @choices = { self.name => self.systemT } unless @choices
        @choices[k] = eigen
        # At the HDLRuby::Low level
        self.add_systemT(eigen)
    end
end

#configure(sys) ⇒ Object

(Re)Configuration of system instance to systemT designated by +sys+. +sys+ may be the index or the name of the configuration, the first configuration being named by the systemI name.



2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
# File 'lib/HDLRuby/hruby_high.rb', line 2174

def configure(sys)
    if sys.respond_to?(:to_i) then
        # The argument is an index.
        # Create the (re)configuration node.
        High.top_user.add_statement(
            Configure.new(RefObject.new(RefThis.new,self),sys.to_i))
    else
        # The argument is a name (should be).
        # Get the index corresponding to the name.
        num = @choices.find_index { |k,_| k == sys.to_sym }
        unless num then
            raise "Invalid name for configuration: #{sys.to_s}"
        end
        # Create the (re)configuration node.
        High.top_user.add_statement(
            Configure.new(RefObject.new(RefThis.new,self),num))
    end
end

#get_export(name) ⇒ Object

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



2128
2129
2130
# File 'lib/HDLRuby/hruby_high.rb', line 2128

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

#namespaceObject

Gets the private namespace.



2211
2212
2213
2214
# File 'lib/HDLRuby/hruby_high.rb', line 2211

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.



2137
2138
2139
2140
2141
2142
2143
# File 'lib/HDLRuby/hruby_high.rb', line 2137

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.



2206
2207
2208
# File 'lib/HDLRuby/hruby_high.rb', line 2206

def public_namespace
    self.systemT.public_namespace
end

#to_low(name = self.name) ⇒ Object

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



2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
# File 'lib/HDLRuby/hruby_high.rb', line 2218

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 |systemTc|
        if systemTc != self.systemT
            systemTcL = systemTc.to_low
            systemIL.add_systemT(systemTcL)
        end
    end
    return systemIL
end

#to_refObject

Converts to a new reference.



2052
2053
2054
2055
2056
2057
2058
2059
2060
# File 'lib/HDLRuby/hruby_high.rb', line 2052

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



2047
2048
2049
# File 'lib/HDLRuby/hruby_high.rb', line 2047

def type
    return void
end