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_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,
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).
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types! ⇒ Object
Explicit the types conversions in the signal.
-
#hash ⇒ Object
Hash function.
-
#immutable? ⇒ Boolean
Tells if the signal is immutable (cannot be written.).
-
#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(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code.
-
#to_c_alias(res, target, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code in case the signals is actually an alias to another signal.
-
#to_c_signal(res, level = 0) ⇒ Object
Generates the C text for an access to the signal.
-
#to_ch(res) ⇒ Object
Generates the content of the h file.
-
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high signal.
-
#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
2447 2448 2449 |
# File 'lib/HDLRuby/hruby_low.rb', line 2447 def name @name end |
#type ⇒ Object (readonly)
The type of the signal
2450 2451 2452 |
# File 'lib/HDLRuby/hruby_low.rb', line 2450 def type @type end |
#value ⇒ Object (readonly)
The initial value of the signal if any.
2453 2454 2455 |
# File 'lib/HDLRuby/hruby_low.rb', line 2453 def value @value end |
Instance Method Details
#clone ⇒ Object
Clones (deeply)
2521 2522 2523 |
# File 'lib/HDLRuby/hruby_low.rb', line 2521 def clone return SignalI.new(self.name,self.type) end |
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 |
# File 'lib/HDLRuby/hruby_low.rb', line 2491 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 type. self.type.each_deep(&ruby_block) # Then apply on the value. self.value.each_deep(&ruby_block) if self.value end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
2503 2504 2505 2506 2507 2508 |
# File 'lib/HDLRuby/hruby_low.rb', line 2503 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.
2511 2512 2513 |
# File 'lib/HDLRuby/hruby_low.rb', line 2511 def hash return [@name,@type].hash end |
#immutable? ⇒ Boolean
Tells if the signal is immutable (cannot be written.)
2480 2481 2482 2483 |
# File 'lib/HDLRuby/hruby_low.rb', line 2480 def immutable? # By default, signals are not immutable. false end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
404 405 406 407 408 409 410 411 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 404 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.
490 491 492 493 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 490 def set_name!(name) # Check and set the name. @name = name.to_sym end |
#set_type!(type) ⇒ Object
Sets the type.
496 497 498 499 500 501 502 503 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 496 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).
506 507 508 509 510 511 512 513 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 506 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(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)
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 860 def to_c(res,level = 0) # puts "Signal.to_c with name: #{Low2C.obj_name(self)}" # Declare the global variable holding the signal. res << "SignalI " self.to_c_signal(res,level+1) res << ";\n\n" # The header of the signal generation. res << " " * level*3 res << "SignalI " << Low2C.make_name(self) << "() {\n" # res << " " * level*3 # res << "Value l,r,d;\n" # res << " " * (level+1)*3 # res << "unsigned long long i;\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 self.to_c_signal(res,level+1) res << " = signalI;\n" # Set the owner if any. if self.parent then res << " " * (level+1)*3 res << "signalI->owner = (Object)" res << 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" res << "signalI->type = " self.type.to_c(res,level+2) res << ";\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_expr(res,level+2) # res << ",signalI->c_value);\n" res << "copy_value(" self.value.to_c_expr(res,level+2) res << ",signalI->f_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_alias(res, target, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code in case the signals is actually an alias to another signal. +other+ is the target signal of the alias. +level+ is the hierachical level of the object.
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 979 def to_c_alias(res,target,level = 0) # puts "Signal.to_c_alias with name: #{Low2C.obj_name(self)}" # The resulting string. # res = "" # Declare the global variable holding the signal. res << "SignalI " self.to_c_signal(res,level+1) res << ";\n\n" # The header of the signal generation. res << " " * level*3 res << "SignalI " << Low2C.make_name(self) << "() {\n" res << "SignalI signalI = #{Low2C.obj_name(target)};\n" # Sets the global variable of the signal. res << "\n" res << " " * (level+1)*3 self.to_c_signal(res,level+1) res << " = 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(res, level = 0) ⇒ Object
Generates the C text for an access to the signal. +level+ is the hierachical level of the object. def to_c_signal(level = 0)
845 846 847 848 849 850 851 852 853 854 855 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 845 def to_c_signal(res,level = 0) # res = Low2C.obj_name(self) 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(res) ⇒ Object
Generates the content of the h file. def to_ch
960 961 962 963 964 965 966 967 968 969 970 971 972 973 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 960 def to_ch(res) # res = "" # puts "to_ch for SignalI: #{self.to_c_signal()}" # Declare the global variable holding the signal. # res << "extern SignalI #{self.to_c_signal()};\n\n" res << "extern SignalI " self.to_c_signal(res) res << ";\n\n" # Generate the access to the function making the behavior. res << "extern SignalI " << Low2C.make_name(self) << "();\n\n" return res; end |
#to_hdr(level = 0) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object.
304 305 306 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 304 def to_hdr(level = 0) return Low2HDR.hdr_use_name(self.name) end |
#to_high ⇒ Object
Creates a new high signal.
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 165 def to_high # Is there an initial value? if (self.value) then # Yes, create a new high signal with it. return HDLRuby::High::SignalI.new(self.name,self.type.to_high, self.val.to_high) else # No, create a new high signal with it. return HDLRuby::High::SignalI.new(self.name,self.type.to_high) end end |
#to_verilog ⇒ Object
Converts the system to Verilog code.
1746 1747 1748 1749 1750 1751 |
# File 'lib/HDLRuby/hruby_verilog.rb', line 1746 def to_verilog # Convert unusable characters and return them. vname = name_to_verilog(self.name) # self.properties[:verilog_name] = vname return "#{vname}" end |
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.
865 866 867 868 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 865 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.
2516 2517 2518 |
# File 'lib/HDLRuby/hruby_low.rb', line 2516 def width return @type.width end |