HDLRuby 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
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,220 @@
1
+
2
+ module HDLRuby::High::Std
3
+
4
+ ##
5
+ # Standard HDLRuby::High library: pipeline
6
+ #
7
+ ########################################################################
8
+
9
+
10
+ ##
11
+ # Describes a high-level pipeline type.
12
+ class PipelineT
13
+ include HDLRuby::High::HScope_missing
14
+
15
+ # The stage class
16
+ class Stage < Array
17
+ attr_accessor :code
18
+ end
19
+
20
+ # The pipeline signal generator class
21
+ class PipeSignal
22
+ include HDLRuby::High::HExpression
23
+
24
+ attr_reader :name # The name of the signal to generate
25
+ attr_reader :type # The type of the signal to generate
26
+ attr_reader :signal # The generated signal
27
+
28
+ # Create a new pipeline signal generator with +name+ whose
29
+ # resulting signal is to be added to +scope+.
30
+ def initialize(name,scope)
31
+ @name = name.to_sym
32
+ @scope = scope
33
+ @type = nil
34
+ @signal = nil
35
+ end
36
+
37
+ # Assigns +expr+ to the signal. Is the signal is not generated
38
+ # yet, generate it.
39
+ def <=(expr)
40
+ # Ensures expr is an expression
41
+ expr = expr.to_expr
42
+ # Generate the signal if not existant
43
+ # puts "@scope=#{@scope}"
44
+ puts "For @name=#{@name} @signal=#{@signal}"
45
+ @signal = @scope.make_inners(expr.type,@name) unless @signal
46
+ # Performs the assignment.
47
+ @signal <= expr
48
+ end
49
+
50
+ # Converts to an expression.
51
+ def to_expr
52
+ return @signal.to_expr
53
+ end
54
+
55
+ # Converts to a reference.
56
+ def to_ref
57
+ return @signal.to_ref
58
+ end
59
+
60
+ # # The HDLRuby operators on expressions.
61
+ # HDLRuby::High::Operators.each do |op|
62
+ # define_method(op) do |val|
63
+ # self.to_expr.send(op,val)
64
+ # end
65
+ # end
66
+ end
67
+
68
+ # The name of the pipeline type.
69
+ attr_reader :name
70
+
71
+ # The namespace associated with the pipeline
72
+ attr_reader :namespace
73
+
74
+ # Creates a new pipeline type with +name+.
75
+ #
76
+ # The proc +ruby_block+ is executed when instantiating the fsm.
77
+ def initialize(name)
78
+ # Check and set the name
79
+ @name = name.to_sym
80
+
81
+ # Initialize the internals of the pipeline.
82
+
83
+
84
+ # Initialize the environment for building the pipeline
85
+
86
+ # The stages
87
+ @stages = []
88
+
89
+ # The event synchronizing the pipeline
90
+ @mk_ev = proc { $clk.posedge }
91
+
92
+ # The reset
93
+ @mk_rst = proc { $rst }
94
+
95
+ # Creates the namespace to execute the pipeline block in.
96
+ @namespace = Namespace.new(self)
97
+
98
+ # Generates the function for setting up the pipeline.
99
+ obj = self # For using the right self within the proc
100
+ HDLRuby::High.space_reg(@name) do |&ruby_block|
101
+ if ruby_block then
102
+ # Builds the pipeline.
103
+ obj.build(&ruby_block)
104
+ else
105
+ # Return the pipeline as is.
106
+ return obj
107
+ end
108
+ end
109
+
110
+ end
111
+
112
+ ## builds the pipeline by executing +ruby_block+.
113
+ def build(&ruby_block)
114
+ # Use local variable for accessing the attribute since they will
115
+ # be hidden when opening the sytem.
116
+ name = @name
117
+ stages = @stages
118
+ namespace = @namespace
119
+ this = self
120
+ mk_ev = @mk_ev
121
+ mk_rst = @mk_rst
122
+ scope = HDLRuby::High.cur_system.scope
123
+
124
+ return_value = nil
125
+
126
+ # Enters the current system
127
+ HDLRuby::High.cur_system.open do
128
+ sub do
129
+ HDLRuby::High.space_push(namespace)
130
+ # Execute the instantiation block
131
+ return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
132
+ HDLRuby::High.space_pop
133
+
134
+ # Create the pipeline code.
135
+
136
+ # Declare and register the pipeline registers generators.
137
+ prs = []
138
+ stages.each do |st|
139
+ st.each do |rn|
140
+ r = PipeSignal.new(name.to_s+"::"+rn.to_s,scope)
141
+ prs << r
142
+ namespace.add_method(rn) { r }
143
+ end
144
+ end
145
+
146
+ # Build the pipeline structure.
147
+ return_value = par(mk_ev.call) do
148
+ hif(mk_rst.call == 0) do
149
+ # No reset, pipeline handling.
150
+ stages.each do |st|
151
+ # Generate the code for the stage.
152
+ HDLRuby::High.space_push(namespace)
153
+ HDLRuby::High.top_user.instance_exec(&st.code)
154
+ HDLRuby::High.space_pop
155
+ end
156
+ end
157
+ helse do
158
+ prs.each { |r| r <= 0 }
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ return return_value
165
+ end
166
+
167
+ ## The interface for building the pipeline
168
+
169
+ # Sets the event synchronizing the pipeline.
170
+ def for_event(event = nil,&ruby_block)
171
+ if event then
172
+ # An event is passed as argument, use it.
173
+ @mk_ev = proc { event.to_event }
174
+ else
175
+ # No event given, use the ruby_block as event generator.
176
+ @mk_ev = ruby_block
177
+ end
178
+ end
179
+
180
+ # Sets the reset.
181
+ def for_reset(reset = nil,&ruby_block)
182
+ if reset then
183
+ # An reset is passed as argument, use it.
184
+ @mk_rst = proc { reset.to_expr }
185
+ else
186
+ # No reset given, use the ruby_block as event generator.
187
+ @mk_rst = ruby_block
188
+ end
189
+ end
190
+
191
+
192
+ # Declare a new stage synchronized on registers declared in +regs+
193
+ # and executing +ruby_block+.
194
+ def stage(*regs, &ruby_block)
195
+ # Create the resulting state
196
+ result = Stage.new
197
+ # Test and set the registers.
198
+ regs.each do |reg|
199
+ # Ensure it is a symbol.
200
+ reg = reg.to_sym
201
+ # Add it.
202
+ result << reg
203
+ end
204
+ # Sets the generation code.
205
+ result.code = ruby_block
206
+ # Add it to the list of states.
207
+ @stages << result
208
+ # Return it.
209
+ return result
210
+ end
211
+
212
+ end
213
+
214
+
215
+ ## Declare a new pipeline with +name+.
216
+ def pipeline(name)
217
+ return PipelineT.new(name)
218
+ end
219
+
220
+ end
@@ -0,0 +1,309 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: reconfigurable components.
5
+ #
6
+ ########################################################################
7
+
8
+ ## Describes a high-level reconfigurable component type.
9
+ class ReconfT
10
+
11
+ # The name of the reconfigurable component type.
12
+ attr_reader :name
13
+
14
+ # Creates a new reconfigurable type with +name+ built whose
15
+ # instances are created from +ruby_block+.
16
+ def initialize(name,&ruby_block)
17
+ # Checks and sets the name.
18
+ @name = name.to_sym
19
+ # Sets the block for instantiating a channel.
20
+ @ruby_block = ruby_block
21
+ # Sets the instantiation procedure.
22
+ obj = self
23
+ HDLRuby::High.space_reg(@name) do |*args|
24
+ obj.instantiate(*args)
25
+ end
26
+ end
27
+
28
+ ## Intantiates a reconfigurable component.
29
+ def instantiate(*args)
30
+ obj = self
31
+ # No argument, so not an instantiation but actually
32
+ # an access to the channel type.
33
+ return obj if args.empty?
34
+ # Process the case of generic channel.
35
+ if @ruby_block.arity > 0 then
36
+ # Actually the arguments are generic arguments,
37
+ # generates a new channel type with these arguments
38
+ # fixed.
39
+ ruby_block = @ruby_block
40
+ return ReconfT.new(:"") do
41
+ HDLRuby::High.top_user.instance_exec(*args,&ruby_block)
42
+ end
43
+ end
44
+ # Generates the reconfigurable components.
45
+ args.each do |nameI|
46
+ # puts "for #{nameI} ruby_block=#{@ruby_block}"
47
+ reconfI = ReconfI.new(name,&@ruby_block)
48
+ HDLRuby::High.space_reg(nameI) { reconfI }
49
+ reconfI
50
+ end
51
+ end
52
+
53
+ alias_method :call, :instantiate
54
+ end
55
+
56
+
57
+ ## Creates a new reconfigurable component type named +name+ whose
58
+ # instances are creating executing +ruby_block+.
59
+ def reconf(name,&ruby_block)
60
+ # puts "reconf with ruby_block=#{ruby_block}"
61
+ return ReconfT.new(name,&ruby_block)
62
+ end
63
+
64
+
65
+
66
+
67
+ ##
68
+ # Describes a high-level reconfigurable component instance.
69
+ class ReconfI
70
+ # include HDLRuby::High::HScope_missing
71
+ include HDLRuby::High::Hmissing
72
+
73
+ # The name of the reconfigurable component instance.
74
+ attr_reader :name
75
+
76
+ # The namespace associated with the current execution when
77
+ # building a reconfigurable component, its reader or its writer.
78
+ attr_reader :namespace
79
+
80
+ # The instance representing the reconfigurable component.
81
+ attr_reader :instance
82
+
83
+ ## Creates a new reconfigurable component instance with +name+ built
84
+ # from +ruby_block+.
85
+ def initialize(name,&ruby_block)
86
+ # Check and set the name
87
+ @name = name.to_sym
88
+
89
+ # Sets the block for building:
90
+ @ruby_block = ruby_block
91
+
92
+ # Create the namespace for building the reconfigurable component.
93
+ @namespace = Namespace.new(self)
94
+ # # Make it give access to the internal of the class.
95
+ # @namespace.add_method(:each_input, &method(:each_input))
96
+
97
+ # Initialize the set of systems that can be used for this
98
+ # component.
99
+ @systemTs = []
100
+
101
+ # Initialize the interface of the component.
102
+ @inputs = []
103
+ @outputs = []
104
+ @inouts = []
105
+
106
+ # Initialize the switch procedure to nil: it must be defined.
107
+ @switcher_proc = nil
108
+ # Initialize the reconfiguration index: it is defined when
109
+ # building the reconfigurable object.
110
+ @index = nil
111
+
112
+ # Gives access to the reconfigurable component by registering
113
+ # its name.
114
+ obj = self
115
+ HDLRuby::High.space_reg(@name) { obj }
116
+ end
117
+
118
+ ## Builds the reconfigurable component with systems types from
119
+ # +systems+
120
+ def build(*systemTs)
121
+ # Checks and sets the first system.
122
+ if systemTs.empty? then
123
+ raise "No system given for reconfiguble component: #{name}"
124
+ end
125
+
126
+ unless systemTs[0].is_a?(SystemT) then
127
+ raise "Invalid object for a systemT: #{systems[0].class}"
128
+ end
129
+ # Set the default main systemT as the first one.
130
+ @main = self.add_system(systemTs[0])
131
+
132
+ # Sets the interface from the first system
133
+ expanded = @main.expand(:"")
134
+ expanded.each_input {|sig| @inputs << sig.clone }
135
+ expanded.each_output {|sig| @outputs << sig.clone }
136
+ expanded.each_inout {|sig| @inouts << sig.clone }
137
+
138
+ # Add the other systems.
139
+ systemTs[1..-1].each { |systemT| self.add_system(systemT) }
140
+
141
+ # Generate the name and the size of the reconfiguration index
142
+ # signal.
143
+ index_name = HDLRuby.uniq_name
144
+ index_size = systemTs.size.width
145
+ index_ref = nil # The reference to the signal, will be set
146
+ # in the context of the current system.
147
+
148
+ # Builds the reconfigurable component.
149
+ ruby_block = @ruby_block
150
+ HDLRuby::High.space_push(@namespace)
151
+ HDLRuby::High.top_user.instance_eval do
152
+ # Generate the index
153
+ index_ref = [index_size].inner(index_name)
154
+ end
155
+ HDLRuby::High.top_user.instance_eval(&ruby_block)
156
+ HDLRuby::High.space_pop
157
+
158
+ # Set the index signal.
159
+ @index = index_ref
160
+
161
+ # Builds the system instance.
162
+ # Creates its name.
163
+ name = HDLRuby.uniq_name
164
+ # Make the instantiation of the main system.
165
+ @instance = @main.instantiate(name)
166
+ # Adds the other possible systems.
167
+ @systemTs.each do |systemT|
168
+ unless systemT == @main
169
+ systemT = systemT.expand(systemT.name.to_s + ":rT")
170
+ @instance.add_systemT(systemT)
171
+ end
172
+ end
173
+ end
174
+ alias_method :call, :build
175
+
176
+ # The methods for defining the reconfigurable component.
177
+
178
+ ## Adds system +systemT+.
179
+ def add_system(systemT)
180
+ # Checks the system.
181
+ unless systemT.is_a?(SystemT) then
182
+ raise "Invalid object for a systemT: #{systemT.class}"
183
+ end
184
+
185
+ # Expand the system to add to know the inputs.
186
+ expanded = systemT.expand(:"")
187
+
188
+ # Check its interface if it is not the firs system.
189
+ unless @systemTs.empty? then
190
+ expanded.each_input.with_index do |sig,idx|
191
+ unless sig.eql?(@inputs[idx]) then
192
+ raise "Invalid input signal ##{idx} for system " +
193
+ "#{systemT.name} got #{sig} but "+
194
+ "expecting: #{@inputs[idx]}"
195
+ end
196
+ end
197
+ expanded.each_output.with_index do |sig,idx|
198
+ unless sig.eql?(@outputs[idx]) then
199
+ raise "Invalid output signal ##{idx} for system " +
200
+ "#{systemT.name} got #{sig} but "+
201
+ "expecting: #{@outputs[idx]}"
202
+ end
203
+ end
204
+ expanded.each_inout.with_index do |sig,idx|
205
+ unless sig.eql?(@inouts[idx]) then
206
+ raise "Invalid inout signal ##{idx} for system " +
207
+ "#{systemT.name} got #{sig} but "+
208
+ "expecting: #{@inouts[idx]}"
209
+ end
210
+ end
211
+ end
212
+
213
+ # Add the system (not the expanded version!)
214
+ @systemTs << systemT
215
+ systemT
216
+ end
217
+
218
+ ## Sets and adds a new main system to be +systemT+.
219
+ def set_main(systemT)
220
+ # puts "set_main with systemT=#{systemT.name}"
221
+ # Add the system if not already present.
222
+ # NOTE: also checks the system.
223
+ systemT = self.add_system(systemT)
224
+ # Set the system to be a main.
225
+ @main = systemT
226
+ end
227
+
228
+ ## Iterates on the input signals.
229
+ #
230
+ # Returns an enumerator if no ruby block is given.
231
+ def each_input(&ruby_block)
232
+ # No ruby block? Return an enumerator.
233
+ return to_enum(:each_input) unless ruby_block
234
+ # A ruby block? Apply it on each input signal instance.
235
+ @inputs.each(&ruby_block)
236
+ end
237
+
238
+ ## Iterates on the output signals.
239
+ #
240
+ # Returns an enumerator if no ruby block is given.
241
+ def each_output(&ruby_block)
242
+ # No ruby block? Return an enumerator.
243
+ return to_enum(:each_output) unless ruby_block
244
+ # A ruby block? Apply it on each output signal instance.
245
+ @outputs.each(&ruby_block)
246
+ end
247
+
248
+ ## Iterates on the inout signals.
249
+ #
250
+ # Returns an enumerator if no ruby block is given.
251
+ def each_inout(&ruby_block)
252
+ # No ruby block? Return an enumerator.
253
+ return to_enum(:each_inout) unless ruby_block
254
+ # A ruby block? Apply it on each inout signal instance.
255
+ @inouts.each(&ruby_block)
256
+ end
257
+
258
+ ## Defines the switching command to be +ruby_block+.
259
+ def switcher(&ruby_block)
260
+ @switcher_proc = ruby_block
261
+ end
262
+
263
+ ## Defines new command +name+ to execute +ruby_block+ for the
264
+ # channel.
265
+ def command(name,&ruby_block)
266
+ # Ensures name is a symbol.
267
+ name = name.to_sym
268
+ # Sets the new command.
269
+ self.define_singleton_method(name) do
270
+ # Executes the command in the right environment.
271
+ HDLRuby::High.space_push(@namespace)
272
+ res = HDLRuby::High.top_user.instance_exec(&ruby_block)
273
+ HDLRuby::High.space_pop
274
+ res
275
+ end
276
+ end
277
+
278
+ # For accessing and controlling the reconfiguration state.
279
+
280
+ ## Gives access to the signal giving the current reconfiguration
281
+ # index.
282
+ def index
283
+ return @index
284
+ end
285
+
286
+ ## Generate the switching code to configuration number +idx+,
287
+ # and executing the code generated by +ruby_block+ when the
288
+ # switch is completed.
289
+ def switch(idx,&ruby_block)
290
+ switcher_proc = @switcher_proc
291
+ index = @index
292
+ inputs = @inputs
293
+ outputs = @outputs
294
+ inouts = @inouts
295
+ systemTs = @systemTs
296
+ # Execute the code generating the reader in context.
297
+ HDLRuby::High.space_push(@namespace)
298
+ HDLRuby::High.cur_block.open do
299
+ instance_exec(idx,ruby_block,&switcher_proc)
300
+ end
301
+ HDLRuby::High.space_pop
302
+ end
303
+ end
304
+ end
305
+
306
+
307
+
308
+
309
+