Class: HDLRuby::Low::Scope
- Inherits:
-
Object
- Object
- HDLRuby::Low::Scope
- Includes:
- ForceName, 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_low2seq.rb,
lib/HDLRuby/hruby_low2sym.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_cleanup.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_resolve.rb,
lib/HDLRuby/hruby_low_skeleton.rb,
lib/HDLRuby/hruby_low_fix_types.rb,
lib/HDLRuby/hruby_low_with_port.rb,
lib/HDLRuby/hruby_low_bool2select.rb,
lib/HDLRuby/hruby_low_without_concat.rb,
lib/HDLRuby/hruby_low_without_select.rb,
lib/HDLRuby/backend/hruby_c_allocator.rb,
lib/HDLRuby/hruby_low_without_parinseq.rb,
lib/HDLRuby/hruby_low_without_namespace.rb,
lib/HDLRuby/hruby_low_without_subsignals.rb,
lib/HDLRuby/hruby_low_casts_without_expression.rb
Overview
Extend the Scope class for conversion to Viz format.
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 scope if any.
Attributes included from Hparent
Instance Method Summary collapse
-
#add_behavior(behavior) ⇒ Object
Adds a +behavior+.
-
#add_code(code) ⇒ Object
Adds code chunk +code+.
-
#add_connection(connection) ⇒ Object
Adds a +connection+.
-
#add_inner(signal) ⇒ Object
Adds inner signal +signal+.
-
#add_program(prog) ⇒ Object
Adds program +prog+.
-
#add_scope(scope) ⇒ Object
Adds a new +scope+.
-
#add_systemI(systemI) ⇒ Object
Adds system instance +systemI+.
-
#add_systemT(systemT) ⇒ Object
Adds system instance +systemT+.
-
#add_type(type) ⇒ Object
Adds system instance +type+.
-
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
-
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
-
#break_concat_assigns! ⇒ Object
Breaks the assignments to concats.
-
#break_types! ⇒ Object
Breaks the hierarchical types into sequences of type definitions.
-
#c_code_allocate(allocator) ⇒ Object
Allocates signals within C code using +allocator+.
-
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
-
#cleanup!(keep) ⇒ Object
Cleans up.
-
#delete_all_behaviors! ⇒ Object
Deletes all the behaviors.
-
#delete_all_connections! ⇒ Object
Deletes all the connections.
-
#delete_behavior!(behavior) ⇒ Object
Deletes a behavior.
-
#delete_connection!(connection) ⇒ Object
Deletes a connection.
-
#delete_inner!(signal) ⇒ Object
Deletes an inner.
-
#delete_related!(*names) ⇒ Object
Deletes the elements related to one of +names+: either they have one of the names or they use an element with these names.
-
#delete_scope!(scope) ⇒ Object
Deletes a scope.
-
#delete_systemI!(systemI) ⇒ Object
Deletes a systemI.
-
#delete_systemT!(systemT) ⇒ Object
Deletes a systemT.
-
#delete_type!(type) ⇒ Object
Deletes a type.
-
#delete_unless!(keep) ⇒ Object
Removes the signals and corresponding assignments whose name is not in +keep+.
-
#each_behavior(&ruby_block) ⇒ Object
Iterates over the behaviors.
-
#each_behavior_deep(&ruby_block) ⇒ Object
Iterates over all the behaviors of the system type and its system instances.
-
#each_block_deep(&ruby_block) ⇒ Object
Iterates over all the blocks of the system type and its system instances.
-
#each_code(&ruby_block) ⇒ Object
Iterates over the non-HDLRuby code chunks.
-
#each_connection(&ruby_block) ⇒ Object
Iterates over the connections.
-
#each_connection_deep(&ruby_block) ⇒ Object
Iterates over all the connections of the system type and its system instances.
-
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
-
#each_inner(&ruby_block) ⇒ Object
Iterates over the inner signals.
-
#each_node_deep(&ruby_block) ⇒ Object
Iterates over all the nodes of the system type and its system instances.
-
#each_program(&ruby_block) ⇒ Object
Iterates over the programs.
-
#each_scope(&ruby_block) ⇒ Object
Iterates over the sub scopes.
-
#each_scope_deep(&ruby_block) ⇒ Object
Iterates over the scopes deeply.
-
#each_signal(&ruby_block) ⇒ Object
Iterates over all the signals (Equivalent to each_inner).
-
#each_signal_deep(&ruby_block) ⇒ Object
Iterates over all the signals of the scope, its behaviors', its instances' and its sub scopes'.
-
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the stamements of the system type and its system instances.
-
#each_systemI(&ruby_block) ⇒ Object
Iterates over the system instances.
-
#each_systemT(&ruby_block) ⇒ Object
Iterates over the system instances.
-
#each_type(&ruby_block) ⇒ Object
Iterates over the system instances.
-
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
-
#explicit_types! ⇒ Object
Explicit the types conversions in the scope.
-
#extract_behaviors! ⇒ Object
Extract the behaviors from the scope and returns them into an array.
-
#extract_connections! ⇒ Object
Extract the connections from the scope and returns them into an array.
-
#extract_declares! ⇒ Object
Extract the declares from the scope and returns them into an array.
-
#extract_port_assign!(systemI, signal) ⇒ Object
Extracts the assignments to port +systemI.signal+ and returns the resulting reference to a port wire.
-
#get_all_inners ⇒ Object
Gets an array containing all the inner signals.
-
#get_by_name(name) ⇒ Object
Find an inner object by +name+.
-
#get_code(name) ⇒ Object
Gets a code chunk by +name+.
-
#get_inner(name) ⇒ Object
Gets an inner signal by +name+.
-
#get_signal(name) ⇒ Object
Gets an inner signal by +name+, equivalent to get_inner.
-
#get_systemI(name) ⇒ Object
Gets a system instance by +name+.
-
#get_systemT(name) ⇒ Object
Gets a system instance by +name+.
-
#get_type(name) ⇒ Object
Gets a system instance by +name+.
-
#has_behavior? ⇒ Boolean
Tells if there is any inner.
-
#has_code? ⇒ Boolean
Tells if there is any non-HDLRuby code chunk.
-
#has_connection? ⇒ Boolean
Tells if there is any connection.
-
#has_inner? ⇒ Boolean
Tells if there is any inner.
-
#has_program? ⇒ Boolean
Tells if there is any program.
-
#has_scope? ⇒ Boolean
Tells if there is any sub scope.
-
#has_signal? ⇒ Boolean
Tells if there is any signal, equivalent to has_inner?.
-
#has_systemI? ⇒ Boolean
Tells if there is any system instance.
-
#has_systemT? ⇒ Boolean
Tells if there is any system instance.
-
#has_type? ⇒ Boolean
Tells if there is any system instance.
-
#hash ⇒ Object
Hash function.
-
#initial_concat_to_timed! ⇒ Object
Converts initial array of value of signals to assignment in timed blocks (for making the code compatible with verilog translation).
-
#initialize(name = :"") ⇒ Scope
constructor
Creates a new scope with a possible +name+.
-
#instance_port?(node) ⇒ Boolean
Tells if a +node+ is a reference to an instance's port.
-
#last_behavior ⇒ Object
Returns the last behavior.
-
#make_portw(ref) ⇒ Object
Generates a port wire from a reference.
-
#map_behaviors!(&ruby_block) ⇒ Object
Maps on the behaviors.
-
#map_connections!(&ruby_block) ⇒ Object
Maps on the connections.
-
#map_inners!(&ruby_block) ⇒ Object
Maps on the inners.
-
#map_scopes!(&ruby_block) ⇒ Object
Maps on the scopes.
-
#map_systemIs!(&ruby_block) ⇒ Object
Maps on the systemIs.
-
#map_systemTs!(&ruby_block) ⇒ Object
Maps on the local systemTs.
-
#map_types!(&ruby_block) ⇒ Object
Maps on the local types.
-
#mixblocks2seq! ⇒ Object
Converts the par sub blocks to seq if they are not full par.
-
#par_in_seq2seq! ⇒ Object
Converts par blocks within seq blocks to seq blocks.
-
#parent_system ⇒ Object
Gets the parent system, i.e., the parent of the top scope.
-
#port_assign?(expr, systemI, signal) ⇒ Boolean
Tells if an expression is a reference to port +systemI.signal+.
-
#portw2ref(portw) ⇒ Object
Converts a port wire to a reference to it.
-
#portw_name2sym(name) ⇒ Object
Converts a port wire +name+ to the symbol giving the corresponding HDLRuby reference.
-
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
-
#replace_names_subs!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared in the internals.
-
#reverse_each_behavior(&ruby_block) ⇒ Object
Reverse iterates over the behaviors.
-
#select2case! ⇒ Object
Converts the Select expressions to Case statements.
-
#signal2subs! ⇒ Object
Decompose the hierarchical signals in the statements.
-
#sym2portw_name(sym) ⇒ Object
Converts symbol +sym+ representing an HDLRuby reference to a instance port to a port wire.
-
#to_c(res, level = 0) ⇒ Object
Generates the C text of the equivalent HDLRuby code.
-
#to_ch(res) ⇒ Object
Generates the content of the h file.
-
#to_hdr(level = 0, header = true) ⇒ Object
Generates the text of the equivalent hdr text.
-
#to_high ⇒ Object
Creates a new high scope.
-
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
-
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code.
-
#to_viz(world, regs, ports, links, rname = "") ⇒ Object
Converts the scope to a Viz struture inside +world+, updating the table of ports +ports+, the table of registers +regs+ and explicit port connections +links+ with root name +rname+.
-
#top_scope ⇒ Object
Gets the top scope, i.e.
-
#with_port! ⇒ Object
Converts to a port-compatible system.
Methods included from ForceName
Methods included from Low2Symbol
Methods included from Hparent
#absolute_ref, #hierarchy, #no_parent!, #scope
Constructor Details
#initialize(name = :"") ⇒ Scope
Creates a new scope with a possible +name+.
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/HDLRuby/hruby_low.rb', line 544 def initialize(name = :"") # Check and set the name. @name = name.to_sym # Initialize the local types. @types = HashName.new # Initialize the local system types. @systemTs = HashName.new # Initialize the sub scopes. @scopes = [] # Initialize the inner signal instance lists. @inners = HashName.new # Initialize the system instances list. @systemIs = HashName.new # Initialize the programs list. @programs = [] # Initialize the non-HDLRuby code chunks list. @codes = [] # Initialize the connections list. @connections = [] # Initialize the behaviors lists. @behaviors = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the scope if any
541 542 543 |
# File 'lib/HDLRuby/hruby_low.rb', line 541 def name @name end |
Instance Method Details
#add_behavior(behavior) ⇒ Object
Adds a +behavior+.
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
# File 'lib/HDLRuby/hruby_low.rb', line 1105 def add_behavior(behavior) unless behavior.is_a?(Behavior) raise AnyError,"Invalid class for a behavior: #{behavior.class}" end # Set its parent behavior.parent = self # And add it @behaviors << behavior behavior end |
#add_code(code) ⇒ Object
Adds code chunk +code+.
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/HDLRuby/hruby_low.rb', line 874 def add_code(code) # Check and add the code chunk. unless code.is_a?(Code) raise AnyError, "Invalid class for a non-hDLRuby code chunk: #{code.class}" end # if @codes.include?(code) then # raise AnyError, "Code #{code.name} already present." # end # Set the parent of the code chunk. code.parent = self # puts "code = #{code}, parent=#{self}" # Add the code chunk. @codes << code code end |
#add_connection(connection) ⇒ Object
Adds a +connection+.
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 |
# File 'lib/HDLRuby/hruby_low.rb', line 1050 def add_connection(connection) unless connection.is_a?(Connection) raise AnyError, "Invalid class for a connection: #{connection.class}" end # Set the parent of the connection. connection.parent = self # And add it. @connections << connection connection end |
#add_inner(signal) ⇒ Object
Adds inner signal +signal+.
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/HDLRuby/hruby_low.rb', line 915 def add_inner(signal) # puts "adding inner signal: #{signal.name}(#{signal})" # Check and add the signal. unless signal.is_a?(SignalI) raise AnyError, "Invalid class for a signal instance: #{signal.class}" end # if @inners.include?(signal) then # raise AnyError, "SignalI #{signal.name} already present." # end # Set the parent of the signal. signal.parent = self # And add the signal. @inners.add(signal) return signal end |
#add_program(prog) ⇒ Object
Adds program +prog+.
842 843 844 845 846 847 848 849 850 851 852 853 |
# File 'lib/HDLRuby/hruby_low.rb', line 842 def add_program(prog) # Check and add the program. unless prog.is_a?(Program) raise AnyError, "Invalid class for a program: #{prog.class}" end # Set the parent of the program. prog.parent = self # Add the program. @programs << prog prog end |
#add_scope(scope) ⇒ Object
Adds a new +scope+.
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/HDLRuby/hruby_low.rb', line 732 def add_scope(scope) # Check and add the scope. unless scope.is_a?(Scope) raise AnyError, "Invalid class for a system instance: #{scope.class}" end # if @scopes.include?(scope) then # raise AnyError, "Scope #{scope} already present." # end # Set the parent of the scope scope.parent = self # Remove a former scope with same name if present (override) @scopes.delete_if { |sc| sc.name && sc.name == scope.name } # Add the scope @scopes << scope end |
#add_systemI(systemI) ⇒ Object
Adds system instance +systemI+.
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 |
# File 'lib/HDLRuby/hruby_low.rb', line 789 def add_systemI(systemI) # puts "add_systemI with name #{systemI.name}" # Check and add the systemI. unless systemI.is_a?(SystemI) raise AnyError, "Invalid class for a system instance: #{systemI.class}" end # if @systemIs.include?(systemI) then # raise AnyError, "SystemI #{systemI.name} already present." # end # Set the parent of the instance systemI.parent = self # puts "systemI = #{systemI}, parent=#{self}" # Add the instance @systemIs.add(systemI) end |
#add_systemT(systemT) ⇒ Object
Adds system instance +systemT+.
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/HDLRuby/hruby_low.rb', line 626 def add_systemT(systemT) # puts "add_systemT with name #{systemT.name}" # Check and add the systemT. unless systemT.is_a?(SystemT) raise AnyError, "Invalid class for a system type: #{systemT.class}" end # if @systemTs.include?(systemT) then # raise AnyError, "SystemT #{systemT.name} already present." # end # Set the parent of the instance systemT.parent = self # puts "systemT = #{systemT}, parent=#{self}" # Add the instance @systemTs.add(systemT) end |
#add_type(type) ⇒ Object
Adds system instance +type+.
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/HDLRuby/hruby_low.rb', line 678 def add_type(type) # puts "add_type with name #{type.name}" # Check and add the type. unless type.is_a?(Type) raise AnyError, "Invalid class for a type: #{type.class}" end # if @types.include?(type) then # raise AnyError, "Type #{type.name} already present." # end # Set the parent of the instance type.parent = self # puts "type = #{type}, parent=#{self}" # Add the instance @types.add(type) end |
#blocks2seq! ⇒ Object
Converts the par sub blocks to seq.
41 42 43 44 45 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 41 def blocks2seq! # Recurse on the behaviors. self.each_behavior { |beh| beh.blocks2seq! } return self end |
#boolean_in_assign2select! ⇒ Object
Converts booleans in assignments to select operators.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/HDLRuby/hruby_low_bool2select.rb', line 35 def boolean_in_assign2select! # Recurse on the sub scopes. self.each_scope(&:boolean_in_assign2select!) # Apply on the connections. self.each_connection(&:boolean_in_assign2select!) # Apply on the behaviors. self.each_behavior do |behavior| behavior.block.boolean_in_assign2select! end return self end |
#break_concat_assigns! ⇒ Object
Breaks the assignments to concats.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/HDLRuby/hruby_low_without_concat.rb', line 42 def break_concat_assigns! # Recruse on the sub scopes. self.each_scope(&:break_concat_assigns!) # Recurse on the statements. self.each_behavior do |behavior| # behavior.block.each_block_deep(&:break_concat_assigns!) behavior.break_concat_assigns! end # Work on the connections. self.each_connection.to_a.each do |connection| nconnection = connection.break_concat_assigns if nconnection.is_a?(Block) then # The connection has been broken, remove the former # version and add the generated block as a behavior. # self.remove_connection(connection) self.delete_connection!(connection) self.add_behavior(Behavior.new(nconnection)) end end end |
#break_types! ⇒ Object
Breaks the hierarchical types into sequences of type definitions. Assumes to_upper_space! has been called before.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 266 def break_types! # The created types by structure. types = {} # Break the local types. self.each_type {|type| type.break_types!(types)} # Break the types in the inners. # self.each_inner {|inner| inner.type.break_types!(types) } self.each_inner do |inner| inner.set_type!(inner.type.break_types!(types)) end # Break the types in the connections. self.each_connection do |connection| connection.left.break_types!(types) connection.right.break_types!(types) end # Break the types in the behaviors. self.each_behavior do |behavior| behavior.each_event do |event| event.ref.break_types!(types) end behavior.block.break_types!(types) end # Add the resulting types. types.each_value {|type| self.add_type(type) } end |
#c_code_allocate(allocator) ⇒ Object
Allocates signals within C code using +allocator+.
28 29 30 31 32 33 |
# File 'lib/HDLRuby/backend/hruby_c_allocator.rb', line 28 def c_code_allocate(allocator) # Interrate on the sub scopes. self.each_scope { |scope| scope.c_code_allocate(allocator) } # Ally thr allocator on the codes. self.each_code { |code| code.c_code_allocate(allocator) } end |
#casts_without_expression! ⇒ Object
Extracts the expressions from the casts.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/HDLRuby/hruby_low_casts_without_expression.rb', line 36 def casts_without_expression! # Recurse on the sub scopes. self.each_scope(&:casts_without_expression!) # Apply on the connections. self.each_connection(&:casts_without_expression!) # Apply on the behaviors. self.each_behavior do |behavior| behavior.block.casts_without_expression! end return self end |
#cleanup!(keep) ⇒ Object
Cleans up. +keep+ includes the list of names to be kept.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/HDLRuby/hruby_low_cleanup.rb', line 38 def cleanup!(keep) # Complete the list of signals to keep with the signals parts # of the right values of connections and statements or # instance interface. self.each_scope_deep do |scope| # Connections. scope.each_connection do |connection| connection.right.each_node_deep do |node| # Leaf right value references are to keep. # They are either signal of current system or # system instance names. if node.is_a?(RefName) && !node.ref.is_a?(RefName) then keep << node.name end end end # System instances. scope.each_systemI do |systemI| keep << systemI.name end # Behaviors. scope.each_behavior do |behavior| behavior.block.each_node_deep do |node| # Skip left values. next if node.respond_to?(:leftvalue?) && node.leftvalue? # Leaf right value references are to keep. # They are either signal of current system or # system instance names. if node.is_a?(RefName) && !node.ref.is_a?(RefName) then keep << node.name end end end end # Remove the signals and correspondong assignments that are not # to keep. self.delete_unless!(keep) end |
#delete_all_behaviors! ⇒ Object
Deletes all the behaviors.
238 239 240 241 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 238 def delete_all_behaviors! @behaviors.each { |beh| beh.parent = nil } @behaviors = [] end |
#delete_all_connections! ⇒ Object
Deletes all the connections.
222 223 224 225 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 222 def delete_all_connections! @connections.each { |cnx| cnx.parent = nil } @connections = [] end |
#delete_behavior!(behavior) ⇒ Object
Deletes a behavior.
228 229 230 231 232 233 234 235 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 228 def delete_behavior!(behavior) if @behaviors.include?(behavior) then # The behavior is present, delete it. @behaviors.delete(behavior) # And remove its parent. behavior.parent = nil end end |
#delete_connection!(connection) ⇒ Object
Deletes a connection.
211 212 213 214 215 216 217 218 219 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 211 def delete_connection!(connection) if @connections.include?(connection) then # The connection is present, delete it. @connections.delete(connection) # And remove its parent. connection.parent = nil end connection end |
#delete_inner!(signal) ⇒ Object
Deletes an inner.
189 190 191 192 193 194 195 196 197 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 189 def delete_inner!(signal) if @inners.key?(signal.name) then # The signal is present, delete it. @inners.delete(signal.name) # And remove its parent. signal.parent = nil end signal end |
#delete_related!(*names) ⇒ Object
Deletes the elements related to one of +names+: either they have one of the names or they use an element with these names. NOTE: only delete actual instantiated elements, types or systemTs are left as is.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 247 def (*names) # Delete the sub scopes whose name are in names. @scopes.delete_if { |scope| names.include?(scope.name) } # Delete the inner signals whose name are in names. @inners.delete_if { |sig| names.include?(sig.name) } # Delete the connections that contain signals whose name are # in names. @connections.delete_if { |connection| connection.use_name?(*names) } # Delete the behaviors whose block name or events' name are in # names. @behaviors.delete_if do |behavior| names.include?(behavior.block.name) or behavior.each_event.include? do |event| event.ref.use_name?(*names) end end # Recurse on the sub scopes. @scopes.each { |scope| scope.(names) } # Recurse on the behaviors. @behaviors.each { |behavior| behavior.block.(names) } end |
#delete_scope!(scope) ⇒ Object
Deletes a scope.
179 180 181 182 183 184 185 186 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 179 def delete_scope!(scope) # Remove the scope from the list @scopes.delete(scope) # And remove its parent. scope.parent = nil # Return the deleted scope scope end |
#delete_systemI!(systemI) ⇒ Object
Deletes a systemI.
200 201 202 203 204 205 206 207 208 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 200 def delete_systemI!(systemI) if @systemIs.key?(systemI.name) then # The instance is present, do remove it. @systemIs.delete(systemI.name) # And remove its parent. systemI.parent = nil end systemI end |
#delete_systemT!(systemT) ⇒ Object
Deletes a systemT.
168 169 170 171 172 173 174 175 176 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 168 def delete_systemT!(systemT) if @systemTs.key?(systemT.name) then # The systemT is present, delete it. @systemTs.delete(systemT.name) # And remove its parent. systemT.parent = nil end systemT end |
#delete_type!(type) ⇒ Object
Deletes a type.
157 158 159 160 161 162 163 164 165 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 157 def delete_type!(type) if @types.key?(type.name) then # The type is present, delete it. @types.delete(type.name) # And remove its parent. type.parent = nil end type end |
#delete_unless!(keep) ⇒ Object
Removes the signals and corresponding assignments whose name is not in +keep+.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/HDLRuby/hruby_low_cleanup.rb', line 80 def delete_unless!(keep) # Recurse on the sub scopes. self.each_scope { |scope| scope.delete_unless!(keep) } # Remove the unessary inner signals. self.each_inner.to_a.each do |inner| unless keep.include?(inner.name) then self.delete_inner!(inner) end end # Remove the unessary connections. self.each_connection.to_a.each do |connection| # puts "connection with left=#{connection.left.name}" unless connection.left.each_node_deep.any? { |node| node.is_a?(RefName) && keep.include?(node.name) } self.delete_connection!(connection) end end # Recurse on the blocks. self.each_behavior do |behavior| behavior.block.delete_unless!(keep) end end |
#each_behavior(&ruby_block) ⇒ Object
Iterates over the behaviors.
Returns an enumerator if no ruby block is given.
1119 1120 1121 1122 1123 1124 |
# File 'lib/HDLRuby/hruby_low.rb', line 1119 def each_behavior(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_behavior) unless ruby_block # A ruby block? Apply it on each behavior. @behaviors.each(&ruby_block) end |
#each_behavior_deep(&ruby_block) ⇒ Object
Iterates over all the behaviors of the system type and its system instances.
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 |
# File 'lib/HDLRuby/hruby_low.rb', line 1159 def each_behavior_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_behavior_deep) unless ruby_block # A ruby block? # First recurse on the sub scopes. self.each_scope_deep do |scope| scope.each_behavior(&ruby_block) end # Then iterate over current system type's behavior. self.each_behavior(&ruby_block) end |
#each_block_deep(&ruby_block) ⇒ Object
Iterates over all the blocks of the system type and its system instances.
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 |
# File 'lib/HDLRuby/hruby_low.rb', line 1188 def each_block_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_block_deep) unless ruby_block # A ruby block? # Then apply on each sub scope. self.each_scope do |scope| scope.each_block_deep(&ruby_block) end # And apply it on each behavior's block deeply. self.each_behavior do |behavior| behavior.each_block_deep(&ruby_block) end end |
#each_code(&ruby_block) ⇒ Object
Iterates over the non-HDLRuby code chunks.
Returns an enumerator if no ruby block is given.
894 895 896 897 898 899 900 |
# File 'lib/HDLRuby/hruby_low.rb', line 894 def each_code(&ruby_block) # puts "each_code from scope=#{self}" # No ruby block? Return an enumerator. return to_enum(:each_code) unless ruby_block # A ruby block? Apply it on each code. @codes.each(&ruby_block) end |
#each_connection(&ruby_block) ⇒ Object
Iterates over the connections.
Returns an enumerator if no ruby block is given.
1065 1066 1067 1068 1069 1070 |
# File 'lib/HDLRuby/hruby_low.rb', line 1065 def each_connection(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_connection) unless ruby_block # A ruby block? Apply it on each connection. @connections.each(&ruby_block) end |
#each_connection_deep(&ruby_block) ⇒ Object
Iterates over all the connections of the system type and its system instances.
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 |
# File 'lib/HDLRuby/hruby_low.rb', line 1090 def each_connection_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_connection_deep) unless ruby_block # A ruby block? # First iterate over current system type's connection. self.each_connection(&ruby_block) # Then recurse on the system instances. self.each_systemI do |systemI| systemI.each_connection_deep(&ruby_block) end end |
#each_deep(&ruby_block) ⇒ Object
Iterates over each object deeply.
Returns an enumerator if no ruby block is given.
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 |
# File 'lib/HDLRuby/hruby_low.rb', line 1298 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) # The apply on each type. self.each_type do |type| type.each_deep(&ruby_block) end # Then apply on each systemT. self.each_systemT do |systemT| systemT.each_deep(&ruby_block) end # Then apply on each scope. self.each_scope do |scope| scope.each_deep(&ruby_block) end # Then apply on each inner signal. self.each_inner do |inner| inner.each_deep(&ruby_block) end # Then apply on each systemI. self.each_systemI do |systemI| systemI.each_deep(&ruby_block) end # Then apply on each code. self.each_code do |code| code.each_deep(&ruby_block) end # Then apply on each connection. self.each_connection do |connection| connection.each_deep(&ruby_block) end # Then apply on each behavior. self.each_behavior do |behavior| behavior.each_deep(&ruby_block) end end |
#each_inner(&ruby_block) ⇒ Object
Iterates over the inner signals.
Returns an enumerator if no ruby block is given.
935 936 937 938 939 940 941 |
# File 'lib/HDLRuby/hruby_low.rb', line 935 def each_inner(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_inner) unless ruby_block # A ruby block? Apply it on each inner signal instance. # @inners.each_value(&ruby_block) @inners.each(&ruby_block) end |
#each_node_deep(&ruby_block) ⇒ Object
Iterates over all the nodes of the system type and its system instances.
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 |
# File 'lib/HDLRuby/hruby_low.rb', line 1233 def each_node_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_node_deep) unless ruby_block # A ruby block? # Then apply on each sub scope. self.each_scope do |scope| scope.each_node_deep(&ruby_block) end # And apply it on each behavior's block deeply. self.each_behavior do |behavior| behavior.each_node_deep(&ruby_block) end end |
#each_program(&ruby_block) ⇒ Object
Iterates over the programs.
Returns an enumerator if no ruby block is given.
858 859 860 861 862 863 864 |
# File 'lib/HDLRuby/hruby_low.rb', line 858 def each_program(&ruby_block) # puts "each_program from scope=#{self}" # No ruby block? Return an enumerator. return to_enum(:each_program) unless ruby_block # A ruby block? Apply it on each program. @programs.each(&ruby_block) end |
#each_scope(&ruby_block) ⇒ Object
Iterates over the sub scopes.
Returns an enumerator if no ruby block is given.
752 753 754 755 756 757 |
# File 'lib/HDLRuby/hruby_low.rb', line 752 def each_scope(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_scope) unless ruby_block # A ruby block? Apply it on each sub scope. @scopes.each(&ruby_block) end |
#each_scope_deep(&ruby_block) ⇒ Object
Iterates over the scopes deeply.
Returns an enumerator if no ruby block is given.
762 763 764 765 766 767 768 769 |
# File 'lib/HDLRuby/hruby_low.rb', line 762 def each_scope_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_scope_deep) unless ruby_block # A ruby block? Apply it on self. ruby_block.call(self) # And recurse each sub scope. @scopes.each {|scope| scope.each_scope_deep(&ruby_block) } end |
#each_signal(&ruby_block) ⇒ Object
Iterates over all the signals (Equivalent to each_inner).
Returns an enumerator if no ruby block is given.
946 947 948 949 950 951 |
# File 'lib/HDLRuby/hruby_low.rb', line 946 def each_signal(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_signal) unless ruby_block # A ruby block? Apply it on each signal instance. @inners.each(&ruby_block) end |
#each_signal_deep(&ruby_block) ⇒ Object
Iterates over all the signals of the scope, its behaviors', its instances' and its sub scopes'.
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/HDLRuby/hruby_low.rb', line 955 def each_signal_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_signal_deep) unless ruby_block # A ruby block? # First iterate over the current system type's signals. self.each_signal(&ruby_block) # Then apply on the behaviors (since in HDLRuby:High, blocks can # include signals). self.each_behavior do |behavior| behavior.block.each_signal_deep(&ruby_block) end # Then recurse on the system instances. self.each_systemI do |systemI| systemI.each_signal_deep(&ruby_block) end # The recurse on the sub scopes. self.each_scope do |scope| scope.each_signal_deep(&ruby_block) end end |
#each_statement_deep(&ruby_block) ⇒ Object
Iterates over all the stamements of the system type and its system instances.
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/HDLRuby/hruby_low.rb', line 1217 def each_statement_deep(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_statement_deep) unless ruby_block # A ruby block? # Then apply on each sub scope. self.each_scope do |scope| scope.each_statement_deep(&ruby_block) end # And apply it on each behavior's block deeply. self.each_behavior do |behavior| behavior.each_statement_deep(&ruby_block) end end |
#each_systemI(&ruby_block) ⇒ Object
Iterates over the system instances.
Returns an enumerator if no ruby block is given.
809 810 811 812 813 814 815 |
# File 'lib/HDLRuby/hruby_low.rb', line 809 def each_systemI(&ruby_block) # puts "each_systemI from scope=#{self}" # No ruby block? Return an enumerator. return to_enum(:each_systemI) unless ruby_block # A ruby block? Apply it on each system instance. @systemIs.each(&ruby_block) end |
#each_systemT(&ruby_block) ⇒ Object
Iterates over the system instances.
Returns an enumerator if no ruby block is given.
646 647 648 649 650 651 652 |
# File 'lib/HDLRuby/hruby_low.rb', line 646 def each_systemT(&ruby_block) # puts "each_systemT from scope=#{self}" # No ruby block? Return an enumerator. return to_enum(:each_systemT) unless ruby_block # A ruby block? Apply it on each system instance. @systemTs.each(&ruby_block) end |
#each_type(&ruby_block) ⇒ Object
Iterates over the system instances.
Returns an enumerator if no ruby block is given.
698 699 700 701 702 703 704 |
# File 'lib/HDLRuby/hruby_low.rb', line 698 def each_type(&ruby_block) # puts "each_type from scope=#{self}" # No ruby block? Return an enumerator. return to_enum(:each_type) unless ruby_block # A ruby block? Apply it on each system instance. @types.each(&ruby_block) end |
#eql?(obj) ⇒ Boolean
Comparison for hash: structural comparison.
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/HDLRuby/hruby_low.rb', line 571 def eql?(obj) return false unless obj.is_a?(Scope) idx = 0 obj.each_systemT do |systemT| return false unless @systemTs[systemT.name].eql?(systemT) idx += 1 end return false unless idx == @systemTs.size idx = 0 obj.each_type do |type| return false unless @types[type.name].eql?(type) idx += 1 end return false unless idx == @types.size idx = 0 obj.each_scope do |scope| return false unless @scopes[idx].eql?(scope) idx += 1 end return false unless idx == @scopes.size idx = 0 obj.each_inner do |inner| return false unless @inners[inner.name].eql?(inner) idx += 1 end return false unless idx == @inners.size idx = 0 obj.each_systemI do |systemI| return false unless @systemIs[systemI.name].eql?(systemI) idx += 1 end return false unless idx == @systemIs.size idx = 0 obj.each_connection do |connection| return false unless @connections[idx].eql?(connection) idx += 1 end return false unless idx == @connections.size idx = 0 obj.each_behavior do |behavior| return false unless @behaviors[idx].eql?(behavior) idx += 1 end return false unless idx == @behaviors.size return true end |
#explicit_types! ⇒ Object
Explicit the types conversions in the scope.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/HDLRuby/hruby_low_fix_types.rb', line 31 def explicit_types! # Recurse on the sub scopes. self.each_scope(&:explicit_types!) # Fix the types of the declarations. self.each_inner(&:explicit_types!) # Fix the types of the connections. self.each_connection(&:explicit_types!) # Fix the types of the behaviors. self.each_behavior(&:explicit_types!) return self end |
#extract_behaviors! ⇒ Object
Extract the behaviors from the scope and returns them into an array.
NOTE: do not recurse into the sub scopes!
142 143 144 145 146 147 148 149 150 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 142 def extract_behaviors! # Get the behaviors. behs = self.each_behavior.to_a # Remove them from the scope. # behs.each { |beh| self.delete_behavior!(beh) } self.delete_all_behaviors! # Return the behaviors. return behs end |
#extract_connections! ⇒ Object
Extract the connections from the scope and returns them into an array.
NOTE: do not recurse into the sub scopes!
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 155 def extract_connections! # Get the connections. cnxs = self.each_connection.to_a # Remove them from the scope. # cnxs.each { |cnx| self.delete_connection!(cnx) } # cnxs.delete_all_connections! self.delete_all_connections! # Return the connections. return cnxs end |
#extract_declares! ⇒ Object
Extract the declares from the scope and returns them into an array.
NOTE: do not recurse into the sub scopes or behaviors!
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 169 def extract_declares! # Ensure there is a name. self.force_name! # The extracted declares. decls = [] # Extract the types. types = [] self.each_type {|type| types << type } types.each {|type| self.delete_type!(type) } # Renames them with the current level. types.each do |type| former = type.name self.extend_name!(type) self.replace_names_subs!(former,type.name) end # Adds the types decls << types # Extract the systemTs. systemTs = [] self.each_systemT {|systemT| systemTs << systemT } systemTs.each {|systemT| self.delete_systemT!(systemT) } # Renames them with the current level. systemTs.each do |systemT| former = systemT.name self.extend_name!(systemT) self.replace_names_subs!(former,systemT.name) end # Adds the systemTs decls << systemTs # Extract the inners. inners = [] self.each_inner {|inner| inners << inner } inners.each {|inner| self.delete_inner!(inner) } # Renames them with the current level. inners.each do |inner| former = inner.name self.extend_name!(inner) self.replace_names_subs!(former,inner.name) end # Adds the inners decls << inners # Extract the systemIs systemIs = [] self.each_systemI {|systemI| systemIs << systemI } systemIs.each {|systemI| self.delete_systemI!(systemI) } # Renames them with the current level. systemIs.each do |systemI| former = systemI.name self.extend_name!(systemI) self.replace_names_subs!(former,systemI.name) end # Adds the systemIs decls << systemIs # Returns the extracted declares. return decls end |
#extract_port_assign!(systemI, signal) ⇒ Object
Extracts the assignments to port +systemI.signal+ and returns the resulting reference to a port wire.
NOTE: assumes to_upper_space! and with_port! has been called.
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 419 def extract_port_assign!(systemI,signal) # Extract the assignment. assign = nil self.each_connection.to_a.each do |connection| if self.port_assign?(connection.left,systemI,signal) then # The left is the port. # Delete the connection. self.delete_connection!(connection) # And return a copy of the right. return connection.right.clone elsif self.port_assign?(connection.right,systemI,signal) then # The right is the port. # Delete the connection. self.delete_connection!(connection) # And return a copy of the left. return connection.left.clone end end # No port found, nothing to do return nil end |
#get_all_inners ⇒ Object
Gets an array containing all the inner signals.
987 988 989 |
# File 'lib/HDLRuby/hruby_low.rb', line 987 def get_all_inners return each_inner.to_a end |
#get_by_name(name) ⇒ Object
Find an inner object by +name+. NOTE: return nil if not found.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/HDLRuby/hruby_low_resolve.rb', line 41 def get_by_name(name) # puts "getbyname for name=#{name} with self=#{self}" # Ensure the name is a symbol. name = name.to_sym # Look in the signals. found = self.get_inner(name) return found if found # Look in the instances. found = self.each_systemI.find { |systemI| systemI.name == name } return found if found # Maybe it is a sub scope. return self.each_scope.find { |scope| scope.name == name } # Maybe it in the behavior. return self.behavior.get_by_name end |
#get_code(name) ⇒ Object
Gets a code chunk by +name+.
908 909 910 |
# File 'lib/HDLRuby/hruby_low.rb', line 908 def get_code(name) return @codes[name] end |
#get_inner(name) ⇒ Object
Gets an inner signal by +name+.
992 993 994 |
# File 'lib/HDLRuby/hruby_low.rb', line 992 def get_inner(name) return @inners[name.to_sym] end |
#get_signal(name) ⇒ Object
Gets an inner signal by +name+, equivalent to get_inner.
1032 1033 1034 |
# File 'lib/HDLRuby/hruby_low.rb', line 1032 def get_signal(name) return @inners[name] end |
#get_systemI(name) ⇒ Object
Gets a system instance by +name+.
823 824 825 |
# File 'lib/HDLRuby/hruby_low.rb', line 823 def get_systemI(name) return @systemIs[name] end |
#get_systemT(name) ⇒ Object
Gets a system instance by +name+.
660 661 662 |
# File 'lib/HDLRuby/hruby_low.rb', line 660 def get_systemT(name) return @systemTs[name] end |
#get_type(name) ⇒ Object
Gets a system instance by +name+.
712 713 714 |
# File 'lib/HDLRuby/hruby_low.rb', line 712 def get_type(name) return @types[name] end |
#has_behavior? ⇒ Boolean
Tells if there is any inner.
1172 1173 1174 |
# File 'lib/HDLRuby/hruby_low.rb', line 1172 def has_behavior? return !@behaviors.empty? end |
#has_code? ⇒ Boolean
Tells if there is any non-HDLRuby code chunk.
903 904 905 |
# File 'lib/HDLRuby/hruby_low.rb', line 903 def has_code? return !@codes.empty? end |
#has_connection? ⇒ Boolean
Tells if there is any connection.
1073 1074 1075 |
# File 'lib/HDLRuby/hruby_low.rb', line 1073 def has_connection? return !@connections.empty? end |
#has_inner? ⇒ Boolean
Tells if there is any inner.
977 978 979 |
# File 'lib/HDLRuby/hruby_low.rb', line 977 def has_inner? return !@inners.empty? end |
#has_program? ⇒ Boolean
Tells if there is any program.
867 868 869 |
# File 'lib/HDLRuby/hruby_low.rb', line 867 def has_program? return !@programs.empty? end |
#has_scope? ⇒ Boolean
Tells if there is any sub scope.
772 773 774 |
# File 'lib/HDLRuby/hruby_low.rb', line 772 def has_scope? return !@scopes.empty? end |
#has_signal? ⇒ Boolean
Tells if there is any signal, equivalent to has_inner?
982 983 984 |
# File 'lib/HDLRuby/hruby_low.rb', line 982 def has_signal? return self.has_inner? end |
#has_systemI? ⇒ Boolean
Tells if there is any system instance.
818 819 820 |
# File 'lib/HDLRuby/hruby_low.rb', line 818 def has_systemI? return !@systemIs.empty? end |
#has_systemT? ⇒ Boolean
Tells if there is any system instance.
655 656 657 |
# File 'lib/HDLRuby/hruby_low.rb', line 655 def has_systemT? return !@systemTs.empty? end |
#has_type? ⇒ Boolean
Tells if there is any system instance.
707 708 709 |
# File 'lib/HDLRuby/hruby_low.rb', line 707 def has_type? return !@types.empty? end |
#hash ⇒ Object
Hash function.
619 620 621 |
# File 'lib/HDLRuby/hruby_low.rb', line 619 def hash return [@systemTs,@types,@scopes,@inners,@systemIs,@connections,@behaviors].hash end |
#initial_concat_to_timed! ⇒ Object
Converts initial array of value of signals to assignment in timed blocks (for making the code compatible with verilog translation).
NOTE: Assumes such array as at the top level.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/HDLRuby/hruby_low_without_concat.rb', line 68 def initial_concat_to_timed! # Gather the signal with concat as initial values. sigs = [] # For the interface signals of the upper system. self.parent.each_signal do |sig| sigs << sig if sig.value.is_a?(Concat) end # For the inner signals of the scope. self.each_signal do |sig| sigs << sig if sig.value.is_a?(Concat) end # No initial concat? End here. return if sigs.empty? # Create a timed block for moving the concat initialization # to it. initial = TimeBlock.new(:seq) self.add_behavior(TimeBehavior.new(initial)) # Adds to it the initializations. sigs.each do |sig| name = sig.name styp = sig.type btyp = styp.base value = sig.value sig.value.each_expression.with_index do |expr,i| left = RefIndex.new(btyp, RefName.new(styp,RefThis.new,name), i.to_expr) initial.add_statement(Transmit.new(left,expr.clone)) end end # Remove the initial values from the signals. sigs.each do |sig| sig.set_value!(nil) end end |
#instance_port?(node) ⇒ Boolean
Tells if a +node+ is a reference to an instance's port.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/HDLRuby/hruby_low_with_port.rb', line 65 def instance_port?(node) # First the node must be a name reference. return false unless node.is_a?(RefName) # Then its sub ref must be a RefName of an instance. sub = node.ref return false unless sub.is_a?(RefName) # puts "@systemIs.keys=#{@systemIs.keys}" # System instance in current scope? return true if @systemIs.key?(sub.name) # if self.parent.is_a?(Scope) then # # Recurse the search in the parent. # return parent.instance_port?(node) # else # # No parent, failure. # return false # end return false end |
#last_behavior ⇒ Object
Returns the last behavior.
1137 1138 1139 |
# File 'lib/HDLRuby/hruby_low.rb', line 1137 def last_behavior return @behaviors[-1] end |
#make_portw(ref) ⇒ Object
Generates a port wire from a reference.
57 58 59 60 61 62 |
# File 'lib/HDLRuby/hruby_low_with_port.rb', line 57 def make_portw(ref) # First generates the name of the port. name = sym2portw_name(ref.to_sym) # Then generate the port wire. return SignalI.new(name,ref.type) end |
#map_behaviors!(&ruby_block) ⇒ Object
Maps on the behaviors.
148 149 150 151 152 153 154 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 148 def map_behaviors!(&ruby_block) @behaviors.map! do |behavior| behavior = ruby_block.call(behavior) behavior.parent = self unless behavior.parent behavior end end |
#map_connections!(&ruby_block) ⇒ Object
Maps on the connections.
139 140 141 142 143 144 145 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 139 def map_connections!(&ruby_block) @connections.map! do |connection| connection = ruby_block.call(connection) connection.parent = self unless connection.parent connection end end |
#map_inners!(&ruby_block) ⇒ Object
Maps on the inners.
121 122 123 124 125 126 127 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 121 def map_inners!(&ruby_block) @inners.map! do |inner| inner = ruby_block.call(inner) inner.parent = self unless inner.parent inner end end |
#map_scopes!(&ruby_block) ⇒ Object
Maps on the scopes.
112 113 114 115 116 117 118 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 112 def map_scopes!(&ruby_block) @scopes.map! do |scope| scope = ruby_block.call(scope) scope.parent = self unless scope.parent scope end end |
#map_systemIs!(&ruby_block) ⇒ Object
Maps on the systemIs.
130 131 132 133 134 135 136 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 130 def map_systemIs!(&ruby_block) @systemIs.map! do |systemI| systemI = ruby_block.call(systemI) systemI.parent = self unless systemI.parent systemI end end |
#map_systemTs!(&ruby_block) ⇒ Object
Maps on the local systemTs.
107 108 109 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 107 def map_systemTs!(&ruby_block) @systemTs.map(&ruby_block) end |
#map_types!(&ruby_block) ⇒ Object
Maps on the local types.
102 103 104 |
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 102 def map_types!(&ruby_block) @types.map(&ruby_block) end |
#mixblocks2seq! ⇒ Object
Converts the par sub blocks to seq if they are not full par.
48 49 50 51 |
# File 'lib/HDLRuby/hruby_low2seq.rb', line 48 def mixblocks2seq! # Recurse on the behaviors. self.each_behavior { |beh| beh.mixblocs2seq! } end |
#par_in_seq2seq! ⇒ Object
Converts par blocks within seq blocks to seq blocks.
32 33 34 35 36 37 38 39 |
# File 'lib/HDLRuby/hruby_low_without_parinseq.rb', line 32 def par_in_seq2seq! # Recruse on the sub scopes. self.each_scope(&:par_in_seq2seq!) # Recurse on the block. self.each_behavior do |behavior| behavior.block.par_in_seq2seq! end end |
#parent_system ⇒ Object
Gets the parent system, i.e., the parent of the top scope.
1345 1346 1347 |
# File 'lib/HDLRuby/hruby_low.rb', line 1345 def parent_system return self.top_scope.parent end |
#port_assign?(expr, systemI, signal) ⇒ Boolean
Tells if an expression is a reference to port +systemI.signal+.
410 411 412 413 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 410 def port_assign?(expr, systemI, signal) return expr.is_a?(RefName) && expr.name == signal.name && expr.ref.is_a?(RefName) && expr.ref.name == systemI.name end |
#portw2ref(portw) ⇒ Object
Converts a port wire to a reference to it.
40 41 42 |
# File 'lib/HDLRuby/hruby_low_with_port.rb', line 40 def portw2ref(portw) return RefName.new(portw.type,RefThis.new,portw.name) end |
#portw_name2sym(name) ⇒ Object
Converts a port wire +name+ to the symbol giving the corresponding HDLRuby reference.
52 53 54 |
# File 'lib/HDLRuby/hruby_low_with_port.rb', line 52 def portw_name2sym(name) return name[1..-1].to_sym end |
#replace_names!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared.
255 256 257 258 259 260 261 262 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 255 def replace_names!(former,nname) # Stop here if the name is redeclared. return if self.each_type.find {|type| type.name == former } return if self.each_systemT.find {|systemT| systemT.name == former } return if self.each_inner.find {|inner| inner.name == former } # Recurse on the internals. replace_names_subs!(former,nname) end |
#replace_names_subs!(former, nname) ⇒ Object
Replaces recursively +former+ name by +nname+ until it is redeclared in the internals.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 228 def replace_names_subs!(former,nname) # puts "replace_names_subs! for #{self} with former=#{former} and nname=#{nname}" # No need? # self.each_type do |type| # type.replace_names!(former,nname) # end self.each_systemT do |systemT| systemT.replace_names!(former,nname) end self.each_scope do |scope| scope.replace_names!(former,nname) end self.each_inner do |inner| inner.replace_names!(former,nname) end self.each_systemI do |systemI| systemI.replace_names!(former,nname) end self.each_connection do |connection| connection.replace_names!(former,nname) end self.each_behavior do |behavior| behavior.replace_names!(former,nname) end end |
#reverse_each_behavior(&ruby_block) ⇒ Object
Reverse iterates over the behaviors.
Returns an enumerator if no ruby block is given.
1129 1130 1131 1132 1133 1134 |
# File 'lib/HDLRuby/hruby_low.rb', line 1129 def reverse_each_behavior(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:reverse_each_behavior) unless ruby_block # A ruby block? Apply it on each behavior. @behaviors.reverse_each(&ruby_block) end |
#select2case! ⇒ Object
Converts the Select expressions to Case statements.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/HDLRuby/hruby_low_without_select.rb', line 72 def select2case! # Recruse on the sub scopes. self.each_scope(&:select2case!) # Recurse on the blocks. self.each_behavior do |behavior| behavior.block.each_block_deep(&:select2case!) end # Work on the connections. self.each_connection.to_a.each do |connection| selects = connection.extract_selects! if selects.any? then # Selects have been extract, replace the connection # by a behavior. # Generate the block with cases. blk = LowWithoutSelect.selects2block(selects) # Add a transmit replacing the connection. blk.add_statement( Transmit.new(connection.left.clone, connection.right.clone)) # Remove the connection and add a behavior instead. self.delete_connection!(connection) self.add_behavior(Behavior.new(blk)) end end end |
#signal2subs! ⇒ Object
Decompose the hierarchical signals in the statements.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/HDLRuby/hruby_low_without_subsignals.rb', line 47 def signal2subs! # Recruse on the sub scopes. self.each_scope(&:signal2subs!) # Recurse on the blocks. self.each_behavior do |behavior| # behavior.block.each_block_deep(&:signal2subs!) behavior.signal2subs! end # Work on the connections. self.each_connection.to_a.each do |connection| # Recurse on the left and right. connection.set_left!(connection.left.signal2subs!) connection.set_right!(connection.right.signal2subs!) end end |
#sym2portw_name(sym) ⇒ Object
Converts symbol +sym+ representing an HDLRuby reference to a instance port to a port wire.
46 47 48 |
# File 'lib/HDLRuby/hruby_low_with_port.rb', line 46 def sym2portw_name(sym) return ("^" + sym.to_s).to_sym 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)
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 411 def to_c(res,level = 0) # The resulting string. # res = "" # Declare the global variable holding the scope. res << "Scope " << Low2C.obj_name(self) << ";\n\n" # Generate the code makeing the complex sub components. # Generates the code for making signals if any. # self.each_signal { |signal| res << signal.to_c(level) } self.each_signal { |signal| signal.to_c(res,level) } # Generates the code for making signals if any. # self.each_systemI { |systemI| res << systemI.to_c(level) } self.each_systemI { |systemI| systemI.to_c(res,level) } # Generates the code for making sub scopes if any. # self.each_scope { |scope| res << scope.to_c(level) } self.each_scope { |scope| scope.to_c(res,level) } # Generate the code for making the behaviors. # self.each_behavior { |behavior| res << behavior.to_c(level) } self.each_behavior { |behavior| behavior.to_c(res,level) } # Generate the code for making the non-HDLRuby codes. # self.each_code { |code| res << code.to_c(level) } self.each_code { |code| code.to_c(res,level) } # Generate the code of the scope. # The header of the scope. res << " " * level*3 res << "Scope " << Low2C.make_name(self) << "() {\n" res << " " * (level+1)*3 res << "Scope scope = malloc(sizeof(ScopeS));\n" res << " " * (level+1)*3 res << "scope->kind = SCOPE;\n"; # Sets the global variable of the scope. res << "\n" res << " " * (level+1)*3 res << Low2C.obj_name(self) << " = scope;\n" # Set the owner if any. if self.parent then res << " " * (level+1)*3 res << "scope->owner = (Object)" res << Low2C.obj_name(self.parent) << ";\n" else res << "scope->owner = NULL;\n" end # The name res << " " * (level+1)*3 res << "scope->name = \"#{self.name}\";\n" # Add the system instances declaration. res << " " * (level+1)*3 res << "scope->num_systemIs = #{self.each_systemI.to_a.size};\n" res << " " * (level+1)*3 res << "scope->systemIs = calloc(sizeof(SystemI)," + "scope->num_systemIs);\n" self.each_systemI.with_index do |systemI,i| res << " " * (level+1)*3 res << "scope->systemIs[#{i}] = " res << Low2C.make_name(systemI) << "();\n" end # Add the inner signals declaration. res << " " * (level+1)*3 res << "scope->num_inners = #{self.each_inner.to_a.size};\n" res << " " * (level+1)*3 res << "scope->inners = calloc(sizeof(SignalI)," res << "scope->num_inners);\n" self.each_inner.with_index do |inner,i| res << " " * (level+1)*3 res << "scope->inners[#{i}] = " res << Low2C.make_name(inner) << "();\n" end # Add the sub scopes. res << " " * (level+1)*3 res << "scope->num_scopes = #{self.each_scope.to_a.size};\n" res << " " * (level+1)*3 res << "scope->scopes = calloc(sizeof(Scope)," res << "scope->num_scopes);\n" self.each_scope.with_index do |scope,i| res << " " * (level+1)*3 res << "scope->scopes[#{i}] = " res << Low2C.make_name(scope) << "();\n" end # Add the behaviors. res << " " * (level+1)*3 res << "scope->num_behaviors = #{self.each_behavior.to_a.size};\n" res << " " * (level+1)*3 res << "scope->behaviors = calloc(sizeof(Behavior)," res << "scope->num_behaviors);\n" self.each_behavior.with_index do |behavior,i| res << " " * (level+1)*3 res << "scope->behaviors[#{i}] = " res << Low2C.make_name(behavior) << "();\n" end # Add the non-HDLRuby codes. res << " " * (level+1)*3 res << "scope->num_codes = #{self.each_code.to_a.size};\n" res << " " * (level+1)*3 res << "scope->codes = calloc(sizeof(Code)," + "scope->num_codes);\n" self.each_code.with_index do |code,i| res << " " * (level+1)*3 res << "scope->codes[#{i}] = " res << Low2C.make_name(code) << "();\n" end # Generate the Returns of the result. res << "\n" res << " " * (level+1)*3 res << "return scope;\n" # Close the scope. res << " " * level*3 res << "}\n\n" return res end |
#to_ch(res) ⇒ Object
Generates the content of the h file. def to_ch
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/HDLRuby/hruby_low2c.rb', line 537 def to_ch(res) # res = "" # Declare the global variable holding the signal. res << "extern Scope " << Low2C.obj_name(self) << ";\n\n" # Generate the access to the function making the scope. res << "extern Scope " << Low2C.make_name(self) << "();\n\n" # Generate the accesses to the system instances. # self.each_systemI { |systemI| res << systemI.to_ch } self.each_systemI { |systemI| systemI.to_ch(res) } # Generate the accesses to the signals. # self.each_inner { |inner| res << inner.to_ch } self.each_inner { |inner| inner.to_ch(res) } # Generate the access to the sub scopes. # self.each_scope { |scope| res << scope.to_ch } self.each_scope { |scope| scope.to_ch(res) } # Generate the access to the behaviors. # self.each_behavior { |behavior| res << behavior.to_ch } self.each_behavior { |behavior| behavior.to_ch(res) } # Generate the access to the non-HDLRuby code. # self.each_behavior { |code| res << code.to_ch } self.each_behavior { |code| code.to_ch(res) } return res; end |
#to_hdr(level = 0, header = true) ⇒ Object
Generates the text of the equivalent hdr text. +level+ is the hierachical level of the object and +header+ tells if the header is to generate or not.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/HDLRuby/hruby_low2hdr.rb', line 111 def to_hdr(level = 0,header = true) # The resulting string. res = "" # Generate the header if required. if header then res << (" " * (level*3)) << "sub " unless self.name.empty? then res << ":" << Low2HDR.hdr_decl_name(self.name) << " " end res << "do\n" end level = level + 1 if header # Generate the sub types. # Assume the types are TypeDef. self.each_type do |type| res << " " * (level*3) res << "typedef :#{type.name} do\n" res << " " * ((level+1)*3) << type.def.to_hdr(level) res << " " * (level*3) << "end\n" end # Generaste the sub system types. self.each_systemT { |systemT| res << systemT.to_hdr(level) } # Generate the inners declaration. self.each_inner do |inner| res << " " * (level*3) res << inner.type.to_high(level) res << ".inner :" << Low2HDR.hdr_decl_name(inner.name) << "\n" end # Generate the instances. res << "\n" if self.each_inner.any? self.each_systemI do |systemI| res << " " * (level*3) res << systemI.to_hdr(level) << "\n" end # Generate the sub scopes. self.each_scope do |scope| res << scope.to_hdr(level) end # Generate the connections. res << "\n" if self.each_scope.any? self.each_connection do |connection| res << connection.to_hdr(level) end # Generate the behaviors. res << "\n" if self.each_connection.any? self.each_behavior do |behavior| res << behavior.to_hdr(level) end # Close the scope if required. if header then res << " " * ((level-1)*3) << "end\n" end # Return the result. return res end |
#to_high ⇒ Object
Creates a new high scope.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/HDLRuby/hruby_low2high.rb', line 36 def to_high # Create the high scope. res = new HDLRuby::High::Scope.new(self.name) # Add the local types. self.each_type { |t| res.add_type(t.to_high) } # Add the local system types. self.each_systemT { |s| res.add_systemT(s.to_high) } # Add the sub scopes. self.each_scope { |s| res.add_scope(s.to_high) } # Add the inner signals. self.each_inner { |i| res.add_inner(i.to_high) } # Add the system instances. self.each_systemI { |s| res.add_systemI(s.to_high) } # Add the non-HDLRuby cofe chunks. self.each_code { |c| res.add_code(c.to_high) } # Add the connections. self.each_connection { |c| res.add_connection(c.to_high) } # Add the behaviors. self.each_behavior { |b| res.add_behavior(b.to_high) } return res end |
#to_upper_space! ⇒ Object
Moves the declarations to the upper namespace.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/HDLRuby/hruby_low_without_namespace.rb', line 90 def to_upper_space! # puts "to_upper_space for scope=#{self}" # First recurse. # On the sub scopes. self.each_scope(&:to_upper_space!) # On the behaviors. self.each_behavior(&:to_upper_space!) # Then extract the declarations from the sub scope. decls = self.each_scope.map(&:extract_declares!) # And do the same with the behaviors'. decls << self.each_behavior.map(&:extract_declares!) # Reinsert the extracted declares to self. decls.flatten.each do |decl| if decl.is_a?(Type) then self.add_type(decl) elsif decl.is_a?(SystemT) then self.add_systemT(decl) elsif decl.is_a?(SignalI) then self.add_inner(decl) elsif decl.is_a?(SystemI) then self.add_systemI(decl) else raise AnyError, "Internal error: invalid class for a declaration: #{decl.class}" end end # Extract the behaviors of the sub scopes. behs = self.each_scope.map(&:extract_behaviors!).flatten # Reinsert them to self. behs.each { |beh| self.add_behavior(beh) } # Extract the connections of the sub scopes. cnxs = self.each_scope.map(&:extract_connections!).flatten # Reinsert them to self. cnxs.each { |cnx| self.add_connection(cnx) } # The fix the RefName using sub scopes since their target have # been deplaced to current scope and renamed. self_scopes = self.each_scope.to_a self.each_behavior { |beh| beh.fix_scope_refnames!(self_scopes) } self.each_connection { |cnx| cnx.fix_scope_refnames!(self_scopes) } # Now can delete the sub scopes since they are empty. # self.each_scope.to_a.each { |scope| self.delete_scope!(scope) } self_scopes.each { |scope| self.delete_scope!(scope) } end |
#to_vhdl(level = 0) ⇒ Object
Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object and
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 443 def to_vhdl(level = 0) # The resulting string. res = "" # Generate the architecture's header # The instances' headers self.each_systemI do |systemI| systemT = systemI.systemT # Its entity res << (" " * level*3) res << "component #{Low2VHDL.entity_name(systemT.name)}\n" res << (" " * (level+1)*3) # Its ports res << "port(\n" # Inputs systemT.each_input do |input| res << " " * ((level+2)*3) res << Low2VHDL.vhdl_name(input.name) << ": in " res << input.type.to_vhdl << ";\n" end # Outputs systemT.each_output do |output| res << " " * ((level+2)*3) res << Low2VHDL.vhdl_name(output.name) << ": out " res << output.type.to_vhdl << ";\n" end # Inouts systemT.each_inout do |inout| res << " " * ((level+2)*3) res << Low2VHDL.vhdl_name(inout.name) << ": inout " res << inout.type.to_vhdl << ";\n" end # Remove the last ";" for conforming with VHDL syntax. res[-2..-1] = "\n" if res[-2] == ";" res << " " * ((level+1)*3) # Close the port declaration. res << ");\n" # Close the component. res << " " * (level*3) res << "end component;\n\n" end # Generate the architecture's type definition. # It is assumed that these types are all TypeDef. self.each_type do |type| res << (" " * level*3) res << "type #{Low2VHDL.vhdl_name(type.name)} is " res << type.def.to_vhdl(level+1) res << ";\n" end ## Generates the required mux functions. mtps = [] # The mux functions to generate by type. # Gather the mux functions to generate. self.each_scope_deep do |scope| # Checks the connections. scope.each_connection do |connection| connection.right.each_node_deep do |node| if node.is_a?(Select) then mtps << [node.type,node.each_choice.to_a.size] end end end # Checks the statements. scope.each_behavior do |behavior| behavior.block.each_node_deep do |node| if node.is_a?(Select) then mtps << [node.type,node.each_choice.to_a.size] end end end end # Generate the gathered functions (only one per type). mtps.uniq! mtps.each do |type,num| res << Low2VHDL.mux_function(type,num," " * level*3) end # Generate the inner signals declaration. self.each_inner do |inner| res << " " * (level * 3) # General signal or constant signal? res << (inner.is_a?(SignalC) ? "constant " : "signal ") # Signal name. res << Low2VHDL.vhdl_name(inner.name) << ": " # Signal type. res << inner.type.to_vhdl(level) # Signal value. if inner.value then if inner.value.is_a?(Concat) then # Concat are to be given the expected type of the # elements for casting them equally. # res << " := " << inner.value.to_vhdl(inner.type.base,level) res << " := " << inner.value.to_vhdl(level,inner.type.base) else res << " := " << inner.value.to_vhdl(level) end end res << ";\n" end # Generate the architecture's content. res << " " * ((level-1)*3) << "begin\n" # Generate the instances connections. self.each_systemI do |systemI| # Its Declaration. res << " " * (level*3) res << Low2VHDL.vhdl_name(systemI.name) << ": " systemT = systemI.systemT res << Low2VHDL.entity_name(systemT.name).to_s << "\n" res << " " * ((level+1)*3) # Its ports res << "port map(\n" # Inputs systemT.each_input do |input| ref = self.extract_port_assign!(systemI,input) if ref then res << " " * ((level+2)*3) res << Low2VHDL.vhdl_name(input.name) << " => " res << ref.to_vhdl(level) res << ",\n" end end # Outputs systemT.each_output do |output| ref = self.extract_port_assign!(systemI,output) if ref then res << " " * ((level+2)*3) res << Low2VHDL.vhdl_name(output.name) << " => " res << ref.to_vhdl(level) res << ",\n" end end # Inouts systemT.each_inout do |inout| ref = self.extract_port_assign!(systemI,inout) if ref then res << " " * ((level+2)*3) res << Low2VHDL.vhdl_name(inout.name) << " => " res << ref.to_vhdl(level) res << ",\n" end end # Remove the last ";" for conforming with VHDL syntax. res[-2..-1] = "\n" if res[-2] == "," # Close the port map declaration. res << " " * ((level+1)*3) res << ");\n" end # Generate the connections. res << "\n" if self.each_scope.any? self.each_scope_deep do |scope| scope.each_connection do |connection| res << connection.to_vhdl([],level) end end # Generate the behaviors. # Current scope's res << "\n" if self.each_connection.any? self.each_scope_deep do |scope| scope.each_behavior do |behavior| res << behavior.to_vhdl(level) end end return res end |
#to_viz(world, regs, ports, links, rname = "") ⇒ Object
Converts the scope to a Viz struture inside +world+, updating the table of ports +ports+, the table of registers +regs+ and explicit port connections +links+ with root name +rname+.
4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 |
# File 'lib/HDLRuby/hruby_viz.rb', line 4468 def to_viz(world, regs, ports, links, rname = "") # If it is a sub scope: # Compute the name of the scope which will be used as prefix. if self.parent.is_a?(HDLRuby::Low::Scope) then sname = self.name.empty? ? "" : self.name.to_s + "." sname = rname + sname # Add the root name. else sname = "" end # Adds the inner as "registers" with input and output ports # of identical name. self.each_inner do |inner| typ = inner.type typ = typ.def while typ.is_a?(HDLRuby::Low::TypeDef) # name = sname + inner.name.to_s # name = inner.name.to_s name = sname + inner.name.to_s # Create the viz for the "register" if typ.is_a?(HDLRuby::Low::TypeVector) and typ.base.width > 1 then puts "Adding scope register #{name} to #{world.name}" # This is in fact a memory matrix. reg = HDLRuby::Viz::IC.new(name,:memory,world) else puts "Adding plain register #{name} to #{world.name}" # This is a plain register. reg = HDLRuby::Viz::IC.new(name,:register,world) end regs[reg.name] = reg # Create the corresponding input and output ports. iname = HDLRuby::Viz.reg2input_name(name) puts "Adding input port #{iname} to reg #{reg.name}" ports[iname] << reg.add_port(iname,:input) oname = HDLRuby::Viz.reg2output_name(name) puts "Adding output port #{oname} to reg #{reg.name}" ports[oname] << reg.add_port(oname,:output) if typ.is_a?(HDLRuby::Low::TypeStruct) then # Add ports for each sub type. typ.each do |sub,styp| isname = HDLRuby::Viz.reg2input_name(name + "." + sub.to_s) puts "Adding input sub port #{isname} to reg #{reg.name}" ports[isname] << reg.add_port(isname,:input) osname = HDLRuby::Viz.reg2output_name(name + "." + sub.to_s) puts "Adding output sub port #{osname} to reg #{reg.name}" ports[osname] << reg.add_port(osname,:output) end end end # Adds the instances. self.each_systemI do |instance| # Create the viz for the systemT it is instantiating. sys_viz = instance.systemT.to_viz # Create the viz for the instance. # ic = HDLRuby::Viz::IC.new(instance.name.to_s,:instance,world,sys_viz) ic = HDLRuby::Viz::IC.new(sname + instance.name.to_s,:instance,world,sys_viz) # And adds its ports. instance.each_input do |port| name = ic.name + "." + port.name.to_s puts "Adding input port #{name} to #{ic.name}" ports[name] << ic.add_port(name, :input) end instance.each_output do |port| name = ic.name + "." + port.name.to_s puts "Adding output port #{name} to #{ic.name}" ports[name] << ic.add_port(port.name, :output) end instance.each_inout do |port| name = ic.name + "." + port.name.to_s puts "Adding inout port #{name} to #{ic.name}" ports[name] << ic.add_port(port.name, :inout) end end # Adds its connections with expressions, # they will also be considered as inner ICs. # For the other connections, register then a explicit port # connections. self.each_connection do |connection| if connection.right.is_a?(HDLRuby::Low::RefName) then # Explicit port connect case. links << [ connection.left.to_viz_names[0], connection.right.to_viz_names[0] ] # # Get the right refered name. # rname = connection.right.to_viz_names[0] # # If it is a register make the name its output. # rname = HDLRuby::Viz.reg2output_name(rname) if regs[rname] # # Get the left refered name. # lname = connection.left.to_viz_names[0] # # If it is a register make the name its input. # lname = HDLRuby::Viz.reg2input_name(lname) if regs[lname] # # Make the explicit port connect. # links << [ lname, rname ] # Add the explicit port connection. puts "added link between #{links[-1][0]} and #{links[-1][1]}" next end ic = HDLRuby::Viz::IC.new(HDLRuby.uniq_name("cxn"),:assign,world) # Add its ports. # Output. name = connection.left.to_viz_names[0] puts "Adding output port #{name} to #{ic.name}" ports[name] << ic.add_port(name, :output) unless ic.port?(name) # Inputs. connection.right.to_viz_names.each do |name| puts "Adding input port #{name} to #{ic.name}" ports[name] << ic.add_port(name, :input) unless ic.port?(name) end # Create its control flow. connection.to_viz_node(ic) end # Adds its behaviors, they will also be considered as inner ICs. self.each_behavior do |behavior| bname = HDLRuby.uniq_name("proc").to_s # Is it a clocked process. if (behavior.each_event.any? { |ev| ev.on_edge? }) then # Yes. ic = HDLRuby::Viz::IC.new(bname,:clocked_process,world) # No, is it a timed process. elsif behavior.block.is_a?(HDLRuby::Low::TimeBlock) # Yes ic = HDLRuby::Viz::IC.new(bname,:timed_process,world) else # No, use a standard process type. ic = HDLRuby::Viz::IC.new(bname,:process,world) end # Add its ports. # For the events. behavior.each_event do |ev| name = ev.ref.to_viz_names[0] next if ic.port?(name) # The port has already been added. # Is it a clocked event? if ev.on_edge? then # Yes. ports[name] << ic.add_port(name, :input, ev.type) else # No, use a standard port. ports[name] << ic.add_port(name, :input) end end # Recurse on its blocks. # behavior.block.to_viz(world,ic,ports) behavior.block.to_viz(world,ic,regs,ports) end # Recurse on the sub scopes. # self.each_scope {|scope| scope.to_viz(world,regs,ports,scope.name.to_s) } self.each_scope {|scope| scope.to_viz(world,regs,ports,sname) } # Return the world, not necessary but is more coherent. return world end |
#top_scope ⇒ Object
Gets the top scope, i.e. the first scope of the current system.
1340 1341 1342 |
# File 'lib/HDLRuby/hruby_low.rb', line 1340 def top_scope return self.parent.is_a?(SystemT) ? self : self.parent.top_scope end |
#with_port! ⇒ Object
Converts to a port-compatible system.
NOTE: the result is the same scope.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/HDLRuby/hruby_low_with_port.rb', line 88 def with_port! # # Recurse on the sub scope. # self.each_scope(&:with_port!) # Gather the references to instance ports. # Also remember if the references were left values or not. # And remember where the node was. refs = [] ref_sym2leftvalue = {} # ref_parents = Set.new ref_parents = [] self.each_block_deep do |block| block.each_node_deep do |node| if instance_port?(node) then # puts "port for node: #{node.ref.name}.#{node.name}" refs << node ref_sym2leftvalue[node.to_sym] = node.leftvalue? ref_parents << node.parent # ref_parents[node.parent] = node end end end self.each_connection do |connection| connection.each_node_deep do |node| if instance_port?(node) then # puts "port for node: #{node.ref.name}.#{node.name}" # puts "leftvalue? #{node.leftvalue?}" refs << node ref_sym2leftvalue[node.to_sym] = node.leftvalue? ref_parents << node.parent # ref_parents[node.parent] = node end end end # Generate the port wire from the refs. ref_sym2portw = {} refs.each { |ref| ref_sym2portw[ref.to_sym] = make_portw(ref) } # Declare the port wires. ref_sym2portw.each_value { |portw| self.add_inner(portw.clone) } # Replace the references by their corresponding port wires. self.each_block_deep do |block| block.each_node_deep do |node| if ref_parents.include?(node) then node.map_nodes! do |expr| next expr unless instance_port?(expr) portw = ref_sym2portw[expr.to_sym] portw ? portw2ref(portw) : expr end end end end self.each_connection do |connection| connection.each_node_deep do |node| if ref_parents.include?(node) then node.map_nodes! do |expr| next expr unless instance_port?(expr) portw = ref_sym2portw[expr.to_sym] portw ? portw2ref(portw) : expr end end end end # Finally adds the connections with the port wires. ref_sym2portw.each do |sym,portw| ref = sym.to_hdr if ref_sym2leftvalue[sym] then # The reference was a left value, assign the port wire # to the ref. self.add_connection( Connection.new(ref.clone,portw2ref(portw)) ) else # The reference was a right value, assign it to the # port wire. self.add_connection( Connection.new(portw2ref(portw),ref.clone) ) end end return self end |