HDLRuby 2.11.2 → 2.11.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 284593b60cc81aa5e8f0f80a4370ffa33452763e22cf8928d3af1d773c69e8d4
4
- data.tar.gz: 1f2f0a10ec13a7050740b621a436cf61b80895f0205033768bba101a358b911f
3
+ metadata.gz: 71e8ee2662101e18157249150f4766654b0c049e08c87190fa6e06e2805d087b
4
+ data.tar.gz: cfc13c02e2fae3ad7d2a3831be9728cc35dffa3096016c2790d9649d19348f18
5
5
  SHA512:
6
- metadata.gz: 14458d5c7ae19883a43231859bce22f2e29efdbdaeb8b721af8178eab50626bbe49393c9b009eeb33b1301aeba0dec136cec804faf8c9e63a33c85ecd7595bc8
7
- data.tar.gz: 542354d84103276c6875dab37528d4a7a7218d71d11a8dc70b6d49aa43a9c72c8967d729282126a24b84e763eb94297ffffae50dc9c785deb2d811cf29125c4b
6
+ metadata.gz: cae45da4c41f556fc550a53272861e3def26bc15107a7bcb2cce1b3f8e99491d4b9cb8d2d4f4f621f422ef99c64ed704ac2e05a5f7c2b6d906133f420994aaf1
7
+ data.tar.gz: d29fb9b5ba800bcc4dff27c78e8a5762b9e7be1550ec1cb916a3cda543fabce878cc317c11e208e7a299896a7fc308cb307db0667dc6b3f416920b3d1c5fa2b0
@@ -11,6 +11,20 @@
11
11
 
12
12
  #include "hruby_sim.h"
13
13
 
14
+ // #if defined(_WIN32) || defined(_WIN64)
15
+ // #define show_access(POINTER,IDX) \
16
+ // printf("In %s accessing range [%p,%p](%i) at=%p with size=%i\n",__func__,(POINTER),(unsigned long long)(POINTER)+_msize((POINTER)),_msize((POINTER)),&((POINTER)[(IDX)]),sizeof((POINTER[(IDX)]))); fflush(stdout)
17
+ // #elif defined(__APPLE__)
18
+ // #define show_access(POINTER,IDX) \
19
+ // printf("In %s accessing range [%p,%p](%i) at=%p with size=%i\n",__func__,(POINTER),(unsigned long long)(POINTER)+malloc_size((POINTER)),malloc_size((POINTER)),&((POINTER)[(IDX)]),sizeof((POINTER[(IDX)]))); fflush(stdout)
20
+ // #else
21
+ // #define show_access(POINTER,IDX) \
22
+ // printf("In %s accessing range [%p,%p](%i) at=%p with size=%i\n",__func__,(POINTER),(unsigned long long)(POINTER)+malloc_usable_size((POINTER)),malloc_usable_size((POINTER)),&((POINTER)[(IDX)]),sizeof((POINTER[(IDX)]))); fflush(stdout)
23
+ // #endif
24
+
25
+ // #define show_access(POINTER,IDX)
26
+
27
+
14
28
  /**
15
29
  * The C-Ruby hybrid HDLRuby simulation builder.
16
30
  **/
@@ -62,13 +76,23 @@ static VALUE RCSimPointer;
62
76
 
63
77
  #define rcsim_to_value(TYPE,POINTER,VALUE) \
64
78
  (VALUE) = Data_Wrap_Struct(RCSimPointer, 0, 0, (POINTER))
65
- // (VALUE) = Data_Wrap_Struct(RCSimPointer, 0, free, (POINTER))
66
79
  // (VALUE) = ULL2NUM((unsigned long long)(POINTER))
80
+ // (VALUE) = Data_Wrap_Struct(RCSimPointer, 0, free, (POINTER))
67
81
 
68
82
  #define value_to_rcsim(TYPE,VALUE,POINTER) \
69
83
  Data_Get_Struct((VALUE),TYPE,(POINTER))
70
84
  // (POINTER) = (TYPE*)NUM2ULL((VALUE))
71
85
 
86
+
87
+ /* My own realloc. */
88
+ static void* my_realloc(void* pointer, size_t old_size, size_t new_size) {
89
+ if(old_size >= new_size) { return pointer; }
90
+ void* new_pointer = malloc(new_size);
91
+ memcpy(new_pointer,pointer,old_size);
92
+ free(pointer);
93
+ return new_pointer;
94
+ }
95
+
72
96
  /*#### Generates the list of ID coressponding to the HDLRuby symbols. ####*/
73
97
 
74
98
  static ID id_ANYEDGE;
@@ -168,12 +192,15 @@ VALUE rcsim_get_type_vector(VALUE mod, VALUE baseV, VALUE numV) {
168
192
 
169
193
  /* Creating a systemT C object. */
170
194
  VALUE rcsim_make_systemT(VALUE mod, VALUE name) {
195
+ // printf("rcsim_make_systemT\n");
171
196
  /* Allocates the systemT. */
172
197
  SystemT systemT = (SystemT)malloc(sizeof(SystemTS));
198
+ // printf("systemT=%p\n",systemT);
173
199
  /* Set it up. */
174
200
  systemT->kind = SYSTEMT;
175
201
  systemT->owner = NULL;
176
202
  systemT->name = strdup(StringValueCStr(name));
203
+ // printf("systemT->name=%p\n",systemT->name);
177
204
  systemT->num_inputs = 0;
178
205
  systemT->inputs = NULL;
179
206
  systemT->num_outputs = 0;
@@ -191,12 +218,15 @@ VALUE rcsim_make_systemT(VALUE mod, VALUE name) {
191
218
 
192
219
  /* Creating a scope C object. */
193
220
  VALUE rcsim_make_scope(VALUE mod, VALUE name) {
221
+ // printf("rcsim_make_scope\n");
194
222
  /* Allocates the scope. */
195
223
  Scope scope = (Scope)malloc(sizeof(ScopeS));
224
+ // printf("scope=%p\n",scope);
196
225
  /* Set it up. */
197
226
  scope->kind = SCOPE;
198
227
  scope->owner = NULL;
199
228
  scope->name = strdup(StringValueCStr(name));
229
+ // printf("scope->name=%p\n",scope->name);
200
230
  scope->num_systemIs = 0;
201
231
  scope->systemIs = NULL;
202
232
  scope->num_inners = 0;
@@ -216,9 +246,10 @@ VALUE rcsim_make_scope(VALUE mod, VALUE name) {
216
246
 
217
247
  /* Creating a behavior C object. */
218
248
  VALUE rcsim_make_behavior(VALUE mod, VALUE timed) {
249
+ // printf("rcsim_make_behavior\n");
219
250
  /* Allocates the behavior. */
220
251
  Behavior behavior = (Behavior)malloc(sizeof(BehaviorS));
221
- // printf("new behavior=%p\n",behavior);
252
+ // printf("behavior=%p\n",behavior);
222
253
  /* Set it up. */
223
254
  behavior->kind = BEHAVIOR;
224
255
  behavior->owner = NULL;
@@ -246,8 +277,10 @@ VALUE rcsim_make_behavior(VALUE mod, VALUE timed) {
246
277
 
247
278
  /* Creating an event C object. */
248
279
  VALUE rcsim_make_event(VALUE mod, VALUE typeV, VALUE sigV) {
280
+ // printf("rcsim_make_event\n");
249
281
  /* Allocates the event. */
250
282
  Event event = (Event)malloc(sizeof(EventS));
283
+ // printf("event=%p\n",event);
251
284
  /* Set it up. */
252
285
  event->kind = EVENT;
253
286
  event->owner = NULL;
@@ -268,28 +301,36 @@ VALUE rcsim_make_event(VALUE mod, VALUE typeV, VALUE sigV) {
268
301
 
269
302
  /* Creating a signal C object. */
270
303
  VALUE rcsim_make_signal(VALUE mod, VALUE name, VALUE type) {
304
+ // printf("rcsim_make_signal\n");
271
305
  /* Allocates the signal. */
272
306
  SignalI signal = (SignalI)malloc(sizeof(SignalIS));
307
+ // printf("signal=%p\n",signal);
273
308
  /* Set it up. */
274
309
  signal->kind = SIGNALI;
275
310
  signal->owner = NULL;
276
311
  signal->name = strdup(StringValueCStr(name));
312
+ // printf("signal->name=%p\n",signal->name);
277
313
  // printf("Creating signal named=%s\n",signal->name);
278
314
  value_to_rcsim(TypeS,type,signal->type);
279
315
  // printf("type width=%llu\n",type_width(signal->type));
280
316
  signal->c_value = make_value(signal->type,0);
317
+ // printf("signal->c_value=%p\n",signal->c_value);
281
318
  signal->c_value->signal = signal;
282
319
  // printf("c_value=%p type=%p\n",signal->c_value,signal->c_value->type);
283
320
  // printf("c_value type width=%llu\n",type_width(signal->c_value->type));
284
321
  signal->f_value = make_value(signal->type,0);
322
+ // printf("signal->f_value=%p\n",signal->f_value);
285
323
  signal->f_value->signal = signal;
286
324
  signal->fading = 1; /* Initially the signal can be overwritten by anything.*/
287
325
  signal->num_any = 0;
288
326
  signal->any = NULL;
327
+ // signal->any = (SignalI*)calloc(32,sizeof(SignalI));
289
328
  signal->num_pos = 0;
290
329
  signal->pos = NULL;
330
+ // signal->pos = (SignalI*)calloc(32,sizeof(SignalI));
291
331
  signal->num_neg = 0;
292
332
  signal->neg = NULL;
333
+ // signal->neg = (SignalI*)calloc(32,sizeof(SignalI));
293
334
  /* Register the signal. */
294
335
  register_signal(signal);
295
336
  /* Returns the C signal embedded into a ruby VALUE. */
@@ -301,17 +342,21 @@ VALUE rcsim_make_signal(VALUE mod, VALUE name, VALUE type) {
301
342
 
302
343
  /* Creating a system instance C object. */
303
344
  VALUE rcsim_make_systemI(VALUE mod, VALUE name, VALUE systemT) {
345
+ // printf("rcsim_make_systemI\n");
304
346
  /* Allocates the system instance. */
305
347
  SystemI systemI = (SystemI)malloc(sizeof(SystemIS));
348
+ // printf("systemI=%p\n",systemI);
306
349
  /* Set it up. */
307
350
  systemI->kind = SYSTEMI;
308
351
  systemI->owner = NULL;
309
352
  systemI->name = strdup(StringValueCStr(name));
353
+ // printf("systemI->name=%p\n",systemI->name);
310
354
  // /* Name is made empty since redundant with Eigen system. */
311
355
  // systemI->name = "";
312
356
  value_to_rcsim(SystemTS,systemT,systemI->system);
313
357
  systemI->num_systems = 1;
314
- systemI->systems = (SystemT*)malloc(sizeof(SystemT));
358
+ systemI->systems = (SystemT*)malloc(sizeof(SystemT[1]));
359
+ // printf("systemI->systems=%p\n",systemI->systems); fflush(stdout);
315
360
  systemI->systems[0] = systemI->system;
316
361
  /* Configure the systemI to execute the default systemT. */
317
362
  configure(systemI,0);
@@ -324,8 +369,10 @@ VALUE rcsim_make_systemI(VALUE mod, VALUE name, VALUE systemT) {
324
369
 
325
370
  /* Creating a transmit C object. */
326
371
  VALUE rcsim_make_transmit(VALUE mod, VALUE left, VALUE right) {
372
+ // printf("rcsim_make_transmit\n");
327
373
  /* Allocates the transmit. */
328
374
  Transmit transmit = (Transmit)malloc(sizeof(TransmitS));
375
+ // printf("transmit=%p\n",transmit);
329
376
  /* Set it up. */
330
377
  transmit->kind = TRANSMIT;
331
378
  value_to_rcsim(ReferenceS,left,transmit->left);
@@ -339,8 +386,10 @@ VALUE rcsim_make_transmit(VALUE mod, VALUE left, VALUE right) {
339
386
 
340
387
  /* Creating a print C object. */
341
388
  VALUE rcsim_make_print(VALUE mod) {
389
+ // printf("rcsim_make_print\n");
342
390
  /* Allocates the print. */
343
391
  Print print = (Print)malloc(sizeof(PrintS));
392
+ // printf("print=%p\n",print);
344
393
  /* Set it up. */
345
394
  print->kind = PRINT;
346
395
  print->num_args = 0;
@@ -354,8 +403,10 @@ VALUE rcsim_make_print(VALUE mod) {
354
403
 
355
404
  /* Creating a time wait C object. */
356
405
  VALUE rcsim_make_timeWait(VALUE mod, VALUE unitV, VALUE delayV) {
406
+ // printf("rcsim_make_timeWait\n");
357
407
  /* Allocates the time wait. */
358
408
  TimeWait timeWait = (TimeWait)malloc(sizeof(TimeWaitS));
409
+ // printf("timeWait=%p\n",timeWait);
359
410
  /* Set it up. */
360
411
  timeWait->kind = TIME_WAIT;
361
412
  /* Compute the delay. */
@@ -382,8 +433,10 @@ VALUE rcsim_make_timeWait(VALUE mod, VALUE unitV, VALUE delayV) {
382
433
 
383
434
  /* Creating a time terminate C object. */
384
435
  VALUE rcsim_make_timeTerminate(VALUE mod) {
436
+ // printf("rcsim_make_timeTerminate\n");
385
437
  /* Allocates the time terminate. */
386
438
  TimeTerminate timeTerminate = (TimeTerminate)malloc(sizeof(TimeTerminateS));
439
+ // printf("timeTerminate=%p\n",timeTerminate);
387
440
  /* Set it up. */
388
441
  timeTerminate->kind = TIME_TERMINATE;
389
442
  /* Returns the C time terminate embedded into a ruby VALUE. */
@@ -395,8 +448,10 @@ VALUE rcsim_make_timeTerminate(VALUE mod) {
395
448
 
396
449
  /* Creating a hardware if C object. */
397
450
  VALUE rcsim_make_hif(VALUE mod, VALUE condition, VALUE yes, VALUE no) {
451
+ // printf("rcsim_make_hif\n");
398
452
  /* Allocates the hardware if. */
399
453
  HIf hif = (HIf)malloc(sizeof(HIfS));
454
+ // printf("hif=%p\n",hif);
400
455
  /* Set it up. */
401
456
  hif->kind = HIF;
402
457
  value_to_rcsim(ExpressionS,condition,hif->condition);
@@ -417,8 +472,10 @@ VALUE rcsim_make_hif(VALUE mod, VALUE condition, VALUE yes, VALUE no) {
417
472
 
418
473
  /* Creating a hardware case C object. */
419
474
  VALUE rcsim_make_hcase(VALUE mod, VALUE value, VALUE defolt) {
475
+ // printf("rcsim_make_hcase\n");
420
476
  /* Allocates the hardware case. */
421
477
  HCase hcase = (HCase)malloc(sizeof(HCaseS));
478
+ // printf("hcase=%p\n",hcase);
422
479
  /* Set it up. */
423
480
  hcase->kind = HCASE;
424
481
  value_to_rcsim(ExpressionS,value,hcase->value);
@@ -438,8 +495,10 @@ VALUE rcsim_make_hcase(VALUE mod, VALUE value, VALUE defolt) {
438
495
 
439
496
  /* Creating a block C object. */
440
497
  VALUE rcsim_make_block(VALUE mod, VALUE mode) {
498
+ // printf("rcsim_make_block\n");
441
499
  /* Allocates the block. */
442
500
  Block block = (Block)malloc(sizeof(BlockS));
501
+ // printf("block=%p\n",block);
443
502
  /* Set it up. */
444
503
  block->kind = BLOCK;
445
504
  block->owner = NULL;
@@ -458,15 +517,13 @@ VALUE rcsim_make_block(VALUE mod, VALUE mode) {
458
517
 
459
518
  /* Creating a numeric value C object. */
460
519
  VALUE rcsim_make_value_numeric(VALUE mod, VALUE typeV, VALUE contentV) {
461
- // /* Allocates the value. */
462
- // Value value = get_value();
463
- // /* Sets its type. */
464
- // value_to_rcsim(TypeS,typeV,value->type);
520
+ // printf("rcsim_make_value_numeric\n");
465
521
  /* Get the type. */
466
522
  Type type;
467
523
  value_to_rcsim(TypeS,typeV,type);
468
524
  /* Create the value. */
469
525
  Value value = make_value(type,0);
526
+ // printf("value=%p\n",value);
470
527
  /* Set it to numeric. */
471
528
  value->numeric = 1;
472
529
  value->capacity = 0;
@@ -481,15 +538,13 @@ VALUE rcsim_make_value_numeric(VALUE mod, VALUE typeV, VALUE contentV) {
481
538
 
482
539
  /* Creating a bitstring value C object. */
483
540
  VALUE rcsim_make_value_bitstring(VALUE mod, VALUE typeV, VALUE contentV) {
484
- // /* Allocates the value. */
485
- // Value value = get_value();
486
- // /* Sets its type. */
487
- // value_to_rcsim(TypeS,type,value->type);
541
+ // printf("rcsim_make_value_bitstring\n");
488
542
  /* Get the type. */
489
543
  Type type;
490
544
  value_to_rcsim(TypeS,typeV,type);
491
545
  /* Create the value. */
492
546
  Value value = make_value(type,0);
547
+ // printf("value=%p\n",value);
493
548
  // printf("Created from bitstring value=%p with type=%p\n",value,value->type);
494
549
  // printf("and width=%llu\n",type_width(value->type));
495
550
  /* Set it to bitstring. */
@@ -497,7 +552,8 @@ VALUE rcsim_make_value_bitstring(VALUE mod, VALUE typeV, VALUE contentV) {
497
552
  /* Generate the string of the content. */
498
553
  char* str = StringValueCStr(contentV);
499
554
  value->capacity = strlen(str)+1;
500
- value->data_str = calloc(sizeof(char),value->capacity);
555
+ value->data_str = calloc(value->capacity,sizeof(char));
556
+ // printf("value->data_str=%p\n",value->data_str);
501
557
  strcpy(value->data_str,str);
502
558
  /* Returns the C value embedded into a ruby VALUE. */
503
559
  VALUE res;
@@ -508,8 +564,10 @@ VALUE rcsim_make_value_bitstring(VALUE mod, VALUE typeV, VALUE contentV) {
508
564
 
509
565
  /* Creating a cast C object. */
510
566
  VALUE rcsim_make_cast(VALUE mod, VALUE type, VALUE child) {
567
+ // printf("rcsim_make_cast\n");
511
568
  /* Allocates the cast. */
512
569
  Cast cast = (Cast)malloc(sizeof(CastS));
570
+ // printf("cast=%p\n",cast);
513
571
  /* Set it up. */
514
572
  cast->kind = CAST;
515
573
  value_to_rcsim(TypeS,type,cast->type);
@@ -522,8 +580,10 @@ VALUE rcsim_make_cast(VALUE mod, VALUE type, VALUE child) {
522
580
 
523
581
  /* Creating a unary value C object. */
524
582
  VALUE rcsim_make_unary(VALUE mod, VALUE type, VALUE operator, VALUE child) {
583
+ // printf("rcsim_make_unary\n");
525
584
  /* Allocates the unary. */
526
585
  Unary unary= (Unary)malloc(sizeof(UnaryS));
586
+ // printf("unary=%p\n",unary);
527
587
  /* Set it up. */
528
588
  unary->kind = UNARY;
529
589
  value_to_rcsim(TypeS,type,unary->type);
@@ -541,8 +601,10 @@ VALUE rcsim_make_unary(VALUE mod, VALUE type, VALUE operator, VALUE child) {
541
601
 
542
602
  /* Creating a binary value C object. */
543
603
  VALUE rcsim_make_binary(VALUE mod, VALUE type, VALUE operator, VALUE left, VALUE right) {
604
+ // printf("rcsim_make_binary\n");
544
605
  /* Allocates the binary. */
545
606
  Binary binary = (Binary)malloc(sizeof(BinaryS));
607
+ // printf("binary=%p\n",binary);
546
608
  /* Set it up. */
547
609
  binary->kind = BINARY;
548
610
  value_to_rcsim(TypeS,type,binary->type);
@@ -575,8 +637,10 @@ VALUE rcsim_make_binary(VALUE mod, VALUE type, VALUE operator, VALUE left, VALUE
575
637
 
576
638
  /* Creating a select C object. */
577
639
  VALUE rcsim_make_select(VALUE mod, VALUE type, VALUE sel) {
640
+ // printf("rcsim_make_select\n");
578
641
  /* Allocates the select. */
579
642
  Select select = (Select)malloc(sizeof(SelectS));
643
+ // printf("select=%p\n",select);
580
644
  /* Set it up. */
581
645
  select->kind = SELECT;
582
646
  value_to_rcsim(TypeS,type,select->type);
@@ -591,8 +655,10 @@ VALUE rcsim_make_select(VALUE mod, VALUE type, VALUE sel) {
591
655
 
592
656
  /* Creating a concat C object. */
593
657
  VALUE rcsim_make_concat(VALUE mod, VALUE type, VALUE dirV) {
658
+ // printf("rcsim_make_concat\n");
594
659
  /* Allocates the concat. */
595
660
  Concat concat = (Concat)malloc(sizeof(ConcatS));
661
+ // printf("concat=%p\n",concat);
596
662
  /* Set it up. */
597
663
  concat->kind = CONCAT;
598
664
  value_to_rcsim(TypeS,type,concat->type);
@@ -607,8 +673,10 @@ VALUE rcsim_make_concat(VALUE mod, VALUE type, VALUE dirV) {
607
673
 
608
674
  /* Creating a ref concat C object. */
609
675
  VALUE rcsim_make_refConcat(VALUE mod, VALUE type, VALUE dirV) {
676
+ // printf("rcsim_make_refConcat\n");
610
677
  /* Allocates the ref concat. */
611
678
  RefConcat refConcat = (RefConcat)malloc(sizeof(RefConcatS));
679
+ // printf("refConcat=%p\n",refConcat);
612
680
  /* Set it up. */
613
681
  refConcat->kind = REF_CONCAT;
614
682
  value_to_rcsim(TypeS,type,refConcat->type);
@@ -623,8 +691,10 @@ VALUE rcsim_make_refConcat(VALUE mod, VALUE type, VALUE dirV) {
623
691
 
624
692
  /* Creating a ref index C object. */
625
693
  VALUE rcsim_make_refIndex(VALUE mod, VALUE type, VALUE index, VALUE ref) {
694
+ // printf("rcsim_make_refIndex\n");
626
695
  /* Allocates the ref index. */
627
696
  RefIndex refIndex = (RefIndex)malloc(sizeof(RefIndexS));
697
+ // printf("refIndex=%p\n",refIndex);
628
698
  /* Set it up. */
629
699
  refIndex->kind = REF_INDEX;
630
700
  value_to_rcsim(TypeS,type,refIndex->type);
@@ -638,8 +708,10 @@ VALUE rcsim_make_refIndex(VALUE mod, VALUE type, VALUE index, VALUE ref) {
638
708
 
639
709
  /* Creating a ref range C object. */
640
710
  VALUE rcsim_make_refRange(VALUE mod, VALUE type, VALUE first, VALUE last, VALUE ref) {
711
+ // printf("rcsim_make_refRange\n");
641
712
  /* Allocates the ref range. */
642
713
  RefRangeE refRange = (RefRangeE)malloc(sizeof(RefRangeES));
714
+ // printf("refRange=%p\n",refRange);
643
715
  /* Set it up. */
644
716
  refRange->kind = REF_RANGE;
645
717
  value_to_rcsim(TypeS,type,refRange->type);
@@ -655,8 +727,10 @@ VALUE rcsim_make_refRange(VALUE mod, VALUE type, VALUE first, VALUE last, VALUE
655
727
 
656
728
  /* Creating a character string C object. */
657
729
  VALUE rcsim_make_stringE(VALUE mod, VALUE strV) {
730
+ // printf("rcsim_make_stringE\n");
658
731
  /* Allocates the string. */
659
732
  StringE stringE = (StringE)malloc(sizeof(StringES));
733
+ // printf("stringE=%p\n",stringE);
660
734
  /* Set it up. */
661
735
  stringE->kind = STRINGE;
662
736
  stringE->str = strdup(StringValueCStr(strV));
@@ -673,19 +747,24 @@ VALUE rcsim_add_systemT_inputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
673
747
  /* Get the C systemT from the Ruby value. */
674
748
  SystemT systemT;
675
749
  value_to_rcsim(SystemTS,systemTV,systemT);
750
+ // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
676
751
  // printf("Adding to systemT with kind=%d and name=%s\n",systemT->kind, systemT->name);
677
752
  /* Prepare the size for the inputs. */
678
753
  long num = RARRAY_LEN(sigVs);
679
754
  long old_num = systemT->num_inputs;
680
755
  systemT->num_inputs += num;
681
- systemT->inputs=realloc(systemT->inputs,sizeof(SignalI)*systemT->num_inputs);
682
- // printf("size=%d num=%i\n",malloc_size(systemT->inputs),systemT->num_inputs);
683
- // printf("required size=%lu\n",sizeof(SignalI)*systemT->num_inputs);
756
+ // printf("first systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
757
+ // systemT->inputs=realloc(systemT->inputs,
758
+ // sizeof(SignalI[systemT->num_inputs]));
759
+ systemT->inputs=my_realloc(systemT->inputs,sizeof(SignalI[old_num]),
760
+ sizeof(SignalI[systemT->num_inputs]));
761
+ // printf("now systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
762
+ // printf("access test: %p\n",systemT->inputs[0]); fflush(stdout);
684
763
  /* Get and add the signals from the Ruby value. */
685
- for(int i=0; i< num; ++i) {
764
+ for(long i=0; i< num; ++i) {
686
765
  SignalI sig;
766
+ // show_access(systemT->inputs,old_num+i);
687
767
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
688
- // printf("old_num+i=%ld\n",old_num+i);
689
768
  systemT->inputs[old_num + i] = sig;
690
769
  }
691
770
  return systemTV;
@@ -696,14 +775,22 @@ VALUE rcsim_add_systemT_outputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
696
775
  /* Get the C systemT from the Ruby value. */
697
776
  SystemT systemT;
698
777
  value_to_rcsim(SystemTS,systemTV,systemT);
778
+ // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
699
779
  /* Prepare the size for the outputs. */
700
780
  long num = RARRAY_LEN(sigVs);
701
781
  long old_num = systemT->num_outputs;
702
782
  systemT->num_outputs += num;
703
- systemT->outputs =realloc(systemT->outputs,sizeof(SignalI)*systemT->num_outputs);
783
+ // printf("first systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
784
+ // systemT->outputs =realloc(systemT->outputs,
785
+ // sizeof(SignalI[systemT->num_outputs]));
786
+ systemT->outputs =my_realloc(systemT->outputs,sizeof(SignalI[old_num]),
787
+ sizeof(SignalI[systemT->num_outputs]));
788
+ // printf("now systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
789
+ // printf("access test: %p\n",systemT->outputs[0]); fflush(stdout);
704
790
  /* Get and add the signals from the Ruby value. */
705
- for(int i=0; i< num; ++i) {
791
+ for(long i=0; i< num; ++i) {
706
792
  SignalI sig;
793
+ // show_access(systemT->outputs,old_num+i);
707
794
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
708
795
  systemT->outputs[old_num + i] = sig;
709
796
  }
@@ -715,14 +802,22 @@ VALUE rcsim_add_systemT_inouts(VALUE mod, VALUE systemTV, VALUE sigVs) {
715
802
  /* Get the C systemT from the Ruby value. */
716
803
  SystemT systemT;
717
804
  value_to_rcsim(SystemTS,systemTV,systemT);
805
+ // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
718
806
  /* Prepare the size for the inouts. */
719
807
  long num = RARRAY_LEN(sigVs);
720
808
  long old_num = systemT->num_inouts;
721
809
  systemT->num_inouts += num;
722
- systemT->inouts =realloc(systemT->inouts,sizeof(SignalI)*systemT->num_inouts);
810
+ // printf("first systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
811
+ // systemT->inouts =realloc(systemT->inouts,
812
+ // sizeof(SignalI[systemT->num_inouts]));
813
+ systemT->inouts =my_realloc(systemT->inouts,sizeof(SignalI[old_num]),
814
+ sizeof(SignalI[systemT->num_inouts]));
815
+ // printf("now systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
816
+ // printf("access test: %p\n",systemT->inouts[0]); fflush(stdout);
723
817
  /* Get and add the signals from the Ruby value. */
724
- for(int i=0; i< num; ++i) {
818
+ for(long i=0; i< num; ++i) {
725
819
  SignalI sig;
820
+ // show_access(systemT->inouts,old_num+i);
726
821
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
727
822
  systemT->inouts[old_num + i] = sig;
728
823
  }
@@ -734,14 +829,22 @@ VALUE rcsim_add_scope_inners(VALUE mod, VALUE scopeV, VALUE sigVs) {
734
829
  /* Get the C scope from the Ruby value. */
735
830
  Scope scope;
736
831
  value_to_rcsim(ScopeS,scopeV,scope);
832
+ // printf("rcsim_add_scope_inners with scope=%p\n",scope);
737
833
  /* Prepare the size for the inners. */
738
834
  long num = RARRAY_LEN(sigVs);
739
835
  long old_num = scope->num_inners;
740
836
  scope->num_inners += num;
741
- scope->inners = realloc(scope->inners,sizeof(SignalI)*scope->num_inners);
837
+ // printf("first scope->inners=%p\n",scope->inners); fflush(stdout);
838
+ // scope->inners = realloc(scope->inners,
839
+ // sizeof(SignalI[scope->num_inners]));
840
+ scope->inners = my_realloc(scope->inners,sizeof(SignalI[old_num]),
841
+ sizeof(SignalI[scope->num_inners]));
842
+ // printf("now scope->inners=%p\n",scope->inners); fflush(stdout);
843
+ // printf("access test: %p\n",scope->inners[0]); fflush(stdout);
742
844
  /* Get and add the signals from the Ruby value. */
743
- for(int i=0; i< num; ++i) {
845
+ for(long i=0; i< num; ++i) {
744
846
  SignalI sig;
847
+ // show_access(scope->inners,old_num+i);
745
848
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
746
849
  scope->inners[old_num + i] = sig;
747
850
  }
@@ -750,18 +853,28 @@ VALUE rcsim_add_scope_inners(VALUE mod, VALUE scopeV, VALUE sigVs) {
750
853
 
751
854
  /* Adds behaviors to a C scope. */
752
855
  VALUE rcsim_add_scope_behaviors(VALUE mod, VALUE scopeV, VALUE behVs) {
856
+ // printf("rcsim_add_scope_behaviors\n");
753
857
  /* Get the C scope from the Ruby value. */
754
858
  Scope scope;
755
859
  value_to_rcsim(ScopeS,scopeV,scope);
860
+ // printf("rcsim_add_scope_behaviors with scope=%p\n",scope);
756
861
  /* Prepare the size for the behaviors. */
757
862
  long num = RARRAY_LEN(behVs);
758
863
  long old_num = scope->num_behaviors;
864
+ // printf("num=%lu old_num=%lu\n",num,old_num);
865
+ // printf("scope->behaviors=%p\n",scope->behaviors);
759
866
  scope->num_behaviors += num;
760
- scope->behaviors = realloc(scope->behaviors,
761
- sizeof(Behavior)*scope->num_behaviors);
867
+ // printf("first scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
868
+ // scope->behaviors = realloc(scope->behaviors,
869
+ // sizeof(Behavior[scope->num_behaviors]));
870
+ scope->behaviors = my_realloc(scope->behaviors,sizeof(Behavior[old_num]),
871
+ sizeof(Behavior[scope->num_behaviors]));
872
+ // printf("now scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
873
+ // printf("access test: %p\n",scope->behaviors[0]); fflush(stdout);
762
874
  /* Get and add the behaviors from the Ruby value. */
763
- for(int i=0; i< num; ++i) {
875
+ for(long i=0; i< num; ++i) {
764
876
  Behavior beh;
877
+ // show_access(scope->behaviors,old_num+i);
765
878
  value_to_rcsim(BehaviorS,rb_ary_entry(behVs,i),beh);
766
879
  scope->behaviors[old_num + i] = beh;
767
880
  }
@@ -773,15 +886,22 @@ VALUE rcsim_add_scope_systemIs(VALUE mod, VALUE scopeV, VALUE sysVs) {
773
886
  /* Get the C scope from the Ruby value. */
774
887
  Scope scope;
775
888
  value_to_rcsim(ScopeS,scopeV,scope);
889
+ // printf("rcsim_add_scope_systemIs with scope=%p\n",scope);
776
890
  /* Prepare the size for the system instances. */
777
891
  long num = RARRAY_LEN(sysVs);
778
892
  long old_num = scope->num_systemIs;
779
893
  scope->num_systemIs += num;
780
- scope->systemIs = realloc(scope->systemIs,
781
- sizeof(SystemI)*scope->num_systemIs);
894
+ // printf("first scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
895
+ // scope->systemIs = realloc(scope->systemIs,
896
+ // sizeof(SystemI[scope->num_systemIs]));
897
+ scope->systemIs = my_realloc(scope->systemIs,sizeof(SystemI[old_num]),
898
+ sizeof(SystemI[scope->num_systemIs]));
899
+ // printf("now scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
900
+ // printf("access test: %p\n",scope->systemIs[0]); fflush(stdout);
782
901
  /* Get and add the system instances from the Ruby value. */
783
- for(int i=0; i< num; ++i) {
902
+ for(long i=0; i< num; ++i) {
784
903
  SystemI sys;
904
+ // show_access(scope->systemIs,old_num+i);
785
905
  value_to_rcsim(SystemIS,rb_ary_entry(sysVs,i),sys);
786
906
  scope->systemIs[old_num + i] = sys;
787
907
  }
@@ -793,15 +913,22 @@ VALUE rcsim_add_scope_scopes(VALUE mod, VALUE scopeV, VALUE scpVs) {
793
913
  /* Get the C scope from the Ruby value. */
794
914
  Scope scope;
795
915
  value_to_rcsim(ScopeS,scopeV,scope);
916
+ // printf("rcsim_add_scope_scopes with scope=%p\n",scope);
796
917
  /* Prepare the size for the sub scopes. */
797
918
  long num = RARRAY_LEN(scpVs);
798
919
  long old_num = scope->num_scopes;
799
920
  scope->num_scopes += num;
800
- scope->scopes = realloc(scope->scopes,
801
- sizeof(Scope)*scope->num_scopes);
921
+ // printf("first scope->scopes=%p\n",scope->scopes); fflush(stdout);
922
+ // scope->scopes = realloc(scope->scopes,
923
+ // sizeof(Scope[scope->num_scopes]));
924
+ scope->scopes = my_realloc(scope->scopes,sizeof(Scope[old_num]),
925
+ sizeof(Scope[scope->num_scopes]));
926
+ // printf("now scope->scopes=%p\n",scope->scopes); fflush(stdout);
927
+ // printf("access test: %p\n",scope->scopes[0]); fflush(stdout);
802
928
  /* Get and add the sub scopes from the Ruby value. */
803
- for(int i=0; i< num; ++i) {
929
+ for(long i=0; i< num; ++i) {
804
930
  Scope scp;
931
+ // show_access(scope->scopes,old_num+i);
805
932
  value_to_rcsim(ScopeS,rb_ary_entry(scpVs,i),scp);
806
933
  scope->scopes[old_num + i] = scp;
807
934
  }
@@ -813,15 +940,22 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
813
940
  /* Get the C behavior from the Ruby value. */
814
941
  Behavior behavior;
815
942
  value_to_rcsim(BehaviorS,behaviorV,behavior);
943
+ // printf("rcsim_add_behavior_events with behavior=%p\n",behavior);
816
944
  /* Prepare the size for the events. */
817
945
  long num = RARRAY_LEN(eventVs);
818
946
  long old_num = behavior->num_events;
819
947
  behavior->num_events += num;
820
- behavior->events = realloc(behavior->events,
821
- sizeof(Event)*behavior->num_events);
948
+ // printf("first behavior->events=%p\n",behavior->events); fflush(stdout);
949
+ // behavior->events = realloc(behavior->events,
950
+ // sizeof(Event[behavior->num_events]));
951
+ behavior->events = my_realloc(behavior->events,sizeof(Event[old_num]),
952
+ sizeof(Event[behavior->num_events]));
953
+ // printf("now behavior->events=%p\n",behavior->events); fflush(stdout);
954
+ // printf("access test: %p\n",behavior->events[0]); fflush(stdout);
822
955
  /* Get and add the events from the Ruby value. */
823
- for(int i=0; i< num; ++i) {
956
+ for(long i=0; i< num; ++i) {
824
957
  Event event;
958
+ // show_access(behavior->events,old_num+i);
825
959
  value_to_rcsim(EventS,rb_ary_entry(eventVs,i),event);
826
960
  behavior->events[old_num + i] = event;
827
961
  /* Update the signal of the event to say it activates the behavior. */
@@ -829,17 +963,35 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
829
963
  switch(event->edge) {
830
964
  case ANYEDGE:
831
965
  sig->num_any++;
832
- sig->any = realloc(sig->any,sizeof(Object)*sig->num_any);
966
+ // printf("first sig->any=%p\n",sig->any); fflush(stdout);
967
+ // sig->any = realloc(sig->any,sizeof(Object[sig->num_any]));
968
+ sig->any = my_realloc(sig->any,sizeof(Object[sig->num_any-1]),sizeof(Object[sig->num_any]));
969
+ // printf("now sig->any=%p\n",sig->any); fflush(stdout);
970
+ // printf("access test: %p\n",sig->any[0]); fflush(stdout);
971
+ // show_access(sig->any,sig->num_any-1);
972
+ // printf("sig->any=%p\n",sig->any);
833
973
  sig->any[sig->num_any-1] = (Object)behavior;
834
974
  break;
835
975
  case POSEDGE:
836
976
  sig->num_pos++;
837
- sig->pos = realloc(sig->pos,sizeof(Object)*sig->num_pos);
977
+ // printf("first sig->pos=%p\n",sig->pos); fflush(stdout);
978
+ // sig->pos = realloc(sig->pos,sizeof(Object[sig->num_pos]));
979
+ sig->pos = my_realloc(sig->pos,sizeof(Object[sig->num_pos-1]),sizeof(Object[sig->num_pos]));
980
+ // printf("now sig->pos=%p\n",sig->pos); fflush(stdout);
981
+ // printf("access test: %p\n",sig->pos[0]); fflush(stdout);
982
+ // show_access(sig->pos,sig->num_pos-1);
983
+ // printf("sig->pos=%p\n",sig->pos);
838
984
  sig->pos[sig->num_pos-1] = (Object)behavior;
839
985
  break;
840
986
  case NEGEDGE:
841
987
  sig->num_neg++;
842
- sig->neg = realloc(sig->neg,sizeof(Object)*sig->num_neg);
988
+ // printf("first sig->neg=%p\n",sig->neg); fflush(stdout);
989
+ // sig->neg = realloc(sig->neg,sizeof(Object[sig->num_neg]));
990
+ sig->neg = my_realloc(sig->neg,sizeof(Object[sig->num_neg-1]),sizeof(Object[sig->num_neg]));
991
+ // printf("now sig->neg=%p\n",sig->neg); fflush(stdout);
992
+ // printf("access test: %p\n",sig->neg[0]); fflush(stdout);
993
+ // show_access(sig->neg,sig->num_neg-1);
994
+ // printf("sig->neg=%p\n",sig->neg);
843
995
  sig->neg[sig->num_neg-1] = (Object)behavior;
844
996
  break;
845
997
  default:
@@ -854,14 +1006,22 @@ VALUE rcsim_add_systemI_systemTs(VALUE mod, VALUE systemIV, VALUE sysVs) {
854
1006
  /* Get the C systemI from the Ruby value. */
855
1007
  SystemI systemI;
856
1008
  value_to_rcsim(SystemIS,systemIV,systemI);
1009
+ // printf("rcsim_add_systemI_systemTs with systemI=%p\n",systemI);
857
1010
  /* Prepare the size for the alternate system types. */
858
1011
  long num = RARRAY_LEN(sysVs);
859
1012
  long old_num = systemI->num_systems;
860
1013
  systemI->num_systems += num;
861
- systemI->systems=realloc(systemI->systems,sizeof(SystemT)*systemI->num_systems);
1014
+ // printf("first systemI->systems=%p\n",systemI->systems); fflush(stdout);
1015
+ // systemI->systems=realloc(systemI->systems,
1016
+ // sizeof(SystemT[systemI->num_systems]));
1017
+ systemI->systems=my_realloc(systemI->systems,sizeof(SystemT[old_num]),
1018
+ sizeof(SystemT[systemI->num_systems]));
1019
+ // printf("now systemI->systems=%p\n",systemI->systems); fflush(stdout);
1020
+ // printf("access test: %p\n",systemI->systems[0]); fflush(stdout);
862
1021
  /* Get and add the alternate system types from the Ruby value. */
863
- for(int i=0; i< num; ++i) {
1022
+ for(long i=0; i< num; ++i) {
864
1023
  SystemT sys;
1024
+ // show_access(systemI->systems,old_num+i);
865
1025
  value_to_rcsim(SystemTS,rb_ary_entry(sysVs,i),sys);
866
1026
  systemI->systems[old_num + i] = sys;
867
1027
  }
@@ -873,15 +1033,22 @@ VALUE rcsim_add_print_args(VALUE mod, VALUE printV, VALUE argVs) {
873
1033
  /* Get the C print from the Ruby value. */
874
1034
  Print print;
875
1035
  value_to_rcsim(PrintS,printV,print);
1036
+ // printf("rcsim_add_print_args with print=%p\n",print);
876
1037
  /* Prepare the size for the arguments. */
877
1038
  long num = RARRAY_LEN(argVs);
878
1039
  long old_num = print->num_args;
879
1040
  print->num_args += num;
880
- print->args = realloc(print->args,
881
- sizeof(Expression)*print->num_args);
1041
+ // printf("first print->args=%p\n",print->args); fflush(stdout);
1042
+ // print->args = realloc(print->args,
1043
+ // sizeof(Expression[print->num_args]));
1044
+ print->args = my_realloc(print->args,sizeof(Expression[old_num]),
1045
+ sizeof(Expression[print->num_args]));
1046
+ // printf("now print->args=%p\n",print->args); fflush(stdout);
1047
+ // printf("access test: %p\n",print->args[0]); fflush(stdout);
882
1048
  /* Get and add the arguments from the Ruby value. */
883
- for(int i=0; i< num; ++i) {
1049
+ for(long i=0; i< num; ++i) {
884
1050
  Expression arg;
1051
+ // show_access(print->args,old_num+i);
885
1052
  value_to_rcsim(ExpressionS,rb_ary_entry(argVs,i),arg);
886
1053
  print->args[old_num + i] = arg;
887
1054
  }
@@ -893,16 +1060,27 @@ VALUE rcsim_add_hif_noifs(VALUE mod, VALUE hifV, VALUE condVs, VALUE stmntVs) {
893
1060
  /* Get the C hardware if from the Ruby value. */
894
1061
  HIf hif;
895
1062
  value_to_rcsim(HIfS,hifV,hif);
1063
+ // printf("rcsim_add_hif_noifs with hif=%p\n",hif);
896
1064
  /* Prepare the size for the noifs. */
897
1065
  long num = RARRAY_LEN(condVs);
898
1066
  long old_num = hif->num_noifs;
899
1067
  hif->num_noifs += num;
900
- hif->noconds = realloc(hif->noconds, sizeof(Expression)*hif->num_noifs);
901
- hif->nostmnts = realloc(hif->nostmnts, sizeof(Statement)*hif->num_noifs);
1068
+ // printf("first hif->noconds=%p\n",hif->noconds); fflush(stdout);
1069
+ // printf("first hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
1070
+ // hif->noconds = realloc(hif->noconds,sizeof(Expression[hif->num_noifs]));
1071
+ hif->noconds = my_realloc(hif->noconds,sizeof(Expression[old_num]),sizeof(Expression[hif->num_noifs]));
1072
+ // printf("now hif->noconds=%p\n",hif->noconds); fflush(stdout);
1073
+ // printf("access test: %p\n",hif->noconds[0]); fflush(stdout);
1074
+ // hif->nostmnts = realloc(hif->nostmnts,sizeof(Statement[hif->num_noifs]));
1075
+ hif->nostmnts = my_realloc(hif->nostmnts,sizeof(Statement[old_num]),sizeof(Statement[hif->num_noifs]));
1076
+ // printf("now hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
1077
+ // printf("access test: %p\n",hif->nostmnts[0]); fflush(stdout);
902
1078
  /* Get and add the noifs from the Ruby value. */
903
- for(int i=0; i< num; ++i) {
1079
+ for(long i=0; i< num; ++i) {
904
1080
  Expression cond;
905
1081
  Statement stmnt;
1082
+ // show_access(hif->noconds,old_num+i);
1083
+ // show_access(hif->nostmnts,old_num+i);
906
1084
  value_to_rcsim(ExpressionS,rb_ary_entry(condVs,i),cond);
907
1085
  hif->noconds[old_num + i] = cond;
908
1086
  value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
@@ -916,18 +1094,31 @@ VALUE rcsim_add_hcase_whens(VALUE mod, VALUE hcaseV, VALUE matchVs, VALUE stmntV
916
1094
  /* Get the C hardware case from the Ruby value. */
917
1095
  HCase hcase;
918
1096
  value_to_rcsim(HCaseS,hcaseV,hcase);
1097
+ // printf("rcsim_add_hcase_whens with hcase=%p\n",hcase);
919
1098
  /* Prepare the size for the noifs. */
920
1099
  long num = RARRAY_LEN(matchVs);
921
1100
  long old_num = hcase->num_whens;
922
1101
  hcase->num_whens += num;
923
- hcase->matches = realloc(hcase->matches,
924
- sizeof(Expression)*hcase->num_whens);
925
- hcase->stmnts = realloc(hcase->stmnts,
926
- sizeof(Statement)*hcase->num_whens);
1102
+ // printf("first hcase->matches=%p\n",hcase->matches); fflush(stdout);
1103
+ // printf("first hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
1104
+ // hcase->matches = realloc(hcase->matches,
1105
+ // sizeof(Expression[hcase->num_whens]));
1106
+ hcase->matches = my_realloc(hcase->matches,sizeof(Expression[old_num]),
1107
+ sizeof(Expression[hcase->num_whens]));
1108
+ // printf("now hcase->matches=%p\n",hcase->matches); fflush(stdout);
1109
+ // printf("access test: %p\n",hcase->matches[0]); fflush(stdout);
1110
+ // hcase->stmnts = realloc(hcase->stmnts,
1111
+ // sizeof(Statement[hcase->num_whens]));
1112
+ hcase->stmnts = my_realloc(hcase->stmnts,sizeof(Statement[old_num]),
1113
+ sizeof(Statement[hcase->num_whens]));
1114
+ // printf("now hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
1115
+ // printf("access test: %p\n",hcase->stmnts[0]); fflush(stdout);
927
1116
  /* Get and add the whens from the Ruby value. */
928
- for(int i=0; i< num; ++i) {
1117
+ for(long i=0; i< num; ++i) {
929
1118
  Expression match;
930
1119
  Statement stmnt;
1120
+ // show_access(hcase->matches,old_num+i);
1121
+ // show_access(hcase->stmnts,old_num+i);
931
1122
  value_to_rcsim(ExpressionS,rb_ary_entry(matchVs,i),match);
932
1123
  hcase->matches[old_num + i] = match;
933
1124
  value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
@@ -941,14 +1132,22 @@ VALUE rcsim_add_block_inners(VALUE mod, VALUE blockV, VALUE sigVs) {
941
1132
  /* Get the C block from the Ruby value. */
942
1133
  Block block;
943
1134
  value_to_rcsim(BlockS,blockV,block);
1135
+ // printf("rcsim_add_block_inners with block=%p\n",block);
944
1136
  /* Prepare the size for the inners. */
945
1137
  long num = RARRAY_LEN(sigVs);
946
1138
  long old_num = block->num_inners;
947
1139
  block->num_inners += num;
948
- block->inners = realloc(block->inners,sizeof(SignalI)*block->num_inners);
1140
+ // printf("first block->inners=%p\n",block->inners); fflush(stdout);
1141
+ // block->inners = realloc(block->inners,
1142
+ // sizeof(SignalI[block->num_inners]));
1143
+ block->inners = my_realloc(block->inners,sizeof(SignalI[old_num]),
1144
+ sizeof(SignalI[block->num_inners]));
1145
+ // printf("now block->inners=%p\n",block->inners); fflush(stdout);
1146
+ // printf("access test: %p\n",block->inners[0]); fflush(stdout);
949
1147
  /* Get and add the signals from the Ruby value. */
950
- for(int i=0; i< num; ++i) {
1148
+ for(long i=0; i< num; ++i) {
951
1149
  SignalI sig;
1150
+ // show_access(block->inners,old_num+i);
952
1151
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
953
1152
  block->inners[old_num + i] = sig;
954
1153
  }
@@ -960,14 +1159,22 @@ VALUE rcsim_add_block_statements(VALUE mod, VALUE blockV, VALUE stmntVs) {
960
1159
  /* Get the C block from the Ruby value. */
961
1160
  Block block;
962
1161
  value_to_rcsim(BlockS,blockV,block);
1162
+ // printf("rcsim_add_block_statements with block=%p\n",block);
963
1163
  /* Prepare the size for the statements. */
964
1164
  long num = RARRAY_LEN(stmntVs);
965
1165
  long old_num = block->num_stmnts;
966
1166
  block->num_stmnts += num;
967
- block->stmnts = realloc(block->stmnts,sizeof(Statement)*block->num_stmnts);
1167
+ // printf("first block->stmnts=%p\n",block->stmnts); fflush(stdout);
1168
+ // block->stmnts = realloc(block->stmnts,
1169
+ // sizeof(Statement[block->num_stmnts]));
1170
+ block->stmnts = my_realloc(block->stmnts,sizeof(Statement[old_num]),
1171
+ sizeof(Statement[block->num_stmnts]));
1172
+ // printf("now block->stmnts=%p\n",block->stmnts); fflush(stdout);
1173
+ // printf("access test: %p\n",block->stmnts[0]); fflush(stdout);
968
1174
  /* Get and add the statements from the Ruby value. */
969
- for(int i=0; i< num; ++i) {
1175
+ for(long i=0; i< num; ++i) {
970
1176
  Statement stmnt;
1177
+ // show_access(block->stmnts,old_num+i);
971
1178
  value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
972
1179
  block->stmnts[old_num + i] = stmnt;
973
1180
  }
@@ -979,14 +1186,22 @@ VALUE rcsim_add_select_choices(VALUE mod, VALUE selectV, VALUE choiceVs) {
979
1186
  /* Get the C select from the Ruby value. */
980
1187
  Select select;
981
1188
  value_to_rcsim(SelectS,selectV,select);
1189
+ // printf("rcsim_add_select_choices with select=%p\n",select);
982
1190
  /* Prepare the size for the choices. */
983
1191
  long num = RARRAY_LEN(choiceVs);
984
1192
  long old_num = select->num_choices;
985
1193
  select->num_choices += num;
986
- select->choices = realloc(select->choices,sizeof(Expression)*select->num_choices);
1194
+ // printf("first select->choices=%p\n",select->choices); fflush(stdout);
1195
+ // select->choices = realloc(select->choices,
1196
+ // sizeof(Expression[select->num_choices]));
1197
+ select->choices = my_realloc(select->choices,sizeof(Expression[old_num]),
1198
+ sizeof(Expression[select->num_choices]));
1199
+ // printf("now select->choices=%p\n",select->choices); fflush(stdout);
1200
+ // printf("access test: %p\n",select->choices[0]); fflush(stdout);
987
1201
  /* Get and add the choices from the Ruby value. */
988
- for(int i=0; i< num; ++i) {
1202
+ for(long i=0; i< num; ++i) {
989
1203
  Expression choice;
1204
+ // show_access(select->choices,old_num+i);
990
1205
  value_to_rcsim(ExpressionS,rb_ary_entry(choiceVs,i),choice);
991
1206
  select->choices[old_num + i] = choice;
992
1207
  }
@@ -998,17 +1213,24 @@ VALUE rcsim_add_concat_expressions(VALUE mod, VALUE concatV, VALUE exprVs) {
998
1213
  /* Get the C concat from the Ruby value. */
999
1214
  Concat concat;
1000
1215
  value_to_rcsim(ConcatS,concatV,concat);
1216
+ // printf("rcsim_add_concat_expressions with concat=%p\n",concat);
1001
1217
  /* Prepare the size for the expressions. */
1002
1218
  long num = RARRAY_LEN(exprVs);
1003
1219
  long old_num = concat->num_exprs;
1004
1220
  // printf("add_concat_expressions with num=%li old_num=%li\n",num,old_num);
1005
1221
  concat->num_exprs += num;
1006
- concat->exprs = realloc(concat->exprs,sizeof(Expression)*concat->num_exprs);
1222
+ // printf("first concat->exprs=%p\n",concat->exprs); fflush(stdout);
1223
+ // concat->exprs = realloc(concat->exprs,
1224
+ // sizeof(Expression[concat->num_exprs]));
1225
+ concat->exprs = my_realloc(concat->exprs,sizeof(Expression[old_num]),
1226
+ sizeof(Expression[concat->num_exprs]));
1227
+ // printf("now concat->exprs=%p\n",concat->exprs); fflush(stdout);
1228
+ // printf("access test: %p\n",concat->exprs[0]); fflush(stdout);
1007
1229
  /* Get and add the expressions from the Ruby value. */
1008
- for(int i=0; i< num; ++i) {
1230
+ for(long i=0; i< num; ++i) {
1009
1231
  Expression expr;
1232
+ // show_access(concat->exprs,old_num+i);
1010
1233
  value_to_rcsim(ExpressionS,rb_ary_entry(exprVs,i),expr);
1011
- // printf("Adding expression with type width=%llu\n",type_width(expr->type));
1012
1234
  concat->exprs[old_num + i] = expr;
1013
1235
  }
1014
1236
  return concatV;
@@ -1019,14 +1241,22 @@ VALUE rcsim_add_refConcat_refs(VALUE mod, VALUE refConcatV, VALUE refVs) {
1019
1241
  /* Get the C refConcat from the Ruby value. */
1020
1242
  RefConcat refConcat;
1021
1243
  value_to_rcsim(RefConcatS,refConcatV,refConcat);
1244
+ // printf("rcsim_add_refConcat_refs with refConcat=%p\n",refConcat);
1022
1245
  /* Prepare the size for the references. */
1023
1246
  long num = RARRAY_LEN(refVs);
1024
1247
  long old_num = refConcat->num_refs;
1025
1248
  refConcat->num_refs += num;
1026
- refConcat->refs = realloc(refConcat->refs,sizeof(Reference)*refConcat->num_refs);
1249
+ // printf("first refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
1250
+ // refConcat->refs = realloc(refConcat->refs,
1251
+ // sizeof(Reference[refConcat->num_refs]));
1252
+ refConcat->refs = my_realloc(refConcat->refs,sizeof(Reference[old_num]),
1253
+ sizeof(Reference[refConcat->num_refs]));
1254
+ // printf("now refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
1255
+ // printf("access test: %p\n",refConcat->refs[0]); fflush(stdout);
1027
1256
  /* Get and add the references from the Ruby value. */
1028
- for(int i=0; i< num; ++i) {
1257
+ for(long i=0; i< num; ++i) {
1029
1258
  Reference ref;
1259
+ // show_access(refConcat->refs,old_num+i);
1030
1260
  value_to_rcsim(ReferenceS,rb_ary_entry(refVs,i),ref);
1031
1261
  refConcat->refs[old_num + i] = ref;
1032
1262
  }
@@ -5,9 +5,9 @@
5
5
  #include <limits.h>
6
6
  #include "hruby_sim.h"
7
7
 
8
- #ifndef alloca
9
- #define alloca(x) __builtin_alloca(x)
10
- #endif
8
+ // #ifndef alloca
9
+ // #define alloca(x) __builtin_alloca(x)
10
+ // #endif
11
11
 
12
12
 
13
13
  /**
@@ -147,7 +147,7 @@ Type get_type_signed() {
147
147
  * @number the number of elements */
148
148
  Type make_type_vector(Type base, unsigned long long number) {
149
149
  /* Create the type. */
150
- Type type = calloc(sizeof(TypeS),1);
150
+ Type type = calloc(1,sizeof(TypeS));
151
151
  type->base = type_width(base);
152
152
  type->number = number;
153
153
  type->flags = base->flags;
@@ -201,7 +201,7 @@ Value make_value(Type type, int numeric) {
201
201
  /* Compute the size in words of the data contained in the value. */
202
202
  unsigned long long width = type_width(type);
203
203
  /* Allocate the value. */
204
- Value res = calloc(sizeof(ValueS),1);
204
+ Value res = calloc(1,sizeof(ValueS));
205
205
  /* Allocates the data of the value. */
206
206
  if (!numeric) {
207
207
  /* Allocate the bit string and fill it with u (undefined) by default. */
@@ -232,7 +232,7 @@ void resize_value(Value value, unsigned long long size) {
232
232
  /* Free the former data. */
233
233
  free(value->data_str);
234
234
  /* Reallocate it. */
235
- value->data_str = calloc(sizeof(char),size*2);
235
+ value->data_str = calloc(size*2,sizeof(char));
236
236
  /* Update the size. */
237
237
  value->capacity = size*2;
238
238
  }
@@ -2977,12 +2977,15 @@ Value concat_valueP(unsigned int num, int dir, Value dst, Value* values) {
2977
2977
  }
2978
2978
  Value concat_valueV(unsigned int num, int dir, Value dst, va_list args) {
2979
2979
  unsigned int i;
2980
- Value* values = alloca(num*sizeof(Value)); /* The values to concatenate. */
2980
+ // Value* values = alloca(num*sizeof(Value)); /* The values to concatenate. */
2981
+ Value* values = calloc(num,sizeof(Value)); /* The values to concatenate. */
2981
2982
  /* Copy the arguments to values for easier processing. */
2982
2983
  for(i=0; i<num; ++i) {
2983
2984
  values[i] = va_arg(args,Value);
2984
2985
  }
2985
- return concat_valueP(num,dir,dst,values);
2986
+ Value res = concat_valueP(num,dir,dst,values);
2987
+ free(values);
2988
+ return res;
2986
2989
  }
2987
2990
  Value concat_value(unsigned int num, int dir, Value dst, ...) {
2988
2991
  va_list args;
@@ -72,11 +72,12 @@ void register_timed_behavior(Behavior behavior) {
72
72
  if (cap_timed_behaviors == 0) {
73
73
  /* Need to create the array containing the timed behaviors. */
74
74
  cap_timed_behaviors = 5;
75
- timed_behaviors = calloc(sizeof(Behavior),cap_timed_behaviors);
75
+ timed_behaviors = calloc(cap_timed_behaviors,sizeof(Behavior));
76
76
  } else {
77
77
  /* Need to increase the capacity. */
78
- Behavior* behaviors = calloc(sizeof(Behavior),cap_timed_behaviors*2);
79
- memcpy(behaviors,timed_behaviors,sizeof(Behavior)*cap_timed_behaviors);
78
+ Behavior* behaviors = calloc(cap_timed_behaviors*2,sizeof(Behavior));
79
+ // memcpy(behaviors,timed_behaviors,sizeof(Behavior)*cap_timed_behaviors);
80
+ memcpy(behaviors,timed_behaviors,sizeof(Behavior[cap_timed_behaviors]));
80
81
  timed_behaviors = behaviors;
81
82
  cap_timed_behaviors *= 2;
82
83
  }
@@ -93,11 +94,12 @@ void register_signal(SignalI signal) {
93
94
  if (cap_all_signals == 0) {
94
95
  /* Need to create the array containing the timed behaviors. */
95
96
  cap_all_signals = 100;
96
- all_signals = calloc(sizeof(SignalI),cap_all_signals);
97
+ all_signals = calloc(cap_all_signals,sizeof(SignalI));
97
98
  } else {
98
99
  /* Need to increase the capacity. */
99
- SignalI* new_signals = calloc(sizeof(SignalI),cap_all_signals*2);
100
- memcpy(new_signals,all_signals,sizeof(SignalI)*cap_all_signals);
100
+ SignalI* new_signals = calloc(cap_all_signals*2,sizeof(SignalI));
101
+ // memcpy(new_signals,all_signals,sizeof(SignalI)*cap_all_signals);
102
+ memcpy(new_signals,all_signals,sizeof(SignalI[cap_all_signals]));
101
103
  cap_all_signals *= 2;
102
104
  all_signals=new_signals;
103
105
  }
@@ -20,9 +20,10 @@ Value get_value() {
20
20
  if (pool_cap == 0) {
21
21
  /* First allocation. */
22
22
  pool_cap = 16;
23
- pool_values = (Value*)malloc(pool_cap*sizeof(Value));
23
+ // pool_values = (Value*)malloc(pool_cap*sizeof(Value));
24
+ pool_values = (Value*)calloc(pool_cap,sizeof(Value));
24
25
  /* Allocate the new values. */
25
- ValueS* new_values = (ValueS*)calloc(sizeof(ValueS),pool_cap);
26
+ ValueS* new_values = (ValueS*)calloc(pool_cap,sizeof(ValueS));
26
27
  /* Assign them to the pool. */
27
28
  unsigned int i;
28
29
  for(i=0; i<pool_cap; ++i) {
@@ -32,7 +33,8 @@ Value get_value() {
32
33
  else if (pool_pos == pool_cap) {
33
34
  /* Need to increase the pool capacity. */
34
35
  pool_cap = pool_cap * 2;
35
- pool_values = (Value*)realloc(pool_values,pool_cap*sizeof(Value));
36
+ // pool_values = (Value*)realloc(pool_values,pool_cap*sizeof(Value));
37
+ pool_values = (Value*)realloc(pool_values,sizeof(Value[pool_cap]));
36
38
  if (pool_values == NULL) {
37
39
  perror("Internal error with the pool of values.");
38
40
  exit(1);
@@ -40,7 +42,7 @@ Value get_value() {
40
42
  /* Allocate the new values. */
41
43
  /* Note: now pool_pos is the old pool_cap and is also the number
42
44
  * of new values to allocate. */
43
- ValueS* new_values = (ValueS*)calloc(sizeof(ValueS),pool_pos);
45
+ ValueS* new_values = (ValueS*)calloc(pool_pos,sizeof(ValueS));
44
46
  /* Assign them to the pool. */
45
47
  unsigned int i;
46
48
  for(i=0; i<pool_pos; ++i) {
@@ -107,26 +107,32 @@ module HDLRuby::High
107
107
  # rcsig = sig.to_rcsim(@rcsystemT)
108
108
  # RCSim.rcsim_add_systemT_input(@rcsystemT,rcsig)
109
109
  # end
110
- RCSim.rcsim_add_systemT_inputs(@rcsystemT,
111
- self.each_input.map do |sig|
112
- sig.to_rcsim(@rcsystemT)
113
- end)
110
+ if self.each_input.any? then
111
+ RCSim.rcsim_add_systemT_inputs(@rcsystemT,
112
+ self.each_input.map do |sig|
113
+ sig.to_rcsim(@rcsystemT)
114
+ end)
115
+ end
114
116
  # self.each_output do |sig|
115
117
  # rcsig = sig.to_rcsim(@rcsystemT)
116
118
  # RCSim.rcsim_add_systemT_output(@rcsystemT,rcsig)
117
119
  # end
118
- RCSim.rcsim_add_systemT_outputs(@rcsystemT,
119
- self.each_output.map do |sig|
120
- sig.to_rcsim(@rcsystemT)
121
- end)
120
+ if self.each_output.any? then
121
+ RCSim.rcsim_add_systemT_outputs(@rcsystemT,
122
+ self.each_output.map do |sig|
123
+ sig.to_rcsim(@rcsystemT)
124
+ end)
125
+ end
122
126
  # self.each_inout do |sig|
123
127
  # rcsig = sig.to_rcsim(@rcsystemT)
124
128
  # RCSim.rcsim_add_systemT_inout(@rcsystemT,rcsig)
125
129
  # end
126
- RCSim.rcsim_add_systemT_inouts(@rcsystemT,
127
- self.each_inout.map do |sig|
128
- sig.to_rcsim(@rcsystemT)
129
- end)
130
+ if self.each_inout.any? then
131
+ RCSim.rcsim_add_systemT_inouts(@rcsystemT,
132
+ self.each_inout.map do |sig|
133
+ sig.to_rcsim(@rcsystemT)
134
+ end)
135
+ end
130
136
  # Create and add the scope.
131
137
  RCSim.rcsim_set_systemT_scope(@rcsystemT,
132
138
  self.scope.to_rcsim(@rcsystemT))
@@ -170,44 +176,43 @@ module HDLRuby::High
170
176
  # rcsig = sig.to_rcsim(@rcscope)
171
177
  # RCSim.rcsim_add_scope_inner(@rcscope,rcsig)
172
178
  # end
173
- RCSim.rcsim_add_scope_inners(@rcscope,self.each_inner.map do |sig|
174
- # sig.to_rcsim(@rcscope)
175
- sig.to_rcsim(subowner)
176
- end)
179
+ if self.each_inner.any? then
180
+ RCSim.rcsim_add_scope_inners(@rcscope,self.each_inner.map do|sig|
181
+ # sig.to_rcsim(@rcscope)
182
+ sig.to_rcsim(subowner)
183
+ end)
184
+ end
177
185
 
178
186
  # Create and add the system instances.
179
187
  # self.each_systemI do |sys|
180
188
  # rcsys = sys.to_rcsim(@rcscope)
181
189
  # RCSim.rcsim_add_scope_systemI(@rcscope,rcsys)
182
190
  # end
183
- RCSim.rcsim_add_scope_systemIs(@rcscope,
184
- self.each_systemI.map do |sys|
185
- # sys.to_rcsim(@rcscope)
186
- sys.to_rcsim(subowner)
187
- end)
191
+ if self.each_systemI.any? then
192
+ RCSim.rcsim_add_scope_systemIs(@rcscope,
193
+ self.each_systemI.map do |sys|
194
+ # sys.to_rcsim(@rcscope)
195
+ sys.to_rcsim(subowner)
196
+ end)
197
+ end
188
198
 
189
199
  # Create and add the behaviors.
190
- # self.each_behavior do |beh|
191
- # rcbeh = beh.to_rcsim(@rcscope)
192
- # RCSim.rcsim_add_scope_behavior(@rcscope,rcbeh)
193
- # end
194
- RCSim.rcsim_add_scope_behaviors(@rcscope,
195
- self.each_behavior.map do |beh|
196
- # beh.to_rcsim(@rcscope)
197
- beh.to_rcsim(subowner)
198
- end)
200
+ if self.each_behavior.any? then
201
+ RCSim.rcsim_add_scope_behaviors(@rcscope,
202
+ self.each_behavior.map do |beh|
203
+ # beh.to_rcsim(@rcscope)
204
+ beh.to_rcsim(subowner)
205
+ end)
206
+ end
199
207
 
200
208
  # Create and add the connections.
201
- # self.each_connection do |cnx|
202
- # rccnx = cnx.to_rcsim(@rcscope)
203
- # # Connections are actually converted to behaviors.
204
- # RCSim.rcsim_add_scope_behavior(@rcscope,rccnx)
205
- # end
206
- RCSim.rcsim_add_scope_behaviors(@rcscope,
207
- self.each_connection.map do |cxt|
208
- # cxt.to_rcsim(@rcscope)
209
- cxt.to_rcsim(subowner)
210
- end)
209
+ if self.each_connection.any? then
210
+ RCSim.rcsim_add_scope_behaviors(@rcscope,
211
+ self.each_connection.map do |cxt|
212
+ # cxt.to_rcsim(@rcscope)
213
+ cxt.to_rcsim(subowner)
214
+ end)
215
+ end
211
216
 
212
217
  # Create and add the codes.
213
218
  # TODO!!
@@ -217,10 +222,12 @@ module HDLRuby::High
217
222
  # rcsub = sub.to_rcsim(@rcscope)
218
223
  # RCSim.rcsim_add_scope_scope(@rcscope,rcsub)
219
224
  # end
220
- RCSim.rcsim_add_scope_scopes(@rcscope,self.each_scope.map do |sub|
221
- # sub.to_rcsim(@rcscope)
222
- sub.to_rcsim(subowner)
223
- end)
225
+ if self.each_scope.any? then
226
+ RCSim.rcsim_add_scope_scopes(@rcscope,self.each_scope.map do|sub|
227
+ # sub.to_rcsim(@rcscope)
228
+ sub.to_rcsim(subowner)
229
+ end)
230
+ end
224
231
 
225
232
  return @rcscope
226
233
  end
@@ -349,11 +356,13 @@ module HDLRuby::High
349
356
  # self.each_event do |ev|
350
357
  # RCSim.rcsim_add_behavior_event(@rcbehavior,ev.to_rcsim)
351
358
  # end
352
- RCSim.rcsim_add_behavior_events(@rcbehavior,
353
- self.each_event.map do |ev|
354
- # puts "adding event: #{ev.ref.object.name}(#{ev.type})"
355
- ev.to_rcsim(@rcbehavior)
356
- end)
359
+ if self.each_event.any? then
360
+ RCSim.rcsim_add_behavior_events(@rcbehavior,
361
+ self.each_event.map do |ev|
362
+ # puts "adding event: #{ev.ref.object.name}(#{ev.type})"
363
+ ev.to_rcsim(@rcbehavior)
364
+ end)
365
+ end
357
366
 
358
367
  # Create and add the block.
359
368
  RCSim.rcsim_set_behavior_block(@rcbehavior,self.block.to_rcsim)
@@ -468,12 +477,15 @@ module HDLRuby::High
468
477
  # rcsys = systemT.to_rcsim(@rcsystemI)
469
478
  # RCSim.rcsim_add_systemI_systemT(@rcsystemI,rcsys)
470
479
  # end
471
- RCSim.rcsim_add_systemI_systemTs(@rcsystemI,
472
- self.each_systemT.select do |sys|
473
- sys != self.systemT
474
- end.map do |sys|
475
- sys.to_rcsim(@rcsystemI)
476
- end)
480
+ if self.each_systemI.any? then
481
+ RCSim.rcsim_add_systemI_systemTs(@rcsystemI,
482
+ self.each_systemT.select do|sys|
483
+ sys != self.systemT
484
+ end.map do |sys|
485
+ # sys.to_rcsim(@rcsystemI)
486
+ sys.to_rcsim(rcowner)
487
+ end)
488
+ end
477
489
 
478
490
  return @rcsystemI
479
491
  end
@@ -531,8 +543,10 @@ module HDLRuby::High
531
543
  # self.each_arg do |arg|
532
544
  # RCSim.rcsim_add_print_arg(@rcstatement,arg.to_rcsim)
533
545
  # end
534
- RCSim.rcsim_add_print_args(@rcstatement,
535
- self.each_arg.map(&:to_rcsim))
546
+ if self.each_arg.any? then
547
+ RCSim.rcsim_add_print_args(@rcstatement,
548
+ self.each_arg.map(&:to_rcsim))
549
+ end
536
550
 
537
551
  return @rcstatement
538
552
  end
@@ -576,7 +590,9 @@ module HDLRuby::High
576
590
  # end
577
591
  rcsim_conds = self.each_noif.map {|cond,stmnt| cond.to_rcsim }
578
592
  rcsim_stmnts = self.each_noif.map {|cond,stmnt| stmnt.to_rcsim }
579
- RCSim.rcsim_add_hif_noifs(@rcstatement,rcsim_conds,rcsim_stmnts)
593
+ if rcsim_conds.any? then
594
+ RCSim.rcsim_add_hif_noifs(@rcstatement,rcsim_conds,rcsim_stmnts)
595
+ end
580
596
 
581
597
  return @rcstatement
582
598
  end
@@ -605,7 +621,10 @@ module HDLRuby::High
605
621
  # end
606
622
  rcsim_matches = self.each_when.map {|wh| wh.match.to_rcsim }
607
623
  rcsim_stmnts = self.each_when.map {|wh| wh.statement.to_rcsim }
608
- RCSim.rcsim_add_hcase_whens(@rcstatement,rcsim_matches,rcsim_stmnts)
624
+ if rcsim_matches.any? then
625
+ RCSim.rcsim_add_hcase_whens(@rcstatement,rcsim_matches,
626
+ rcsim_stmnts)
627
+ end
609
628
 
610
629
  return @rcstatement
611
630
  end
@@ -658,19 +677,23 @@ module HDLRuby::High
658
677
  # self.each_inner do |inner|
659
678
  # RCSim.rcsim_add_block_inner(@rcstatement,inner.to_rcsim(@rcstatement))
660
679
  # end
661
- RCSim.rcsim_add_block_inners(@rcstatement,
662
- self.each_inner.map do |sig|
663
- sig.to_rcsim(@rcstatement)
664
- end)
680
+ if self.each_inner.any? then
681
+ RCSim.rcsim_add_block_inners(@rcstatement,
682
+ self.each_inner.map do |sig|
683
+ sig.to_rcsim(@rcstatement)
684
+ end)
685
+ end
665
686
 
666
687
  # Add the statements.
667
688
  # self.each_statement do |stmnt|
668
689
  # RCSim.rcsim_add_block_statement(@rcstatement,stmnt.to_rcsim)
669
690
  # end
670
- RCSim.rcsim_add_block_statements(@rcstatement,
671
- self.each_statement.map do |stmnt|
672
- stmnt.to_rcsim
673
- end)
691
+ if self.each_statement.any? then
692
+ RCSim.rcsim_add_block_statements(@rcstatement,
693
+ self.each_statement.map do |stmnt|
694
+ stmnt.to_rcsim
695
+ end)
696
+ end
674
697
 
675
698
  return @rcstatement
676
699
  end
@@ -710,7 +733,9 @@ module HDLRuby::High
710
733
  rcevs << ev
711
734
  end
712
735
  end
713
- RCSim.rcsim_add_behavior_events(@rcbehavior,rcevs)
736
+ if rcevs.any? then
737
+ RCSim.rcsim_add_behavior_events(@rcbehavior,rcevs)
738
+ end
714
739
 
715
740
  # Create and set the block.
716
741
  rcblock = RCSim.rcsim_make_block(:par)
@@ -843,8 +868,10 @@ module HDLRuby::High
843
868
  # self.each_choice do |choice|
844
869
  # rcsim_add_select_choice(rcexpression,choice.to_rcsim)
845
870
  # end
846
- RCSim.rcsim_add_select_choices(rcexpression,
847
- self.each_choice.map(&:to_rcsim))
871
+ if self.each_choice.any? then
872
+ RCSim.rcsim_add_select_choices(rcexpression,
873
+ self.each_choice.map(&:to_rcsim))
874
+ end
848
875
 
849
876
  return rcexpression
850
877
  end
@@ -865,8 +892,10 @@ module HDLRuby::High
865
892
  # self.each_expression do |expr|
866
893
  # RCSim.rcsim_add_concat_expression(rcexpression,expr.to_rcsim)
867
894
  # end
868
- RCSim.rcsim_add_concat_expressions(rcexpression,
895
+ if self.each_expression.any? then
896
+ RCSim.rcsim_add_concat_expressions(rcexpression,
869
897
  self.each_expression.map(&:to_rcsim))
898
+ end
870
899
 
871
900
  return rcexpression
872
901
  end
@@ -901,7 +930,9 @@ module HDLRuby::High
901
930
  # self.each_ref do |ref|
902
931
  # RCSim.rcsim_add_refConcat_ref(rcref,ref.to_rcsim)
903
932
  # end
904
- RCSim.rcsim_add_refConcat_refs(rcref,self.each_ref(&:to_rcsim))
933
+ if self.each_ref.any? then
934
+ RCSim.rcsim_add_refConcat_refs(rcref,self.each_ref(&:to_rcsim))
935
+ end
905
936
 
906
937
  return rcref
907
938
  end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.11.2"
2
+ VERSION = "2.11.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HDLRuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.2
4
+ version: 2.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-01 00:00:00.000000000 Z
11
+ date: 2022-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler