Class: HDLRuby::Low::SignalI
- Inherits:
-
Base::SignalI
- Object
- Base::SignalI
- HDLRuby::Low::SignalI
- Includes:
- Hparent, Low2Symbol
- Defined in:
- lib/HDLRuby/hruby_db.rb,
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.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,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_without_namespace.rb
Overview
Extends the SignalI class with functionality for moving the declarations to the upper namespace.
Direct Known Subclasses
Constant Summary
Constants included from Low2Symbol
Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the signal.
-
#type ⇒ Object
readonly
The type of the signal.
-
#value ⇒ Object
readonly
The initial value of the signal if any.
Attributes included from Hparent
Instance Method Summary collapse
-
#clone ⇒ Object
Clones (deeply).
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types! ⇒ Object
Explicit the types conversions in the signal.
-
#hash ⇒ Object
Hash function.
-
#initialize(name, type, val = nil) ⇒ SignalI
constructor
Creates a new signal named +name+ typed as +type+.
-
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
-
#set_name!(name) ⇒ Object
Sets the name.
-
#set_type!(type) ⇒ Object
Sets the type.
-
#set_value!(value) ⇒ Object
Sets the value (can also be nil for removing the value).
-
#to_c(level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code.
-
#to_c_signal(level = 0) ⇒ Object
Generates the C text for an access to the signal.
-
#to_ch ⇒ Object
Generates the content of the h file.
-
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#to_verilog ⇒ Object
Converts the system to Verilog code.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#width ⇒ Object
Gets the bit width.
Methods included from Low2Symbol
Methods included from Hparent
Constructor Details
#initialize(name, type, val = nil) ⇒ SignalI
Creates a new signal named +name+ typed as +type+. If +val+ is provided, it will be the initial value of the signal.
234 235 236 237 238 239 |
# File 'lib/HDLRuby/hruby_db.rb', line 234 def initialize(name,type) # Ensures type is from Low::Type type = Type.get(type) # Initialize the signal structure. super(name,type) end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the signal
2239 2240 2241 |
# File 'lib/HDLRuby/hruby_low.rb', line 2239 def name @name end |
#type ⇒ Object (readonly)
The type of the signal
2242 2243 2244 |
# File 'lib/HDLRuby/hruby_low.rb', line 2242 def type @type end |
#value ⇒ Object (readonly)
The initial value of the signal if any.
2245 2246 2247 |
# File 'lib/HDLRuby/hruby_low.rb', line 2245 def value @value end |
Instance Method Details
#clone ⇒ Object
Clones (deeply)
2290 2291 2292 |
# File 'lib/HDLRuby/hruby_low.rb', line 2290 def clone return SignalI.new(self.name,self.type) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
2272 2273 2274 2275 2276 2277 |
# File 'lib/HDLRuby/hruby_low.rb', line 2272 def eql?(obj) return false unless obj.is_a?(SignalI) return false unless @name.eql?(obj.name) return false unless @type.eql?(obj.type) return true end |
#explicit_types! ⇒ Object
Explicit the types conversions in the signal.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 57 def explicit_types! # Is there a value? value = self.value if value then # Yes recurse on it. self.set_value!(value.explicit_types(self.type)) end # No, nothing to do. return self end |
#hash ⇒ Object
Hash function.
2280 2281 2282 |
# File 'lib/HDLRuby/hruby_low.rb', line 2280 def hash return [@name,@type].hash end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
399 400 401 402 403 404 405 406 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 399 def replace_names!(former,nname) # Recurse on the type. self.type.each_type_deep do |type| if type.respond_to?(:name) && type.name == former then type.set_name!(nname) end end end |
#set_name!(name) ⇒ Object
Sets the name.
478 479 480 481 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 478 def set_name!(name) # Check and set the name. @name = name.to_sym end |
#set_type!(type) ⇒ Object
Sets the type.
484 485 486 487 488 489 490 491 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 484 def set_type!(type) # Check and set the type. if type.is_a?(Type) then @type = type else raise AnyError, "Invalid class for a type: #{type.class}." end end |
#set_value!(value) ⇒ Object
Sets the value (can also be nil for removing the value).
494 495 496 497 498 499 500 501 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 494 def set_value!(value) # Check and set teh value. unless value == nil || value.is_a?(Expression) then raise AnyError, "Invalid class for a constant: #{value.class}" end @value = value value.parent = self unless value == nil end |
#to_c(level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 752 def to_c(level = 0) # The resulting string. res = "" # Declare the global variable holding the signal. res << "SignalI #{self.to_c_signal(level+1)};\n\n" # The header of the signal generation. res << " " * level*3 res << "SignalI #{Low2C.make_name(self)}() {\n" res << " " * (level+1)*3 res << "SignalI signalI = malloc(sizeof(SignalIS));\n" res << " " * (level+1)*3 res << "signalI->kind = SIGNALI;\n"; # Sets the global variable of the signal. res << "\n" res << " " * (level+1)*3 res << "#{self.to_c_signal(level+1)} = signalI;\n" # Set the owner if any. if self.parent then res << " " * (level+1)*3 res << "signalI->owner = (Object)" + "#{Low2C.obj_name(self.parent)};\n" else res << "signalI->owner = NULL;\n" end # Set the name res << " " * (level+1)*3 res << "signalI->name = \"#{self.name}\";\n" # Set the type. res << " " * (level+1)*3 res << "signalI->type = #{self.type.to_c(level+2)};\n" # Set the current and the next value. res << " " * (level+1)*3 res << "signalI->c_value = make_value(signalI->type,0);\n" res << " " * (level+1)*3 res << "signalI->c_value->signal = signalI;\n" res << " " * (level+1)*3 res << "signalI->f_value = make_value(signalI->type,0);\n" res << " " * (level+1)*3 res << "signalI->f_value->signal = signalI;\n" if self.value then # There is an initial value. res << " " * (level+1)*3 res << "copy_value(#{self.value.to_c(level+2)}," + "signalI->c_value);\n" end # Initially the signal can be overwritten by anything. res << " " * (level+1)*3 res << "signalI->fading = 1;\n" # Initialize the lists of behavior activated on this signal to 0. res << " " * (level+1)*3 res << "signalI->num_any = 0;\n" res << " " * (level+1)*3 res << "signalI->any = NULL;\n" res << " " * (level+1)*3 res << "signalI->num_pos = 0;\n" res << " " * (level+1)*3 res << "signalI->pos = NULL;\n" res << " " * (level+1)*3 res << "signalI->num_neg = 0;\n" res << " " * (level+1)*3 res << "signalI->neg = NULL;\n" # Register the signal for global processing. res << " " * (level+1)*3 res << "register_signal(signalI);\n" # Generate the return of the signal. res << "\n" res << " " * (level+1)*3 res << "return signalI;\n" # Close the signal. res << " " * level*3 res << "};\n\n" return res end |
#to_c_signal(level = 0) ⇒ Object
Generates the C text for an access to the signal. +level+ is the hierachical level of the object.
739 740 741 742 743 744 745 746 747 748 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 739 def to_c_signal(level = 0) res = Low2C.obj_name(self) # Accumulate the names of each parent until there is no one left. obj = self.parent while(obj) do res << "_" << Low2C.obj_name(obj) obj = obj.parent end return res end |
#to_ch ⇒ Object
Generates the content of the h file.
838 839 840 841 842 843 844 845 846 847 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 838 def to_ch res = "" # Declare the global variable holding the signal. res << "extern SignalI #{self.to_c_signal()};\n\n" # Generate the access to the function making the behavior. res << "extern SignalI #{Low2C.make_name(self)}();\n\n" return res; end |
#to_high(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
304 305 306 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 304 def to_high(level = 0) return Low2High.high_use_name(self.name) end |
#to_verilog ⇒ Object
Converts the system to Verilog code.
1624 1625 1626 1627 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1624 def to_verilog # Convert unusable characters and return them. return "#{name_to_verilog(self.name)}" end |
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
855 856 857 858 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 855 def to_vhdl(level = 0) # Should never be here. raise AnyError, "Internal error: to_vhdl should be implemented in class :#{self.class}" end |
#width ⇒ Object
Gets the bit width.
2285 2286 2287 |
# File 'lib/HDLRuby/hruby_low.rb', line 2285 def width return @type.width end |