HDLRuby 3.7.9 → 3.8.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cd33c7551f3da873475ca05e7047b40cd83abf4016e97fcdcbf266dca32b9b2
4
- data.tar.gz: 4bce7700302da9f025b7bea65102973375746d6f767013a0b4db9259b7aea464
3
+ metadata.gz: b3ecb1e50d09ad4ec7aa0809f93da534ce0672c30240aa9405124a075d29a015
4
+ data.tar.gz: 3b939a8ad0eeef795473657775a83c265597fa13939dae1c91bff685ab6024b4
5
5
  SHA512:
6
- metadata.gz: 9914adec792666008ce4a122d9014ede48b27c7c649c26b969d9eddf34e08a742382feda2925991522f0a9d632763d3d65df444ac48ad3ac5927bc0f44750ed7
7
- data.tar.gz: 297426eacd2fe788c6fb2f7ea239106a3c4eab1ea48e1506f36058ec259479e49a9c2d7aa746b090fe16f147e46568c6cb101b8351bb70ec3b226ccdbf965069
6
+ metadata.gz: 60bf1dcdf1243053841f7033398fce2de880bb412b19142b2356ceaf05261adfde4cac6afe5a861b1026b30139836210c5fa42e496ba2d563822bf05b0333839
7
+ data.tar.gz: e6c56348b4e2cfa38cd0778e4d5d091b983c39b82af33df3cb11883f7ac5a40af920856cc2d9e8a2d79ee6084a82106d03c198c52a51456729d702ec67a8c819
data/README.md CHANGED
@@ -17,6 +17,15 @@ hdrcc --get-tuto
17
17
 
18
18
  __What's new_
19
19
 
20
+ For HDLRuby version 3.8.0:
21
+
22
+ * Added parallel enumerators (e.g., heach): can iterate like Ruby for describing parallel hardware.
23
+
24
+ * Added metaprogramming through standard HDLRuby constructs (e.g., hif): no need to use Ruby code any longer.
25
+
26
+ * Fixed compile bugs for windows.
27
+
28
+
20
29
  For HDLRuby version 3.7.9:
21
30
 
22
31
  * Added Python code generation from the software sequencers.
@@ -280,7 +280,8 @@ VALUE rcsim_make_behavior(VALUE mod, VALUE timed) {
280
280
  register_init_behavior(behavior);
281
281
  }
282
282
  behavior->active_time = 0;
283
- behavior->thread = NULL;
283
+ // behavior->thread = NULL;
284
+ behavior->thread = 0;
284
285
  /* Returns the C behavior embedded into a ruby VALUE. */
285
286
  VALUE res;
286
287
  rcsim_to_value(BehaviorS,behavior,res);
@@ -466,7 +467,8 @@ VALUE rcsim_load_c(VALUE mod, VALUE codeV, VALUE libnameV, VALUE funcnameV) {
466
467
  fprintf(stderr,"LoadLibrary failed with error code %ld\n", dwError);
467
468
  exit(-1);
468
469
  }
469
- code->function = GetProcAddress(handle,funcname);
470
+ // code->function = GetProcAddress(handle,funcname);
471
+ code->function = (void (*)(Code))GetProcAddress(handle,funcname);
470
472
  if (code->function == NULL) {
471
473
  fprintf(stderr,"Unable to get function: %s\n",code->name);
472
474
  exit(-1);
@@ -191,7 +191,7 @@ void calc_ref_rangeS(Reference ref, long long* first, long long *last,
191
191
  Cast refc = (Cast)ref;
192
192
  /* Compute the range for the child. */
193
193
  long long cfirst, clast;
194
- calc_ref_rangeS(refc->child,&cfirst,&clast,sig);
194
+ calc_ref_rangeS((Reference)(refc->child),&cfirst,&clast,sig);
195
195
  /* Update first and last using the cast. */
196
196
  /* Both first and last should be equal since the type of the cast sets
197
197
  * the width */
@@ -207,6 +207,76 @@ static void vcd_print_signal_cvalue(SignalI signal) {
207
207
  }
208
208
 
209
209
 
210
+ /** Checks if a statement contains any declaration.
211
+ * @param stmnt the statement to check. */
212
+ static int vcd_statement_has_decl(Statement stmnt) {
213
+ // printf("stmnt kind=%d\n",stmnt->kind);
214
+ switch(stmnt->kind) {
215
+ case TRANSMIT:
216
+ case PRINT:
217
+ /* No declaration. */
218
+ return 0;
219
+ case HIF:
220
+ {
221
+ HIf hif = (HIf)stmnt;
222
+ /* Recruse on the sub statements of the if.*/
223
+ if (vcd_statement_has_decl(hif->yes)) return 1;
224
+ for(int i=0; i<hif->num_noifs; ++i)
225
+ if (vcd_statement_has_decl(hif->nostmnts[i]))
226
+ return 1;
227
+ if (hif->no)
228
+ return vcd_statement_has_decl(hif->no);
229
+ /* No declaration. */
230
+ return 0;
231
+ }
232
+ case HCASE:
233
+ {
234
+ HCase hcase = (HCase)stmnt;
235
+ /* Recruse on the sub statements of the case.*/
236
+ for(int i=0; i<hcase->num_whens; ++i)
237
+ if (vcd_statement_has_decl(hcase->stmnts[i]))
238
+ return 1;
239
+ if (hcase->defolt)
240
+ return vcd_statement_has_decl(hcase->defolt);
241
+ /* No declaration. */
242
+ return 0;
243
+ }
244
+ case TIME_WAIT:
245
+ /* No declaration. */
246
+ return 0;
247
+ case TIME_REPEAT:
248
+ {
249
+ TimeRepeat rep = (TimeRepeat)stmnt;
250
+ /* Recruse on the sub statements of the repeat.*/
251
+ for(long long i=0; i<rep->number; ++i)
252
+ if (vcd_statement_has_decl(rep->statement))
253
+ return 1;
254
+ /* No declaration. */
255
+ return 0;
256
+ }
257
+ case TIME_TERMINATE:
258
+ /* No declaration. */
259
+ return 0;
260
+ case BLOCK:
261
+ {
262
+ Block blk = (Block)stmnt;
263
+ if (blk->num_inners != 0) return 1;
264
+ /* Recruse on the sub statements. */
265
+ for(int i=0; i<blk->num_stmnts; ++i)
266
+ if (vcd_statement_has_decl(blk->stmnts[i]))
267
+ return 1;
268
+ /* No declaration. */
269
+ return 0;
270
+ }
271
+ default:
272
+ perror("Invalid kind for a statement.");
273
+ }
274
+ /* Should not be here though. */
275
+ return 0;
276
+ }
277
+
278
+
279
+
210
280
  /** Prints the hierarchy content of a system type.
211
281
  * @param system the system to print. */
212
282
  static void vcd_print_systemT_content(SystemT system);
@@ -215,13 +285,74 @@ static void vcd_print_systemT_content(SystemT system);
215
285
  * @param scope the scope to print. */
216
286
  static void vcd_print_scope(Scope scope);
217
287
 
288
+ /** Prints the hierarchy of a block.
289
+ * @param block the block to print. */
290
+ static void vcd_print_block(Block block);
291
+
292
+ /** Prints the hierarchy of a statement.
293
+ * @param stmnt the statement to print. */
294
+ static void vcd_print_statement(Statement stmnt) {
295
+ // printf("stmnt kind=%d\n",stmnt->kind);
296
+ switch(stmnt->kind) {
297
+ case TRANSMIT:
298
+ case PRINT:
299
+ /* Nothing to do. */
300
+ break;
301
+ case HIF:
302
+ {
303
+ HIf hif = (HIf)stmnt;
304
+ /* Recruse on the sub statements of the if.*/
305
+ vcd_print_statement(hif->yes);
306
+ for(int i=0; i<hif->num_noifs; ++i)
307
+ vcd_print_statement(hif->nostmnts[i]);
308
+ if (hif->no)
309
+ vcd_print_statement(hif->no);
310
+ break;
311
+ }
312
+ case HCASE:
313
+ {
314
+ HCase hcase = (HCase)stmnt;
315
+ /* Recruse on the sub statements of the case.*/
316
+ for(int i=0; i<hcase->num_whens; ++i)
317
+ vcd_print_statement(hcase->stmnts[i]);
318
+ if (hcase->defolt)
319
+ vcd_print_statement(hcase->defolt);
320
+ break;
321
+ }
322
+ case TIME_WAIT:
323
+ /* Nothing to do. */
324
+ break;
325
+ case TIME_REPEAT:
326
+ {
327
+ TimeRepeat rep = (TimeRepeat)stmnt;
328
+ /* Recruse on the sub statements of the repeat.*/
329
+ for(long long i=0; i<rep->number; ++i)
330
+ vcd_print_statement(rep->statement);
331
+ break;
332
+ }
333
+ case TIME_TERMINATE:
334
+ /* Nothing to do. */
335
+ break;
336
+ case BLOCK:
337
+ {
338
+ /* Block case: there is a specific function for it. */
339
+ vcd_print_block((Block)stmnt);
340
+ break;
341
+ }
342
+ default:
343
+ perror("Invalid kind for a statement.");
344
+ }
345
+ }
346
+
218
347
 
219
348
  /** Prints the hierarchy of a block.
220
349
  * @param block the block to print. */
221
350
  static void vcd_print_block(Block block) {
222
351
  int i;
352
+ // printf("vcd_print_block\n");
223
353
  /* Do not print block with no declaration. */
224
- if (block->num_inners == 0) return;
354
+ // if (block->num_inners == 0) return;
355
+ if (!vcd_statement_has_decl(block)) return;
225
356
 
226
357
  /* Declares the block if named. */
227
358
  vcd_print("$scope module ");
@@ -233,6 +364,11 @@ static void vcd_print_block(Block block) {
233
364
  vcd_print_var(block->inners[i]);
234
365
  }
235
366
 
367
+ /* Recurse on the statements if any. */
368
+ for(i=0; i<block->num_stmnts; ++i) {
369
+ vcd_print_statement(block->stmnts[i]);
370
+ }
371
+
236
372
  /* Close the hierarchy. */
237
373
  vcd_print("$upscope $end\n");
238
374
  }
@@ -258,6 +394,7 @@ static void vcd_print_systemI(SystemI systemI) {
258
394
  * @param scope the scope to print the inside. */
259
395
  static void vcd_print_scope_content(Scope scope) {
260
396
  int i;
397
+ // printf("vcd_print_scope_content\n");
261
398
 
262
399
  /* Declare the inners of the systems. */
263
400
  for(i=0; i<scope->num_inners; ++i) {
@@ -0,0 +1,26 @@
1
+ # Sample for testing an invalid function: should generate an error.
2
+
3
+
4
+ hdef :func do |val|
5
+ [8].inner :res
6
+ hif (val == 1) { res <= _h60 }
7
+ helse { res <= _h70 }
8
+ end
9
+
10
+
11
+ system :with_func do
12
+ [8].inner :val,:res
13
+
14
+ res <= func(val)
15
+
16
+ timed do
17
+ val <= 0
18
+ !10.ns
19
+ val <= 1
20
+ !10.ns
21
+ val <= 2
22
+ !10.ns
23
+ val <= 3
24
+ !10.ns
25
+ end
26
+ end
@@ -7,7 +7,7 @@ include HDLRuby::High::Std
7
7
  # - The second check is for hany?
8
8
  # - The third check is for hchain
9
9
  # - The forth check is for hmap
10
- # - The fifth check is for hmap with with_index
10
+ # - The fifth check is for hmap with hwith_index
11
11
  # - The sixth check is for hcompact
12
12
  # - The seventh checks is for hcount
13
13
  # - The eighth check is for hcycle
@@ -35,6 +35,8 @@ include HDLRuby::High::Std
35
35
  # - The thirtieth check is for suniq
36
36
  # - The thirty first check is for hzip
37
37
  #
38
+ # - The remaing checks the enumerators apply on values directly.
39
+ #
38
40
 
39
41
  system :henmerable_checks do
40
42
 
@@ -89,11 +91,11 @@ system :henmerable_checks do
89
91
 
90
92
  bit[8][-8].inner :res14, :res15
91
93
 
92
- res14 <= vals.hmap.with_index { |val,i| val + i }
94
+ res14 <= vals.hmap.hwith_index { |val,i| val + i }
93
95
 
94
96
  par(clk.posedge) do
95
97
  # hprint("&0\n");
96
- res15 <= vals.hmap.with_index { |val,i| val + i }
98
+ res15 <= vals.hmap.hwith_index { |val,i| val + i }
97
99
  end
98
100
 
99
101
  bit[8][-8].inner vals2: [ _h00, _h10, _h00, _h0B, _hFE, _h00, _h5C, _h00 ]
@@ -147,14 +149,14 @@ system :henmerable_checks do
147
149
 
148
150
  par(clk.posedge) do
149
151
  # hprint("*0\n")
150
- vals.heach_cons(3).with_index { |(a,b,c),i| res27[i] <= a+b+c }
152
+ vals.heach_cons(3).hwith_index { |(a,b,c),i| res27[i] <= a+b+c }
151
153
  end
152
154
 
153
155
  bit[8][-8].inner :res28
154
156
 
155
157
  par(clk.posedge) do
156
158
  # hprint("/0\n")
157
- vals.heach_slice(3).with_index do |(a,b,c),i|
159
+ vals.heach_slice(3).hwith_index do |(a,b,c),i|
158
160
  if c then
159
161
  res28[i] <= a+b+c
160
162
  elsif b then
@@ -204,7 +206,7 @@ system :henmerable_checks do
204
206
 
205
207
  par(clk.posedge) do
206
208
  # hprint(":0\n")
207
- res36 <= vals.hinject(:+)
209
+ res36 <= vals.(:+)
208
210
  end
209
211
 
210
212
  [8].inner :res37
@@ -284,7 +286,7 @@ system :henmerable_checks do
284
286
 
285
287
  par(clk.posedge) do
286
288
  # hprint("_0\n")
287
- (5..10).hreverse_each.with_index { |val,i| res52[i] <= val }
289
+ (5..10).hreverse_each.hwith_index { |val,i| res52[i] <= val }
288
290
  end
289
291
 
290
292
  bit[8][-10].inner :res53X, :res54X
@@ -325,10 +327,10 @@ system :henmerable_checks do
325
327
 
326
328
  # res59 <= vals3.huniq
327
329
 
328
- # par(clk.posedge) do
329
- # # hprint("~0\n")
330
- # res60 <= vals.huniq { |val| val & _h0F }
331
- # end
330
+ # # par(clk.posedge) do
331
+ # # # hprint("~0\n")
332
+ # # res60 <= vals.huniq { |val| val & _h0F }
333
+ # # end
332
334
 
333
335
  bit[8][-8].inner :res61
334
336
  bit[8][-8].inner :res62
@@ -340,6 +342,28 @@ system :henmerable_checks do
340
342
  vals.hzip([_h12]*8).each_with_index { |(a,b),i| res62[i] <= a+b }
341
343
  end
342
344
 
345
+ # Test enumerators of values.
346
+ inner :res63, :res64, :res65
347
+
348
+ res63 <= _b0101011.(:|)
349
+ res64 <= _b0101011.(:^)
350
+ res65 <= _b0101011.(:&)
351
+
352
+ [8].inner :res66
353
+
354
+ res66 <= [_h01, _h02, _h03, _h04].(:+)
355
+
356
+
357
+ # Test signal declarations within iterator block.
358
+ vals.heach do |v,i|
359
+ inner :sig
360
+ sig <= v[0]
361
+ end
362
+
363
+ [_h0001, _h0002, _h0003].heach.hwith_index do |v,i|
364
+ [16].inner :sig
365
+ sig <= v + i
366
+ end
343
367
 
344
368
 
345
369
 
@@ -0,0 +1,107 @@
1
+
2
+
3
+ # A benchmark for testing hif with value condition: the sould produce
4
+ # meta programming.
5
+ system :with_seq_if_bench do
6
+ inner :clk
7
+ [2].inner :s
8
+ [8].inner :x,:y, :z
9
+ [8].inner :u,:v, :w
10
+ [8].inner :a, :b
11
+
12
+ hif(9) do
13
+ puts "hif(9)"
14
+ [8].inner q: 6
15
+ seq do
16
+ hif(s==2) { x <= 1 }
17
+ end
18
+ end
19
+ helse do
20
+ [8].inner r: 6
21
+ puts "hif(9) helse"
22
+ seq do
23
+ hif(s==1) { x <= 2 }
24
+ end
25
+ end
26
+
27
+ hif(0) do
28
+ puts "hif(0)"
29
+ [8].inner q: 7
30
+ seq do
31
+ hif(s==2) { y <= 1 }
32
+ end
33
+ end
34
+ helse do
35
+ [8].inner r: 7
36
+ puts "hif(0) helse"
37
+ seq do
38
+ hif(s==1) { y <= 2 }
39
+ end
40
+ end
41
+
42
+ hif(0) do
43
+ puts "hif(0)"
44
+ [8].inner q: 9
45
+ z <= 0
46
+ end
47
+ helsif(2) do
48
+ puts "hif(0) helsif(2)"
49
+ [8].inner r: 9
50
+ z <= 4
51
+ end
52
+ helse do
53
+ puts "hif(0) helsif(2) helse"
54
+ [8].inner t: 9
55
+ z <= 5
56
+ end
57
+
58
+ hcase(2)
59
+ hwhen(0) { puts "hcase(2) hwhen(0)"; [8].inner(q: 13); u <= 0 }
60
+ hwhen(1) { puts "hcase(2) hwhen(1)"; [8].inner(q: 14); u <= 1 }
61
+ hwhen(2) { puts "hcase(2) hwhen(2)"; [8].inner(q: 15); u <= 2 }
62
+ helse { puts "hcase(2) helse" ; [8].inner(q: 16); u <= 3 }
63
+
64
+ hcase(4)
65
+ hwhen(0) { puts "hcase(4) hwhen(0)"; [8].inner(r: 13); v <= 0 }
66
+ hwhen(1) { puts "hcase(4) hwhen(1)"; [8].inner(r: 14); v <= 1 }
67
+ hwhen(2) { puts "hcase(4) hwhen(2)"; [8].inner(r: 15); v <= 2 }
68
+ helse { puts "hcase(4) helse" ; [8].inner(r: 16); v <= 3 }
69
+
70
+ seq(clk.posedge) do
71
+ hif(6) do
72
+ [8].inner q: 20
73
+ puts "hif(6)"
74
+ w <= w + 1
75
+ end
76
+ end
77
+
78
+ seq(mux(1,s,clk.posedge)) do
79
+ a <= a + 1
80
+ end
81
+
82
+ seq(mux(0,s,clk.posedge)) do
83
+ b <= b + 1
84
+ end
85
+
86
+
87
+
88
+ timed do
89
+ clk <= 0
90
+ w <= 0
91
+ a <= 0
92
+ b <= 0
93
+ !10.ns
94
+ clk <= ~clk
95
+ s <= 0
96
+ !10.ns
97
+ clk <= ~clk
98
+ s <= 1
99
+ !10.ns
100
+ clk <= ~clk
101
+ s <= 2
102
+ !10.ns
103
+ clk <= ~clk
104
+ s <= 3
105
+ !10.ns
106
+ end
107
+ end
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -549,12 +549,23 @@ $optparse = OptionParser.new do |opts|
549
549
  end
550
550
  $optparse.parse!
551
551
 
552
- # show? "options=#{$options}"
552
+ # puts "options=#{$options}"
553
553
 
554
554
  # Check the compatibility of the options
555
- if $options.count {|op| [:yaml,:hdr,:verilog,:vhdl,:svg].include?(op) } > 1 then
556
- warn("Please choose either YAML, HDLRuby, Verilog HDL, VHDL, SVG (visualize) output.")
557
- puts $optparse.help()
555
+ if $options.count {|op,val| [:yaml,:hdr,:verilog,:vhdl,:svg].include?(op) } > 1 then
556
+ warn("**Warning**: please choose either YAML, HDLRuby, Verilog HDL, VHDL, SVG (visualize) output.")
557
+ # puts $optparse.help()
558
+ exit
559
+ end
560
+ if $options.count {|op,val| [:rcsim, :csim, :rsim].include?(op) } > 1 then
561
+ warn("**Warning**: please choose either RCSIM, CSIM or RSIM simulator.")
562
+ # puts $optparse.help()
563
+ exit
564
+ end
565
+ if $options.count {|op,val| [:yaml,:hdr,:verilog,:vhdl,:svg,:rcsim,:csim,:rsim].include?(op) } > 1 then
566
+ warn("**Warning**: please choose either simulation or code generation.")
567
+ # puts $optparse.help()
568
+ exit
558
569
  end
559
570
 
560
571
  # Get the the input and the output files.