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, #scope

Constructor Details

#initialize(value, unit) ⇒ Delay

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



3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
# File 'lib/HDLRuby/hruby_low.rb', line 3626

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.



3620
3621
3622
# File 'lib/HDLRuby/hruby_low.rb', line 3620

def unit
  @unit
end

#valueObject (readonly)

The time value.



3623
3624
3625
# File 'lib/HDLRuby/hruby_low.rb', line 3623

def value
  @value
end

Instance Method Details

#cloneObject

Clones the Delay (deeply)



3666
3667
3668
# File 'lib/HDLRuby/hruby_low.rb', line 3666

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.



3643
3644
3645
3646
3647
3648
3649
3650
# File 'lib/HDLRuby/hruby_low.rb', line 3643

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)


3653
3654
3655
3656
3657
3658
# File 'lib/HDLRuby/hruby_low.rb', line 3653

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.



3661
3662
3663
# File 'lib/HDLRuby/hruby_low.rb', line 3661

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)



1674
1675
1676
1677
1678
1679
1680
# File 'lib/HDLRuby/hruby_low2c.rb', line 1674

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



1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
# File 'lib/HDLRuby/hruby_verilog.rb', line 1786

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.



1022
1023
1024
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 1022

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