Class: HDLRuby::Low::Delay

Inherits:
Base::Delay
  • Object
show all
Includes:
Hparent, Low2Symbol
Defined in:
lib/HDLRuby/hruby_db.rb,
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.



1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1013

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.



1002
1003
1004
1005
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1002

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

#set_value!(value) ⇒ Object

Sets the value.



992
993
994
995
996
997
998
999
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 992

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)



1864
1865
1866
1867
1868
1869
1870
# File 'lib/HDLRuby/hruby_low2c.rb', line 1864

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.



428
429
430
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 428

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

#to_highObject

Creates a new high delay.



300
301
302
# File 'lib/HDLRuby/hruby_low2high.rb', line 300

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

#to_verilogObject



1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
# File 'lib/HDLRuby/hruby_verilog.rb', line 1828

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.



1035
1036
1037
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1035

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