HDLRuby 2.11.2 → 2.11.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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. */
@@ -379,11 +430,34 @@ VALUE rcsim_make_timeWait(VALUE mod, VALUE unitV, VALUE delayV) {
379
430
  return res;
380
431
  }
381
432
 
433
+ /* Creating a time repeat C object. */
434
+ VALUE rcsim_make_timeRepeat(VALUE mod, VALUE numberV, VALUE statementV) {
435
+ // printf("rcsim_make_timeRepeat\n"); fflush(stdout);
436
+ /* Allocates the time repeat. */
437
+ TimeRepeat timeRepeat = (TimeRepeat)malloc(sizeof(TimeRepeatS));
438
+ // printf("timeRepeat=%p\n",timeRepeat); fflush(stdout);
439
+ /* Set it up. */
440
+ timeRepeat->kind = TIME_REPEAT;
441
+ /* Get and set the number of repeatition. */
442
+ long long number;
443
+ number = NUM2LL(numberV);
444
+ // printf("number=%lld\n",number); fflush(stdout);
445
+ timeRepeat->number = number;
446
+ /* Get and set the statement. */
447
+ value_to_rcsim(StatementS,statementV,timeRepeat->statement);
448
+ /* Returns the C time wait embedded into a ruby VALUE. */
449
+ VALUE res;
450
+ rcsim_to_value(TimeRepeatS,timeRepeat,res);
451
+ return res;
452
+ }
453
+
382
454
 
383
455
  /* Creating a time terminate C object. */
384
456
  VALUE rcsim_make_timeTerminate(VALUE mod) {
457
+ // printf("rcsim_make_timeTerminate\n");
385
458
  /* Allocates the time terminate. */
386
459
  TimeTerminate timeTerminate = (TimeTerminate)malloc(sizeof(TimeTerminateS));
460
+ // printf("timeTerminate=%p\n",timeTerminate);
387
461
  /* Set it up. */
388
462
  timeTerminate->kind = TIME_TERMINATE;
389
463
  /* Returns the C time terminate embedded into a ruby VALUE. */
@@ -394,17 +468,19 @@ VALUE rcsim_make_timeTerminate(VALUE mod) {
394
468
 
395
469
 
396
470
  /* Creating a hardware if C object. */
397
- VALUE rcsim_make_hif(VALUE mod, VALUE condition, VALUE yes, VALUE no) {
471
+ VALUE rcsim_make_hif(VALUE mod, VALUE conditionV, VALUE yesV, VALUE noV) {
472
+ // printf("rcsim_make_hif\n");
398
473
  /* Allocates the hardware if. */
399
474
  HIf hif = (HIf)malloc(sizeof(HIfS));
475
+ // printf("hif=%p\n",hif);
400
476
  /* Set it up. */
401
477
  hif->kind = HIF;
402
- value_to_rcsim(ExpressionS,condition,hif->condition);
403
- value_to_rcsim(StatementS,yes,hif->yes);
404
- if (TYPE(no) == T_NIL)
478
+ value_to_rcsim(ExpressionS,conditionV,hif->condition);
479
+ value_to_rcsim(StatementS,yesV,hif->yes);
480
+ if (TYPE(noV) == T_NIL)
405
481
  hif->no = NULL;
406
482
  else
407
- value_to_rcsim(StatementS,no,hif->no);
483
+ value_to_rcsim(StatementS,noV,hif->no);
408
484
  hif->num_noifs = 0;
409
485
  hif->noconds = NULL;
410
486
  hif->nostmnts = NULL;
@@ -416,19 +492,21 @@ VALUE rcsim_make_hif(VALUE mod, VALUE condition, VALUE yes, VALUE no) {
416
492
 
417
493
 
418
494
  /* Creating a hardware case C object. */
419
- VALUE rcsim_make_hcase(VALUE mod, VALUE value, VALUE defolt) {
495
+ VALUE rcsim_make_hcase(VALUE mod, VALUE valueV, VALUE defoltV) {
496
+ // printf("rcsim_make_hcase\n");
420
497
  /* Allocates the hardware case. */
421
498
  HCase hcase = (HCase)malloc(sizeof(HCaseS));
499
+ // printf("hcase=%p\n",hcase);
422
500
  /* Set it up. */
423
501
  hcase->kind = HCASE;
424
- value_to_rcsim(ExpressionS,value,hcase->value);
502
+ value_to_rcsim(ExpressionS,valueV,hcase->value);
425
503
  hcase->num_whens = 0;
426
504
  hcase->matches = NULL;
427
505
  hcase->stmnts = NULL;
428
- if (TYPE(defolt) == T_NIL)
506
+ if (TYPE(defoltV) == T_NIL)
429
507
  hcase->defolt = NULL;
430
508
  else
431
- value_to_rcsim(StatementS,defolt,hcase->defolt);
509
+ value_to_rcsim(StatementS,defoltV,hcase->defolt);
432
510
  /* Returns the C hardware case embedded into a ruby VALUE. */
433
511
  VALUE res;
434
512
  rcsim_to_value(HCaseS,hcase,res);
@@ -437,9 +515,11 @@ VALUE rcsim_make_hcase(VALUE mod, VALUE value, VALUE defolt) {
437
515
 
438
516
 
439
517
  /* Creating a block C object. */
440
- VALUE rcsim_make_block(VALUE mod, VALUE mode) {
518
+ VALUE rcsim_make_block(VALUE mod, VALUE modeV) {
519
+ // printf("rcsim_make_block\n");
441
520
  /* Allocates the block. */
442
521
  Block block = (Block)malloc(sizeof(BlockS));
522
+ // printf("block=%p\n",block);
443
523
  /* Set it up. */
444
524
  block->kind = BLOCK;
445
525
  block->owner = NULL;
@@ -448,7 +528,7 @@ VALUE rcsim_make_block(VALUE mod, VALUE mode) {
448
528
  block->inners = NULL;
449
529
  block->num_stmnts = 0;
450
530
  block->stmnts = NULL;
451
- block->mode = SYM2ID(mode) == id_PAR ? PAR : SEQ;
531
+ block->mode = SYM2ID(modeV) == id_PAR ? PAR : SEQ;
452
532
  /* Returns the C block embedded into a ruby VALUE. */
453
533
  VALUE res;
454
534
  rcsim_to_value(BlockS,block,res);
@@ -458,15 +538,13 @@ VALUE rcsim_make_block(VALUE mod, VALUE mode) {
458
538
 
459
539
  /* Creating a numeric value C object. */
460
540
  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);
541
+ // printf("rcsim_make_value_numeric\n");
465
542
  /* Get the type. */
466
543
  Type type;
467
544
  value_to_rcsim(TypeS,typeV,type);
468
545
  /* Create the value. */
469
546
  Value value = make_value(type,0);
547
+ // printf("value=%p\n",value);
470
548
  /* Set it to numeric. */
471
549
  value->numeric = 1;
472
550
  value->capacity = 0;
@@ -481,15 +559,13 @@ VALUE rcsim_make_value_numeric(VALUE mod, VALUE typeV, VALUE contentV) {
481
559
 
482
560
  /* Creating a bitstring value C object. */
483
561
  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);
562
+ // printf("rcsim_make_value_bitstring\n");
488
563
  /* Get the type. */
489
564
  Type type;
490
565
  value_to_rcsim(TypeS,typeV,type);
491
566
  /* Create the value. */
492
567
  Value value = make_value(type,0);
568
+ // printf("value=%p\n",value);
493
569
  // printf("Created from bitstring value=%p with type=%p\n",value,value->type);
494
570
  // printf("and width=%llu\n",type_width(value->type));
495
571
  /* Set it to bitstring. */
@@ -497,7 +573,8 @@ VALUE rcsim_make_value_bitstring(VALUE mod, VALUE typeV, VALUE contentV) {
497
573
  /* Generate the string of the content. */
498
574
  char* str = StringValueCStr(contentV);
499
575
  value->capacity = strlen(str)+1;
500
- value->data_str = calloc(sizeof(char),value->capacity);
576
+ value->data_str = calloc(value->capacity,sizeof(char));
577
+ // printf("value->data_str=%p\n",value->data_str);
501
578
  strcpy(value->data_str,str);
502
579
  /* Returns the C value embedded into a ruby VALUE. */
503
580
  VALUE res;
@@ -508,8 +585,10 @@ VALUE rcsim_make_value_bitstring(VALUE mod, VALUE typeV, VALUE contentV) {
508
585
 
509
586
  /* Creating a cast C object. */
510
587
  VALUE rcsim_make_cast(VALUE mod, VALUE type, VALUE child) {
588
+ // printf("rcsim_make_cast\n");
511
589
  /* Allocates the cast. */
512
590
  Cast cast = (Cast)malloc(sizeof(CastS));
591
+ // printf("cast=%p\n",cast);
513
592
  /* Set it up. */
514
593
  cast->kind = CAST;
515
594
  value_to_rcsim(TypeS,type,cast->type);
@@ -522,8 +601,10 @@ VALUE rcsim_make_cast(VALUE mod, VALUE type, VALUE child) {
522
601
 
523
602
  /* Creating a unary value C object. */
524
603
  VALUE rcsim_make_unary(VALUE mod, VALUE type, VALUE operator, VALUE child) {
604
+ // printf("rcsim_make_unary\n");
525
605
  /* Allocates the unary. */
526
606
  Unary unary= (Unary)malloc(sizeof(UnaryS));
607
+ // printf("unary=%p\n",unary);
527
608
  /* Set it up. */
528
609
  unary->kind = UNARY;
529
610
  value_to_rcsim(TypeS,type,unary->type);
@@ -541,8 +622,10 @@ VALUE rcsim_make_unary(VALUE mod, VALUE type, VALUE operator, VALUE child) {
541
622
 
542
623
  /* Creating a binary value C object. */
543
624
  VALUE rcsim_make_binary(VALUE mod, VALUE type, VALUE operator, VALUE left, VALUE right) {
625
+ // printf("rcsim_make_binary\n");
544
626
  /* Allocates the binary. */
545
627
  Binary binary = (Binary)malloc(sizeof(BinaryS));
628
+ // printf("binary=%p\n",binary);
546
629
  /* Set it up. */
547
630
  binary->kind = BINARY;
548
631
  value_to_rcsim(TypeS,type,binary->type);
@@ -575,8 +658,10 @@ VALUE rcsim_make_binary(VALUE mod, VALUE type, VALUE operator, VALUE left, VALUE
575
658
 
576
659
  /* Creating a select C object. */
577
660
  VALUE rcsim_make_select(VALUE mod, VALUE type, VALUE sel) {
661
+ // printf("rcsim_make_select\n");
578
662
  /* Allocates the select. */
579
663
  Select select = (Select)malloc(sizeof(SelectS));
664
+ // printf("select=%p\n",select);
580
665
  /* Set it up. */
581
666
  select->kind = SELECT;
582
667
  value_to_rcsim(TypeS,type,select->type);
@@ -591,8 +676,10 @@ VALUE rcsim_make_select(VALUE mod, VALUE type, VALUE sel) {
591
676
 
592
677
  /* Creating a concat C object. */
593
678
  VALUE rcsim_make_concat(VALUE mod, VALUE type, VALUE dirV) {
679
+ // printf("rcsim_make_concat\n");
594
680
  /* Allocates the concat. */
595
681
  Concat concat = (Concat)malloc(sizeof(ConcatS));
682
+ // printf("concat=%p\n",concat);
596
683
  /* Set it up. */
597
684
  concat->kind = CONCAT;
598
685
  value_to_rcsim(TypeS,type,concat->type);
@@ -607,8 +694,10 @@ VALUE rcsim_make_concat(VALUE mod, VALUE type, VALUE dirV) {
607
694
 
608
695
  /* Creating a ref concat C object. */
609
696
  VALUE rcsim_make_refConcat(VALUE mod, VALUE type, VALUE dirV) {
697
+ // printf("rcsim_make_refConcat\n");
610
698
  /* Allocates the ref concat. */
611
699
  RefConcat refConcat = (RefConcat)malloc(sizeof(RefConcatS));
700
+ // printf("refConcat=%p\n",refConcat);
612
701
  /* Set it up. */
613
702
  refConcat->kind = REF_CONCAT;
614
703
  value_to_rcsim(TypeS,type,refConcat->type);
@@ -623,8 +712,10 @@ VALUE rcsim_make_refConcat(VALUE mod, VALUE type, VALUE dirV) {
623
712
 
624
713
  /* Creating a ref index C object. */
625
714
  VALUE rcsim_make_refIndex(VALUE mod, VALUE type, VALUE index, VALUE ref) {
715
+ // printf("rcsim_make_refIndex\n");
626
716
  /* Allocates the ref index. */
627
717
  RefIndex refIndex = (RefIndex)malloc(sizeof(RefIndexS));
718
+ // printf("refIndex=%p\n",refIndex);
628
719
  /* Set it up. */
629
720
  refIndex->kind = REF_INDEX;
630
721
  value_to_rcsim(TypeS,type,refIndex->type);
@@ -638,8 +729,10 @@ VALUE rcsim_make_refIndex(VALUE mod, VALUE type, VALUE index, VALUE ref) {
638
729
 
639
730
  /* Creating a ref range C object. */
640
731
  VALUE rcsim_make_refRange(VALUE mod, VALUE type, VALUE first, VALUE last, VALUE ref) {
732
+ // printf("rcsim_make_refRange\n");
641
733
  /* Allocates the ref range. */
642
734
  RefRangeE refRange = (RefRangeE)malloc(sizeof(RefRangeES));
735
+ // printf("refRange=%p\n",refRange);
643
736
  /* Set it up. */
644
737
  refRange->kind = REF_RANGE;
645
738
  value_to_rcsim(TypeS,type,refRange->type);
@@ -655,8 +748,10 @@ VALUE rcsim_make_refRange(VALUE mod, VALUE type, VALUE first, VALUE last, VALUE
655
748
 
656
749
  /* Creating a character string C object. */
657
750
  VALUE rcsim_make_stringE(VALUE mod, VALUE strV) {
751
+ // printf("rcsim_make_stringE\n");
658
752
  /* Allocates the string. */
659
753
  StringE stringE = (StringE)malloc(sizeof(StringES));
754
+ // printf("stringE=%p\n",stringE);
660
755
  /* Set it up. */
661
756
  stringE->kind = STRINGE;
662
757
  stringE->str = strdup(StringValueCStr(strV));
@@ -673,19 +768,24 @@ VALUE rcsim_add_systemT_inputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
673
768
  /* Get the C systemT from the Ruby value. */
674
769
  SystemT systemT;
675
770
  value_to_rcsim(SystemTS,systemTV,systemT);
771
+ // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
676
772
  // printf("Adding to systemT with kind=%d and name=%s\n",systemT->kind, systemT->name);
677
773
  /* Prepare the size for the inputs. */
678
774
  long num = RARRAY_LEN(sigVs);
679
775
  long old_num = systemT->num_inputs;
680
776
  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);
777
+ // printf("first systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
778
+ // systemT->inputs=realloc(systemT->inputs,
779
+ // sizeof(SignalI[systemT->num_inputs]));
780
+ systemT->inputs=my_realloc(systemT->inputs,sizeof(SignalI[old_num]),
781
+ sizeof(SignalI[systemT->num_inputs]));
782
+ // printf("now systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
783
+ // printf("access test: %p\n",systemT->inputs[0]); fflush(stdout);
684
784
  /* Get and add the signals from the Ruby value. */
685
- for(int i=0; i< num; ++i) {
785
+ for(long i=0; i< num; ++i) {
686
786
  SignalI sig;
787
+ // show_access(systemT->inputs,old_num+i);
687
788
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
688
- // printf("old_num+i=%ld\n",old_num+i);
689
789
  systemT->inputs[old_num + i] = sig;
690
790
  }
691
791
  return systemTV;
@@ -696,14 +796,22 @@ VALUE rcsim_add_systemT_outputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
696
796
  /* Get the C systemT from the Ruby value. */
697
797
  SystemT systemT;
698
798
  value_to_rcsim(SystemTS,systemTV,systemT);
799
+ // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
699
800
  /* Prepare the size for the outputs. */
700
801
  long num = RARRAY_LEN(sigVs);
701
802
  long old_num = systemT->num_outputs;
702
803
  systemT->num_outputs += num;
703
- systemT->outputs =realloc(systemT->outputs,sizeof(SignalI)*systemT->num_outputs);
804
+ // printf("first systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
805
+ // systemT->outputs =realloc(systemT->outputs,
806
+ // sizeof(SignalI[systemT->num_outputs]));
807
+ systemT->outputs =my_realloc(systemT->outputs,sizeof(SignalI[old_num]),
808
+ sizeof(SignalI[systemT->num_outputs]));
809
+ // printf("now systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
810
+ // printf("access test: %p\n",systemT->outputs[0]); fflush(stdout);
704
811
  /* Get and add the signals from the Ruby value. */
705
- for(int i=0; i< num; ++i) {
812
+ for(long i=0; i< num; ++i) {
706
813
  SignalI sig;
814
+ // show_access(systemT->outputs,old_num+i);
707
815
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
708
816
  systemT->outputs[old_num + i] = sig;
709
817
  }
@@ -715,14 +823,22 @@ VALUE rcsim_add_systemT_inouts(VALUE mod, VALUE systemTV, VALUE sigVs) {
715
823
  /* Get the C systemT from the Ruby value. */
716
824
  SystemT systemT;
717
825
  value_to_rcsim(SystemTS,systemTV,systemT);
826
+ // printf("rcsim_add_systemT_inputs with systemT=%p\n",systemT);
718
827
  /* Prepare the size for the inouts. */
719
828
  long num = RARRAY_LEN(sigVs);
720
829
  long old_num = systemT->num_inouts;
721
830
  systemT->num_inouts += num;
722
- systemT->inouts =realloc(systemT->inouts,sizeof(SignalI)*systemT->num_inouts);
831
+ // printf("first systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
832
+ // systemT->inouts =realloc(systemT->inouts,
833
+ // sizeof(SignalI[systemT->num_inouts]));
834
+ systemT->inouts =my_realloc(systemT->inouts,sizeof(SignalI[old_num]),
835
+ sizeof(SignalI[systemT->num_inouts]));
836
+ // printf("now systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
837
+ // printf("access test: %p\n",systemT->inouts[0]); fflush(stdout);
723
838
  /* Get and add the signals from the Ruby value. */
724
- for(int i=0; i< num; ++i) {
839
+ for(long i=0; i< num; ++i) {
725
840
  SignalI sig;
841
+ // show_access(systemT->inouts,old_num+i);
726
842
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
727
843
  systemT->inouts[old_num + i] = sig;
728
844
  }
@@ -734,14 +850,22 @@ VALUE rcsim_add_scope_inners(VALUE mod, VALUE scopeV, VALUE sigVs) {
734
850
  /* Get the C scope from the Ruby value. */
735
851
  Scope scope;
736
852
  value_to_rcsim(ScopeS,scopeV,scope);
853
+ // printf("rcsim_add_scope_inners with scope=%p\n",scope);
737
854
  /* Prepare the size for the inners. */
738
855
  long num = RARRAY_LEN(sigVs);
739
856
  long old_num = scope->num_inners;
740
857
  scope->num_inners += num;
741
- scope->inners = realloc(scope->inners,sizeof(SignalI)*scope->num_inners);
858
+ // printf("first scope->inners=%p\n",scope->inners); fflush(stdout);
859
+ // scope->inners = realloc(scope->inners,
860
+ // sizeof(SignalI[scope->num_inners]));
861
+ scope->inners = my_realloc(scope->inners,sizeof(SignalI[old_num]),
862
+ sizeof(SignalI[scope->num_inners]));
863
+ // printf("now scope->inners=%p\n",scope->inners); fflush(stdout);
864
+ // printf("access test: %p\n",scope->inners[0]); fflush(stdout);
742
865
  /* Get and add the signals from the Ruby value. */
743
- for(int i=0; i< num; ++i) {
866
+ for(long i=0; i< num; ++i) {
744
867
  SignalI sig;
868
+ // show_access(scope->inners,old_num+i);
745
869
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
746
870
  scope->inners[old_num + i] = sig;
747
871
  }
@@ -750,18 +874,28 @@ VALUE rcsim_add_scope_inners(VALUE mod, VALUE scopeV, VALUE sigVs) {
750
874
 
751
875
  /* Adds behaviors to a C scope. */
752
876
  VALUE rcsim_add_scope_behaviors(VALUE mod, VALUE scopeV, VALUE behVs) {
877
+ // printf("rcsim_add_scope_behaviors\n");
753
878
  /* Get the C scope from the Ruby value. */
754
879
  Scope scope;
755
880
  value_to_rcsim(ScopeS,scopeV,scope);
881
+ // printf("rcsim_add_scope_behaviors with scope=%p\n",scope);
756
882
  /* Prepare the size for the behaviors. */
757
883
  long num = RARRAY_LEN(behVs);
758
884
  long old_num = scope->num_behaviors;
885
+ // printf("num=%lu old_num=%lu\n",num,old_num);
886
+ // printf("scope->behaviors=%p\n",scope->behaviors);
759
887
  scope->num_behaviors += num;
760
- scope->behaviors = realloc(scope->behaviors,
761
- sizeof(Behavior)*scope->num_behaviors);
888
+ // printf("first scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
889
+ // scope->behaviors = realloc(scope->behaviors,
890
+ // sizeof(Behavior[scope->num_behaviors]));
891
+ scope->behaviors = my_realloc(scope->behaviors,sizeof(Behavior[old_num]),
892
+ sizeof(Behavior[scope->num_behaviors]));
893
+ // printf("now scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
894
+ // printf("access test: %p\n",scope->behaviors[0]); fflush(stdout);
762
895
  /* Get and add the behaviors from the Ruby value. */
763
- for(int i=0; i< num; ++i) {
896
+ for(long i=0; i< num; ++i) {
764
897
  Behavior beh;
898
+ // show_access(scope->behaviors,old_num+i);
765
899
  value_to_rcsim(BehaviorS,rb_ary_entry(behVs,i),beh);
766
900
  scope->behaviors[old_num + i] = beh;
767
901
  }
@@ -773,15 +907,22 @@ VALUE rcsim_add_scope_systemIs(VALUE mod, VALUE scopeV, VALUE sysVs) {
773
907
  /* Get the C scope from the Ruby value. */
774
908
  Scope scope;
775
909
  value_to_rcsim(ScopeS,scopeV,scope);
910
+ // printf("rcsim_add_scope_systemIs with scope=%p\n",scope);
776
911
  /* Prepare the size for the system instances. */
777
912
  long num = RARRAY_LEN(sysVs);
778
913
  long old_num = scope->num_systemIs;
779
914
  scope->num_systemIs += num;
780
- scope->systemIs = realloc(scope->systemIs,
781
- sizeof(SystemI)*scope->num_systemIs);
915
+ // printf("first scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
916
+ // scope->systemIs = realloc(scope->systemIs,
917
+ // sizeof(SystemI[scope->num_systemIs]));
918
+ scope->systemIs = my_realloc(scope->systemIs,sizeof(SystemI[old_num]),
919
+ sizeof(SystemI[scope->num_systemIs]));
920
+ // printf("now scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
921
+ // printf("access test: %p\n",scope->systemIs[0]); fflush(stdout);
782
922
  /* Get and add the system instances from the Ruby value. */
783
- for(int i=0; i< num; ++i) {
923
+ for(long i=0; i< num; ++i) {
784
924
  SystemI sys;
925
+ // show_access(scope->systemIs,old_num+i);
785
926
  value_to_rcsim(SystemIS,rb_ary_entry(sysVs,i),sys);
786
927
  scope->systemIs[old_num + i] = sys;
787
928
  }
@@ -793,15 +934,22 @@ VALUE rcsim_add_scope_scopes(VALUE mod, VALUE scopeV, VALUE scpVs) {
793
934
  /* Get the C scope from the Ruby value. */
794
935
  Scope scope;
795
936
  value_to_rcsim(ScopeS,scopeV,scope);
937
+ // printf("rcsim_add_scope_scopes with scope=%p\n",scope);
796
938
  /* Prepare the size for the sub scopes. */
797
939
  long num = RARRAY_LEN(scpVs);
798
940
  long old_num = scope->num_scopes;
799
941
  scope->num_scopes += num;
800
- scope->scopes = realloc(scope->scopes,
801
- sizeof(Scope)*scope->num_scopes);
942
+ // printf("first scope->scopes=%p\n",scope->scopes); fflush(stdout);
943
+ // scope->scopes = realloc(scope->scopes,
944
+ // sizeof(Scope[scope->num_scopes]));
945
+ scope->scopes = my_realloc(scope->scopes,sizeof(Scope[old_num]),
946
+ sizeof(Scope[scope->num_scopes]));
947
+ // printf("now scope->scopes=%p\n",scope->scopes); fflush(stdout);
948
+ // printf("access test: %p\n",scope->scopes[0]); fflush(stdout);
802
949
  /* Get and add the sub scopes from the Ruby value. */
803
- for(int i=0; i< num; ++i) {
950
+ for(long i=0; i< num; ++i) {
804
951
  Scope scp;
952
+ // show_access(scope->scopes,old_num+i);
805
953
  value_to_rcsim(ScopeS,rb_ary_entry(scpVs,i),scp);
806
954
  scope->scopes[old_num + i] = scp;
807
955
  }
@@ -813,15 +961,22 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
813
961
  /* Get the C behavior from the Ruby value. */
814
962
  Behavior behavior;
815
963
  value_to_rcsim(BehaviorS,behaviorV,behavior);
964
+ // printf("rcsim_add_behavior_events with behavior=%p\n",behavior);
816
965
  /* Prepare the size for the events. */
817
966
  long num = RARRAY_LEN(eventVs);
818
967
  long old_num = behavior->num_events;
819
968
  behavior->num_events += num;
820
- behavior->events = realloc(behavior->events,
821
- sizeof(Event)*behavior->num_events);
969
+ // printf("first behavior->events=%p\n",behavior->events); fflush(stdout);
970
+ // behavior->events = realloc(behavior->events,
971
+ // sizeof(Event[behavior->num_events]));
972
+ behavior->events = my_realloc(behavior->events,sizeof(Event[old_num]),
973
+ sizeof(Event[behavior->num_events]));
974
+ // printf("now behavior->events=%p\n",behavior->events); fflush(stdout);
975
+ // printf("access test: %p\n",behavior->events[0]); fflush(stdout);
822
976
  /* Get and add the events from the Ruby value. */
823
- for(int i=0; i< num; ++i) {
977
+ for(long i=0; i< num; ++i) {
824
978
  Event event;
979
+ // show_access(behavior->events,old_num+i);
825
980
  value_to_rcsim(EventS,rb_ary_entry(eventVs,i),event);
826
981
  behavior->events[old_num + i] = event;
827
982
  /* Update the signal of the event to say it activates the behavior. */
@@ -829,17 +984,35 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
829
984
  switch(event->edge) {
830
985
  case ANYEDGE:
831
986
  sig->num_any++;
832
- sig->any = realloc(sig->any,sizeof(Object)*sig->num_any);
987
+ // printf("first sig->any=%p\n",sig->any); fflush(stdout);
988
+ // sig->any = realloc(sig->any,sizeof(Object[sig->num_any]));
989
+ sig->any = my_realloc(sig->any,sizeof(Object[sig->num_any-1]),sizeof(Object[sig->num_any]));
990
+ // printf("now sig->any=%p\n",sig->any); fflush(stdout);
991
+ // printf("access test: %p\n",sig->any[0]); fflush(stdout);
992
+ // show_access(sig->any,sig->num_any-1);
993
+ // printf("sig->any=%p\n",sig->any);
833
994
  sig->any[sig->num_any-1] = (Object)behavior;
834
995
  break;
835
996
  case POSEDGE:
836
997
  sig->num_pos++;
837
- sig->pos = realloc(sig->pos,sizeof(Object)*sig->num_pos);
998
+ // printf("first sig->pos=%p\n",sig->pos); fflush(stdout);
999
+ // sig->pos = realloc(sig->pos,sizeof(Object[sig->num_pos]));
1000
+ sig->pos = my_realloc(sig->pos,sizeof(Object[sig->num_pos-1]),sizeof(Object[sig->num_pos]));
1001
+ // printf("now sig->pos=%p\n",sig->pos); fflush(stdout);
1002
+ // printf("access test: %p\n",sig->pos[0]); fflush(stdout);
1003
+ // show_access(sig->pos,sig->num_pos-1);
1004
+ // printf("sig->pos=%p\n",sig->pos);
838
1005
  sig->pos[sig->num_pos-1] = (Object)behavior;
839
1006
  break;
840
1007
  case NEGEDGE:
841
1008
  sig->num_neg++;
842
- sig->neg = realloc(sig->neg,sizeof(Object)*sig->num_neg);
1009
+ // printf("first sig->neg=%p\n",sig->neg); fflush(stdout);
1010
+ // sig->neg = realloc(sig->neg,sizeof(Object[sig->num_neg]));
1011
+ sig->neg = my_realloc(sig->neg,sizeof(Object[sig->num_neg-1]),sizeof(Object[sig->num_neg]));
1012
+ // printf("now sig->neg=%p\n",sig->neg); fflush(stdout);
1013
+ // printf("access test: %p\n",sig->neg[0]); fflush(stdout);
1014
+ // show_access(sig->neg,sig->num_neg-1);
1015
+ // printf("sig->neg=%p\n",sig->neg);
843
1016
  sig->neg[sig->num_neg-1] = (Object)behavior;
844
1017
  break;
845
1018
  default:
@@ -854,14 +1027,22 @@ VALUE rcsim_add_systemI_systemTs(VALUE mod, VALUE systemIV, VALUE sysVs) {
854
1027
  /* Get the C systemI from the Ruby value. */
855
1028
  SystemI systemI;
856
1029
  value_to_rcsim(SystemIS,systemIV,systemI);
1030
+ // printf("rcsim_add_systemI_systemTs with systemI=%p\n",systemI);
857
1031
  /* Prepare the size for the alternate system types. */
858
1032
  long num = RARRAY_LEN(sysVs);
859
1033
  long old_num = systemI->num_systems;
860
1034
  systemI->num_systems += num;
861
- systemI->systems=realloc(systemI->systems,sizeof(SystemT)*systemI->num_systems);
1035
+ // printf("first systemI->systems=%p\n",systemI->systems); fflush(stdout);
1036
+ // systemI->systems=realloc(systemI->systems,
1037
+ // sizeof(SystemT[systemI->num_systems]));
1038
+ systemI->systems=my_realloc(systemI->systems,sizeof(SystemT[old_num]),
1039
+ sizeof(SystemT[systemI->num_systems]));
1040
+ // printf("now systemI->systems=%p\n",systemI->systems); fflush(stdout);
1041
+ // printf("access test: %p\n",systemI->systems[0]); fflush(stdout);
862
1042
  /* Get and add the alternate system types from the Ruby value. */
863
- for(int i=0; i< num; ++i) {
1043
+ for(long i=0; i< num; ++i) {
864
1044
  SystemT sys;
1045
+ // show_access(systemI->systems,old_num+i);
865
1046
  value_to_rcsim(SystemTS,rb_ary_entry(sysVs,i),sys);
866
1047
  systemI->systems[old_num + i] = sys;
867
1048
  }
@@ -873,15 +1054,22 @@ VALUE rcsim_add_print_args(VALUE mod, VALUE printV, VALUE argVs) {
873
1054
  /* Get the C print from the Ruby value. */
874
1055
  Print print;
875
1056
  value_to_rcsim(PrintS,printV,print);
1057
+ // printf("rcsim_add_print_args with print=%p\n",print);
876
1058
  /* Prepare the size for the arguments. */
877
1059
  long num = RARRAY_LEN(argVs);
878
1060
  long old_num = print->num_args;
879
1061
  print->num_args += num;
880
- print->args = realloc(print->args,
881
- sizeof(Expression)*print->num_args);
1062
+ // printf("first print->args=%p\n",print->args); fflush(stdout);
1063
+ // print->args = realloc(print->args,
1064
+ // sizeof(Expression[print->num_args]));
1065
+ print->args = my_realloc(print->args,sizeof(Expression[old_num]),
1066
+ sizeof(Expression[print->num_args]));
1067
+ // printf("now print->args=%p\n",print->args); fflush(stdout);
1068
+ // printf("access test: %p\n",print->args[0]); fflush(stdout);
882
1069
  /* Get and add the arguments from the Ruby value. */
883
- for(int i=0; i< num; ++i) {
1070
+ for(long i=0; i< num; ++i) {
884
1071
  Expression arg;
1072
+ // show_access(print->args,old_num+i);
885
1073
  value_to_rcsim(ExpressionS,rb_ary_entry(argVs,i),arg);
886
1074
  print->args[old_num + i] = arg;
887
1075
  }
@@ -893,16 +1081,27 @@ VALUE rcsim_add_hif_noifs(VALUE mod, VALUE hifV, VALUE condVs, VALUE stmntVs) {
893
1081
  /* Get the C hardware if from the Ruby value. */
894
1082
  HIf hif;
895
1083
  value_to_rcsim(HIfS,hifV,hif);
1084
+ // printf("rcsim_add_hif_noifs with hif=%p\n",hif);
896
1085
  /* Prepare the size for the noifs. */
897
1086
  long num = RARRAY_LEN(condVs);
898
1087
  long old_num = hif->num_noifs;
899
1088
  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);
1089
+ // printf("first hif->noconds=%p\n",hif->noconds); fflush(stdout);
1090
+ // printf("first hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
1091
+ // hif->noconds = realloc(hif->noconds,sizeof(Expression[hif->num_noifs]));
1092
+ hif->noconds = my_realloc(hif->noconds,sizeof(Expression[old_num]),sizeof(Expression[hif->num_noifs]));
1093
+ // printf("now hif->noconds=%p\n",hif->noconds); fflush(stdout);
1094
+ // printf("access test: %p\n",hif->noconds[0]); fflush(stdout);
1095
+ // hif->nostmnts = realloc(hif->nostmnts,sizeof(Statement[hif->num_noifs]));
1096
+ hif->nostmnts = my_realloc(hif->nostmnts,sizeof(Statement[old_num]),sizeof(Statement[hif->num_noifs]));
1097
+ // printf("now hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
1098
+ // printf("access test: %p\n",hif->nostmnts[0]); fflush(stdout);
902
1099
  /* Get and add the noifs from the Ruby value. */
903
- for(int i=0; i< num; ++i) {
1100
+ for(long i=0; i< num; ++i) {
904
1101
  Expression cond;
905
1102
  Statement stmnt;
1103
+ // show_access(hif->noconds,old_num+i);
1104
+ // show_access(hif->nostmnts,old_num+i);
906
1105
  value_to_rcsim(ExpressionS,rb_ary_entry(condVs,i),cond);
907
1106
  hif->noconds[old_num + i] = cond;
908
1107
  value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
@@ -916,18 +1115,31 @@ VALUE rcsim_add_hcase_whens(VALUE mod, VALUE hcaseV, VALUE matchVs, VALUE stmntV
916
1115
  /* Get the C hardware case from the Ruby value. */
917
1116
  HCase hcase;
918
1117
  value_to_rcsim(HCaseS,hcaseV,hcase);
1118
+ // printf("rcsim_add_hcase_whens with hcase=%p\n",hcase);
919
1119
  /* Prepare the size for the noifs. */
920
1120
  long num = RARRAY_LEN(matchVs);
921
1121
  long old_num = hcase->num_whens;
922
1122
  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);
1123
+ // printf("first hcase->matches=%p\n",hcase->matches); fflush(stdout);
1124
+ // printf("first hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
1125
+ // hcase->matches = realloc(hcase->matches,
1126
+ // sizeof(Expression[hcase->num_whens]));
1127
+ hcase->matches = my_realloc(hcase->matches,sizeof(Expression[old_num]),
1128
+ sizeof(Expression[hcase->num_whens]));
1129
+ // printf("now hcase->matches=%p\n",hcase->matches); fflush(stdout);
1130
+ // printf("access test: %p\n",hcase->matches[0]); fflush(stdout);
1131
+ // hcase->stmnts = realloc(hcase->stmnts,
1132
+ // sizeof(Statement[hcase->num_whens]));
1133
+ hcase->stmnts = my_realloc(hcase->stmnts,sizeof(Statement[old_num]),
1134
+ sizeof(Statement[hcase->num_whens]));
1135
+ // printf("now hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
1136
+ // printf("access test: %p\n",hcase->stmnts[0]); fflush(stdout);
927
1137
  /* Get and add the whens from the Ruby value. */
928
- for(int i=0; i< num; ++i) {
1138
+ for(long i=0; i< num; ++i) {
929
1139
  Expression match;
930
1140
  Statement stmnt;
1141
+ // show_access(hcase->matches,old_num+i);
1142
+ // show_access(hcase->stmnts,old_num+i);
931
1143
  value_to_rcsim(ExpressionS,rb_ary_entry(matchVs,i),match);
932
1144
  hcase->matches[old_num + i] = match;
933
1145
  value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
@@ -941,14 +1153,22 @@ VALUE rcsim_add_block_inners(VALUE mod, VALUE blockV, VALUE sigVs) {
941
1153
  /* Get the C block from the Ruby value. */
942
1154
  Block block;
943
1155
  value_to_rcsim(BlockS,blockV,block);
1156
+ // printf("rcsim_add_block_inners with block=%p\n",block);
944
1157
  /* Prepare the size for the inners. */
945
1158
  long num = RARRAY_LEN(sigVs);
946
1159
  long old_num = block->num_inners;
947
1160
  block->num_inners += num;
948
- block->inners = realloc(block->inners,sizeof(SignalI)*block->num_inners);
1161
+ // printf("first block->inners=%p\n",block->inners); fflush(stdout);
1162
+ // block->inners = realloc(block->inners,
1163
+ // sizeof(SignalI[block->num_inners]));
1164
+ block->inners = my_realloc(block->inners,sizeof(SignalI[old_num]),
1165
+ sizeof(SignalI[block->num_inners]));
1166
+ // printf("now block->inners=%p\n",block->inners); fflush(stdout);
1167
+ // printf("access test: %p\n",block->inners[0]); fflush(stdout);
949
1168
  /* Get and add the signals from the Ruby value. */
950
- for(int i=0; i< num; ++i) {
1169
+ for(long i=0; i< num; ++i) {
951
1170
  SignalI sig;
1171
+ // show_access(block->inners,old_num+i);
952
1172
  value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
953
1173
  block->inners[old_num + i] = sig;
954
1174
  }
@@ -960,14 +1180,22 @@ VALUE rcsim_add_block_statements(VALUE mod, VALUE blockV, VALUE stmntVs) {
960
1180
  /* Get the C block from the Ruby value. */
961
1181
  Block block;
962
1182
  value_to_rcsim(BlockS,blockV,block);
1183
+ // printf("rcsim_add_block_statements with block=%p\n",block);
963
1184
  /* Prepare the size for the statements. */
964
1185
  long num = RARRAY_LEN(stmntVs);
965
1186
  long old_num = block->num_stmnts;
966
1187
  block->num_stmnts += num;
967
- block->stmnts = realloc(block->stmnts,sizeof(Statement)*block->num_stmnts);
1188
+ // printf("first block->stmnts=%p\n",block->stmnts); fflush(stdout);
1189
+ // block->stmnts = realloc(block->stmnts,
1190
+ // sizeof(Statement[block->num_stmnts]));
1191
+ block->stmnts = my_realloc(block->stmnts,sizeof(Statement[old_num]),
1192
+ sizeof(Statement[block->num_stmnts]));
1193
+ // printf("now block->stmnts=%p\n",block->stmnts); fflush(stdout);
1194
+ // printf("access test: %p\n",block->stmnts[0]); fflush(stdout);
968
1195
  /* Get and add the statements from the Ruby value. */
969
- for(int i=0; i< num; ++i) {
1196
+ for(long i=0; i< num; ++i) {
970
1197
  Statement stmnt;
1198
+ // show_access(block->stmnts,old_num+i);
971
1199
  value_to_rcsim(StatementS,rb_ary_entry(stmntVs,i),stmnt);
972
1200
  block->stmnts[old_num + i] = stmnt;
973
1201
  }
@@ -979,14 +1207,22 @@ VALUE rcsim_add_select_choices(VALUE mod, VALUE selectV, VALUE choiceVs) {
979
1207
  /* Get the C select from the Ruby value. */
980
1208
  Select select;
981
1209
  value_to_rcsim(SelectS,selectV,select);
1210
+ // printf("rcsim_add_select_choices with select=%p\n",select);
982
1211
  /* Prepare the size for the choices. */
983
1212
  long num = RARRAY_LEN(choiceVs);
984
1213
  long old_num = select->num_choices;
985
1214
  select->num_choices += num;
986
- select->choices = realloc(select->choices,sizeof(Expression)*select->num_choices);
1215
+ // printf("first select->choices=%p\n",select->choices); fflush(stdout);
1216
+ // select->choices = realloc(select->choices,
1217
+ // sizeof(Expression[select->num_choices]));
1218
+ select->choices = my_realloc(select->choices,sizeof(Expression[old_num]),
1219
+ sizeof(Expression[select->num_choices]));
1220
+ // printf("now select->choices=%p\n",select->choices); fflush(stdout);
1221
+ // printf("access test: %p\n",select->choices[0]); fflush(stdout);
987
1222
  /* Get and add the choices from the Ruby value. */
988
- for(int i=0; i< num; ++i) {
1223
+ for(long i=0; i< num; ++i) {
989
1224
  Expression choice;
1225
+ // show_access(select->choices,old_num+i);
990
1226
  value_to_rcsim(ExpressionS,rb_ary_entry(choiceVs,i),choice);
991
1227
  select->choices[old_num + i] = choice;
992
1228
  }
@@ -998,17 +1234,24 @@ VALUE rcsim_add_concat_expressions(VALUE mod, VALUE concatV, VALUE exprVs) {
998
1234
  /* Get the C concat from the Ruby value. */
999
1235
  Concat concat;
1000
1236
  value_to_rcsim(ConcatS,concatV,concat);
1237
+ // printf("rcsim_add_concat_expressions with concat=%p\n",concat);
1001
1238
  /* Prepare the size for the expressions. */
1002
1239
  long num = RARRAY_LEN(exprVs);
1003
1240
  long old_num = concat->num_exprs;
1004
1241
  // printf("add_concat_expressions with num=%li old_num=%li\n",num,old_num);
1005
1242
  concat->num_exprs += num;
1006
- concat->exprs = realloc(concat->exprs,sizeof(Expression)*concat->num_exprs);
1243
+ // printf("first concat->exprs=%p\n",concat->exprs); fflush(stdout);
1244
+ // concat->exprs = realloc(concat->exprs,
1245
+ // sizeof(Expression[concat->num_exprs]));
1246
+ concat->exprs = my_realloc(concat->exprs,sizeof(Expression[old_num]),
1247
+ sizeof(Expression[concat->num_exprs]));
1248
+ // printf("now concat->exprs=%p\n",concat->exprs); fflush(stdout);
1249
+ // printf("access test: %p\n",concat->exprs[0]); fflush(stdout);
1007
1250
  /* Get and add the expressions from the Ruby value. */
1008
- for(int i=0; i< num; ++i) {
1251
+ for(long i=0; i< num; ++i) {
1009
1252
  Expression expr;
1253
+ // show_access(concat->exprs,old_num+i);
1010
1254
  value_to_rcsim(ExpressionS,rb_ary_entry(exprVs,i),expr);
1011
- // printf("Adding expression with type width=%llu\n",type_width(expr->type));
1012
1255
  concat->exprs[old_num + i] = expr;
1013
1256
  }
1014
1257
  return concatV;
@@ -1019,14 +1262,22 @@ VALUE rcsim_add_refConcat_refs(VALUE mod, VALUE refConcatV, VALUE refVs) {
1019
1262
  /* Get the C refConcat from the Ruby value. */
1020
1263
  RefConcat refConcat;
1021
1264
  value_to_rcsim(RefConcatS,refConcatV,refConcat);
1265
+ // printf("rcsim_add_refConcat_refs with refConcat=%p\n",refConcat);
1022
1266
  /* Prepare the size for the references. */
1023
1267
  long num = RARRAY_LEN(refVs);
1024
1268
  long old_num = refConcat->num_refs;
1025
1269
  refConcat->num_refs += num;
1026
- refConcat->refs = realloc(refConcat->refs,sizeof(Reference)*refConcat->num_refs);
1270
+ // printf("first refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
1271
+ // refConcat->refs = realloc(refConcat->refs,
1272
+ // sizeof(Reference[refConcat->num_refs]));
1273
+ refConcat->refs = my_realloc(refConcat->refs,sizeof(Reference[old_num]),
1274
+ sizeof(Reference[refConcat->num_refs]));
1275
+ // printf("now refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
1276
+ // printf("access test: %p\n",refConcat->refs[0]); fflush(stdout);
1027
1277
  /* Get and add the references from the Ruby value. */
1028
- for(int i=0; i< num; ++i) {
1278
+ for(long i=0; i< num; ++i) {
1029
1279
  Reference ref;
1280
+ // show_access(refConcat->refs,old_num+i);
1030
1281
  value_to_rcsim(ReferenceS,rb_ary_entry(refVs,i),ref);
1031
1282
  refConcat->refs[old_num + i] = ref;
1032
1283
  }
@@ -1143,6 +1394,7 @@ void Init_hruby_sim() {
1143
1394
  rb_define_singleton_method(mod,"rcsim_make_transmit",rcsim_make_transmit,2);
1144
1395
  rb_define_singleton_method(mod,"rcsim_make_print",rcsim_make_print,0);
1145
1396
  rb_define_singleton_method(mod,"rcsim_make_timeWait",rcsim_make_timeWait,2);
1397
+ rb_define_singleton_method(mod,"rcsim_make_timeRepeat",rcsim_make_timeRepeat,2);
1146
1398
  rb_define_singleton_method(mod,"rcsim_make_timeTerminate",rcsim_make_timeTerminate,0);
1147
1399
  rb_define_singleton_method(mod,"rcsim_make_hif",rcsim_make_hif,3);
1148
1400
  rb_define_singleton_method(mod,"rcsim_make_hcase",rcsim_make_hcase,2);