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.



3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
# File 'lib/HDLRuby/hruby_low.rb', line 3702

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.



3696
3697
3698
# File 'lib/HDLRuby/hruby_low.rb', line 3696

def unit
  @unit
end

#valueObject (readonly)

The time value.



3699
3700
3701
# File 'lib/HDLRuby/hruby_low.rb', line 3699

def value
  @value
end

Instance Method Details

#cloneObject

Clones the Delay (deeply)



3742
3743
3744
# File 'lib/HDLRuby/hruby_low.rb', line 3742

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.



3719
3720
3721
3722
3723
3724
3725
3726
# File 'lib/HDLRuby/hruby_low.rb', line 3719

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)


3729
3730
3731
3732
3733
3734
# File 'lib/HDLRuby/hruby_low.rb', line 3729

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.



3737
3738
3739
# File 'lib/HDLRuby/hruby_low.rb', line 3737

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.



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 1006

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.



995
996
997
998
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 995

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

#set_value!(value) ⇒ Object

Sets the value.



985
986
987
988
989
990
991
992
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 985

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)



1772
1773
1774
1775
1776
1777
1778
# File 'lib/HDLRuby/hruby_low2c.rb', line 1772

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



1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
# File 'lib/HDLRuby/hruby_verilog.rb', line 1801

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.



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

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