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,27 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Describes an 8-bit data 16-bit address RAM.
6
+ system :ram8_16 do
7
+ input :rwb, :en
8
+ [15..0].input :addr
9
+ [7..0].inout :data
10
+
11
+ bit[7..0][2**16].inner :content
12
+
13
+ # Reading the memory
14
+ data <= mux(en && rwb, content[addr], _bhZZ)
15
+ # Writing the memory
16
+ ( content[addr] <= data ).hif(en && ~rwb)
17
+ end
18
+
19
+ # Instantiate it for checking.
20
+ ram8_16 :ram8_16I
21
+
22
+
23
+ # Generate the low level representation.
24
+ low = ram8_16I.systemT.to_low
25
+
26
+ # Displays it
27
+ puts low.to_yaml
@@ -0,0 +1,139 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Describes a simple D-FF
6
+ system :dff0 do
7
+ bit.input :clk, :rst, :d
8
+ bit.output :q, :qb
9
+
10
+ qb <= ~q
11
+
12
+ par(clk.posedge) do
13
+ q <= d & ~rst
14
+ end
15
+ end
16
+
17
+ # Instantiate it for checking.
18
+ dff0 :dff0I
19
+
20
+
21
+ # Decribes another D-FF
22
+ system :dff1 do
23
+ input :clk, :rst, :d
24
+ output :q, :qb
25
+
26
+ qb <= ~q
27
+ (q <= d & ~rst).at(clk.posedge)
28
+ end
29
+
30
+ # Instantiate it for checking.
31
+ dff1 :dff1I
32
+
33
+
34
+ # Describes an 8-bit register
35
+ system :reg8 do
36
+ input :clk, :rst
37
+ [7..0].input :d
38
+ [7..0].output :q, :qb
39
+
40
+ qb <= ~q
41
+ (q <= d & [~rst]*8).at(clk.posedge)
42
+ end
43
+
44
+ # Instantiate it for checking.
45
+ reg8 :reg8I
46
+
47
+
48
+ # Describes a n-bit register.
49
+ system :regn do |n|
50
+ input :clk, :rst
51
+ [n-1..0].input :d
52
+ [n-1..0].output :q,:qb
53
+
54
+ qb <= ~q
55
+ (q <= d & [~rst]*n).at(clk.posedge)
56
+ end
57
+
58
+ # Instantiate it for checking.
59
+ regn :regn8I,8
60
+
61
+
62
+ # Describes a register of generic type.
63
+ system :reg do |typ|
64
+ input :clk, :rst
65
+ typ.input :d
66
+ typ.output :q,:qb
67
+
68
+ qb <= ~q
69
+ (q <= d & [~rst]*typ.width).at(clk.posedge)
70
+ end
71
+
72
+ # Instantiate it for checking.
73
+ reg :regbit8I, bit[7..0]
74
+
75
+
76
+
77
+ # Function generating the body of a register description.
78
+ def make_reg_body(typ)
79
+ input :clk, :rst
80
+ typ.input :d
81
+ typ.output :q,:qb
82
+
83
+ qb <= ~q
84
+ (q <= d & [~rst]*typ.width).at(clk.posedge)
85
+ end
86
+
87
+ # Now declare the systems decribing the registers.
88
+ system :dff_body do
89
+ make_reg_body(bit)
90
+ end
91
+
92
+ system :reg8_body do
93
+ make_reg_body(bit[7..0])
94
+ end
95
+
96
+ system :regn_body do |n|
97
+ make_reg_body(bit[n-1..0])
98
+ end
99
+
100
+ system :reg_body do |typ|
101
+ make_reg_body(typ)
102
+ end
103
+
104
+ # Instantiate these systems for checking them.
105
+ dff_body :dff_bodyI
106
+ reg8_body :reg8_bodyI
107
+ regn_body :regn_bodyI, 8
108
+ reg_body :reg_bodyI, bit[7..0]
109
+
110
+
111
+ # Function generating a register declaration.
112
+ def make_reg(name,&blk)
113
+ system name do |*arg|
114
+ input :clk, :rst
115
+ blk.(*arg).input :d
116
+ blk.(*arg).output :q,:qb
117
+
118
+ qb <= ~q
119
+ (q <= d & [~rst]*blk.(*arg).width).at(clk.posedge)
120
+ end
121
+ end
122
+
123
+ # Now let's generate the register declarations.
124
+ make_reg(:dff_make) { bit }
125
+ make_reg(:reg8_make){ bit[7..0] }
126
+ make_reg(:regn_make){ |n| bit[n-1..0] }
127
+ make_reg(:reg_make) { |typ| typ }
128
+
129
+ # Instantiate these systems for checking them.
130
+ dff_make :dff_makeI
131
+ reg8_make :reg8_makeI
132
+ regn_make :regn_makeI, 8
133
+ reg_make :reg_makeI, bit[7..0]
134
+
135
+ # Generate the low level representation.
136
+ low = reg_makeI.systemT.to_low
137
+
138
+ # Displays it
139
+ puts low.to_yaml
@@ -0,0 +1,23 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Describes an 8-bit data 8-bit address ROM.
6
+ system :rom8_8 do
7
+ [7..0].input :addr
8
+ [7..0].inout :data
9
+
10
+ bit[7..0][2**8].constant content: (2**8).times.to_a
11
+
12
+ data <= content[addr]
13
+ end
14
+
15
+ # Instantiate it for checking.
16
+ rom8_8 :rom8_8I
17
+
18
+
19
+ # Generate the low level representation.
20
+ low = rom8_8I.systemT.to_low
21
+
22
+ # Displays it
23
+ puts low.to_yaml
@@ -0,0 +1,37 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A system with named scopes and blocks.
7
+ system :with_names do
8
+ [15..0].input :x, :y, :z
9
+ [16..0].output :u, :v
10
+
11
+ sub :me do
12
+ inner :a
13
+ a <= x + y
14
+ end
15
+
16
+ par do
17
+ inner :a
18
+ a <= me.a * z
19
+
20
+ sub :myself do
21
+ inner :a
22
+ a <= y - z
23
+ end
24
+ u <= a * myself.a
25
+ end
26
+
27
+ v <= me.a - z
28
+ end
29
+
30
+ # Instantiate it for checking.
31
+ with_names :with_namesI
32
+
33
+ # Generate the low level representation.
34
+ low = with_namesI.systemT.to_low
35
+
36
+ # Displays it
37
+ puts low.to_yaml
@@ -0,0 +1,26 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # System with scopes within scopes.
6
+ system :scopescope do
7
+ input :i0,:i1
8
+ output :o0,:o1
9
+ inner :s0
10
+
11
+ sub do
12
+ inner :s0
13
+ sub do
14
+ inner :s0
15
+ end
16
+ end
17
+ end
18
+
19
+ # Instantiate it for checking.
20
+ scopescope :scopescopeI
21
+
22
+ # Generate the low level representation.
23
+ low = scopescopeI.systemT.to_low
24
+
25
+ # Displays it
26
+ puts low.to_yaml
@@ -0,0 +1,31 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # Describes an 16-bit shift register.
7
+ system :shift16 do
8
+ input :clk, :rst, :din
9
+ output :dout
10
+
11
+ [15..0].inner :reg
12
+
13
+ dout <= reg[15] # The output is the last bit of the register.
14
+
15
+ par(clk.posedge) do
16
+ hif(rst) { reg <= 0 }
17
+ helse seq do
18
+ reg[0] <= din
19
+ reg[15..1] <= reg[14..0]
20
+ end
21
+ end
22
+ end
23
+
24
+ # Instantiate it for checking.
25
+ shift16 :shift16I
26
+
27
+ # Generate the low level representation.
28
+ low = shift16I.systemT.to_low
29
+
30
+ # Displays it
31
+ puts low.to_yaml
@@ -0,0 +1,40 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ system :dff do
7
+ input :clk, :rst, :d
8
+ output :q, :qb
9
+
10
+ qb <= ~q
11
+
12
+ (q <= d & ~rst).at(clk.posedge)
13
+ end
14
+
15
+ system :shifter do |n|
16
+ input :i0
17
+ output :o0, :o0b
18
+
19
+ # Instantiating n D-FF
20
+ [n].dff :dffIs
21
+
22
+ # Interconnect them as a shift register
23
+ dffIs[0..-2].zip(dffIs[1..-1]) do |ff0,ff1|
24
+ ff1.d <= ff0.q
25
+ end
26
+
27
+ # Connects the input and output of the circuit
28
+ dffIs[0].d <= i0
29
+ o0 <= dffIs[-1].q
30
+ o0b <= dffIs[-1].qb
31
+ end
32
+
33
+ # Instantiate it for checking.
34
+ shifter(16).(:shifterI)
35
+
36
+ # Generate the low level representation.
37
+ low = shifterI.systemT.to_low
38
+
39
+ # Displays it
40
+ puts low.to_yaml
@@ -0,0 +1,31 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Simple test of instantiation.
6
+
7
+
8
+ system :io do
9
+ input :i
10
+ output :o
11
+
12
+ i <= o
13
+ end
14
+
15
+ system :with_io do
16
+ input :i
17
+ output :o
18
+
19
+ io(:ioI).(i: i, o: o)
20
+ end
21
+
22
+
23
+
24
+ # Instantiate it for checking.
25
+ with_io :with_ioI
26
+
27
+ # Generate the low level representation.
28
+ low = with_ioI.systemT.to_low
29
+
30
+ # Displays it
31
+ puts low.to_yaml
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ # Script for testing all the samples
3
+
4
+ for file in *.rb
5
+ do
6
+ # Skip the samples starting by "_" (they are WIP)
7
+ if [[ ${file:0:1} == "_" ]] ; then continue; fi
8
+ # A sample to check
9
+ bundle exec ruby "$file" || exit 1
10
+ done
@@ -0,0 +1,24 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Definition of the word type.
6
+ [15..0].typedef(:word)
7
+
8
+
9
+ # A simple adder using previously defined type word
10
+ system :adder do
11
+ word.input :x,:y
12
+ word.output :s
13
+
14
+ s <= x + y
15
+ end
16
+
17
+ # Instantiate it for checking.
18
+ adder :adderI
19
+
20
+ # Generate the low level representation.
21
+ low = adderI.systemT.to_low
22
+
23
+ # Displays it
24
+ puts low.to_yaml
@@ -0,0 +1,70 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Describes a system including several value.
6
+ system :values do
7
+ [3..0].output :sig
8
+
9
+ timed do
10
+ !1.us
11
+ sig <= _1010
12
+ !1.us
13
+ sig <= _b4b1010
14
+ !1.us
15
+ sig <= _bb1001
16
+ !1.us
17
+ sig <= _b1100
18
+
19
+ !1.us
20
+ sig <= _u4b1010
21
+ !1.us
22
+ sig <= _ub1001
23
+ !1.us
24
+ sig <= _u1100
25
+
26
+ !1.us
27
+ sig <= _s4b1010
28
+ !1.us
29
+ sig <= _sb1001
30
+ !1.us
31
+ sig <= _s1100
32
+
33
+ !1.us
34
+ sig <= _b12o0623
35
+ !1.us
36
+ sig <= _bo0623
37
+ !1.us
38
+ sig <= _b12d0923
39
+ !1.us
40
+ sig <= _bd0923
41
+ !1.us
42
+ sig <= _b16h0F2E
43
+ !1.us
44
+ sig <= _bh0F2E
45
+
46
+ !1.us
47
+ sig <= _b1ZZX
48
+
49
+ !1.us
50
+ sig <= _b0110 + _b0110
51
+ !1.us
52
+ sig <= _b0110 - _b0110
53
+ !1.us
54
+ sig <= _b0110 * _b0010
55
+ !1.us
56
+ sig <= _b0110 / _b0010
57
+ !1.us
58
+ sig <= _b0110 % _b0010
59
+ end
60
+ end
61
+
62
+
63
+ # Instantiate it for checking.
64
+ values :valuesI
65
+
66
+ # Generate the low level representation.
67
+ low = valuesI.systemT.to_low
68
+
69
+ # Displays it
70
+ puts low.to_yaml
@@ -0,0 +1,22 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ # Describes a system including several vector types.
6
+ system :vectors do
7
+ [7..0].input :byte
8
+ [ bit[8], signed[16], unsigned[16] ].output :bss
9
+
10
+ # For testing each_type, no hardware is generated.
11
+ bss.type.each_type {|t| }
12
+ end
13
+
14
+
15
+ # Instantiate it for checking.
16
+ vectors :vectorsI
17
+
18
+ # Generate the low level representation.
19
+ low = vectorsI.systemT.to_low
20
+
21
+ # Displays it
22
+ puts low.to_yaml
@@ -0,0 +1,30 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ require 'HDLRuby/std/decoder'
6
+ include HDLRuby::High::Std
7
+
8
+ # Implementation of a decoder.
9
+ system :my_decoder do
10
+ [7..0].input :a
11
+ [7..0].output :z
12
+
13
+ decoder(a) do
14
+ entry("1000uuvv") { z <= u + v }
15
+ entry("101uuuvv") { z <= u - v }
16
+ entry("1100uuvv") { z <= u & v }
17
+ entry("1101uuvv") { z <= u | v }
18
+ entry("1110uuvv") { z <= u ^ v }
19
+ default { z <= 0 }
20
+ end
21
+ end
22
+
23
+ # Instantiate it for checking.
24
+ my_decoder :my_decoderI
25
+
26
+ # Generate the low level representation.
27
+ low = my_decoderI.systemT.to_low
28
+
29
+ # Displays it
30
+ puts low.to_yaml
@@ -0,0 +1,46 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+ require 'HDLRuby/std/fsm'
6
+ include HDLRuby::High::Std
7
+
8
+ # Implementation of a fsm.
9
+ system :my_fsm do
10
+ input :clk,:rst
11
+ [7..0].input :a, :b
12
+ [7..0].output :z
13
+
14
+ # fsm :fsmI
15
+ # fsmI.for_event { clk.posedge }
16
+ # # Shortcut: fsmI.for_event(clk)
17
+ # fsmI.for_reset { rst }
18
+ # # Shortcut: fsmI.for_reset(rst)
19
+ # fsmI do
20
+ # state { z <= 0 }
21
+ # state(:there) { z <= a+b }
22
+ # state do
23
+ # hif (a>0) { z <= a-b }
24
+ # helse { goto(:there) }
25
+ # end
26
+ # end
27
+ # Other alternative:
28
+ fsm(clk.posedge,rst) do
29
+ reset { z <= 0 }
30
+ state { z <= a+b }
31
+ state(:there) do
32
+ hif (z!=0) { z <= a-b }
33
+ goto(z==0,:end,:there)
34
+ end
35
+ state(:end) { goto(:end) }
36
+ end
37
+ end
38
+
39
+ # Instantiate it for checking.
40
+ my_fsm :my_fsmI
41
+
42
+ # Generate the low level representation.
43
+ low = my_fsmI.systemT.to_low
44
+
45
+ # Displays it
46
+ puts low.to_yaml
@@ -0,0 +1,43 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ require 'HDLRuby/std/pipeline'
7
+ include HDLRuby::High::Std
8
+
9
+
10
+ # A simple test of the pipeline construct
11
+ system :with_pipe do
12
+ input :clk,:rst
13
+ [15..0].input :x, :y
14
+ [31..0].input :z
15
+ [31..0].output :u, :v
16
+
17
+
18
+ pipeline :pipeI # Shortcut: pipeline(clk,rst).(:fsmI)
19
+ pipeI.for_event { clk.posedge }
20
+ # Shortcut: pipeI.clk = clk
21
+ pipeI.for_reset { rst }
22
+ # Shortcut: pipeI.rst = rst
23
+
24
+ pipeI do
25
+ stage { a <= x + y }
26
+ stage(:a) do
27
+ b <= a + z
28
+ c <= a - z
29
+ d <= a * z
30
+ end
31
+ stage(:b,:c) { e <= b + c }
32
+ stage(:d,:e) { v <= d + e }
33
+ end
34
+ end
35
+
36
+ # Instantiate it for checking.
37
+ with_pipe :with_pipeI
38
+
39
+ # Generate the low level representation.
40
+ low = with_pipeI.systemT.to_low
41
+
42
+ # Displays it
43
+ puts low.to_yaml
@@ -0,0 +1,25 @@
1
+ require 'HDLRuby'
2
+
3
+ configure_high
4
+
5
+
6
+ # A example of behavior with default seq
7
+ system :with_seq do
8
+ [15..0].input :x,:y, :clk
9
+ [16..0].inner :w
10
+ [16..0].output :o
11
+
12
+ seq(clk.posedge) do
13
+ w <= x + y
14
+ o <= w + y
15
+ end
16
+ end
17
+
18
+ # Instantiate it for checking.
19
+ with_seq :with_seqI
20
+
21
+ # Generate the low level representation.
22
+ low = with_seqI.systemT.to_low
23
+
24
+ # Displays it
25
+ puts low.to_yaml