Class: HDLRuby::Low::Delay
- Inherits:
-
Base::Delay
- Object
- Base::Delay
- HDLRuby::Low::Delay
- 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
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
The time unit.
-
#value ⇒ Object
readonly
The time value.
Attributes included from Hparent
Instance Method Summary collapse
-
#clone ⇒ Object
Clones the Delay (deeply).
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#hash ⇒ Object
Hash function.
-
#initialize(value, unit) ⇒ Delay
constructor
Creates a new delay of +value+ +unit+ of time.
-
#replace_expressions!(node2rep) ⇒ Object
Replaces sub expressions using +node2rep+ table indicating the node to replace and the corresponding replacement.
-
#set_unit!(unit) ⇒ Object
Sets the unit.
-
#set_value!(value) ⇒ Object
Sets the value.
-
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code.
-
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high delay.
- #to_verilog ⇒ Object
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
Methods included from Low2Symbol
Methods included from Hparent
Constructor Details
#initialize(value, unit) ⇒ Delay
Creates a new delay of +value+ +unit+ of time.
3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 |
# File 'lib/HDLRuby/hruby_low.rb', line 3668 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
#unit ⇒ Object (readonly)
The time unit.
3662 3663 3664 |
# File 'lib/HDLRuby/hruby_low.rb', line 3662 def unit @unit end |
#value ⇒ Object (readonly)
The time value.
3665 3666 3667 |
# File 'lib/HDLRuby/hruby_low.rb', line 3665 def value @value end |
Instance Method Details
#clone ⇒ Object
Clones the Delay (deeply)
3708 3709 3710 |
# File 'lib/HDLRuby/hruby_low.rb', line 3708 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.
3685 3686 3687 3688 3689 3690 3691 3692 |
# File 'lib/HDLRuby/hruby_low.rb', line 3685 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.
3695 3696 3697 3698 3699 3700 |
# File 'lib/HDLRuby/hruby_low.rb', line 3695 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 |
#hash ⇒ Object
Hash function.
3703 3704 3705 |
# File 'lib/HDLRuby/hruby_low.rb', line 3703 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)
1767 1768 1769 1770 1771 1772 1773 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 1767 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_high ⇒ Object
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_verilog ⇒ Object
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1794 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 |