Class: Fhlow::Unit

Inherits:
Leaf
  • Object
show all
Defined in:
lib/module_fhlow/leafs/Unit.rb

Overview

This is a concrete implementation of the abstract class Leaf. A Unit represents one Leaf with the prefix “unit”. It also contains information about it’s architectures. Architectures are stored in a Hash (@architectures) whose keys are references to Leafs that have dependencies on this Unit.

TODO

  • make this explaination more clear

Instance Attribute Summary

Attributes inherited from Leaf

#conf, #name, #prefix

Instance Method Summary collapse

Methods inherited from Leaf

#fetchOneDependency, #getPath, #getTarget, #printMe

Constructor Details

#initialize(_name, _parent, _log, _pen) ⇒ Unit

Calls the constructor of Leaf and initializes the architecture member.

_name

The Name of the Leaf.

_parent

The reference to the parent.

_conf

The configuration information from higher levels.

_log

The reference to the Log object.

_pen

The reference to a Pen object.



20
21
22
23
# File 'lib/module_fhlow/leafs/Unit.rb', line 20

def initialize (_name, _parent, _log, _pen)
    super("unit", _name, _parent, _log, _pen)    
    @architectures = Hash.new
end

Instance Method Details

#addArchitectures(_owner, _deptype, _architectures) ⇒ Object

This function adds information to a Unit which of its architectures are needed by which owner-Unit.

_owner

Reference to the owner-Unit.

_deptype

Type of the dependency for which the architectures will be added. (could be Units, BhvUnits, Packages and so on)

_architectures

An Arra of architecture names.



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/module_fhlow/leafs/Unit.rb', line 114

def addArchitectures(_owner, _deptype, _architectures)
    if @architectures.empty? || @architectures[_owner].nil? || @architectures[_owner][_deptype].nil?
        if @architectures[_owner].nil?
            @architectures[_owner] = { _deptype => _architectures} 
        else
            @architectures[_owner][_deptype] = _architectures
        end
    else
        @architectures[_owner][_deptype] += _architectures
    end

    @architectures[_owner][_deptype] = @architectures[_owner][_deptype].uniq
end

#fetchDependenciesObject

This function is an extension to Leaf.fetchDependencies. The section [Self] in the config file holds the information about the architectures which are needed by this Unit for itself.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/module_fhlow/leafs/Unit.rb', line 34

def fetchDependencies()

    # call the fetchDependencies() function from Leaf
    super()
    
    # there needs to be a [Self] section the config file 
    if @conf["Self"].nil?
        raise FhlowException.new(getPath), "Couldn't find section [Self] in any config.flw file responsible for this leaf."
    end

    # iterate through all items of the [Dependencies] section
    @conf["Self"].each do |item|    # item -> one item of the [Self] section
        raise FhlowException.new(getPath), "Wrong item found in section [Self] in any config.flw file responsible for this leaf." unless item.instance_of?(Config::SimpleArchitecture)

        # The substition of "Architectures" with "Units" is done in order to improve the usability of the config files.
        # The section [Self] contains only informations about architectures so the user should work with items with a
        # proper name. Internally there should be no difference between the architectures from [Dependencies] and [Self]
        #    Architectures   -> Units
        #    tbArchitectures -> tbUnits
        addArchitectures(self, item.name.gsub("Architectures", "Units"), item.value)
    end
    
end

#getArchitectures(_caller) ⇒ Object

Return the architectures needed by caller. Most likely a call of this function will look like this:

someLeaf.getArchitectures(self)
_caller

The reference to the caller.



28
29
30
# File 'lib/module_fhlow/leafs/Unit.rb', line 28

def getArchitectures(_caller)
    @architectures[_caller]
end

#getFiles(_deptype, _istoplevel = true, _caller = nil, _files = Array.new) ⇒ Object

This function returns an Array of filenames in respect of the dependency tree.

_deptype

Type of the requested dependencies (could be Units, BhvUnits, Packages and so on)

_istoplevel

Is used to indicate the first entrance to this function.

_caller

Reference to the caller of the function. This is needed to request architectures.

_files

The Array of the files which will be filled with the requested filenames and returned in the end.

TODO

  • configuration handling -c
  • file not found exception
  • -e -ea -eac -ac handling


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/module_fhlow/leafs/Unit.rb', line 68

def getFiles(_deptype, _istoplevel=true, _caller=nil, _files=Array.new)
    @dependencies[_deptype].each { |dep| dep.getFiles(_deptype, false, self, _files)} unless @dependencies[_deptype].nil?
    
    # only act if the Unit is able to handle the _deptype
    case _deptype
        when "Units", "BhvUnits", "tbUnits"
            
            if _istoplevel and (getArchitectures(self).nil? or getArchitectures(self)[_deptype].nil?)
                raise FhlowException.new(@prefix+@name), "No architectures for <#{_deptype}> specified!"
            end

            if getArchitectures(_istoplevel ? self : _caller) and 
               getArchitectures(_istoplevel ? self : _caller)[_deptype] and
               !getArchitectures(_istoplevel ? self : _caller)[_deptype].empty?

                localfiles = Dir[getPath+"src/"+ (_deptype=="tbUnits" ? "tb" : "") +@name+"-e.vhd"]
                
                getArchitectures(_istoplevel ? self : _caller)[_deptype].each do |arch| 
                    localfiles = localfiles | Dir[getPath+"src/"+ (_deptype=="tbUnits" ? "tb" : "") +@name+"-"+arch+"-{a,ea,eac,ac,c}.vhd"]
                end
                    
                raise FhlowFileNotFoundException.new(getPath+"src/"), "No entity file found." unless localfiles.find { |str| str =~ /.*#{@name}-(e|\w+-e\w{1,2})\.vhd/ }

                localfiles.each do |file| 
                    raise FhlowFileNotFoundException.new(file), "File not found." unless File.exist?(file)
                    _files.push(file) 
                end
            end

    end
    _files.uniq!
    _files
end


129
130
131
132
133
134
135
# File 'lib/module_fhlow/leafs/Unit.rb', line 129

def print(_prefix="    ", _depth=0, _caller=nil)
    str = ""
    @pen.puts _prefix, @pen.magenta, @prefix, @name, @pen.clear, 
              @architectures[_depth==0 ? self : _caller].nil? ? 
                "\n" :  
                "(  "+(@architectures[_depth==0 ? self : _caller].each { |key, value| str += "#{@pen.blue}#{key}#{@pen.clear} -> #{value.join(", ")};  " }; str+=")")
end