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,14 @@
1
+ require 'HDLRuby'
2
+ configure_high
3
+
4
+ system :sub do
5
+
6
+ [15..0].input :ina,:inb
7
+ [16..0].output :result
8
+
9
+ result <= ina - inb
10
+ end
11
+
12
+ sub :subI
13
+
14
+ puts subI.to_low.to_yaml
@@ -0,0 +1,32 @@
1
+ require 'HDLRuby'
2
+ configure_high
3
+
4
+ system :z2 do
5
+
6
+ input :clk,:reset
7
+ signed[31..0].input :k1,:k2
8
+ signed[31..0].input :w2_1,:w2_2
9
+ signed[31..0].input :b2
10
+ signed[7..0].output :z2
11
+
12
+ signed[63..0].inner :net1,:net2
13
+ signed[31..0].inner :z2_tmp
14
+
15
+ par(clk.posedge)do
16
+ hif(reset==1)do
17
+ net1<=0
18
+ net2<=0
19
+ z2_tmp<=0
20
+ end
21
+ helse do
22
+ net1<=k1*w2_1
23
+ net2<=k2*w2_2
24
+ z2_tmp<=net1[55..24]+net2[55..24] + b2
25
+ end
26
+ end
27
+
28
+ z2<=z2_tmp[27..20]
29
+ end
30
+ z2 :z2I
31
+
32
+ puts z2I.to_low.to_yaml
@@ -0,0 +1,32 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple decoder for testing the case statement.
7
+ system :decoder do
8
+ [3..0].input :x
9
+ [7..0].output :s
10
+
11
+ par do
12
+ hcase(x)
13
+ hwhen(0) { s <= 1 }
14
+ hwhen(1) { s <= 2 }
15
+ hwhen(2) { s <= 4 }
16
+ hwhen(3) { s <= 8 }
17
+ hwhen(4) { s <= 16 }
18
+ hwhen(5) { s <= 32 }
19
+ hwhen(6) { s <= 64 }
20
+ hwhen(7) { s <= 128 }
21
+ helse { s <= 0 }
22
+ end
23
+ end
24
+
25
+ # Instantiate it for checking.
26
+ decoder :decoderI
27
+
28
+ # Generate the low level representation.
29
+ low = decoderI.systemT.to_low
30
+
31
+ # Displays it
32
+ puts low.to_yaml
@@ -0,0 +1,30 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple decoder for testing the case statement.
7
+ system :decoder do
8
+ [3..0].input :x
9
+ [7..0].output :s
10
+
11
+ hcase(x)
12
+ hwhen(0) { s <= 1 }
13
+ hwhen(1) { s <= 2 }
14
+ hwhen(2) { s <= 4 }
15
+ hwhen(3) { s <= 8 }
16
+ hwhen(4) { s <= 16 }
17
+ hwhen(5) { s <= 32 }
18
+ hwhen(6) { s <= 64 }
19
+ hwhen(7) { s <= 128 }
20
+ helse { s <= 0 }
21
+ end
22
+
23
+ # Instantiate it for checking.
24
+ decoder :decoderI
25
+
26
+ # Generate the low level representation.
27
+ low = decoderI.systemT.to_low
28
+
29
+ # Displays it
30
+ puts low.to_yaml
@@ -0,0 +1,23 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple test for using signals as event.
7
+ system :with_change do
8
+ [15..0].input :x,:y
9
+ [16..0].output :s
10
+
11
+ par x,y do
12
+ s <= x + y
13
+ end
14
+ end
15
+
16
+ # Instantiate it for checking.
17
+ with_change :with_changeI
18
+
19
+ # Generate the low level representation.
20
+ low = with_changeI.systemT.to_low
21
+
22
+ # Displays it
23
+ puts low.to_yaml
@@ -0,0 +1,35 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ require 'HDLRuby/std/clocks'
7
+ include HDLRuby::High::Std
8
+
9
+
10
+ # A simple test of the event multiplication constructs
11
+ system :with_clocks do
12
+ input :clk,:rst
13
+ output :sig0, :sig1
14
+
15
+ configure_clocks(rst)
16
+
17
+ par(clk.posedge * 2) do
18
+ hif(rst) { sig0 <= 0 }
19
+ helse { sig0 <= ~sig0 }
20
+ end
21
+
22
+ par(clk.posedge * 3) do
23
+ hif(rst) { sig1 <= 0 }
24
+ helse { sig1 <= ~sig1 }
25
+ end
26
+ end
27
+
28
+ # Instantiate it for checking.
29
+ with_clocks :with_clocksI
30
+
31
+ # Generate the low level representation.
32
+ low = with_clocksI.systemT.to_low
33
+
34
+ # Displays it
35
+ puts low.to_yaml
@@ -0,0 +1,21 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple 16-bit comparer
7
+ system :comparer do
8
+ [15..0].input :x,:y
9
+ output :s
10
+
11
+ s <= (x < y)
12
+ end
13
+
14
+ # Instantiate it for checking.
15
+ comparer :comparerI
16
+
17
+ # Generate the low level representation.
18
+ low = comparerI.systemT.to_low
19
+
20
+ # Displays it
21
+ puts low.to_yaml
@@ -0,0 +1,29 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A system for testing conditionals
7
+ system :conditionals do
8
+ [15..0].input :x,:y
9
+ output :s
10
+
11
+ par do
12
+ hif x <= y do
13
+ s <= 0
14
+ end
15
+ helse do
16
+ s <= 1
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ # Instantiate it for checking.
23
+ conditionals :conditionalsI
24
+
25
+ # Generate the low level representation.
26
+ low = conditionalsI.systemT.to_low
27
+
28
+ # Displays it
29
+ puts low.to_yaml
@@ -0,0 +1,23 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple D-FF
7
+ system :dff do
8
+ input :clk, :rst, :d
9
+ output :q, :qb
10
+
11
+ qb <= ~q
12
+
13
+ par(clk.posedge) { q <= d & ~rst }
14
+ end
15
+
16
+ # Instantiate it for checking.
17
+ dff :dffI
18
+
19
+ # Generate the low level representation.
20
+ low = dffI.systemT.to_low
21
+
22
+ # Displays it
23
+ puts low.to_yaml
@@ -0,0 +1,28 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple test of using each on signals.
7
+ system :with_each do
8
+ [15..0].input :x
9
+ [15..0].output :s
10
+ [15..0].inout :y
11
+
12
+ x.each.with_index do |b,i|
13
+ s[i] <= b
14
+ end
15
+
16
+ y.each_cons(2) do |b0,b1|
17
+ b0 <= b1
18
+ end
19
+ end
20
+
21
+ # Instantiate it for checking.
22
+ with_each :with_eachI
23
+
24
+ # Generate the low level representation.
25
+ low = with_eachI.systemT.to_low
26
+
27
+ # Displays it
28
+ puts low.to_yaml
@@ -0,0 +1,42 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # A simple D-FF
6
+ system :dff do
7
+ input :clk, :rst, :d
8
+ output :q
9
+
10
+ par(clk.posedge) { q <= d & ~rst }
11
+ end
12
+
13
+ # A system wrapping a D-FF and exporting things.
14
+ system :exporter do
15
+ input :d
16
+ inner :clk, :rst
17
+
18
+ dff(:dff0).(clk: clk, rst: rst, d: d)
19
+
20
+ # Comment one of the following to check that without export, they cannot
21
+ # be used in a system inheriting from exporter
22
+ export :clk, :rst , :dff0
23
+ end
24
+
25
+ # A system inheriting from exporter
26
+ system :importer, exporter do
27
+ input :clk0, :rst0
28
+ output :q
29
+
30
+ clk <= clk0
31
+ rst <= rst0
32
+ dff0.q <= q
33
+ end
34
+
35
+ # # Instantiate it for checking.
36
+ importer :importerI
37
+
38
+ # Generate the low level representation.
39
+ low = importerI.systemT.to_low
40
+
41
+ # Displays it
42
+ puts low.to_yaml
@@ -0,0 +1,60 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ def hello_out
7
+ puts "hello_out"
8
+ end
9
+
10
+ def hello_mix(u,v,w)
11
+ puts "hello_mix"
12
+ par do
13
+ inner :something
14
+ w <= u - v
15
+ end
16
+ end
17
+
18
+ function :hello_sub do |name|
19
+ inner :nothing
20
+ puts "hello_sub, #{name}"
21
+ 1
22
+ end
23
+
24
+ # A system for testing functions
25
+ system :functions do
26
+ [15..0].input :x,:y, :z
27
+ [15..0].output :a, :b, :c, :d
28
+
29
+ hello_out
30
+
31
+ def hello_in
32
+ puts "hello_in"
33
+ a <= x + y
34
+ end
35
+
36
+ function :hello_in_sub do
37
+ inner :nothing_really
38
+ puts "hello_in_sub"
39
+ d <= x - y
40
+ end
41
+
42
+ hello_in
43
+
44
+ hello_mix(x,y,b)
45
+
46
+ c <= hello_sub("John Doe")
47
+
48
+ hello_in_sub
49
+ end
50
+
51
+ hello_out
52
+
53
+ # Instantiate it for checking.
54
+ functions :functionsI
55
+
56
+ # Generate the low level representation.
57
+ low = functionsI.systemT.to_low
58
+
59
+ # Displays it
60
+ puts low.to_yaml
@@ -0,0 +1,26 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A example of behavior with an if using a seq block
7
+ system :if_seq do
8
+ [15..0].input :x,:y, :clk
9
+ [16..0].inner :w
10
+ [16..0].output :o
11
+
12
+ par(clk.posedge) do
13
+ hif x>100, seq do
14
+ w <= y
15
+ end
16
+ end
17
+ end
18
+
19
+ # Instantiate it for checking.
20
+ if_seq :if_seqI
21
+
22
+ # Generate the low level representation.
23
+ low = if_seqI.systemT.to_low
24
+
25
+ # Displays it
26
+ puts low.to_yaml
@@ -0,0 +1,32 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple D-FF
7
+ system :dff do
8
+ input :clk, :rst, :d
9
+ output :q
10
+
11
+ inner :db
12
+
13
+ db <= ~d
14
+
15
+ par(clk.posedge) { q <= d & ~rst }
16
+ end
17
+
18
+ # A D-FF with inverted ouput inheriting from dff
19
+ system :dff_full,dff do
20
+ output :qb
21
+
22
+ qb <= as(dff).db
23
+ end
24
+
25
+ # Instantiate it for checking.
26
+ dff_full :dff_fullI
27
+
28
+ # Generate the low level representation.
29
+ low = dff_fullI.systemT.to_low
30
+
31
+ # Displays it
32
+ puts low.to_yaml
@@ -0,0 +1,36 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple D-FF
7
+ system :dff do
8
+ input :clk, :rst, :d
9
+ output :q
10
+
11
+ par(clk.posedge) { q <= d & ~rst }
12
+ end
13
+
14
+ # A D-FF with inverted ouput inheriting from dff
15
+ system :dff_full,dff do
16
+ output :qb
17
+
18
+ qb <= ~q
19
+ end
20
+
21
+ # A D-FF with a secondary output
22
+ system :dff_fullest, dff_full do
23
+ output :qq
24
+ qq <= q
25
+ end
26
+
27
+ # Instantiate it for checking.
28
+ # dff_full :dff_fullI
29
+ dff_fullest :dff_fullestI
30
+
31
+ # Generate the low level representation.
32
+ # low = dff_fullI.systemT.to_low
33
+ low = dff_fullestI.systemT.to_low
34
+
35
+ # Displays it
36
+ puts low.to_yaml
@@ -0,0 +1,37 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A simple 16-bit or
7
+ system :or16 do
8
+ [15..0].input :x,:y
9
+ [16..0].output :s
10
+
11
+ s <= x | y
12
+ end
13
+
14
+ # A 32-bit or made of two 16-bit ones.
15
+ system :or32 do
16
+ [31..0].input :x,:y
17
+ [32..0].output :s
18
+
19
+ or16 :or0
20
+
21
+ or0.x <= x[15..0]
22
+ or0.y <= y[15..0]
23
+ s[15..0] <= or0.s[15..0]
24
+
25
+ or16(:or1).(x[31..16],y[31..16])
26
+
27
+ s[31..16] <= or1.s[31..16]
28
+ end
29
+
30
+ # Instantiate it for checking.
31
+ or32 :or32I
32
+
33
+ # Generate the low level representation.
34
+ low = or32I.systemT.to_low
35
+
36
+ # Displays it
37
+ puts low.to_yaml
@@ -0,0 +1,64 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Describes an 8-bit data 16-bit address memory.
6
+ system :mem8_16 do
7
+ input :clk, :rwb
8
+ [15..0].input :addr
9
+ [7..0].inout :data
10
+
11
+ bit[7..0][2**16].inner :content
12
+
13
+ par(clk.posedge) do
14
+ hif(rwb) { data <= content[addr] }
15
+ helse { content[addr] <= data }
16
+ end
17
+ end
18
+
19
+ # Instantiate it for checking.
20
+ mem8_16 :mem8_16I
21
+
22
+
23
+ # Describes a 16-bit memory made of 8-bit memories.
24
+ system :mem16_16 do
25
+ input :clk, :rwb
26
+ [15..0].input :addr
27
+ [15..0].inout :data
28
+
29
+ mem8_16(:memL).(clk: clk, rwb: rwb, addr: addr, data: data[7..0])
30
+ mem8_16(:memH).(clk: clk, rwb: rwb, addr: addr, data: data[15..8])
31
+ end
32
+
33
+ # Instantiate it for checking.
34
+ mem16_16 :mem16_16I
35
+
36
+
37
+ # Describes a 16-bit memory made of 8-bit memories the long way.
38
+ system :mem16_16_long do
39
+ input :clk, :rwb
40
+ [15..0].input :addr
41
+ [15..0].inout :data
42
+
43
+ mem8_16 [:memL, :memH]
44
+
45
+ memL.clk <= clk
46
+ memL.rwb <= rwb
47
+ memL.addr <= addr
48
+ memL.data <= data[7..0]
49
+
50
+ memH.clk <= clk
51
+ memH.rwb <= rwb
52
+ memH.addr <= addr
53
+ memH.data <= data[15..8]
54
+ end
55
+
56
+ # Instantiate it for checking.
57
+ mem16_16_long :mem16_16_longI
58
+
59
+ # Generate the low level representation.
60
+ # low = mem16_16I.to_low
61
+ low = mem16_16_longI.systemT.to_low
62
+
63
+ # Displays it
64
+ puts low.to_yaml
@@ -0,0 +1,27 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Tests the inclusion of other files.
6
+
7
+ require "./adder.rb"
8
+
9
+
10
+ # Two parallel adders
11
+ system :adder16_2 do
12
+ [15..0].input :x0,:y0,:x1,:y1
13
+ [16..0].output :s0,:s1
14
+
15
+ adder(:adder0).(x0,y0,s0)
16
+
17
+ adder(:adder1).(x1,y1,s1)
18
+ end
19
+
20
+ # Instantiate it for checking.
21
+ adder16_2 :adder16_2I
22
+
23
+ # Generate the low level representation.
24
+ low = adder16_2I.systemT.to_low
25
+
26
+ # Displays it
27
+ puts low.to_yaml
@@ -0,0 +1,32 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A 16-bit type with overloaded addition (saturated addition).
7
+ [15..0].typedef(:sat16)
8
+ sat16.define_operator(:+) do |left,right|
9
+ [16..0].inner :res
10
+ seq do
11
+ res <= left.as([15..0]) + right
12
+ hif (res[16]) { res <= 0xFFFF }
13
+ end
14
+ res
15
+ end
16
+
17
+ # A simple 16-bit adder
18
+ system :adder do
19
+ sat16.input :x,:y
20
+ [15..0].output :s
21
+
22
+ s <= x + y
23
+ end
24
+
25
+ # Instantiate it for checking.
26
+ adder :adderI
27
+
28
+ # Generate the low level representation.
29
+ low = adderI.systemT.to_low
30
+
31
+ # Displays it
32
+ puts low.to_yaml
@@ -0,0 +1,49 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ def after(number, clk = $clk, rst = $rst, &code)
6
+ if in_behavior? and cur_behavior.on_edge? then
7
+ counter = HDLRuby.uniq_name
8
+ counter = [Math::log2(number).to_i+1].inner counter
9
+ hif(rst) { counter <= 0 }
10
+ helsif(counter < number) do
11
+ counter <= counter + 1
12
+ end
13
+ # hif(counter >= number) { code.call }
14
+ hif(counter >= number) { instance_eval(&code) }
15
+ else
16
+ counter = HDLRuby.uniq_name
17
+ cur_system.open do
18
+ counter = [Math::log2(number).to_i+1].inner counter
19
+ par(clk.posedge,rst.posedge) do
20
+ hif(rst) { counter <= 0 }
21
+ helse { counter <= counter + 1 }
22
+ end
23
+ end
24
+ # hif(counter >= number) { code.call }
25
+ hif(counter >= number) { instance_eval(&code) }
26
+ end
27
+ end
28
+
29
+
30
+ system :test_after0 do
31
+ input :clk,:rst
32
+ inner :sig0, :sig1
33
+
34
+ after(10,clk,rst) { sig0 <= 1 }
35
+ helse { sig0 <= 0 }
36
+
37
+ par(clk.posedge,rst.posedge) do
38
+ sig1 <= 0
39
+ after(20) { sig1 <= 1 }
40
+ end
41
+ end
42
+
43
+
44
+ test_after0 :test_after0I
45
+
46
+ low = test_after0I.systemT.to_low
47
+
48
+ # Displays it
49
+ puts low.to_yaml