HDLRuby 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +5 -0
  4. data/.yardopts +1 -0
  5. data/Gemfile +4 -0
  6. data/HDLRuby.gemspec +36 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +2774 -0
  9. data/README.pdf +0 -0
  10. data/Rakefile +10 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/exe/hdrcc +3 -0
  14. data/lib/HDLRuby/alcc.rb +137 -0
  15. data/lib/HDLRuby/backend/hruby_allocator.rb +69 -0
  16. data/lib/HDLRuby/backend/hruby_c_allocator.rb +76 -0
  17. data/lib/HDLRuby/hdr_samples/adder.rb +7 -0
  18. data/lib/HDLRuby/hdr_samples/adder_assign_error.rb +11 -0
  19. data/lib/HDLRuby/hdr_samples/adder_bench.rb +27 -0
  20. data/lib/HDLRuby/hdr_samples/adder_gen.rb +7 -0
  21. data/lib/HDLRuby/hdr_samples/adder_nodef_error.rb +7 -0
  22. data/lib/HDLRuby/hdr_samples/addsub.rb +19 -0
  23. data/lib/HDLRuby/hdr_samples/addsubz.rb +22 -0
  24. data/lib/HDLRuby/hdr_samples/alu.rb +47 -0
  25. data/lib/HDLRuby/hdr_samples/calculator.rb +48 -0
  26. data/lib/HDLRuby/hdr_samples/counter_bench.rb +83 -0
  27. data/lib/HDLRuby/hdr_samples/dff.rb +9 -0
  28. data/lib/HDLRuby/hdr_samples/dff_bench.rb +66 -0
  29. data/lib/HDLRuby/hdr_samples/dff_counter.rb +20 -0
  30. data/lib/HDLRuby/hdr_samples/include.rb +14 -0
  31. data/lib/HDLRuby/hdr_samples/instance_open.rb +23 -0
  32. data/lib/HDLRuby/hdr_samples/mei8.rb +256 -0
  33. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +309 -0
  34. data/lib/HDLRuby/hdr_samples/multer_gen.rb +8 -0
  35. data/lib/HDLRuby/hdr_samples/multer_seq.rb +29 -0
  36. data/lib/HDLRuby/hdr_samples/neural/a.rb +9 -0
  37. data/lib/HDLRuby/hdr_samples/neural/a_sub.rb +5 -0
  38. data/lib/HDLRuby/hdr_samples/neural/bw.rb +23 -0
  39. data/lib/HDLRuby/hdr_samples/neural/counter.rb +16 -0
  40. data/lib/HDLRuby/hdr_samples/neural/dadz.rb +9 -0
  41. data/lib/HDLRuby/hdr_samples/neural/dadz_sub.rb +4 -0
  42. data/lib/HDLRuby/hdr_samples/neural/forward.rb +153 -0
  43. data/lib/HDLRuby/hdr_samples/neural/forward_sub.rb +62 -0
  44. data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand.rb +41 -0
  45. data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand_typedef.rb +47 -0
  46. data/lib/HDLRuby/hdr_samples/neural/mem.rb +30 -0
  47. data/lib/HDLRuby/hdr_samples/neural/random.rb +23 -0
  48. data/lib/HDLRuby/hdr_samples/neural/selector.rb +29 -0
  49. data/lib/HDLRuby/hdr_samples/neural/sigmoid.rb +20 -0
  50. data/lib/HDLRuby/hdr_samples/neural/z.rb +33 -0
  51. data/lib/HDLRuby/hdr_samples/prog.obj +256 -0
  52. data/lib/HDLRuby/hdr_samples/ram.rb +18 -0
  53. data/lib/HDLRuby/hdr_samples/register_with_code_bench.rb +98 -0
  54. data/lib/HDLRuby/hdr_samples/rom.rb +10 -0
  55. data/lib/HDLRuby/hdr_samples/struct.rb +14 -0
  56. data/lib/HDLRuby/hdr_samples/sumprod.rb +29 -0
  57. data/lib/HDLRuby/hdr_samples/sw_encrypt_bench.rb +103 -0
  58. data/lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb +261 -0
  59. data/lib/HDLRuby/hdr_samples/sw_encrypt_cpusim_bench.rb +302 -0
  60. data/lib/HDLRuby/hdr_samples/system_open.rb +11 -0
  61. data/lib/HDLRuby/hdr_samples/tuple.rb +16 -0
  62. data/lib/HDLRuby/hdr_samples/with_channel.rb +118 -0
  63. data/lib/HDLRuby/hdr_samples/with_class.rb +199 -0
  64. data/lib/HDLRuby/hdr_samples/with_decoder.rb +17 -0
  65. data/lib/HDLRuby/hdr_samples/with_fsm.rb +34 -0
  66. data/lib/HDLRuby/hdr_samples/with_reconf.rb +103 -0
  67. data/lib/HDLRuby/hdrcc.rb +623 -0
  68. data/lib/HDLRuby/high_samples/_adder_fault.rb +23 -0
  69. data/lib/HDLRuby/high_samples/_generic_transmission2.rb +146 -0
  70. data/lib/HDLRuby/high_samples/adder.rb +21 -0
  71. data/lib/HDLRuby/high_samples/adder_common_errors.rb +25 -0
  72. data/lib/HDLRuby/high_samples/addsub.rb +33 -0
  73. data/lib/HDLRuby/high_samples/addsubz.rb +37 -0
  74. data/lib/HDLRuby/high_samples/after.rb +28 -0
  75. data/lib/HDLRuby/high_samples/all_signals.rb +29 -0
  76. data/lib/HDLRuby/high_samples/alu.rb +61 -0
  77. data/lib/HDLRuby/high_samples/anonymous.rb +41 -0
  78. data/lib/HDLRuby/high_samples/before.rb +28 -0
  79. data/lib/HDLRuby/high_samples/blockblock.rb +26 -0
  80. data/lib/HDLRuby/high_samples/bugs/dadz.rb +22 -0
  81. data/lib/HDLRuby/high_samples/bugs/misample_instan.rb +20 -0
  82. data/lib/HDLRuby/high_samples/bugs/misample_updown.rb +22 -0
  83. data/lib/HDLRuby/high_samples/bugs/sample_add.rb +16 -0
  84. data/lib/HDLRuby/high_samples/bugs/sample_barrel.rb +13 -0
  85. data/lib/HDLRuby/high_samples/bugs/sample_daice.rb +57 -0
  86. data/lib/HDLRuby/high_samples/bugs/sample_kumiawase.rb +52 -0
  87. data/lib/HDLRuby/high_samples/bugs/sample_multi.rb +18 -0
  88. data/lib/HDLRuby/high_samples/bugs/sample_sub.rb +14 -0
  89. data/lib/HDLRuby/high_samples/bugs/z2.rb +32 -0
  90. data/lib/HDLRuby/high_samples/case.rb +32 -0
  91. data/lib/HDLRuby/high_samples/case2.rb +30 -0
  92. data/lib/HDLRuby/high_samples/change.rb +23 -0
  93. data/lib/HDLRuby/high_samples/clocks.rb +35 -0
  94. data/lib/HDLRuby/high_samples/comparer.rb +21 -0
  95. data/lib/HDLRuby/high_samples/conditionals.rb +29 -0
  96. data/lib/HDLRuby/high_samples/dff.rb +23 -0
  97. data/lib/HDLRuby/high_samples/each.rb +28 -0
  98. data/lib/HDLRuby/high_samples/exporter.rb +42 -0
  99. data/lib/HDLRuby/high_samples/functions.rb +60 -0
  100. data/lib/HDLRuby/high_samples/if_seq.rb +26 -0
  101. data/lib/HDLRuby/high_samples/inherit_as_dff.rb +32 -0
  102. data/lib/HDLRuby/high_samples/inherit_dff.rb +36 -0
  103. data/lib/HDLRuby/high_samples/instance.rb +37 -0
  104. data/lib/HDLRuby/high_samples/memory.rb +64 -0
  105. data/lib/HDLRuby/high_samples/multi_file.rb +27 -0
  106. data/lib/HDLRuby/high_samples/overload.rb +32 -0
  107. data/lib/HDLRuby/high_samples/paper_after.rb +49 -0
  108. data/lib/HDLRuby/high_samples/ram.rb +27 -0
  109. data/lib/HDLRuby/high_samples/registers.rb +139 -0
  110. data/lib/HDLRuby/high_samples/rom.rb +23 -0
  111. data/lib/HDLRuby/high_samples/scopeblockname.rb +37 -0
  112. data/lib/HDLRuby/high_samples/scopescope.rb +26 -0
  113. data/lib/HDLRuby/high_samples/shift.rb +31 -0
  114. data/lib/HDLRuby/high_samples/shift2.rb +40 -0
  115. data/lib/HDLRuby/high_samples/simple_instance.rb +31 -0
  116. data/lib/HDLRuby/high_samples/test_all.sh +10 -0
  117. data/lib/HDLRuby/high_samples/typedef.rb +24 -0
  118. data/lib/HDLRuby/high_samples/values.rb +70 -0
  119. data/lib/HDLRuby/high_samples/vector.rb +22 -0
  120. data/lib/HDLRuby/high_samples/with_decoder.rb +30 -0
  121. data/lib/HDLRuby/high_samples/with_fsm.rb +46 -0
  122. data/lib/HDLRuby/high_samples/with_pipe.rb +43 -0
  123. data/lib/HDLRuby/high_samples/with_seq.rb +25 -0
  124. data/lib/HDLRuby/hruby_bstr.rb +1085 -0
  125. data/lib/HDLRuby/hruby_check.rb +317 -0
  126. data/lib/HDLRuby/hruby_db.rb +432 -0
  127. data/lib/HDLRuby/hruby_error.rb +44 -0
  128. data/lib/HDLRuby/hruby_high.rb +4103 -0
  129. data/lib/HDLRuby/hruby_low.rb +4735 -0
  130. data/lib/HDLRuby/hruby_low2c.rb +1986 -0
  131. data/lib/HDLRuby/hruby_low2high.rb +738 -0
  132. data/lib/HDLRuby/hruby_low2seq.rb +248 -0
  133. data/lib/HDLRuby/hruby_low2sym.rb +126 -0
  134. data/lib/HDLRuby/hruby_low2vhd.rb +1437 -0
  135. data/lib/HDLRuby/hruby_low_bool2select.rb +295 -0
  136. data/lib/HDLRuby/hruby_low_cleanup.rb +193 -0
  137. data/lib/HDLRuby/hruby_low_fix_types.rb +437 -0
  138. data/lib/HDLRuby/hruby_low_mutable.rb +1803 -0
  139. data/lib/HDLRuby/hruby_low_resolve.rb +165 -0
  140. data/lib/HDLRuby/hruby_low_skeleton.rb +129 -0
  141. data/lib/HDLRuby/hruby_low_with_bool.rb +141 -0
  142. data/lib/HDLRuby/hruby_low_with_port.rb +167 -0
  143. data/lib/HDLRuby/hruby_low_with_var.rb +302 -0
  144. data/lib/HDLRuby/hruby_low_without_bit2vector.rb +88 -0
  145. data/lib/HDLRuby/hruby_low_without_concat.rb +162 -0
  146. data/lib/HDLRuby/hruby_low_without_connection.rb +113 -0
  147. data/lib/HDLRuby/hruby_low_without_namespace.rb +718 -0
  148. data/lib/HDLRuby/hruby_low_without_outread.rb +107 -0
  149. data/lib/HDLRuby/hruby_low_without_select.rb +206 -0
  150. data/lib/HDLRuby/hruby_serializer.rb +398 -0
  151. data/lib/HDLRuby/hruby_tools.rb +37 -0
  152. data/lib/HDLRuby/hruby_types.rb +239 -0
  153. data/lib/HDLRuby/hruby_values.rb +64 -0
  154. data/lib/HDLRuby/hruby_verilog.rb +1888 -0
  155. data/lib/HDLRuby/hruby_verilog_name.rb +52 -0
  156. data/lib/HDLRuby/low_samples/adder.yaml +97 -0
  157. data/lib/HDLRuby/low_samples/after.yaml +228 -0
  158. data/lib/HDLRuby/low_samples/before.yaml +223 -0
  159. data/lib/HDLRuby/low_samples/blockblock.yaml +48 -0
  160. data/lib/HDLRuby/low_samples/bugs/sample_add.yaml +97 -0
  161. data/lib/HDLRuby/low_samples/bugs/sample_daice.yaml +444 -0
  162. data/lib/HDLRuby/low_samples/bugs/sample_kumiawase.yaml +332 -0
  163. data/lib/HDLRuby/low_samples/bugs/sample_sub.yaml +97 -0
  164. data/lib/HDLRuby/low_samples/bugs/seqpar.yaml +184 -0
  165. data/lib/HDLRuby/low_samples/case.yaml +327 -0
  166. data/lib/HDLRuby/low_samples/change.yaml +135 -0
  167. data/lib/HDLRuby/low_samples/clocks.yaml +674 -0
  168. data/lib/HDLRuby/low_samples/cloner.rb +22 -0
  169. data/lib/HDLRuby/low_samples/comparer.yaml +85 -0
  170. data/lib/HDLRuby/low_samples/conditionals.yaml +133 -0
  171. data/lib/HDLRuby/low_samples/dff.yaml +107 -0
  172. data/lib/HDLRuby/low_samples/each.yaml +1328 -0
  173. data/lib/HDLRuby/low_samples/exporter.yaml +226 -0
  174. data/lib/HDLRuby/low_samples/functions.yaml +298 -0
  175. data/lib/HDLRuby/low_samples/generic_transmission.yaml +597 -0
  176. data/lib/HDLRuby/low_samples/inherit_as_dff.yaml +125 -0
  177. data/lib/HDLRuby/low_samples/inherit_dff.yaml +107 -0
  178. data/lib/HDLRuby/low_samples/load_yaml.rb +11 -0
  179. data/lib/HDLRuby/low_samples/memory.yaml +678 -0
  180. data/lib/HDLRuby/low_samples/namespace_extractor.rb +23 -0
  181. data/lib/HDLRuby/low_samples/overload.yaml +226 -0
  182. data/lib/HDLRuby/low_samples/paper_after.yaml +431 -0
  183. data/lib/HDLRuby/low_samples/port_maker.rb +14 -0
  184. data/lib/HDLRuby/low_samples/ram.yaml +207 -0
  185. data/lib/HDLRuby/low_samples/registers.yaml +228 -0
  186. data/lib/HDLRuby/low_samples/rom.yaml +2950 -0
  187. data/lib/HDLRuby/low_samples/shift.yaml +230 -0
  188. data/lib/HDLRuby/low_samples/shift2.yaml +2095 -0
  189. data/lib/HDLRuby/low_samples/simple_instance.yaml +102 -0
  190. data/lib/HDLRuby/low_samples/test_all.sh +43 -0
  191. data/lib/HDLRuby/low_samples/typedef.yaml +115 -0
  192. data/lib/HDLRuby/low_samples/values.yaml +577 -0
  193. data/lib/HDLRuby/low_samples/variable_maker.rb +14 -0
  194. data/lib/HDLRuby/low_samples/vector.yaml +56 -0
  195. data/lib/HDLRuby/low_samples/with_seq.yaml +188 -0
  196. data/lib/HDLRuby/low_samples/yaml2hdr.rb +10 -0
  197. data/lib/HDLRuby/low_samples/yaml2vhd.rb +19 -0
  198. data/lib/HDLRuby/sim/Makefile +19 -0
  199. data/lib/HDLRuby/sim/hruby_sim.h +590 -0
  200. data/lib/HDLRuby/sim/hruby_sim_calc.c +2362 -0
  201. data/lib/HDLRuby/sim/hruby_sim_core.c +589 -0
  202. data/lib/HDLRuby/sim/hruby_sim_list.c +93 -0
  203. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +91 -0
  204. data/lib/HDLRuby/sim/hruby_value_pool.c +64 -0
  205. data/lib/HDLRuby/std/channel.rb +354 -0
  206. data/lib/HDLRuby/std/clocks.rb +165 -0
  207. data/lib/HDLRuby/std/counters.rb +82 -0
  208. data/lib/HDLRuby/std/decoder.rb +214 -0
  209. data/lib/HDLRuby/std/fsm.rb +516 -0
  210. data/lib/HDLRuby/std/pipeline.rb +220 -0
  211. data/lib/HDLRuby/std/reconf.rb +309 -0
  212. data/lib/HDLRuby/test_hruby_bstr.rb +2259 -0
  213. data/lib/HDLRuby/test_hruby_high.rb +594 -0
  214. data/lib/HDLRuby/test_hruby_high_low.rb +99 -0
  215. data/lib/HDLRuby/test_hruby_low.rb +934 -0
  216. data/lib/HDLRuby/v_samples/adder.v +10 -0
  217. data/lib/HDLRuby/v_samples/dff.v +12 -0
  218. data/lib/HDLRuby/v_samples/ram.v +20 -0
  219. data/lib/HDLRuby/v_samples/rom.v +270 -0
  220. data/lib/HDLRuby/version.rb +3 -0
  221. data/lib/HDLRuby.rb +11 -0
  222. data/makedoc +1 -0
  223. data/metadata.yaml +4 -0
  224. metadata +299 -0
@@ -0,0 +1,718 @@
1
+ require 'HDLRuby'
2
+ require 'HDLRuby/hruby_tools'
3
+ require 'HDLRuby/hruby_low_mutable'
4
+
5
+
6
+ module HDLRuby::Low
7
+
8
+
9
+ ##
10
+ # Moves the declarations to the upper namespace.
11
+ # Makes conversion to other languages easier since no namespace processing
12
+ # is required.
13
+ #
14
+ ########################################################################
15
+
16
+ ## Module allowing to force a name to a HDLRuby::Low object.
17
+ module ForceName
18
+
19
+ # Sets a name if there is no name.
20
+ def force_name!
21
+ @name = HDLRuby.uniq_name if self.name.empty?
22
+ end
23
+
24
+ # Extends the name of object +obj+ with current's one.
25
+ def extend_name!(obj)
26
+ obj.set_name!((self.name.to_s + "::" + obj.name.to_s).to_sym)
27
+ end
28
+ end
29
+
30
+ ## Extends the SystemT class with functionality for moving the declarations
31
+ # to the upper namespace.
32
+ class SystemT
33
+
34
+ include ForceName
35
+
36
+ # Moves the declarations to the upper namespace.
37
+ def to_upper_space!
38
+ self.scope.to_upper_space!
39
+ end
40
+
41
+ # Moves local systemTs to global.
42
+ #
43
+ # NOTE: assumes to_upper_space! has been called.
44
+ def to_global_systemTs!
45
+ # Force a name if not.
46
+ self.force_name!
47
+ # For each local systemT
48
+ self.scope.each_systemT.to_a.each do |systemT|
49
+ # Rename it for globalization.
50
+ former = systemT.name
51
+ self.extend_name!(systemT)
52
+ # Apply the renaming to all the inner objects.
53
+ self.scope.replace_names_subs!(former,systemT.name)
54
+ # Remove it.
55
+ self.scope.delete_systemT!(systemT)
56
+ end
57
+ end
58
+
59
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
60
+ def replace_names!(former,nname)
61
+ # Replace owns name if required.
62
+ if self.name == former then
63
+ self.set_name!(nname)
64
+ end
65
+ # Recurse on the interface.
66
+ self.each_input {|input| input.replace_names!(former,nname) }
67
+ self.each_output {|output| output.replace_names!(former,nname) }
68
+ self.each_inout {|inout| inout.replace_names!(former,nname) }
69
+ # Recurse on the scope.
70
+ self.scope.replace_names!(former,nname)
71
+ end
72
+
73
+ # Breaks the hierarchical types into sequences of type definitions.
74
+ def break_types!
75
+ self.scope.break_types!
76
+ end
77
+ end
78
+
79
+ ## Extends the Scope class with functionality for moving the declarations
80
+ # to the upper namespace.
81
+ class Scope
82
+
83
+ include ForceName
84
+
85
+ # Moves the declarations to the upper namespace.
86
+ def to_upper_space!
87
+ # First recurse.
88
+ # On the sub scopes.
89
+ self.each_scope(&:to_upper_space!)
90
+ # On the behaviors.
91
+ self.each_behavior(&:to_upper_space!)
92
+
93
+ # Then extract the declarations from the sub scope.
94
+ decls = self.each_scope.map(&:extract_declares!)
95
+ # And do the same with the behaviors'.
96
+ decls << self.each_behavior.map(&:extract_declares!)
97
+
98
+ # Reinsert the extracted declares to self.
99
+ decls.flatten.each do |decl|
100
+ if decl.is_a?(Type) then
101
+ self.add_type(decl)
102
+ elsif decl.is_a?(SystemT) then
103
+ self.add_systemT(decl)
104
+ elsif decl.is_a?(SignalI) then
105
+ self.add_inner(decl)
106
+ elsif decl.is_a?(SystemI) then
107
+ self.add_systemI(decl)
108
+ else
109
+ raise AnyError, "Internal error: invalid class for a declaration: #{decl.class}"
110
+ end
111
+ end
112
+
113
+ # Extract the behaviors of the sub scopes.
114
+ behs = self.each_scope.map(&:extract_behaviors!).flatten
115
+ # Reinsert them to self.
116
+ behs.each { |beh| self.add_behavior(beh) }
117
+
118
+ # Extract the connections of the sub scopes.
119
+ cnxs = self.each_scope.map(&:extract_connections!).flatten
120
+ # Reinsert them to self.
121
+ cnxs.each { |beh| self.add_connection(beh) }
122
+
123
+ # Now can delete the sub scopes since they are empty.
124
+ self.each_scope.to_a.each { |scope| self.delete_scope!(scope) }
125
+ end
126
+
127
+ # Extract the behaviors from the scope and returns them into an array.
128
+ #
129
+ # NOTE: do not recurse into the sub scopes!
130
+ def extract_behaviors!
131
+ # Get the behaviors.
132
+ behs = self.each_behavior.to_a
133
+ # Remove them from the scope.
134
+ behs.each { |beh| self.delete_behavior!(beh) }
135
+ # Return the behaviors.
136
+ return behs
137
+ end
138
+
139
+ # Extract the connections from the scope and returns them into an array.
140
+ #
141
+ # NOTE: do not recurse into the sub scopes!
142
+ def extract_connections!
143
+ # Get the connections.
144
+ cnxs = self.each_connection.to_a
145
+ # Remove them from the scope.
146
+ cnxs.each { |beh| self.delete_connection!(beh) }
147
+ # Return the connections.
148
+ return cnxs
149
+ end
150
+
151
+ # Extract the declares from the scope and returns them into an array.
152
+ #
153
+ # NOTE: do not recurse into the sub scopes or behaviors!
154
+ def extract_declares!
155
+ # Ensure there is a name.
156
+ self.force_name!
157
+ # The extracted declares.
158
+ decls = []
159
+ # Extract the types.
160
+ types = []
161
+ self.each_type {|type| types << type }
162
+ types.each {|type| self.delete_type!(type) }
163
+ # Renames them with the current level.
164
+ types.each do |type|
165
+ former = type.name
166
+ self.extend_name!(type)
167
+ self.replace_names_subs!(former,type.name)
168
+ end
169
+ # Adds the types
170
+ decls << types
171
+ # Extract the systemTs.
172
+ systemTs = []
173
+ self.each_systemT {|systemT| systemTs << systemT }
174
+ systemTs.each {|systemT| self.delete_systemT!(systemT) }
175
+ # Renames them with the current level.
176
+ systemTs.each do |systemT|
177
+ former = systemT.name
178
+ self.extend_name!(systemT)
179
+ self.replace_names_subs!(former,systemT.name)
180
+ end
181
+ # Adds the systemTs
182
+ decls << systemTs
183
+ # Extract the inners.
184
+ inners = []
185
+ self.each_inner {|inner| inners << inner }
186
+ inners.each {|inner| self.delete_inner!(inner) }
187
+ # Renames them with the current level.
188
+ inners.each do |inner|
189
+ former = inner.name
190
+ self.extend_name!(inner)
191
+ self.replace_names_subs!(former,inner.name)
192
+ end
193
+ # Adds the inners
194
+ decls << inners
195
+ # Extract the systemIs
196
+ systemIs = []
197
+ self.each_systemI {|systemI| systemIs << systemI }
198
+ systemIs.each {|systemI| self.delete_systemI!(systemI) }
199
+ # Renames them with the current level.
200
+ systemIs.each do |systemI|
201
+ former = systemI.name
202
+ self.extend_name!(systemI)
203
+ self.replace_names_subs!(former,systemI.name)
204
+ end
205
+ # Adds the systemIs
206
+ decls << systemIs
207
+ # Returns the extracted declares.
208
+ return decls
209
+ end
210
+
211
+ # Replaces recursively +former+ name by +nname+ until it is redeclared
212
+ # in the internals.
213
+ def replace_names_subs!(former,nname)
214
+ self.each_type do |type|
215
+ type.replace_names!(former,nname)
216
+ end
217
+ self.each_systemT do |systemT|
218
+ systemT.replace_names!(former,nname)
219
+ end
220
+ self.each_scope do |scope|
221
+ scope.replace_names!(former,nname)
222
+ end
223
+ self.each_inner do |inner|
224
+ inner.replace_names!(former,nname)
225
+ end
226
+ self.each_systemI do |systemI|
227
+ systemI.replace_names!(former,nname)
228
+ end
229
+ self.each_connection do |connection|
230
+ connection.replace_names!(former,nname)
231
+ end
232
+ self.each_behavior do |behavior|
233
+ behavior.replace_names!(former,nname)
234
+ end
235
+ end
236
+
237
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
238
+ def replace_names!(former,nname)
239
+ # Stop here if the name is redeclared.
240
+ return if self.each_type.find {|type| type.name == former }
241
+ return if self.each_systemT.find {|systemT| systemT.name == former }
242
+ return if self.each_inner.find {|inner| inner.name == former }
243
+ # Recurse on the internals.
244
+ replace_names_subs!(former,nname)
245
+ end
246
+
247
+ # Breaks the hierarchical types into sequences of type definitions.
248
+ # Assumes to_upper_space! has been called before.
249
+ def break_types!
250
+ # The created types by structure.
251
+ types = {}
252
+ # Break the local types.
253
+ self.each_type {|type| type.break_types!(types)}
254
+ # Break the types in the inners.
255
+ # self.each_inner {|inner| inner.type.break_types!(types) }
256
+ self.each_inner do |inner|
257
+ inner.set_type!(inner.type.break_types!(types))
258
+ end
259
+ # Break the types in the connections.
260
+ self.each_connection do |connection|
261
+ connection.left.break_types!(types)
262
+ connection.right.break_types!(types)
263
+ end
264
+ # Break the types in the behaviors.
265
+ self.each_behavior do |behavior|
266
+ behavior.each_event do |event|
267
+ event.ref.break_types!(types)
268
+ end
269
+ behavior.block.break_types!(types)
270
+ end
271
+
272
+ # Add the resulting types.
273
+ types.each_value {|type| self.add_type(type) }
274
+ end
275
+ end
276
+
277
+ ## Extends the Type class with functionality for breaking hierarchical
278
+ # types.
279
+ class Type
280
+
281
+ # Breaks the hierarchical types into sequences of type definitions.
282
+ # Assumes to_upper_space! has been called before.
283
+ # +types+ include the resulting types.
284
+ def break_types!(types)
285
+ # By default, nothing to do.
286
+ return self
287
+ end
288
+ end
289
+
290
+ ## Extends the TypeVector class with functionality for breaking hierarchical
291
+ # types.
292
+ class TypeVector
293
+
294
+ # Breaks the hierarchical types into sequences of type definitions.
295
+ # Assumes to_upper_space! has been called before.
296
+ # +types+ include the resulting types.
297
+ def break_types!(types)
298
+ if self.base.is_a?(TypeVector) || self.base.is_a?(TypeTuple) ||
299
+ self.base.is_a?(TypeStruct) then
300
+ # Need to break
301
+ # First recurse on the base.
302
+ nbase = self.base.break_types!(types)
303
+ # # Maybe such a type already exists.
304
+ # ndef = types[nbase]
305
+ # if ndef then
306
+ # # Yes, use it.
307
+ # self.set_base!(ndef.clone)
308
+ # else
309
+ # # No change it to a type definition
310
+ # ndef = TypeDef.new(HDLRuby.uniq_name,nbase)
311
+ # self.set_base!(ndef)
312
+ # # And add it to the types by structure.
313
+ # types[nbase] = ndef
314
+ # end
315
+ # Sets the base.
316
+ self.set_base!(nbase)
317
+ # And create a new type from current type.
318
+ # Maybe the new type already exists.
319
+ ndef = types[self]
320
+ return self if ndef # Yes, already exists.
321
+ # No, create and register a new typedef.
322
+ ndef = TypeDef.new(HDLRuby.uniq_name,self)
323
+ types[self] = ndef
324
+ return ndef
325
+ end
326
+ return self
327
+ end
328
+ end
329
+
330
+ ## Extends the TypeTuple class with functionality for breaking hierarchical
331
+ # types.
332
+ class TypeTuple
333
+
334
+ # Breaks the hierarchical types into sequences of type definitions.
335
+ # Assumes to_upper_space! has been called before.
336
+ # +types+ include the resulting types.
337
+ def break_types!(types)
338
+ self.map_types! do |sub|
339
+ if sub.is_a?(TypeVector) || sub.is_a?(TypeTuple) ||
340
+ sub.is_a?(TypeStruct) then
341
+ # Need to break
342
+ # First recurse on the sub.
343
+ nsub = sub.break_types!(types)
344
+ # Maybe such a type already exists.
345
+ ndef = types[sub]
346
+ if ndef then
347
+ # Yes, use it.
348
+ ndef.clone
349
+ else
350
+ # No change it to a type definition
351
+ ndef = TypeDef.new(HDLRuby.uniq_name,nsub)
352
+ # And add it to the types by structure.
353
+ types[nsub] = ndef
354
+ nsub
355
+ end
356
+ end
357
+ end
358
+ return self
359
+ end
360
+ end
361
+
362
+ ## Extends the TypeStruct class with functionality for breaking hierarchical
363
+ # types.
364
+ class TypeStruct
365
+
366
+ # Breaks the hierarchical types into sequences of type definitions.
367
+ # Assumes to_upper_space! has been called before.
368
+ # +types+ include the resulting types.
369
+ def break_types!(types)
370
+ self.map_types! do |sub|
371
+ if sub.is_a?(TypeVector) || sub.is_a?(TypeStruct) ||
372
+ sub.is_a?(TypeStruct) then
373
+ # Need to break
374
+ # First recurse on the sub.
375
+ nsub = sub.break_types!(types)
376
+ # Maybe such a type already exists.
377
+ ndef = types[sub]
378
+ if ndef then
379
+ # Yes, use it.
380
+ ndef.clone
381
+ else
382
+ # No change it to a type definition
383
+ ndef = TypeDef.new(HDLRuby.uniq_name,nsub)
384
+ # And add it to the types by structure.
385
+ types[nsub] = ndef
386
+ nsub
387
+ end
388
+ end
389
+ end
390
+ return self
391
+ end
392
+ end
393
+
394
+ ## Extends the SignalI class with functionality for moving the declarations
395
+ # to the upper namespace.
396
+ class SignalI
397
+
398
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
399
+ def replace_names!(former,nname)
400
+ # Recurse on the type.
401
+ self.type.each_type_deep do |type|
402
+ if type.respond_to?(:name) && type.name == former then
403
+ type.set_name!(nname)
404
+ end
405
+ end
406
+ end
407
+ end
408
+
409
+ ## Extends the SystemI class with functionality for moving the declarations
410
+ # to the upper namespace.
411
+ class SystemI
412
+
413
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
414
+ def replace_names!(former,nname)
415
+ # Replace owns name if required.
416
+ if self.name == former then
417
+ self.set_name!(nname)
418
+ end
419
+ # Recurse on the system type.
420
+ self.systemT.replace_names!(former,nname)
421
+ end
422
+ end
423
+
424
+
425
+ ## Extends the Behavior class with functionality for moving the declarations
426
+ # to the upper namespace.
427
+ class Behavior
428
+
429
+ # Moves the declarations to the upper namespace.
430
+ def to_upper_space!
431
+ # Recurse on the block.
432
+ self.block.to_upper_space!
433
+ end
434
+
435
+ # Extract the declares from the scope and returns them into an array.
436
+ #
437
+ # NOTE: do not recurse into the sub scopes or behaviors!
438
+ def extract_declares!
439
+ # Recurse on the block.
440
+ return self.block.extract_declares!
441
+ end
442
+
443
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
444
+ def replace_names!(former,nname)
445
+ # Recurse on the block.
446
+ self.block.replace_names!(former,nname)
447
+ end
448
+ end
449
+
450
+ ## Extends the Statement class with functionality for moving the
451
+ # declarations to the upper namespace.
452
+ class Statement
453
+
454
+ # Moves the declarations to the upper namespace.
455
+ def to_upper_space!
456
+ # By default, nothing to do.
457
+ end
458
+
459
+ # Extract the declares from the scope and returns them into an array.
460
+ #
461
+ # NOTE: do not recurse into the sub scopes or behaviors!
462
+ def extract_declares!
463
+ # By default, nothing to do.
464
+ return []
465
+ end
466
+
467
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
468
+ def replace_names!(former,nname)
469
+ # By default: try to replace the name recursively.
470
+ self.each_node_deep do |node|
471
+ if node.respond_to?(:name) && node.name == former then
472
+ node.set_name!(nname)
473
+ end
474
+ end
475
+ end
476
+
477
+ # Breaks the hierarchical types into sequences of type definitions.
478
+ # Assumes to_upper_space! has been called before.
479
+ # +types+ include the resulting types.
480
+ def break_types!(types)
481
+ self.each_node do |node|
482
+ node.break_types!(types)
483
+ end
484
+ end
485
+ end
486
+
487
+ ## Extends the Expression class with functionality for moving the
488
+ # declarations to the upper namespace.
489
+ class Expression
490
+
491
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
492
+ def replace_names!(former,nname)
493
+ # By default: try to replace the name recursively.
494
+ self.each_node_deep do |node|
495
+ if node.respond_to?(:name) && node.name == former then
496
+ node.set_name!(nname)
497
+ end
498
+ end
499
+ end
500
+
501
+ # Breaks the hierarchical types into sequences of type definitions.
502
+ # Assumes to_upper_space! has been called before.
503
+ # +types+ include the resulting types.
504
+ def break_types!(types)
505
+ self.each_node do |node|
506
+ # Need to break only in the case of a cast.
507
+ if node.is_a?(Cast) then
508
+ # node.type.break_types!(types)
509
+ node.set_type!(node.type.break_types!(types))
510
+ end
511
+ end
512
+ end
513
+ end
514
+
515
+ ## Extends the If class with functionality for moving the declarations
516
+ # to the upper namespace.
517
+ class If
518
+
519
+ # Moves the declarations to the upper namespace.
520
+ def to_upper_space!
521
+ # Recurse on the sub blocks.
522
+ # Yes.
523
+ self.yes.to_upper_space!
524
+ # Noifs.
525
+ self.each_noif {|cond,stmnt| stmnt.to_upper_space! }
526
+ # No if any.
527
+ self.no.to_upper_space! if self.no
528
+ end
529
+
530
+ # Extract the declares from the scope and returns them into an array.
531
+ #
532
+ # NOTE: do not recurse into the sub scopes or behaviors!
533
+ def extract_declares!
534
+ # The extracted declares.
535
+ decls = []
536
+ # Recurse on the sub blocks.
537
+ # Yes.
538
+ decls << self.yes.extract_declares!
539
+ # Noifs.
540
+ decls << self.each_noif.map do |cond,stmnt|
541
+ stmnt.extract_declares!
542
+ end
543
+ # No if any.
544
+ decls << self.no.extract_declares! if self.no
545
+ # Returns the extracted declares.
546
+ return decls
547
+ end
548
+
549
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
550
+ def replace_names!(former,nname)
551
+ # Recurse on the condition.
552
+ self.condition.replace_names!(former,nname)
553
+ # Recurse on the yes.
554
+ self.yes.replace_names!(former,nname)
555
+ # Recurse on the alternate ifs.
556
+ self.each_noif do |cond,stmnt|
557
+ cond.replace_names!(former,nname)
558
+ stmnt.replace_names!(former,nname)
559
+ end
560
+ # Recurse on the no if any.
561
+ self.no.replace_names!(former,nname) if self.no
562
+ end
563
+ end
564
+
565
+ ## Extends the When class with functionality for moving the declarations
566
+ # to the upper namespace.
567
+ class When
568
+
569
+ # Moves the declarations to the upper namespace.
570
+ def to_upper_space!
571
+ # Recurse on the statement.
572
+ self.statement.to_upper_space!
573
+ end
574
+
575
+ # Extract the declares from the scope and returns them into an array.
576
+ #
577
+ # NOTE: do not recurse into the sub scopes or behaviors!
578
+ def extract_declares!
579
+ # Recurse on the statement.
580
+ return self.statement.extract_declares!
581
+ end
582
+
583
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
584
+ def replace_names!(former,nname)
585
+ # Recurse on the match.
586
+ self.match.replace_names!(former,nname)
587
+ # Recurse on the statement.
588
+ self.statement.replace_names!(former,nname)
589
+ end
590
+
591
+ # Breaks the hierarchical types into sequences of type definitions.
592
+ # Assumes to_upper_space! has been called before.
593
+ # +types+ include the resulting types.
594
+ def break_types!(types)
595
+ self.each_node do |node|
596
+ # Need to break only in the case of a cast.
597
+ if node.is_a?(Cast) then
598
+ node.type.break_types!(types)
599
+ end
600
+ end
601
+ end
602
+ end
603
+
604
+ ## Extends the When class with functionality for moving the declarations
605
+ # to the upper namespace.
606
+ class Case
607
+
608
+ # Moves the declarations to the upper namespace.
609
+ def to_upper_space!
610
+ # Recurse on the whens.
611
+ self.each_when(&:to_upper_space!)
612
+ # Recurse on the default if any.
613
+ self.default.to_upper_space! if self.default
614
+ end
615
+
616
+ # Extract the declares from the scope and returns them into an array.
617
+ #
618
+ # NOTE: do not recurse into the sub scopes or behaviors!
619
+ def extract_declares!
620
+ # Recurse on the whens.
621
+ return self.each_when.map(&:extract_declares!)
622
+ # Recurse on the default if any.
623
+ self.default.extract_declares! if self.default
624
+ end
625
+
626
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
627
+ def replace_names!(former,nname)
628
+ # Recurse on the value.
629
+ self.value.replace_names!(former,nname)
630
+ # Recurse on the whens.
631
+ self.each_when {|w| w.replace_names!(former,nname) }
632
+ # Recurse on the default.
633
+ self.default.replace_names!(former,nname) if self.default
634
+ end
635
+ end
636
+
637
+ ## Extends the When class with functionality for moving the declarations
638
+ # to the upper namespace.
639
+ class TimeRepeat
640
+
641
+ # Moves the declarations to the upper namespace.
642
+ def to_upper_space!
643
+ # Recurse on the statement.
644
+ self.statement.to_upper_space!
645
+ end
646
+
647
+ # Extract the declares from the scope and returns them into an array.
648
+ #
649
+ # NOTE: do not recurse into the sub scopes or behaviors!
650
+ def extract_declares!
651
+ # Recurse on the statement.
652
+ return self.statement.extract_declares!
653
+ end
654
+
655
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
656
+ def replace_names!(former,nname)
657
+ # Recurse on the statement.
658
+ self.statement.replace_names!(former,nname)
659
+ end
660
+ end
661
+
662
+ ## Extends the When class with functionality for moving the declarations
663
+ # to the upper namespace.
664
+ class Block
665
+
666
+ include ForceName
667
+
668
+ # Moves the declarations to the upper namespace.
669
+ def to_upper_space!
670
+ # Recurse on the statements.
671
+ self.each_statement(&:to_upper_space!)
672
+
673
+ # Extract the declares from the statements.
674
+ decls = self.each_statement.map(&:extract_declares!)
675
+
676
+ # Reinsert the extracted declares to self.
677
+ decls.flatten.each { |decl| self.add_inner(decl) }
678
+ end
679
+
680
+ # Extract the declares from the scope and returns them into an array.
681
+ #
682
+ # NOTE: do not recurse into the sub scopes or behaviors!
683
+ def extract_declares!
684
+ # Ensure there is a name.
685
+ self.force_name!
686
+ # The extracted declares.
687
+ decls = []
688
+ # Extract the inners.
689
+ self.each_inner {|inner| decls << inner }
690
+ decls.each {|inner| self.delete_inner!(inner) }
691
+ # Renames them with the current level.
692
+ decls.each do |inner|
693
+ former = inner.name
694
+ self.extend_name!(inner)
695
+ self.replace_names_subs!(former,inner.name)
696
+ end
697
+ # Returns the extracted declares.
698
+ return decls
699
+ end
700
+
701
+ # Replaces recursively +former+ name by +nname+ until it is redeclared
702
+ # in the sub scopes and behaviors.
703
+ def replace_names_subs!(former,nname)
704
+ self.each_statement do |stmnt|
705
+ stmnt.replace_names!(former,nname)
706
+ end
707
+ end
708
+
709
+ # Replaces recursively +former+ name by +nname+ until it is redeclared.
710
+ def replace_names!(former,nname)
711
+ # Stop here if the name is redeclared.
712
+ return if self.each_inner.find {|inner| inner.name == former }
713
+ # Recurse on the sub scopes and behaviors.
714
+ replace_names_subs!(former,nname)
715
+ end
716
+ end
717
+
718
+ end