Class: HDLRuby::Low::Delay
- Inherits:
-
Object
- Object
- HDLRuby::Low::Delay
- Includes:
- Hparent, Low2Symbol
- Defined in:
- lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_viz.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
Enhances Delay with generation of verilog code.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#to_viz_node(parent) ⇒ Object
Converts the transmit to a Viz flow node under +parent+.
Methods included from Low2Symbol
Methods included from Hparent
#absolute_ref, #hierarchy, #no_parent!, #scope
Constructor Details
#initialize(value, unit) ⇒ Delay
Creates a new delay of +value+ +unit+ of time.
4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 |
# File 'lib/HDLRuby/hruby_low.rb', line 4036 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.
4030 4031 4032 |
# File 'lib/HDLRuby/hruby_low.rb', line 4030 def unit @unit end |
#value ⇒ Object (readonly)
The time value.
4033 4034 4035 |
# File 'lib/HDLRuby/hruby_low.rb', line 4033 def value @value end |
Instance Method Details
#clone ⇒ Object
Clones the Delay (deeply)
4076 4077 4078 |
# File 'lib/HDLRuby/hruby_low.rb', line 4076 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.
4053 4054 4055 4056 4057 4058 4059 4060 |
# File 'lib/HDLRuby/hruby_low.rb', line 4053 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.
4063 4064 4065 4066 4067 4068 |
# File 'lib/HDLRuby/hruby_low.rb', line 4063 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.
4071 4072 4073 |
# File 'lib/HDLRuby/hruby_low.rb', line 4071 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_high ⇒ Object
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_verilog ⇒ Object
Enhances Delay with generation of verilog code.
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1969 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 |