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,594 @@
1
+ ########################################################################
2
+ ## Program for testing the HDLRuby::Low module. ##
3
+ ########################################################################
4
+
5
+ require "HDLRuby.rb"
6
+ require "HDLRuby/hruby_serializer.rb"
7
+
8
+ configure_high
9
+
10
+
11
+ $success = true
12
+
13
+
14
+ print "Creating an empty system type... "
15
+ begin
16
+ $systemT0 = system(:systemT0) {}
17
+ unless $systemT0 then
18
+ raise "Error: created system type not found."
19
+ $success =false
20
+ end
21
+ if $systemT0.name != :systemT0 then
22
+ raise "Error: invalid system type name, got #{$systemT0.name} but expecting systemT0."
23
+ $success = false
24
+ end
25
+ puts "Ok."
26
+ # rescue Exception => e
27
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
28
+ # $success = false
29
+ end
30
+
31
+ print "Instantiate it... "
32
+ begin
33
+ $systemI0 = $systemT0.instantiate("systemI0")
34
+ puts "Ok."
35
+ # rescue Exception => e
36
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
37
+ # $success = false
38
+ end
39
+
40
+ print "Creating the unsigned char type (bit[8])... "
41
+ begin
42
+ $uchar = typedef(:uchar) { bit[8] }
43
+ puts "Ok."
44
+ # rescue Exception => e
45
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
46
+ # $success = false
47
+ end
48
+
49
+ # print "Converting systemT0 to a type... "
50
+ # begin
51
+ # $sigT0 = type(:sigT0) { $systemT0.to_type([],[]) }
52
+ # puts "Ok."
53
+ # # rescue Exception => e
54
+ # # puts "Error: unexpected exception raised #{e.inspect}\n"
55
+ # # $success = false
56
+ # end
57
+
58
+
59
+ print "\nCreating a system type with content (also using the created char type)... "
60
+ begin
61
+ $systemT1 = system :systemT1 do # |x,y,z|
62
+ bit.input :clk
63
+ systemT0 :my_system
64
+ input :i0, :i1
65
+ output :o0
66
+ uchar.input :i2
67
+ [7..0].input :i3
68
+ bit[7..0].output :o1
69
+ {header: bit[4], data: bit[28]}.inner :frame
70
+ {int: signed[32], uint: bit[32]}.inout :value
71
+ # sigT0.inner :my_sig
72
+ [bit[4],unsigned[8],signed[16]].inner :my_sig
73
+
74
+ o0 <= i0 + i1 # Standard connection
75
+ # x <= mux(o0, y, z) # Connection of generic parameters with a mux
76
+
77
+ par(i0.posedge) do
78
+ (o1 <= i0 * i1).hif(i0 != 0)
79
+ seq do
80
+ value.int[7..0] <= i2 + i3
81
+ end
82
+ hif (i3 > i2) {
83
+ value.int[15..8] <= i3
84
+ }
85
+ helse {
86
+ value.int[15..8] <= i2
87
+ }
88
+ hcase(i2)
89
+ hwhen(5) {
90
+ value.int[15..14] <= 0
91
+ }
92
+ hwhen(i3) {
93
+ value.int[15..14] <= 1
94
+ }
95
+ helse {
96
+ value.int[15..14] <= 2
97
+ }
98
+ end
99
+
100
+ timed do
101
+ clk <= 0
102
+ !10.ns
103
+ clk <= 1
104
+ !10.ns
105
+ clk <= 0
106
+ repeat(1000.ns) do
107
+ !10.ns
108
+ clk <= 1
109
+ !10.ns
110
+ clk <= 0
111
+ end
112
+ end
113
+ # Connection converted to behavior through a at.
114
+ (o1 <= i2 + i3).at(clk.posedge)
115
+ end
116
+ unless $systemT1 then
117
+ raise "Error: created system type not found."
118
+ $success =false
119
+ end
120
+ if $systemT1.name != :systemT1 then
121
+ raise "Error: invalid system type name, got #{$systemT0.name} but expecting systemT0."
122
+ $success = false
123
+ end
124
+ puts "Ok."
125
+ # rescue Exception => e
126
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
127
+ # $success = false
128
+ end
129
+
130
+ print "Instantiate it... "
131
+ begin
132
+ # $systemI1 = $systemT1.instantiate("systemI1",SignalI.new(:"",$uchar,:inner),SignalI.new(:"",$uchar,:inner),SignalI.new(:"",$uchar,:inner))
133
+ $systemI1 = $systemT1.instantiate("systemI1")
134
+ puts "$systemI1 scope=#{$systemI1.systemT.scope}"
135
+ systemI1Is = $systemI1.each_systemI.to_a
136
+ success = true
137
+ if systemI1Is.size != 1 then
138
+ puts "Error: invalid number of inner system instances, got #{systemI1Is.size} but expecting 1."
139
+ success = false
140
+ elsif systemI1Is[0].name != :my_system then
141
+ puts "Error: invalid inner system instance, got #{systemI1Is[0].name} but expecting my_system."
142
+ success = false
143
+ end
144
+ systemI1Ins = $systemI1.each_input.to_a
145
+ if systemI1Ins.size != 5 then
146
+ puts "Error: invalid number of input signals, got #{systemI1Ins.size} but expecting 5."
147
+ success = false
148
+ elsif systemI1Ins[0].name != :clk then
149
+ puts "Error: invalid input signal, got #{systemI1Ins[0].name} but expecting clk."
150
+ success = false
151
+ elsif systemI1Ins[0].type.name != :bit then
152
+ puts "Error: invalid type for clk, got #{systemI1Ins[0].type.name} but expecting clk."
153
+ success = false
154
+ elsif systemI1Ins[1].name != :i0 then
155
+ puts "Error: invalid input signal, got #{systemI1Ins[0].name} but expecting i0."
156
+ success = false
157
+ elsif systemI1Ins[1].type.name != :bit then
158
+ puts "Error: invalid type for i0, got #{systemI1Ins[0].type.name} but expecting bit."
159
+ success = false
160
+ elsif systemI1Ins[2].name != :i1 then
161
+ puts "Error: invalid input signal, got #{systemI1Ins[1].name} but expecting i1."
162
+ success = false
163
+ elsif systemI1Ins[3].name != :i2 then
164
+ puts "Error: invalid input signal, got #{systemI1Ins[2].name} but expecting i2."
165
+ success = false
166
+ elsif !systemI1Ins[3].type.is_a?(TypeDef) then
167
+ puts "Error: invalid type for i2, got #{systemI1Ins[3].type.class} but expecting TypeVector."
168
+ success = false
169
+ elsif systemI1Ins[3].type.base.name != :bit then
170
+ puts "Error: invalid base type for i2, got #{systemI1Ins[2].type.base.name} but expecting bit."
171
+ success = false
172
+ elsif systemI1Ins[3].type.range != (7..0) then
173
+ puts "Error: invalid type range for i2, got #{systemI1Ins[2].type.range} but expecting 7..0."
174
+ success = false
175
+ elsif systemI1Ins[4].name != :i3 then
176
+ puts "Error: invalid input signal, got #{systemI1Ins[3].name} but expecting i3."
177
+ success = false
178
+ end
179
+
180
+ systemI1Outs = $systemI1.each_output.to_a
181
+ if systemI1Outs.size != 2 then
182
+ puts "Error: invalid number of output signals, got #{systemI1Outs.size} but expecting 2."
183
+ success = false
184
+ elsif systemI1Outs[0].name != :o0 then
185
+ puts "Error: invalid output signal, got #{systemI1Outs[0].name} but expecting o0."
186
+ success = false
187
+ elsif systemI1Outs[1].name != :o1 then
188
+ puts "Error: invalid output signal, got #{systemI1Outs[1].name} but expecting o1."
189
+ success = false
190
+ end
191
+
192
+ systemI1Inners = $systemI1.each_inner.to_a
193
+ if systemI1Inners.size != 2 then
194
+ puts "Error: invalid number of inner signals, got #{systemI1Inners.size} but expecting 2."
195
+ success = false
196
+ elsif systemI1Inners[0].name != :frame then
197
+ puts "Error: invalid inner signal, got #{systemI1Inners[0].name} but expecting frame."
198
+ success = false
199
+ elsif !systemI1Inners[0].type.is_a?(TypeStruct) then
200
+ puts "Error: invalid inner type, got #{systemI1Inners[0].type.class} but expecting TypeStruct."
201
+ success = false
202
+ elsif !systemI1Inners[0].type.get_type(:header).is_a?(TypeVector) then
203
+ puts "Error: invalid inner type record for header, got #{systemI1Inners[0].type.get_type(:header).class} but expecting TypeVector."
204
+ success = false
205
+ elsif !systemI1Inners[0].type.get_type(:data).is_a?(TypeVector) then
206
+ puts "Error: invalid inner type record for data, got #{systemI1Inners[0].type.get_type(:data).class} but expecting TypeVector."
207
+ success = false
208
+ elsif systemI1Inners[1].name != :my_sig then
209
+ puts "Error: invalid inner signal, got #{systemI1Inners[1].name} but expecting my_sig."
210
+ success = false
211
+ elsif !systemI1Inners[1].type.is_a?(TypeTuple) then
212
+ puts "Error: invalid inner type, got #{systemI1Inners[1].type.class} but expecting TypeTuple."
213
+ success = false
214
+ end
215
+
216
+ systemI1Inouts = $systemI1.each_inout.to_a
217
+ if systemI1Inouts.size != 1 then
218
+ puts "Error: invalid number of inout signals, got #{systemI1Inouts.size} but expecting 1."
219
+ success = false
220
+ elsif systemI1Inouts[0].name != :value then
221
+ puts "Error: invalid inout signal, got #{systemI1Inouts[0].name} but expecting value."
222
+ success = false
223
+ elsif !systemI1Inouts[0].type.is_a?(TypeStruct) then
224
+ puts "Error: invalid inout type, got #{systemI1Inouts[0].type.class} but expecting TypeStruct."
225
+ success = false
226
+ elsif !systemI1Inouts[0].type.get_type(:uint).is_a?(TypeVector) then
227
+ puts "Error: invalid inout type record for uint, got #{systemI1Inouts[0].type.get_type(:header).class} but expecting TypeVector."
228
+ success = false
229
+ elsif !systemI1Inouts[0].type.get_type(:int).is_a?(TypeVector) then
230
+ puts "Error: invalid inout type record for int, got #{systemI1Inouts[0].type.get_type(:data).class} but expecting TypeVector."
231
+ success = false
232
+ end
233
+
234
+ systemI1Connections = $systemI1.each_connection.to_a
235
+ if systemI1Connections.size != 1 then
236
+ puts "Error: invalid number of connections, got #{systemI1Connections.size} but expecting 1."
237
+ success = false
238
+ elsif systemI1Connections[0].left.object.name != :o0 then
239
+ puts "Error: invalid left for connection, got #{systemI1Connections[0].left.object.name} but expecting o0."
240
+ success = false
241
+ elsif systemI1Connections[0].right.operator != :+ then
242
+ puts "Error: invalid right operator for connection, got #{systemI1Connections[0].right.operator} but expecting +."
243
+ success = false
244
+ elsif systemI1Connections[0].right.left.object.name != :i0 then
245
+ puts "Error: invalid right left for connection, got #{systemI1Connections[0].right.left.object.name} but expecting i0."
246
+ success = false
247
+ elsif systemI1Connections[0].right.right.object.name != :i1 then
248
+ puts "Error: invalid right right for connection, got #{systemI1Connections[0].right.right.object.name} but expecting i1."
249
+ success = false
250
+ end
251
+
252
+ systemI1Behaviors = $systemI1.each_behavior.to_a
253
+ if systemI1Behaviors.size != 3 then
254
+ puts "Error: invalid number of behaviors, got #{systemI1Behaviors.size} but expecting 3."
255
+ success = false
256
+ end
257
+ systemI1Behavior = systemI1Behaviors[0]
258
+ systemI1Events = systemI1Behavior.each_event.to_a
259
+ if systemI1Events.size != 1 then
260
+ puts "Error: invalid number of events, got #{systemI1Events.size} but expecting 1."
261
+ success = false
262
+ elsif systemI1Events[0].type != :posedge then
263
+ puts "Error: invalid type of event, got #{systemI1Events[0].type} but expecting posedge."
264
+ elsif systemI1Events[0].ref.object.name != :i0 then
265
+ puts "Error: invalid event reference, got #{systemI1Events[0].ref.object.name} but expecting i0."
266
+ end
267
+ systemI1Block = systemI1Behavior.block
268
+ if systemI1Block.mode != :par then
269
+ puts "Error: invalid block mode, got #{systemI1Block.type} but expecting par."
270
+ success = false
271
+ end
272
+ systemI1Statements = systemI1Block.each_statement.to_a
273
+ if systemI1Statements.size != 4 then
274
+ puts "Error: invalid number of statements, got #{systemI1Statements.size} but expecting 4."
275
+ success = false
276
+ elsif !systemI1Statements[0].is_a?(Transmit) then
277
+ puts "Error: invalid first statement, got #{systemI1Statements[0].class} but expecting Transmit."
278
+ success = false
279
+ elsif systemI1Statements[0].left.object.name != :o1 then
280
+ puts "Error: invalid first statement left, got #{systemI1Statements[0].left.object.name} but expecting o1."
281
+ success = false
282
+ elsif systemI1Statements[0].right.operator != :* then
283
+ puts "Error: invalid first statement right operator, got #{systemI1Statements[0].right.operator} but expecting *."
284
+ success = false
285
+ elsif systemI1Statements[0].right.left.object.name != :i0 then
286
+ puts "Error: invalid first statement right left, got #{systemI1Statements[0].right.left.object.name} but expecting i0."
287
+ success = false
288
+ elsif systemI1Statements[0].right.right.object.name != :i1 then
289
+ puts "Error: invalid first statement right right, got #{systemI1Statements[0].right.left.object.name} but expecting i1."
290
+ success = false
291
+ elsif !systemI1Statements[2].is_a?(If) then
292
+ puts "Error: invalid third statement, got #{systemI1Statements[2].class} but expecting If."
293
+ success = false
294
+ elsif systemI1Statements[2].condition.operator != :> then
295
+ puts "Error: invalid third statement condition operator, got #{systemI1Statements[2].operator} but expecting <."
296
+ success = false
297
+ elsif !systemI1Statements[2].yes.is_a?(Block) then
298
+ puts "Error: invalid third statement yes, got #{systemI1Statements[2].yes.class} but expecting Block."
299
+ success = false
300
+ elsif !systemI1Statements[2].no.is_a?(Block) then
301
+ puts "Error: invalid third statement no, got #{systemI1Statements[2].no.class} but expecting Block."
302
+ success = false
303
+ elsif !systemI1Statements[3].is_a?(Case) then
304
+ puts "Error: invalid fourth statement, got #{systemI1Statements[3].class} but expecting Case."
305
+ success = false
306
+ elsif systemI1Statements[3].value.object.name != :i2 then
307
+ puts "Error: invalid fourth statement value, got #{systemI1Statements[3].value.object.name} but expecting i2."
308
+ success = false
309
+ elsif systemI1Statements[3].each_when.to_a.size != 2 then
310
+ puts "Error: invalid number of when for fourth statement, got #{systemI1Statements[3].each_when.to_a.size} but expecting 2."
311
+ success = false
312
+ elsif systemI1Statements[3].each_when.first.match.content != 5 then
313
+ puts "Error: invalid match of first when for fourth statement, got #{systemI1Statements[3].each_when.first[0].content} but expecting 5."
314
+ success = false
315
+ elsif !systemI1Statements[3].default then
316
+ puts "Error: no default for fourth statement."
317
+ success = false
318
+ end
319
+ systemI1Seq = systemI1Statements[1]
320
+ if !systemI1Seq.is_a?(Block) then
321
+ puts "Error: invalid second statement, got #{systemI1Seq.class} but expecting Block."
322
+ success = false
323
+ elsif systemI1Seq.mode != :seq then
324
+ puts "Error: invalid type of block, got #{systemI1Seq.type} but expecting seq."
325
+ success = false
326
+ end
327
+ systemI1SeqStatements = systemI1Seq.each_statement.to_a
328
+ if systemI1SeqStatements.size != 1 then
329
+ puts "Error: invalid number of statements, got #{systemI1Statements.size} but expecting 1."
330
+ success = false
331
+ elsif !systemI1SeqStatements[0].is_a?(Transmit) then
332
+ puts "Error: invalid first statement, got #{systemI1SeqStatements[0].class} but expecting Transmit."
333
+ success = false
334
+ elsif systemI1SeqStatements[0].right.operator != :+ then
335
+ puts "Error: invalid first statement right operator, got #{systemI1SeqStatements[0].right.operator} but expecting +."
336
+ success = false
337
+ elsif !systemI1SeqStatements[0].left.is_a?(RefRange) then
338
+ puts "Error: invalid first statement left reference, got #{systemI1SeqStatements[0].left.class} but expecting RefRange."
339
+ success = false
340
+ elsif systemI1SeqStatements[0].left.range.first.content != 7 then
341
+ puts "Error: invalid first statement left reference range, got #{systemI1SeqStatements[0].left.range} but expecting 7..0."
342
+ success = false
343
+ elsif systemI1SeqStatements[0].left.range.last.content != 0 then
344
+ puts "Error: invalid first statement left reference range, got #{systemI1SeqStatements[0].left.range} but expecting 7..0."
345
+ success = false
346
+ elsif !systemI1SeqStatements[0].left.ref.is_a?(RefObject) then
347
+ puts "Error: invalid first statement left left reference, got #{systemI1SeqStatements[0].left.ref.class} but expecting RefName."
348
+ success = false
349
+ elsif systemI1SeqStatements[0].left.ref.name != :int then
350
+ puts "Error: invalid first statement left left reference name, got #{systemI1SeqStatements[0].left.ref.name} but expecting int."
351
+ success = false
352
+ elsif systemI1SeqStatements[0].left.ref.base.object.name != :value then
353
+ puts "Error: invalid first statement left left left reference name, got #{systemI1SeqStatements[0].left.ref.base.object.name} but expecting value."
354
+ success = false
355
+ end
356
+
357
+ systemI1Time = systemI1Behaviors[1]
358
+ unless systemI1Time.is_a?(Low::TimeBehavior) then
359
+ puts "Error: invalid behavior class: got #{systemI1Time.class} but expecting TimeBehavior."
360
+ success = false
361
+ end
362
+ # systemI1TimeBlks = systemI1Time.each_block.to_a
363
+ # unless systemI1TimeBlks.size == 1 then
364
+ # puts "Error: invalid number of timed blocks: got #{systemI1TimeBlks.size} but expecting 1."
365
+ # success = false
366
+ # end
367
+ # systemI1TimeStms = systemI1TimeBlks[0].each_statement.to_a
368
+ systemI1TimeStms = systemI1Time.block.each_statement.to_a
369
+ unless systemI1TimeStms.size == 6 then
370
+ puts "Error: invalid number of timed statements: got #{systemI1TimeStms.size} but expecting 6."
371
+ success = false
372
+ end
373
+ unless systemI1TimeStms[0].is_a?(Transmit) then
374
+ puts "Error: invalid class for first timed statements: got #{systemI1TimeStms[0].class} but expecting Transmit."
375
+ success = false
376
+ end
377
+ unless systemI1TimeStms[1].is_a?(TimeWait) then
378
+ puts "Error: invalid class for second timed statements: got #{systemI1TimeStms[1].class} but expecting TimeDelay."
379
+ success = false
380
+ end
381
+ unless systemI1TimeStms[1].delay.unit == :ns then
382
+ puts "Error: invalid unit for second timed statements: got #{systemI1TimeStms[1].unit} but expecting ns."
383
+ success = false
384
+ end
385
+ unless systemI1TimeStms[1].delay.value == 10 then
386
+ puts "Error: invalid value for second timed statements: got #{systemI1TimeStms[1].value} but expecting 10."
387
+ success = false
388
+ end
389
+ unless systemI1TimeStms[-1].is_a?(TimeRepeat) then
390
+ puts "Error: invalid class for last time statement: got #{systemI1TimeStms[-1].class} but expecting TimeRepeat."
391
+ success = false
392
+ end
393
+ unless systemI1TimeStms[-1].delay.value == 1000 then
394
+ puts "Error: invalid value for second timed statements: got #{systemI1TimeStms[-1].value} but expecting 10."
395
+ success = false
396
+ end
397
+ unless systemI1TimeStms[-1].statement.each_statement.to_a.size == 4 then
398
+ puts "Error: invalid number of statements in the timed repeat: got #{systemI1TimeStms[-1].statement.each_statement.to_a.size} but expecting 4."
399
+ success = false
400
+ end
401
+
402
+ systemI1At = systemI1Behaviors[2]
403
+ systemI1AtEvents = systemI1At.each_event.to_a
404
+ if systemI1AtEvents.size != 1 then
405
+ puts "Error: invalid number of events, got #{systemI1AtEvents.size} but expecting 1."
406
+ success = false
407
+ elsif systemI1AtEvents[0].type != :posedge then
408
+ puts "Error: invalid type of event, got #{systemI1AtEvents[0].type} but expecting posedge."
409
+ elsif systemI1AtEvents[0].ref.object.name != :clk then
410
+ puts "Error: invalid event reference, got #{systemI1AtEvents[0].ref.object.name} but expecting clk."
411
+ end
412
+ systemI1AtBlock = systemI1At.block
413
+ if systemI1AtBlock.mode != :par then
414
+ puts "Error: invalid block mode, got #{systemI1AtBlock.type} but expecting par."
415
+ success = false
416
+ end
417
+ systemI1AtStatements = systemI1AtBlock.each_statement.to_a
418
+ if systemI1AtStatements.size != 1 then
419
+ puts "Error: invalid number of statements, got #{systemI1AtStatements.size} but expecting 1."
420
+ success = false
421
+ elsif !systemI1AtStatements[0].is_a?(Transmit) then
422
+ puts "Error: invalid first statement, got #{systemI1AtStatements[0].class} but expecting Transmit."
423
+ success = false
424
+ elsif systemI1AtStatements[0].left.object.name != :o1 then
425
+ puts "Error: invalid first statement left, got #{systemI1AtStatements[0].left.object.name} but expecting o1."
426
+ success = false
427
+ elsif systemI1AtStatements[0].right.operator != :+ then
428
+ puts "Error: invalid first statement right operator, got #{systemI1AtStatements[0].right.operator} but expecting +."
429
+ success = false
430
+ elsif systemI1AtStatements[0].right.left.object.name != :i2 then
431
+ puts "Error: invalid first statement right left, got #{systemI1AtStatements[0].right.left.object.name} but expecting i2."
432
+ success = false
433
+ elsif systemI1AtStatements[0].right.right.object.name != :i3 then
434
+ puts "Error: invalid first statement right right, got #{systemI1AtStatements[0].right.left.object.name} but expecting i3."
435
+ success = false
436
+ end
437
+
438
+ if success then
439
+ puts "Ok."
440
+ else
441
+ $success = false
442
+ end
443
+ # rescue Exception => e
444
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
445
+ # $success = false
446
+ end
447
+
448
+ print "\nCreating a simple generic system with 2 inputs and 2 outputs... "
449
+ begin
450
+ $systemT2 = system :systemT2 do |type|
451
+ input :clk
452
+ type.input :i0,:i1
453
+ type.output :o0,:o1
454
+ end
455
+ puts "Ok."
456
+ # rescue Exception => e
457
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
458
+ # $success = false
459
+ end
460
+
461
+ # print "Converting it to a type... "
462
+ # begin
463
+ # $sigT2 = type(:sigT2) { $systemT2.to_type([:i0,:i1],[:o0,:o1]) }
464
+ # unless $sigT2.is_a?(TypeSystemT) then
465
+ # raise "Invalid type class: got #{$sigT2.class} but expecting TypeSystemT."
466
+ # end
467
+ # puts "Ok."
468
+ # # rescue Exception => e
469
+ # # puts "Error: unexpected exception raised #{e.inspect}\n"
470
+ # # $success = false
471
+ # end
472
+ #
473
+ # print "Using it in a new system and instantiate the result... "
474
+ # begin
475
+ # $systemT3 = system :systemT3 do
476
+ # sigT2.(uchar).input :x,:y
477
+ # sigT2.(uchar).output :z
478
+ # end
479
+ # $systemI3 = $systemT3.instantiate("systemI3")
480
+ # systemI3inputs = $systemI3.each_input.to_a
481
+ # success = true
482
+ # [:i0,:i1,:o0,:o1].each do |name|
483
+ # unless systemI3inputs[0].respond_to?(name) then
484
+ # puts "Error: systemI3's input does not include #{name} sub signal."
485
+ # success = false
486
+ # end
487
+ # end
488
+ # [:i0,:i1].each do |name|
489
+ # unless systemI3inputs[0].type.left.get_type(name) then
490
+ # puts "Error: systemI3's input type's left side does not include #{name} sub type."
491
+ # success = false
492
+ # end
493
+ # end
494
+ # [:o0,:o1].each do |name|
495
+ # unless systemI3inputs[0].type.right.get_type(name) then
496
+ # puts "Error: systemI3's input type's right side does not include #{name} sub type."
497
+ # success = false
498
+ # end
499
+ # end
500
+ # if (success) then
501
+ # puts "Ok."
502
+ # else
503
+ # $success = false
504
+ # end
505
+ # # rescue Exception => e
506
+ # # puts "Error: unexpected exception raised #{e.inspect}\n"
507
+ # # $success = false
508
+ # end
509
+
510
+ print "Creating another basic system and instantiate it... "
511
+ $systemT3 = system :systemT3 do
512
+ uchar.input :x,:y
513
+ uchar.output :z
514
+ end
515
+ $systemI3 = $systemT3.instantiate("systemI3")
516
+
517
+
518
+ print "\nExtending systemT3 and do a bit of meta programming... "
519
+ begin
520
+ $systemI3.open do
521
+ z <= x & y
522
+ end
523
+ # block_open do
524
+ # def hello(name)
525
+ # $hello = "Hello #{name}."
526
+ # end
527
+ # end
528
+ # par do
529
+ # hello("everybody")
530
+ # end
531
+ # end
532
+ $systemT3.singleton_instance.class_eval do
533
+ def hello(name)
534
+ $hello = "Hello #{name}."
535
+ end
536
+ end
537
+ $systemI32 = $systemT3.instantiate("systemI32")
538
+ $systemI32.hello("everybody")
539
+ success = true
540
+ unless $hello == "Hello everybody." then
541
+ puts "Change of the block classes had no effect."
542
+ success = false
543
+ end
544
+ # Not valid any longer.
545
+ # begin
546
+ # system :fake do
547
+ # par do
548
+ # hello("no one.")
549
+ # end
550
+ # end.instantiate(:faker)
551
+ # puts "The hello method should not be in a general block class."
552
+ # success = false
553
+ # rescue Exception => e
554
+ # unless ( e.is_a?(NoMethodError) and e.message.include?("hello") ) then
555
+ # puts "Error: unexpected exception #{e.inspect}."
556
+ # success = false
557
+ # end
558
+ # end
559
+ $systemI3Connections = $systemI3.each_connection.to_a
560
+ unless $systemI3Connections.size == 1 then
561
+ puts "Invalid number of connection: got #{$systemI3Connections.size} but expecting 1."
562
+ success = false
563
+ end
564
+ unless $systemI3Connections[0].right.operator == :& then
565
+ puts "Invalid operator for connection's right: got #{$systemI3Connections[0].right.operator} but expecting &."
566
+ success = false
567
+ end
568
+ if success then
569
+ puts "Ok."
570
+ else
571
+ $success = false
572
+ end
573
+ # rescue Exception => e
574
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
575
+ # $success = false
576
+ end
577
+
578
+ begin
579
+ # Try to convert to low
580
+ print "\nConverts systemI1 to low... "
581
+ $systemI1low = $systemI1.to_low
582
+ puts "Ok."
583
+ puts "The resulting low level system is: "
584
+ puts $systemI1low.to_yaml
585
+ # rescue Exception => e
586
+ # puts "Error: unexpected exception raised #{e.inspect}\n"
587
+ # $success = false
588
+ end
589
+
590
+ if $success then
591
+ puts "\nSuccess."
592
+ else
593
+ puts "\nFailure."
594
+ end
@@ -0,0 +1,99 @@
1
+ require 'HDLRuby'
2
+ require 'HDLRuby/hruby_low2sym'
3
+
4
+ configure_high
5
+
6
+ # Program for testing both HDLRuby::High and HDLRuby::Low
7
+
8
+
9
+ print "Checking creation of an HDLRuby::High system... "
10
+ # Create a HDLRuby::High testing system
11
+ system :high_test do
12
+ input :clk, :cond0, :cond1
13
+ [15..0].input :x,:y,:z
14
+ [16..0].output :s,:u,:v
15
+
16
+ seq(clk.posedge) do
17
+ hif(cond0) { s <= x+y }
18
+ helsif(cond1) { u <= x+y+2 }
19
+ helse { s <= z }
20
+ v <= x*y*_011
21
+ end
22
+
23
+ [3..0].output :sig
24
+ timed do
25
+ !1.us
26
+ sig <= _1010
27
+ end
28
+ end
29
+
30
+ puts "Ok."
31
+
32
+ print "Checking its instantiation... "
33
+ # Instantiate it for checking.
34
+ high_test :high
35
+
36
+ puts "Ok."
37
+
38
+ print "Checking its conversion to low... "
39
+ # Generate the low level representation.
40
+ low = high.systemT.to_low
41
+
42
+ puts "Ok."
43
+ puts
44
+ puts "##############################"
45
+ puts "Checking HDLRuby::Low methods."
46
+ puts "##############################"
47
+
48
+ puts
49
+ puts "Checking clone."
50
+ # Try clone
51
+ low.each_behavior do |beh|
52
+ beh.each_statement do |statement|
53
+ print "Cloning statement: #{statement}... "
54
+ copy = statement.clone
55
+ if copy.class == statement.class then
56
+ puts "Ok."
57
+ else
58
+ puts "Invalid clone result: #{statement.class}"
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ puts
65
+ puts "Checking eql?."
66
+ puts "Cloning system: #{system}... "
67
+ low_clone = low.clone
68
+ print "Checking eql? with the copy and the original of #{system}... "
69
+ # Try eql?
70
+ res = low.eql?(low_clone)
71
+ if res then
72
+ puts "Ok."
73
+ else
74
+ puts "Invalid eql result: #{res}."
75
+ end
76
+
77
+
78
+ puts
79
+ puts "Checking hash."
80
+ print "Checking hash with the copy and the original of #{system}... "
81
+ low_hash = low.hash
82
+ clone_hash = low_clone.hash
83
+ if low_hash == clone_hash then
84
+ puts "Ok."
85
+ else
86
+ puts "Invalid hashbol expected #{low_hash} but got: #{clone_hash}."
87
+ end
88
+
89
+
90
+ puts
91
+ puts "Checking to_sym."
92
+ print "Checking to_sym with the copy and the original of #{system}... "
93
+ low_to_sym = low.to_sym
94
+ clone_to_sym = low_clone.to_sym
95
+ if low_to_sym == clone_to_sym then
96
+ puts "Ok."
97
+ else
98
+ puts "Invalid to_symbol expected #{low_to_sym} but got: #{clone_to_sym}."
99
+ end