Class: HDLRuby::Low::RefName

Inherits:
Ref show all
Defined in:
lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_verilog.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_resolve.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_bool2select.rb

Overview

Extends the RefName class with functionality for converting booleans in assignments to select operators.

Direct Known Subclasses

High::RefName

Constant Summary

Constants included from Low2Symbol

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

Instance Attribute Summary collapse

Attributes inherited from Expression

#type

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods inherited from Expression

#boolean?, #break_types!, #each_ref_deep, #extract_selects_to!, #leftvalue?, #replace_names!, #rightvalue?, #set_type!, #statement

Methods included from Low2Symbol

#to_sym

Constructor Details

#initialize(type, ref, name) ⇒ RefName

Create a new named reference with +type+ accessing +ref+ with +name+. def initialize(ref,name)



4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
# File 'lib/HDLRuby/hruby_low.rb', line 4640

def initialize(type,ref,name)
    super(type)
    # Check and set the accessed reference.
    unless ref.is_a?(Ref) then
        raise AnyError, "Invalid class for a reference: #{ref.class}."
    end
    @ref = ref
    # And set its parent.
    ref.parent = self
    # Check and set the symbol.
    @name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

The access name.



4636
4637
4638
# File 'lib/HDLRuby/hruby_low.rb', line 4636

def name
  @name
end

#refObject (readonly)

The accessed reference.



4633
4634
4635
# File 'lib/HDLRuby/hruby_low.rb', line 4633

def ref
  @ref
end

Instance Method Details

#ancestor(my) ⇒ Object



1260
1261
1262
1263
1264
1265
1266
# File 'lib/HDLRuby/hruby_verilog.rb', line 1260

def ancestor(my)
    if my.parent.parent.respond_to? (:mode) then
        return ancestor(my.parent)
    else
        return "#{my.parent.mode.to_s}#{my.mode.to_s}"
    end
end

#boolean_in_assign2selectObject

Converts booleans in assignments to select operators.



277
278
279
280
281
282
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 277

def boolean_in_assign2select
    # Recurse on the sub references.
    return RefName.new(self.type,
                       self.ref.boolean_in_assign2select,
                       self.name)
end

#cloneObject

Clones the name references (deeply)



4709
4710
4711
# File 'lib/HDLRuby/hruby_low.rb', line 4709

def clone
    return RefName.new(@type, @ref.clone, @name)
end

#each_node(&ruby_block) ⇒ Object Also known as: each_expression

Iterates over the reference children if any.



4689
4690
4691
4692
4693
4694
# File 'lib/HDLRuby/hruby_low.rb', line 4689

def each_node(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node) unless ruby_block
    # A ruby block? Apply it on the child.
    ruby_block.call(@ref)
end

#each_node_deep(&ruby_block) ⇒ Object

Iterates over the nodes deeply if any.



4699
4700
4701
4702
4703
4704
4705
4706
# File 'lib/HDLRuby/hruby_low.rb', line 4699

def each_node_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_node_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # And recurse on the child.
    @ref.each_node_deep(&ruby_block)
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


4661
4662
4663
4664
4665
4666
4667
4668
4669
# File 'lib/HDLRuby/hruby_low.rb', line 4661

def eql?(obj)
    # General comparison.
    return false unless super(obj)
    # Specific comparison.
    return false unless obj.is_a?(RefName)
    return false unless @name.eql?(obj.name)
    return false unless @ref.eql?(obj.ref)
    return true
end

#explicit_types(type = nil) ⇒ Object

Explicit the types conversions in the index ref where +type+ is the expected type of the condition if any.



410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 410

def explicit_types(type = nil)
    # Is there a type to match, if not use current one.
    type = self.type unless type
    # Cast if required and return the new reference.
    if self.type.eql?(type) then
        # No need to cast.
        return RefName.new(type,self.ref.explicit_types,self.name)
    else
        # Need a cast.
        return Cast.new(type,
           RefName.new(self.type,self.ref.explicit_types,self.name))
    end
end

#from_systemI?Boolean

Tells if it is a reference to a systemI signal.

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/HDLRuby/hruby_low_resolve.rb', line 116

def from_systemI?
    # puts "from_systemI? for #{self.name}"
    # Look for the owner from the name hierarchy.
    if self.ref.is_a?(RefName) then
        # Look in the parent hierachy for the sub reference name.
        parent = self.parent
        while parent
            if parent.respond_to?(:get_by_name) then
                found = parent.get_by_name(self.ref.name)
                # puts "found is a :#{found.class}"
                return found.is_a?(SystemI)
            end
            parent = parent.parent
        end
        # Not found, look further in the reference hierarchy.
        return self.ref.from_systemI?
    end
    # Not from a systemI.
    # puts "Not from systemI for #{self.name}"
    return false
end

#full_nameObject

Get the full name of the reference, i.e. including the sub ref names if any.



4655
4656
4657
4658
# File 'lib/HDLRuby/hruby_low.rb', line 4655

def full_name
    name = self.ref.respond_to?(:full_name) ? self.ref.full_name : :""
    return :"#{name}::#{self.name}"
end

#hashObject

Hash function.



4672
4673
4674
# File 'lib/HDLRuby/hruby_low.rb', line 4672

def hash
    return [super,@name,@ref].hash
end

#map_nodes!(&ruby_block) ⇒ Object

Maps on the children.



1761
1762
1763
1764
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1761

def map_nodes!(&ruby_block)
    @ref = ruby_block.call(@ref)
    @ref.parent = self unless @ref.parent
end

#path_each(&ruby_block) ⇒ Object

Iterates over the names of the path indicated by the reference.

Returns an enumerator if no ruby block is given.



4679
4680
4681
4682
4683
4684
4685
4686
# File 'lib/HDLRuby/hruby_low.rb', line 4679

def path_each(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:path_each) unless ruby_block
    # Recurse on the base reference.
    ref.path_each(&ruby_block)
    # Applies the block on the current name.
    ruby_block.call(@name)
end

#replace_expressions!(node2rep) ⇒ Object

Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement. Returns the actually replaced nodes and their corresponding replacement.

NOTE: the replacement is duplicated.



1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1772

def replace_expressions!(node2rep)
    # First recurse on the ref.
    res = self.ref.replace_expressions!(node2rep)
    
    # Is there a replacement to on the ref?
    rep = node2rep[self.ref]
    if rep then
        # Yes, do it.
        rep = rep.clone
        node = self.ref
        # node.set_parent!(nil)
        self.set_ref!(rep)
        # And register the replacement.
        res[node] = rep
    end
    return res
end

#resolveObject

Resolves the name of the reference and return the corresponding object. NOTE: return nil if could not resolve.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/HDLRuby/hruby_low_resolve.rb', line 142

def resolve
    # puts "Resolve with #{self} and name=#{self.name}"
    # First resolve the sub reference if possible.
    if self.ref.is_a?(RefName) then
        obj = self.ref.resolve
        # Look into the object for the name.
        return obj.get_by_name(self.name)
    else
        # Look in the parent hierachy for the name.
        parent = self.parent
        # puts "parent=#{parent}"
        while parent
            if parent.respond_to?(:get_by_name) then
                found = parent.get_by_name(self.name)
                return found if found
            end
            parent = parent.parent
        end
        # Not found.
        return nil
    end
end

#set_name!(name) ⇒ Object

Sets the name.



1755
1756
1757
1758
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1755

def set_name!(name)
    # Check and set the symbol.
    @name = name.to_sym
end

#set_ref!(ref) ⇒ Object

Sets the base reference.



1744
1745
1746
1747
1748
1749
1750
1751
1752
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1744

def set_ref!(ref)
    # Check and set the accessed reference.
    unless ref.is_a?(Ref) then
        raise AnyError, "Invalid class for a reference: #{ref.class}."
    end
    @ref = ref
    # And set its parent.
    ref.parent = self
end

#to_another_verilogObject

Used for instantiation (emergency procedure).



1256
1257
1258
# File 'lib/HDLRuby/hruby_verilog.rb', line 1256

def to_another_verilog
    return "_#{self.name.to_s}"
end

#to_c(level = 0, left = false) ⇒ Object

Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object and +left+ tells if it is a left value or not.



1947
1948
1949
1950
1951
# File 'lib/HDLRuby/hruby_low2c.rb', line 1947

def to_c(level = 0, left = false)
    # puts "RefName to_c for #{self.name}"
    return "#{self.resolve.to_c_signal(level+1)}->" +
           (left ? "f_value" : "c_value")
end

#to_c_signal(level = 0) ⇒ Object

Generates the C text for reference as left value to a signal. +level+ is the hierarchical level of the object.



1955
1956
1957
# File 'lib/HDLRuby/hruby_low2c.rb', line 1955

def to_c_signal(level = 0)
    return "#{self.resolve.to_c_signal(level+1)}"
end

#to_high(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



706
707
708
709
710
711
712
713
714
715
# File 'lib/HDLRuby/hruby_low2high.rb', line 706

def to_high(level = 0)
    # The resulting string.
    res = ""
    # Generates the sub reference if any.
    res << self.ref.to_high(level) << "." unless self.ref.is_a?(RefThis)
    # Generates the current reference.
    res << Low2High.high_use_name(self.name)
    # Returns the resulting string.
    return res
end

#to_verilogObject

Converts the system to Verilog code using +renamer+ for producing Verilog-compatible names.



1250
1251
1252
1253
# File 'lib/HDLRuby/hruby_verilog.rb', line 1250

def to_verilog
    # return "#{self.name.to_s}"
    return "#{name_to_verilog(self.name)}"
end

#to_vhdl(level = 0, std_logic = false) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object. +std_logic+ tells if std_logic computation is to be done.



1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1407

def to_vhdl(level = 0, std_logic = false)
    # The resulting string.
    res = ""
    # Generate the sub refs if any (case of struct).
    unless self.ref.is_a?(RefThis) then
        res << self.ref.to_vhdl(level) << "."
    end
    # Generates the current reference.
    res << Low2VHDL.vhdl_name(self.name)
    res << "(0)" if std_logic # Force to std_logic if required
    # Returns the resulting string.
    return res
end