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,91 @@
1
+ #include <stdio.h>
2
+ #include "hruby_sim.h"
3
+
4
+
5
+ /**
6
+ * The HDLRuby simulation visualization engine, to be used with C code
7
+ * generated by hruby_low2c.
8
+ **/
9
+
10
+ /** Prints the time.
11
+ * @param time the time to show. */
12
+ void print_time(unsigned long long time) {
13
+ printf("# %lluns",time);
14
+ }
15
+
16
+ /** Prints the time and goes to the next line.
17
+ * @param time the time to show. */
18
+ void println_time(unsigned long long time) {
19
+ print_time(time);
20
+ printf("\n");
21
+ }
22
+
23
+ /** Prints the name of an object.
24
+ * @param object the object to print the name. */
25
+ void print_name(Object object) {
26
+ /* Recurse on the owner if any. */
27
+ // printf("owner=%p\n",object->owner);
28
+ if (object->owner != NULL) {
29
+ print_name(object->owner);
30
+ printf("::");
31
+ }
32
+ /* Depending on the kind of object. */
33
+ switch(object->kind) {
34
+ case SYSTEMT:
35
+ case SIGNALI:
36
+ case SCOPE:
37
+ case SYSTEMI:
38
+ /* Print the name if name. */
39
+ /* Trick: SystemT, SignalI, Scope and SystemI have the
40
+ * field name at the same place. */
41
+ if (((SystemI)object)->name != NULL) {
42
+ printf("%s",((SystemI)object)->name);
43
+ }
44
+ default: /* Nothing to do */
45
+ break;
46
+ }
47
+ }
48
+
49
+ /** Prints a value.
50
+ * @param value the value to print */
51
+ void print_value(Value value) {
52
+ if (value->numeric) {
53
+ unsigned long long width = type_width(value->type);
54
+ unsigned long long mask = 1ULL << (width-1);
55
+ for(; mask > 0; mask >>= 1) {
56
+ printf("%d",(value->data_int & mask) != 0);
57
+ }
58
+ } else {
59
+ /* Display a bitstring value. */
60
+ int i;
61
+ int width = type_width(value->type);
62
+ char* data = value->data_str;
63
+ if (value->capacity == 0) {
64
+ /* The value is empty, therefore undefined. */
65
+ for(i=width; i>0; --i) {
66
+ printf("u");
67
+ }
68
+ }
69
+ else {
70
+ /* The value is not empty. */
71
+ for(i=width; i>0; --i) {
72
+ printf("%c",data[i-1]);
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ /** Prints a signal.
79
+ * @param signal the signal to show */
80
+ void print_signal(SignalI signal) {
81
+ print_name((Object)signal);
82
+ printf(": ");
83
+ print_value(signal->f_value);
84
+ }
85
+
86
+ /** Prints a signal and goes to the next line.
87
+ * @param signal the signal to show */
88
+ void println_signal(SignalI signal) {
89
+ print_signal(signal);
90
+ printf("\n");
91
+ }
@@ -0,0 +1,64 @@
1
+ #include <stdio.h>
2
+ #include <stdarg.h>
3
+ #include <stdlib.h>
4
+ #include <string.h>
5
+ #include <limits.h>
6
+ #include "hruby_sim.h"
7
+
8
+
9
+ /**
10
+ * The HDLRuby pool used for quickly getting empty values, to be used
11
+ * with C code generated by hruby_low2c.
12
+ **/
13
+
14
+ static Value* pool_values = NULL;
15
+ static unsigned int pool_cap = 0; /* The capacity of the pool. */
16
+ static unsigned int pool_pos = 0; /* The position in the pool. */
17
+
18
+ /** Get a fresh value. */
19
+ Value get_value() {
20
+ if (pool_cap == 0) {
21
+ /* First allocation. */
22
+ pool_cap = 16;
23
+ pool_values = (Value*)malloc(pool_cap*sizeof(Value));
24
+ /* Allocate the new values. */
25
+ ValueS* new_values = (ValueS*)calloc(sizeof(ValueS),pool_cap);
26
+ /* Assign them to the pool. */
27
+ unsigned int i;
28
+ for(i=0; i<pool_cap; ++i) {
29
+ pool_values[i] = &(new_values[i]);
30
+ }
31
+ }
32
+ else if (pool_pos == pool_cap) {
33
+ /* Need to increase the pool capacity. */
34
+ pool_cap = pool_cap * 2;
35
+ pool_values = (Value*)realloc(pool_values,pool_cap*sizeof(Value));
36
+ /* Allocate the new values. */
37
+ /* Note: now pool_pos is the old pool_cap and is also the number
38
+ * of new values to allocate. */
39
+ ValueS* new_values = (ValueS*)calloc(sizeof(ValueS),pool_pos);
40
+ /* Assign them to the pool. */
41
+ unsigned int i;
42
+ for(i=0; i<pool_pos; ++i) {
43
+ pool_values[i+pool_pos] = &(new_values[i]);
44
+ }
45
+ }
46
+ /* Readjust the position in the pool and return the value. */
47
+ return pool_values[pool_pos++];
48
+ }
49
+
50
+ /** Frees the last value of the pool. */
51
+ void free_value() {
52
+ if (pool_pos > 0) pool_pos--;
53
+ }
54
+
55
+ /** Gets the current state of the value pool. */
56
+ unsigned int get_value_pos() {
57
+ return pool_pos;
58
+ }
59
+
60
+ /** Restores the state of the value pool.
61
+ * @param pos the new position in the pool */
62
+ void set_value_pos(unsigned int pos) {
63
+ pool_pos = pos;
64
+ }
@@ -0,0 +1,354 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: channels
5
+ #
6
+ ########################################################################
7
+
8
+ ## Describes a high-level channel type.
9
+ class ChannelT
10
+
11
+ # The name of the channel type.
12
+ attr_reader :name
13
+
14
+ # Creates a new channel 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 channel
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 ChannelT.new(:"") do
41
+ HDLRuby::High.top_user.instance_exec(*args,&ruby_block)
42
+ end
43
+ end
44
+ # Generates the channels.
45
+ args.each do |nameI|
46
+ channelI = ChannelI.new(name,&@ruby_block)
47
+ HDLRuby::High.space_reg(nameI) { channelI }
48
+ channelI
49
+ end
50
+ end
51
+
52
+ alias_method :call, :instantiate
53
+ end
54
+
55
+
56
+ ## Creates a new channel type named +name+ whose instances are
57
+ # creating executing +ruby_block+.
58
+ def channel(name,&ruby_block)
59
+ return ChannelT.new(name,&ruby_block)
60
+ end
61
+
62
+
63
+
64
+
65
+ ##
66
+ # Describes a high-level channel instance.
67
+ class ChannelI
68
+ # include HDLRuby::High::HScope_missing
69
+ include HDLRuby::High::Hmissing
70
+
71
+ # The name of the channel instance.
72
+ attr_reader :name
73
+
74
+ # The namespace associated with the current execution when
75
+ # building a channel, its reader or its writer.
76
+ attr_reader :namespace
77
+
78
+ ## Creates a new channel instance with +name+ built from +ruby_block+.
79
+ def initialize(name,&ruby_block)
80
+ # Check and set the name
81
+ @name = name.to_sym
82
+
83
+ obj = self
84
+
85
+ # The reader input ports by name.
86
+ @reader_inputs = {}
87
+ # The reader output ports by name.
88
+ @reader_outputs = {}
89
+ # The reader inout ports by name.
90
+ @reader_inouts = {}
91
+
92
+ # The writer input ports by name.
93
+ @writer_inputs = {}
94
+ # The writer output ports by name.
95
+ @writer_outputs = {}
96
+ # The writer inout ports by name.
97
+ @writer_inouts = {}
98
+
99
+ # Create the namespaces for building the channel, its readers
100
+ # and its writers.
101
+
102
+ # Creates the namespace of the channel.
103
+ @channel_namespace = Namespace.new(self)
104
+ # Make it give access to the internal of the class.
105
+ @channel_namespace.add_method(:reader_input, &method(:reader_input))
106
+ @channel_namespace.add_method(:reader_output,&method(:reader_output))
107
+ @channel_namespace.add_method(:reader_inout, &method(:reader_inout))
108
+ @channel_namespace.add_method(:writer_input, &method(:writer_input))
109
+ @channel_namespace.add_method(:writer_output,&method(:writer_output))
110
+ @channel_namespace.add_method(:writer_inout, &method(:writer_inout))
111
+ @channel_namespace.add_method(:reader, &method(:reader))
112
+ @channel_namespace.add_method(:writer, &method(:writer))
113
+
114
+ # Creates the namespace of the reader.
115
+ @reader_namespace = Namespace.new(self)
116
+ # Creates the namespace of the writer.
117
+ @writer_namespace = Namespace.new(self)
118
+
119
+ # By default the namespace is the one of the namespace
120
+ @namespace = @channel_namespace
121
+
122
+ # Builds the channel.
123
+ HDLRuby::High.space_push(@namespace)
124
+ # puts "top_user=#{HDLRuby::High.top_user}"
125
+ HDLRuby::High.top_user.instance_eval(&ruby_block)
126
+ HDLRuby::High.space_pop
127
+
128
+ # Gives access to the channel by registering its name.
129
+ obj = self
130
+ HDLRuby::High.space_reg(@name) { self }
131
+ end
132
+
133
+ # The methods for defining the channel
134
+
135
+ # For the channel itself
136
+
137
+ ## Defines new command +name+ to execute +ruby_block+ for the
138
+ # channel.
139
+ def command(name,&ruby_block)
140
+ # Ensures name is a symbol.
141
+ name = name.to_sym
142
+ # Sets the new command.
143
+ self.define_singleton_method(name) do
144
+ # Executes the command in the right environment.
145
+ HDLRuby::High.space_push(@namespace)
146
+ res = HDLRuby::High.top_user.instance_exec(&ruby_block)
147
+ HDLRuby::High.space_pop
148
+ res
149
+ end
150
+ end
151
+
152
+ # For the reader and the writer
153
+
154
+ ## Sets the signals accessible through +key+ to be reader input port.
155
+ def reader_input(*keys)
156
+ # Registers each signal as reader port
157
+ keys.each do |key|
158
+ # Ensure the key is a symbol.
159
+ key = key.to_sym
160
+ # Register it with the corresponding signal.
161
+ name = HDLRuby.uniq_name # The name of the signal is uniq.
162
+ @reader_inputs[name] = send(key)
163
+ end
164
+ end
165
+
166
+ ## Sets the signals accessible through +key+ to be reader output port.
167
+ def reader_output(*keys)
168
+ # Registers each signal as reader port
169
+ keys.each do |key|
170
+ # Ensure the key is a symbol.
171
+ key = key.to_sym
172
+ # Register it with the corresponding signal.
173
+ name = HDLRuby.uniq_name # The name of the signal is uniq.
174
+ @reader_outputs[name] = send(key)
175
+ end
176
+ end
177
+
178
+ ## Sets the signals accessible through +key+ to be reader inout port.
179
+ def reader_inout(*keys)
180
+ # Registers each signal as reader port
181
+ keys.each do |key|
182
+ # Ensure the key is a symbol.
183
+ key = key.to_sym
184
+ # Register it with the corresponding signal.
185
+ name = HDLRuby.uniq_name # The name of the signal is uniq.
186
+ @reader_inouts[name] = send(key)
187
+ end
188
+ end
189
+
190
+ ## Sets the signals accessible through +key+ to be writer input port.
191
+ def writer_input(*keys)
192
+ # Registers each signal as writer port
193
+ keys.each do |key|
194
+ # Ensure the key is a symbol.
195
+ key = key.to_sym
196
+ # Register it with the corresponding signal.
197
+ name = HDLRuby.uniq_name # The name of the signal is uniq.
198
+ @writer_inputs[name] = send(key)
199
+ end
200
+ end
201
+
202
+ ## Sets the signals accessible through +key+ to be writer output port.
203
+ def writer_output(*keys)
204
+ # Registers each signal as writer port
205
+ keys.each do |key|
206
+ # Ensure the key is a symbol.
207
+ key = key.to_sym
208
+ # Register it with the corresponding signal.
209
+ name = HDLRuby.uniq_name # The name of the signal is uniq.
210
+ @writer_outputs[name] = send(key)
211
+ end
212
+ end
213
+
214
+ ## Sets the signals accessible through +key+ to be writer inout port.
215
+ def writer_inout(*keys)
216
+ # Registers each signal as writer port
217
+ keys.each do |key|
218
+ # Ensure the key is a symbol.
219
+ key = key.to_sym
220
+ # Register it with the corresponding signal.
221
+ name = HDLRuby.uniq_name # The name of the signal is uniq.
222
+ @writer_inouts[name] = send(key)
223
+ end
224
+ end
225
+
226
+ ## Sets the read procedure to be +ruby_block+.
227
+ def reader(&ruby_block)
228
+ @reader_proc = ruby_block
229
+ end
230
+
231
+ ## Sets the writter procedure to be +ruby_block+.
232
+ def writer(&ruby_block)
233
+ @writer_proc = ruby_block
234
+ end
235
+
236
+ # The methods for accessing the channel
237
+
238
+ # Channel side.
239
+
240
+ ## Gets the list of the signals of the channel to be connected
241
+ # to the reader.
242
+ def reader_signals
243
+ return @reader_inputs.values + @reader_outputs.values +
244
+ @reader_inouts.values
245
+ end
246
+
247
+ ## Gets the list of the signals of the channel to be connected
248
+ # to the writer.
249
+ def writer_signals
250
+ return @writer_inputs.values + @writer_outputs.values +
251
+ @writer_inouts.values
252
+ end
253
+
254
+ # Reader an writer side.
255
+
256
+ ## Declares the ports for the reader.
257
+ def reader_ports
258
+ loc_inputs = @reader_inputs
259
+ loc_outputs = @reader_outputs
260
+ loc_inouts = @reader_inouts
261
+ HDLRuby::High.cur_system.open do
262
+ # The inputs
263
+ loc_inputs.each { |name,sig| sig.type.input name }
264
+ # The outputs
265
+ loc_outputs.each { |name,sig| sig.type.output name }
266
+ # The inouts
267
+ loc_inouts.each { |name,sig| sig.type.inout name }
268
+ end
269
+ end
270
+
271
+ ## Declares the ports for the writer.
272
+ def writer_ports
273
+ loc_inputs = @writer_inputs
274
+ loc_outputs = @writer_outputs
275
+ loc_inouts = @writer_inouts
276
+ HDLRuby::High.cur_system.open do
277
+ # The inputs
278
+ loc_inputs.each { |name,sig| sig.type.input name }
279
+ # The outputs
280
+ loc_outputs.each { |name,sig| sig.type.output name }
281
+ # The inouts
282
+ loc_inouts.each { |name,sig| sig.type.inout name }
283
+ end
284
+ end
285
+
286
+ ## Performs a read on the channel using +args+ and +ruby_block+
287
+ # as arguments.
288
+ def read(*args,&ruby_block)
289
+ # Fill the reader namespace with the access to the reader signals.
290
+ @reader_inputs.each do |name,sig|
291
+ @reader_namespace.add_method(sig.name) do
292
+ HDLRuby::High.top_user.send(name)
293
+ end
294
+ end
295
+ @reader_outputs.each do |name,sig|
296
+ @reader_namespace.add_method(sig.name) do
297
+ HDLRuby::High.top_user.send(name)
298
+ end
299
+ end
300
+ @reader_inouts.each do |name,sig|
301
+ @reader_namespace.add_method(sig.name) do
302
+ HDLRuby::High.top_user.send(name)
303
+ end
304
+ end
305
+ # Gain access to the reader as local variable.
306
+ reader_proc = @reader_proc
307
+ # The context is the one of the reader.
308
+ @namespace = @reader_namespace
309
+ # Execute the code generating the reader in context.
310
+ HDLRuby::High.space_push(@namespace)
311
+ HDLRuby::High.cur_block.open do
312
+ instance_exec(ruby_block,*args,&reader_proc)
313
+ end
314
+ HDLRuby::High.space_pop
315
+ # Restores the default context.
316
+ @namespace = @channel_namespace
317
+ end
318
+
319
+ ## Performs a write on the channel using +args+ and +ruby_block+
320
+ # as arguments.
321
+ def write(*args,&ruby_block)
322
+ # Fill the writer namespace with the access to the writer signals.
323
+ @writer_inputs.each do |name,sig|
324
+ @writer_namespace.add_method(sig.name) do
325
+ HDLRuby::High.top_user.send(name)
326
+ end
327
+ end
328
+ @writer_outputs.each do |name,sig|
329
+ @writer_namespace.add_method(sig.name) do
330
+ HDLRuby::High.top_user.send(name)
331
+ end
332
+ end
333
+ @writer_inouts.each do |name,sig|
334
+ @writer_namespace.add_method(sig.name) do
335
+ HDLRuby::High.top_user.send(name)
336
+ end
337
+ end
338
+ # Gain access to the writer as local variable.
339
+ writer_proc = @writer_proc
340
+ # The context is the one of the writer.
341
+ @namespace = @writer_namespace
342
+ # Execute the code generating the writer in context.
343
+ HDLRuby::High.space_push(@namespace)
344
+ HDLRuby::High.cur_block.open do
345
+ instance_exec(ruby_block,*args,&writer_proc)
346
+ end
347
+ HDLRuby::High.space_pop
348
+ # Restores the default context.
349
+ @namespace = @channel_namespace
350
+ end
351
+ end
352
+
353
+ end
354
+
@@ -0,0 +1,165 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: clocks
5
+ #
6
+ ########################################################################
7
+
8
+
9
+ # Initialize the clock generator with +rst+ as reset signal.
10
+ def configure_clocks(rst = $rst)
11
+ @@__clocks_rst = rst
12
+ end
13
+
14
+ # Create a clock inverted every +times+ occurence of an +event+.
15
+ def make_clock(event, times)
16
+ clock = nil # The resulting clock
17
+
18
+ # Enters the current system
19
+ HDLRuby::High.cur_system.open do
20
+
21
+ # Ensures times is a value.
22
+ times = times.to_value
23
+
24
+ # Create the counter.
25
+ # Create the name of the counter.
26
+ name = HDLRuby.uniq_name
27
+ # Declare the counter.
28
+ [times.width].inner(name)
29
+ # Get the signal of the counter.
30
+ counter = get_inner(name)
31
+
32
+ # Create the clock.
33
+ # Create the name of the clock.
34
+ name = HDLRuby.uniq_name
35
+ # Declares the clock.
36
+ bit.inner(name)
37
+ # Get the signal of the clock.
38
+ clock = get_inner(name)
39
+
40
+ # Control it.
41
+ par(event) do
42
+ hif(@@__clocks_rst) do
43
+ counter.to_ref <= times.to_expr
44
+ clock.to_ref <= 0
45
+ end
46
+ helsif(counter.to_expr == 0) do
47
+ counter.to_ref <= times.to_expr
48
+ clock.to_ref <= ~ clock.to_expr
49
+ end
50
+ helse do
51
+ counter.to_ref <= counter.to_expr + 1
52
+ end
53
+ end
54
+ end
55
+ return clock
56
+ end
57
+
58
+ # module clk_div3(clk,reset, clk_out);
59
+
60
+ # input clk;
61
+ # input reset;
62
+ # output clk_out;
63
+
64
+ # reg [1:0] pos_count, neg_count;
65
+ # wire [1:0] r_nxt;
66
+
67
+ # always @(posedge clk)
68
+ # if (reset)
69
+ # pos_count <=0;
70
+ # else if (pos_count ==2) pos_count <= 0;
71
+ # else pos_count<= pos_count +1;
72
+
73
+ # always @(negedge clk)
74
+ # if (reset)
75
+ # neg_count <=0;
76
+ # else if (neg_count ==2) neg_count <= 0;
77
+ # else neg_count<= neg_count +1;
78
+
79
+ # assign clk_out = ((pos_count == 2) | (neg_count == 2));
80
+ # endmodule
81
+
82
+ # Creates a clock inverted every +times+ occurence of an +event+ and its
83
+ # everted.
84
+ def make_2edge_clock(event,times)
85
+ clock = nil # The resulting clock
86
+
87
+ # Enters the current system
88
+ HDLRuby::High.cur_system.open do
89
+ # Ensure times is a value.
90
+ times = times.to_value
91
+
92
+ # Create the event counter.
93
+ # Create the name of the counter.
94
+ name = HDLRuby.uniq_name
95
+ # Declare the counter.
96
+ [times.width].inner(name)
97
+ # Get the signal of the counter.
98
+ counter = get_inner(name)
99
+
100
+ # Create the inverted event counter.
101
+ # Create the name of the counter.
102
+ name = HDLRuby.uniq_name
103
+ # Declare the counter.
104
+ [times.width].inner(name)
105
+ # Get the signal of the counter.
106
+ counter_inv = get_inner(name)
107
+
108
+ # Create the clock.
109
+ # Create the name of the clock.
110
+ name = HDLRuby.uniq_name
111
+ # Declare the clock.
112
+ bit.inner(name)
113
+ # Get the signal of the clock.
114
+ clock = get_inner(name)
115
+
116
+ # Control the event counter
117
+ par(event) do
118
+ hif(@@__clocks_rst | counter.to_expr == 0) do
119
+ counter.to_ref <= times.to_expr/2 + 1
120
+ end
121
+ end
122
+ # Control the inverteed event counter
123
+ par(event.invert) do
124
+ hif(@@__clocks_rst | counter_inv.to_expr == 0) do
125
+ counter_inv.to_ref <= times.to_expr/2 + 1
126
+ end
127
+ end
128
+ # Compute the clock.
129
+ clock.to_ref <= (counter.to_expr == times.to_expr/2 + 1) |
130
+ (counter_inv.to_expr == times.to_expr/2 + 1)
131
+ end
132
+ # Return it.
133
+ return clock
134
+ end
135
+ end
136
+
137
+
138
+ # Enhnace the events with multiply operator.
139
+ class HDLRuby::High::Event
140
+
141
+ # Creates a new event activated every +times+ occurences of the
142
+ # current event.
143
+ def *(times)
144
+ # The event must be an edge
145
+ unless (self.type == :posedge or self.type == :negedge) then
146
+ raise "Only posedge or negedge events can be multiplied."
147
+ end
148
+ # +times+ must be a value.
149
+ times = times.to_value
150
+ # Creates the clock for the new event.
151
+ clock = nil
152
+ # There are two cases: times is even or times is odd.
153
+ if times.even? then
154
+ # Even case: make a clock inverted every times/2 occurance of
155
+ # current event.
156
+ clock = HDLRuby::High::Std::make_clock(self,times/2)
157
+ else
158
+ # Odd case: make a clock raised every times occurance using
159
+ # both event and inverted event
160
+ clock = HDLRuby::High::Std::make_2edge_clock(self,times)
161
+ end
162
+ # Use the clock to create the new event.
163
+ return clock.posedge
164
+ end
165
+ end