Class: HDLRuby::Low::Delay

Inherits:
Object
  • Object
show all
Includes:
Hparent, Low2Symbol
Defined in:
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2hdr.rb,
lib/HDLRuby/hruby_low2sym.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_skeleton.rb

Overview

Describes a delay: not synthesizable.

Direct Known Subclasses

High::Delay

Constant Summary

Constants included from Low2Symbol

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

Instance Attribute Summary collapse

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#hierarchy, #no_parent!, #scope

Constructor Details

#initialize(value, unit) ⇒ Delay

Creates a new delay of +value+ +unit+ of time.



3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
# File 'lib/HDLRuby/hruby_low.rb', line 3866

def initialize(value,unit)
    # Check and set the value.
    unless value.is_a?(Numeric)
        raise AnyError,
              "Invalid class for a delay value: #{value.class}."
    end
    @value = value
    # Check and set the unit.
    @unit = unit.to_sym
end

Instance Attribute Details

#unitObject (readonly)

The time unit.



3860
3861
3862
# File 'lib/HDLRuby/hruby_low.rb', line 3860

def unit
  @unit
end

#valueObject (readonly)

The time value.



3863
3864
3865
# File 'lib/HDLRuby/hruby_low.rb', line 3863

def value
  @value
end

Instance Method Details

#cloneObject

Clones the Delay (deeply)



3906
3907
3908
# File 'lib/HDLRuby/hruby_low.rb', line 3906

def clone
    return Delay.new(@value,@unit)
end

#each_deep(&ruby_block) ⇒ Object

Iterates over each object deeply.

Returns an enumerator if no ruby block is given.



3883
3884
3885
3886
3887
3888
3889
3890
# File 'lib/HDLRuby/hruby_low.rb', line 3883

def each_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # Then apply on the value.
    self.value.each_deep(&ruby_block)
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


3893
3894
3895
3896
3897
3898
# File 'lib/HDLRuby/hruby_low.rb', line 3893

def eql?(obj)
    return false unless obj.is_a?(Delay)
    return false unless @unit.eql?(obj.unit)
    return false unless @value.eql?(obj.value)
    return true
end

#hashObject

Hash function.



3901
3902
3903
# File 'lib/HDLRuby/hruby_low.rb', line 3901

def hash
    return [@unit,@value].hash
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.



984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 984

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

    return res
end

#set_unit!(unit) ⇒ Object

Sets the unit.



973
974
975
976
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 973

def set_unit!(unit)
    # Check and set the unit.
    @unit = unit.to_sym
end

#set_value!(value) ⇒ Object

Sets the value.



963
964
965
966
967
968
969
970
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 963

def set_value!(value)
    # Check and set the value.
    unless value.is_a?(Numeric)
        raise AnyError,
              "Invalid class for a delay value: #{value.class}."
    end
    @value = value
end

#to_c(res, level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby code. +level+ is the hierachical level of the object. def to_c(level = 0)



1872
1873
1874
1875
1876
1877
1878
# File 'lib/HDLRuby/hruby_low2c.rb', line 1872

def to_c(res,level = 0)
    # return "make_delay(#{self.value.to_s}," +
    #        "#{Low2C.unit_name(self.unit)})"
    res << "make_delay(#{self.value.to_s},"
    res << Low2C.unit_name(self.unit) << ")"
    return res
end

#to_hdr(level = 0) ⇒ Object

Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.



437
438
439
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 437

def to_hdr(level = 0)
    return self.value.to_hdr(level) + ".#{self.unit}"
end

#to_highObject

Creates a new high delay.



323
324
325
# File 'lib/HDLRuby/hruby_low2high.rb', line 323

def to_high
    return HDLRuby::High::Delay.new(self.value,self.unit)
end

#to_verilogObject

Enhances Delay with generation of verilog code.



1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
# File 'lib/HDLRuby/hruby_verilog.rb', line 1866

def to_verilog
    time = self.value.to_s
    if(self.unit.to_s == "ps") then
        return "##{time};"
    elsif(self.unit.to_s == "ns")
        return "##{time}000;"
    elsif(self.unit.to_s == "us")
        return "##{time}000000;"
    elsif(self.unit.to_s == "ms")
        return "##{time}000000000;"
    elsif(self.unit.to_s == "s")
        return "##{time}000000000000;"
    end
end

#to_vhdl(level = 0) ⇒ Object

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



1050
1051
1052
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1050

def to_vhdl(level = 0)
    return self.value.to_vhdl(level) + " #{self.unit}"
end