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,82 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: counters
5
+ #
6
+ ########################################################################
7
+
8
+ ## Sets a counter to +init+ when +rst+ is 1 that is decreased according
9
+ # to +clk+.
10
+ # +code+ will be applied on this counter.
11
+ # When not within a block, a behavior will be created which is
12
+ # activated on the rising edge of +clk+.
13
+ def with_counter(init, rst = $rst, clk = $clk, &code)
14
+ # Are we in a block?
15
+ if HDLRuby::High.top_user.is_a?(HDLRuby::High::SystemT) then
16
+ # No, create a behavior.
17
+ behavior(clk.posedge) do
18
+ with_counter(init,rst,clk,&code)
19
+ end
20
+ else
21
+ # Ensure init is a value.
22
+ init = init.to_value
23
+ # Creates the counter
24
+ # counter = HDLRuby::High::SignalI.new(HDLRuby.uniq_name,
25
+ # TypeVector.new(:"",bit,init.width),
26
+ # :inner)
27
+ # Create the name of the counter.
28
+ name = HDLRuby.uniq_name
29
+ # Declare the counter.
30
+ [init.width].inner(name)
31
+ # Get the signal of the counter.
32
+ counter = HDLRuby::High.cur_block.get_inner(name)
33
+ # Apply the code on the counter.
34
+ # code.call(counter)
35
+ instance_exec(counter,&code)
36
+ end
37
+ end
38
+
39
+
40
+ ## Sets a counter to +init+ when +rst+ is 1 that is decreased according
41
+ # to +clk+.
42
+ # As long as this counter does not reach 0, +code+ is executed.
43
+ # When not within a block, a behavior will be created which is
44
+ # activated on the rising edge of +clk+.
45
+ def before(init, rst = $rst, clk = $clk, &code)
46
+ with_counter(init,rst,clk) do |counter|
47
+ seq do
48
+ hif(rst.to_expr == 1) do
49
+ counter.to_ref <= init.to_expr
50
+ end
51
+ helsif(counter.to_expr != 0) do
52
+ counter.to_ref <= counter.to_expr - 1
53
+ # code.call
54
+ instance_eval(&code)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ ## Sets a counter to +init+ when +rst+ is 1 that is decreased according
61
+ # to +clk+.
62
+ # When this counter reaches 0, +code+ is executed.
63
+ # When not within a block, a behavior will be created which is activated
64
+ # on the rising edge of +clk+.
65
+ def after(init, rst = $rst, clk = $clk, &code)
66
+ with_counter(init,rst,clk) do |counter|
67
+ seq do
68
+ hif(rst.to_expr == 1) do
69
+ counter.to_ref <= init.to_expr
70
+ end
71
+ helsif(counter.to_expr == 0) do
72
+ # code.call
73
+ instance_eval(&code)
74
+ end
75
+ helse do
76
+ counter.to_ref <= counter.to_expr - 1
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,214 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: decoder generator.
5
+ #
6
+ ########################################################################
7
+
8
+
9
+ ##
10
+ # Describes a high-level decoder type.
11
+ class DecoderT
12
+ include HDLRuby::High::HScope_missing
13
+
14
+ # The description of a decoding field.
15
+ class Field
16
+ attr_accessor :range, :content
17
+ end
18
+
19
+ # The entry class
20
+ class Entry
21
+ attr_accessor :id_fields, # The fields for identifying the entry
22
+ :var_fields,# The fields for getting variables
23
+ :code # The code to execute when the entry matches
24
+ end
25
+
26
+ # The name of the decoder type.
27
+ attr_reader :name
28
+
29
+ # The namespace associated with the decoder
30
+ attr_reader :namespace
31
+
32
+ # The default code if any.
33
+ attr_reader :default_code
34
+
35
+
36
+ # Creates a new decoder type with +name+.
37
+ def initialize(name)
38
+ # Check and set the name
39
+ @name = name.to_sym
40
+
41
+ # Initialize the internals of the decoder.
42
+
43
+
44
+ # Initialize the environment for building the decoder.
45
+
46
+ # The main entries.
47
+ @entries = []
48
+
49
+ # The default code to execute when no entry match.
50
+ @default_code = nil
51
+
52
+ # Creates the namespace to execute the fsm block in.
53
+ @namespace = Namespace.new(self)
54
+
55
+ # Generates the function for setting up the decoder
56
+ # provided there is a name.
57
+ obj = self # For using the right self within the proc
58
+ HDLRuby::High.space_reg(@name) do |expr,&ruby_block|
59
+ if ruby_block then
60
+ # Builds the decoder.
61
+ obj.build(expr,&ruby_block)
62
+ else
63
+ # Return the fsm as is.
64
+ return obj
65
+ end
66
+ end unless name.empty?
67
+
68
+ end
69
+
70
+ ## builds the decoder on expression +expr+ by executing +ruby_block+.
71
+ def build(expr,&ruby_block)
72
+ # Use local variable for accessing the attribute since they will
73
+ # be hidden when opening the sytem.
74
+ entries = @entries
75
+ namespace = @namespace
76
+ this = self
77
+ return_value = nil
78
+
79
+ HDLRuby::High.space_push(namespace)
80
+ # Execute the instantiation block
81
+ return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
82
+
83
+ # Create the decoder code
84
+
85
+ # The process
86
+ par do
87
+ # Depending on the type of entry.
88
+ test = :hif # Which command to use for testing
89
+ # (first: hif, then heslif)
90
+ entries.each do |entry|
91
+ # Build the predicate for checking the entry.
92
+ entry_predicate = entry.id_fields.map do |field|
93
+ expr[field.range] == field.content
94
+ end.reduce(:&)
95
+
96
+ send(test,entry_predicate) do
97
+ # Sets the local variables.
98
+ entry.var_fields.each do |field|
99
+ this.
100
+ define_singleton_method(field.content) do
101
+ expr[field.range]
102
+ end
103
+ end
104
+ # Generate the content of the entry.
105
+ entry.code.call
106
+ end
107
+ test = :helsif # Now use helsif for the alternative.
108
+ end
109
+ # Adds the default code if any.
110
+ if default_code then
111
+ helse(&default_code)
112
+ end
113
+ end
114
+
115
+ HDLRuby::High.space_pop
116
+
117
+ return return_value
118
+ end
119
+
120
+
121
+ ## The interface for building the decoder
122
+
123
+
124
+ # Declares a new entry with +format+ and executing +ruby_block+.
125
+ def entry(format, &ruby_block)
126
+ # puts "entry with format=#{format}"
127
+ # Create the resulting entry
128
+ result = Entry.new
129
+ result.code = ruby_block
130
+ # Process the format.
131
+ format = format.to_s
132
+ width = format.size
133
+ # For that purpose create the regular expression used to process it.
134
+ prs = "([0-1]+)|(a+)|(b+)|(c+)|(d+)|(e+)|(g+)|(h+)|(i+)|(j+)|(k+)|(l+)|(m+)|(n+)|(o+)|(p+)|(q+)|(r+)|(s+)|(t+)|(u+)|(v+)|(w+)|(x+)|(y+)|(z+)"
135
+ # Check if the format is compatible with it.
136
+ unless format =~ Regexp.new("^(#{prs})+$") then
137
+ raise AnyError("Invalid format for a field: #{format}")
138
+ end
139
+ # Split the format in fields.
140
+ format = format.split(Regexp.new(prs)).select {|str| !str.empty?}
141
+ # puts "format=#{format}"
142
+ # Fills the entry with each field of the format.
143
+ result.id_fields = []
144
+ result.var_fields = []
145
+ pos = width-1
146
+ format.each do |str|
147
+ # puts "str=#{str}"
148
+ # Create a new field and compute its range.
149
+ field = Field.new
150
+ field.range = pos..(pos-str.size+1)
151
+ # Build its content, and add the field.
152
+ # Depends on wether it is an id or a variable field?
153
+ if str =~ /[0-1]+/ then
154
+ # Id field.
155
+ # Build its type.
156
+ type = TypeVector.new(:"",bit,
157
+ field.range.first-field.range.last..0)
158
+ # Build the content as a value.
159
+ field.content = Value.new(type,str)
160
+ # Add the field.
161
+ result.id_fields << field
162
+ else
163
+ # Variable field.
164
+ # Build the content as a single-character symbol.
165
+ field.content = str[0].to_sym
166
+ # Add the field.
167
+ result.var_fields << field
168
+ end
169
+ # Update the position.
170
+ pos = pos-str.size
171
+ end
172
+ # Add it to the list of entries.
173
+ @entries << result
174
+ # Return it.
175
+ return result
176
+ end
177
+
178
+ # Declares the default code to execute when no format maches.
179
+ def default(&ruby_block)
180
+ @default_code = ruby_block
181
+ end
182
+ end
183
+
184
+
185
+
186
+
187
+ ## Declare a new decoder.
188
+ # The arguments can be any of (but in this order):
189
+ #
190
+ # - +name+:: name.
191
+ # - +expr+:: the expression to decode.
192
+ #
193
+ # If provided, +ruby_block+ the fsm is directly instantiated with it.
194
+ def decoder(*args, &ruby_block)
195
+ # Sets the name if any
196
+ unless args[0].respond_to?(:to_expr) then
197
+ name = args.shift.to_sym
198
+ else
199
+ name = :""
200
+ end
201
+ # Create the decoder.
202
+ decoderI = DecoderT.new(name)
203
+
204
+ # Is there a ruby block?
205
+ if ruby_block then
206
+ # Yes, generate the decoder.
207
+ decoderI.build(*args,&ruby_block)
208
+ else
209
+ # No return the decoder structure for later generation.
210
+ return decoderI
211
+ end
212
+ end
213
+
214
+ end