HDLRuby 2.11.10 → 2.11.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -18
  3. data/ext/hruby_sim/hruby_rcsim_build.c +110 -83
  4. data/ext/hruby_sim/hruby_sim.h +3 -0
  5. data/ext/hruby_sim/hruby_sim_calc.c +14 -6
  6. data/ext/hruby_sim/hruby_sim_core.c +20 -7
  7. data/ext/hruby_sim/hruby_sim_list.c +1 -1
  8. data/ext/hruby_sim/hruby_sim_stack_calc.c +3 -2
  9. data/ext/hruby_sim/hruby_sim_tree_calc.c +8 -1
  10. data/ext/hruby_sim/hruby_sim_vcd.c +24 -7
  11. data/ext/hruby_sim/hruby_sim_vizualize.c +9 -1
  12. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +3 -1
  13. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +3 -1
  14. data/lib/HDLRuby/hdr_samples/huge_rom.rb +1 -1
  15. data/lib/HDLRuby/hdr_samples/mei8.rb +11 -11
  16. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +11 -11
  17. data/lib/HDLRuby/hdr_samples/neg_arith_bench.rb +4 -4
  18. data/lib/HDLRuby/hdr_samples/rom_nest.rb +1 -1
  19. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +4 -4
  20. data/lib/HDLRuby/hdr_samples/struct.rb +44 -10
  21. data/lib/HDLRuby/hdr_samples/with_bram.rb +45 -0
  22. data/lib/HDLRuby/hdr_samples/with_casts.rb +3 -3
  23. data/lib/HDLRuby/hdr_samples/with_concat.rb +6 -6
  24. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -2
  25. data/lib/HDLRuby/hdr_samples/with_def.rb +10 -3
  26. data/lib/HDLRuby/hdr_samples/with_define_operator.rb +44 -0
  27. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +12 -12
  28. data/lib/HDLRuby/hdr_samples/with_init.rb +3 -3
  29. data/lib/HDLRuby/hdr_samples/with_leftright.rb +21 -0
  30. data/lib/HDLRuby/hdr_samples/with_reduce.rb +13 -13
  31. data/lib/HDLRuby/hdr_samples/with_ref_array.rb +6 -6
  32. data/lib/HDLRuby/hdr_samples/with_subsums.rb +3 -3
  33. data/lib/HDLRuby/hdr_samples/with_terminate.rb +3 -3
  34. data/lib/HDLRuby/hdr_samples/with_to_a.rb +10 -10
  35. data/lib/HDLRuby/hdr_samples/with_values.rb +3 -3
  36. data/lib/HDLRuby/hdrcc.rb +14 -1
  37. data/lib/HDLRuby/hruby_bstr.rb +10 -5
  38. data/lib/HDLRuby/hruby_high.rb +114 -27
  39. data/lib/HDLRuby/hruby_low.rb +187 -16
  40. data/lib/HDLRuby/hruby_low2c.rb +71 -11
  41. data/lib/HDLRuby/hruby_low2vhd.rb +2 -1
  42. data/lib/HDLRuby/hruby_low_fix_types.rb +1 -0
  43. data/lib/HDLRuby/hruby_low_mutable.rb +30 -1
  44. data/lib/HDLRuby/hruby_low_resolve.rb +15 -2
  45. data/lib/HDLRuby/hruby_low_without_concat.rb +28 -8
  46. data/lib/HDLRuby/hruby_low_without_parinseq.rb +14 -4
  47. data/lib/HDLRuby/hruby_low_without_select.rb +2 -2
  48. data/lib/HDLRuby/hruby_low_without_subsignals.rb +279 -0
  49. data/lib/HDLRuby/hruby_rcsim.rb +99 -87
  50. data/lib/HDLRuby/hruby_rsim.rb +132 -7
  51. data/lib/HDLRuby/hruby_rsim_vcd.rb +99 -27
  52. data/lib/HDLRuby/hruby_values.rb +35 -31
  53. data/lib/HDLRuby/std/bram.rb +22 -0
  54. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  55. data/lib/HDLRuby/std/fsm.rb +20 -3
  56. data/lib/HDLRuby/std/function_generator.rb +2 -2
  57. data/lib/HDLRuby/version.rb +1 -1
  58. metadata +7 -3
  59. data/lib/HDLRuby/hdr_samples/sumprod.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1abbd8fa7d81751f96e4728d9de4feca367a2fd279f53ba819403de04ed32a7
4
- data.tar.gz: b820d83dffce7d785de1ec0ebffdab501fbd555808b694c5df70c96f4f599fbd
3
+ metadata.gz: 41a83b15623015119b3b9413b535614c9e99b92500e49d52ad6b14cd44fcc158
4
+ data.tar.gz: 38b0fea433d9d418998d72b03639fb02cc84c7345dd7f3a7c40c802166af0a41
5
5
  SHA512:
6
- metadata.gz: 03d6925eef2143a0eead9c30147abe8617597dddddb2911a7b4cee3998a01df9d55a310eab0464676e6f1e58d7f300a377ed6da9cfda96fa66c8d8fa01dadd3e
7
- data.tar.gz: fe6e7c90d8f4913d5cf680c3a65993624f90585d52387d2c04a94d454a6c2d295e22c0d152f4248fd678c13183c6d7c33e58824063a32dc76b58eb0651c341fd
6
+ metadata.gz: ac1c2e087bc1f3c55c7520d9f88230279a12e6500c7321683cd440d122436126e3335199bd1824d3f3018b2af82683a49c4c6982a41dfe5227a64e51519ff29c
7
+ data.tar.gz: 51de0a48243b54f5c5ffc9716609b2aba2604a7604c15938888c50139846f97e69267ace1044e2c3e111cc00bd70e77d4af378980214a6ee3ff1062c8181faba
data/README.md CHANGED
@@ -437,7 +437,7 @@ system :sumprod do |typ,coefs|
437
437
  typ[coefs.size].input :ins
438
438
  typ.output :o
439
439
 
440
- o <= coefs.each_with_index.reduce(_0) do |sum,(coef,i)|
440
+ o <= coefs.each_with_index.reduce(_b0) do |sum,(coef,i)|
441
441
  sum + ins[i]*coef
442
442
  end
443
443
  end
@@ -446,7 +446,7 @@ end
446
446
  In the code above, there are two generic parameters,
447
447
  `typ`, which indicates the data type of the circuit, and `coefs`, which is assumed to be an array of coefficients. Since the number of inputs depends on the number of provided coefficients, it is declared as an array of `width` bit signed whose size is equal to the number of coefficients.
448
448
 
449
- The description of the sum of products may be more difficult to understand for people not familiar with the Ruby language. The `each_with_index` method iterates over the coefficients adding their index as iteration variable, the resulting operation (i.e., the iteration loop) is then modified by the `reduce` method that accumulates the code passed as arguments. This code, starting by `|sum,coef,i|` simply performs the addition of the current accumulation result (`sum`) with the product of the current coefficient (`coef`) and input (`ins[i]`, where `i` is the index) in the iteration. The argument `_0` initializes the sum to `0`.
449
+ The description of the sum of products may be more difficult to understand for people not familiar with the Ruby language. The `each_with_index` method iterates over the coefficients adding their index as iteration variable, the resulting operation (i.e., the iteration loop) is then modified by the `reduce` method that accumulates the code passed as arguments. This code, starting by `|sum,coef,i|` simply performs the addition of the current accumulation result (`sum`) with the product of the current coefficient (`coef`) and input (`ins[i]`, where `i` is the index) in the iteration. The argument `_b0` initializes the sum to `0`.
450
450
 
451
451
  While slightly longer than the previous description, this description allows declaring a circuit implementing a sum of products with any bit width and any number of coefficients. For instance, the following code describes a signed 32-bit sum of products with 16 coefficients (just random numbers here).
452
452
 
@@ -463,7 +463,7 @@ system :sumprod_func do |typ,coefs|
463
463
  typ[coefs.size].input ins
464
464
  typ.output :o
465
465
 
466
- o <= coefs.each_with_index.reduce(_0) do
466
+ o <= coefs.each_with_index.reduce(_b0) do
467
467
  |sum,(coef,i)|
468
468
  add(sum, mult(ins[i]*coef))
469
469
  end
@@ -509,7 +509,7 @@ system :sumprod_proc do |add,mult,typ,coefs|
509
509
  typ[coefs.size].input ins
510
510
  typ.output :o
511
511
 
512
- o <= coefs.each_with_index.reduce(_0) do
512
+ o <= coefs.each_with_index.reduce(_b0) do
513
513
  |sum,(coef,i)|
514
514
  add.(sum, mult.(ins[i]*coef))
515
515
  end
@@ -539,10 +539,8 @@ A second possible approach provided by HDLRuby is to declare a new data type wit
539
539
  signed[16].typedef(:sat16_1000)
540
540
 
541
541
  sat16_1000.define_operator(:+) do |x,y|
542
- [16].inner :res
543
- seq do
544
- res <= x + y
545
- ( res <= 1000 ).hif(res > 1000)
542
+ tmp = x + y
543
+ mux(tmp > 1000,tmp,1000)
546
544
  end
547
545
  end
548
546
  ```
@@ -565,10 +563,8 @@ end
565
563
 
566
564
 
567
565
  sat.define_operator(:+) do |width,max, x,y|
568
- [width].inner :res
569
- seq do
570
- res <= x + y
571
- ( res <= max ).hif(res > max)
566
+ tmp = x + y
567
+ mux(tmp > max, tmp, max)
572
568
  end
573
569
  end
574
570
  ```
@@ -1426,7 +1422,7 @@ They include [immediate values](#values), [reference to signals](#references) an
1426
1422
  ### Immediate values
1427
1423
  <a name="values"></a>
1428
1424
 
1429
- The immediate values of HDLRuby can represent vectors of `bit`, `unsigned`, and `signed`, and integer or floating-point numbers. They are prefixed by a `_` character and include a header that indicates the vector type and the base used for representing the value, followed by a numeral representing the value. The bit width of a value is obtained by default from the width of the numeral, but it is also possible to enforce it in the header.
1425
+ The immediate values of HDLRuby can represent vectors of `bit`, `unsigned`, and `signed`, and integer or floating-point numbers. They are prefixed by a `_` character and include a header that indicates the vector type and the base used for representing the value, followed by a numeral representing the value. The bit width of a value is obtained by default from the width of the numeral, but it is also possible to specify it in the header. In addition, the character `_` can be put anywhere in the number for increasing the readability, it will be ignored.
1430
1426
 
1431
1427
  The vector type specifiers are the followings:
1432
1428
 
@@ -1438,7 +1434,7 @@ The vector type specifiers are the followings:
1438
1434
 
1439
1435
  The base specifiers are the followings:
1440
1436
 
1441
- - `b`: binary, can be omitted,
1437
+ - `b`: binary,
1442
1438
 
1443
1439
  - `o`: octal,
1444
1440
 
@@ -1446,21 +1442,30 @@ The base specifiers are the followings:
1446
1442
 
1447
1443
  - `h`: hexadecimal.
1448
1444
 
1449
- For example, all the following immediate values represent an 8-bit `100` (either in unsigned or signed representation):
1445
+ For example, all the following immediate values represent an 8-bit `hundred` (either in unsigned or signed representation):
1450
1446
 
1451
1447
  ```ruby
1452
1448
  _bb01100100
1453
- _b8b1100100
1449
+ _b8b110_0100
1454
1450
  _b01100100
1455
- _01100100
1456
1451
  _u8d100
1457
1452
  _s8d100
1458
1453
  _uh64
1459
1454
  _s8o144
1460
1455
  ```
1461
1456
 
1457
+ Finally, it is possible to omit either the type specifier, the default being unsigned bit, or the base specifier, the default being binary. For example, all the following immediate values represent an 8-bit unsigned `hundred`:
1458
+
1459
+ ```ruby
1460
+ _b01100100
1461
+ _h64
1462
+ _o144
1463
+ ```
1464
+
1462
1465
  __Notes__:
1463
1466
 
1467
+ - `_01100100` used to be considered as equivalent to `_b01100100`, however due to compatibility troubles with recent version of Ruby it is considered deprecated.
1468
+
1464
1469
  - Ruby immediate values can also be used, their bit width is automatically adjusted to match the data type of the expression they are used in. Please notice this adjusting may change the value of the immediate, for example, the following code will set `sig` to 4 instead of 100:
1465
1470
 
1466
1471
  ```ruby
@@ -2309,7 +2314,7 @@ Where:
2309
2314
  * `type` is the type from which the operation is overloaded.
2310
2315
  * `op` is the operator that is overloaded (e.g., `+`)
2311
2316
  * `args` are the arguments of the operation.
2312
- * `operation description` is an HDLRuby description of the new operation.
2317
+ * `operation description` is an HDLRuby expression of the new operation.
2313
2318
 
2314
2319
  For example, for `fix32` a 32-bit (decimal point at 16-bit) fixed-point type defined as follows:
2315
2320
 
@@ -2813,6 +2818,38 @@ fsm(clk.posedge,rst,:sync) do
2813
2818
  end
2814
2819
  ```
2815
2820
 
2821
+ __Note__: the goto statements acts globally, i.e., they are independant of the place where they are declared within the state. For example for both following statements, the next state will always be `st_a` whatever `cond` maybe:
2822
+
2823
+ ```ruby
2824
+ state(:st_0) do
2825
+ goto(:st_a)
2826
+ end
2827
+ state(:st_1) do
2828
+ hif(cond) { goto(:st_a) }
2829
+ end
2830
+ ```
2831
+
2832
+ That is to say, for a conditional `goto` for `st_1` the code should have been written as follows:
2833
+
2834
+ ```ruby
2835
+ state(:st_1) do
2836
+ goto(cond,:st_a)
2837
+ end
2838
+ ```
2839
+
2840
+ The use of `goto` makes the design of FSM shorter for a majority of the cases, be sometimes, a finer control is required. For that purpose it is also possible to configure the FSM is `static` mode where the `next_state` statement that indicates implicitly the next state. Putting is static mode is done by passing `:static` as argument when declaring the FSM. For example the following FSM uses `next_state` to specify explicitly the next states depending on some condition signals `cond0` and `cond1`:
2841
+
2842
+ ```ruby
2843
+ fsm(clk.posedge,rst,:static)
2844
+ state(:st_0) do
2845
+ next_state(:st_1)
2846
+ state(:st_1) do
2847
+ hif(cond) { next_state(:st_1) }
2848
+ helse { next_state(:st_0) }
2849
+ end
2850
+ end
2851
+ ```
2852
+
2816
2853
 
2817
2854
  ## Fixed-point (fixpoint)
2818
2855
  <a name="fixpoint"></a>
@@ -319,6 +319,9 @@ VALUE rcsim_make_signal(VALUE mod, VALUE name, VALUE type) {
319
319
  // printf("Creating signal named=%s\n",signal->name);
320
320
  value_to_rcsim(TypeS,type,signal->type);
321
321
  // printf("&type=%p type=%p width=%llu\n",&(signal->type),signal->type,type_width(signal->type));
322
+ signal->num_signals= 0;
323
+ signal->signals = NULL;
324
+
322
325
  signal->c_value = make_value(signal->type,0);
323
326
  // printf("signal->c_value=%p\n",signal->c_value);
324
327
  signal->c_value->signal = signal;
@@ -798,10 +801,10 @@ VALUE rcsim_add_systemT_inputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
798
801
  long old_num = systemT->num_inputs;
799
802
  systemT->num_inputs += num;
800
803
  // printf("first systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
801
- // systemT->inputs=realloc(systemT->inputs,
802
- // sizeof(SignalI[systemT->num_inputs]));
803
- systemT->inputs=(SignalI*)my_realloc(systemT->inputs,
804
- sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_inputs]));
804
+ systemT->inputs=realloc(systemT->inputs,
805
+ sizeof(SignalI[systemT->num_inputs]));
806
+ // systemT->inputs=(SignalI*)my_realloc(systemT->inputs,
807
+ // sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_inputs]));
805
808
  // printf("now systemT->inputs=%p\n",systemT->inputs); fflush(stdout);
806
809
  // printf("access test: %p\n",systemT->inputs[0]); fflush(stdout);
807
810
  /* Get and add the signals from the Ruby value. */
@@ -825,10 +828,10 @@ VALUE rcsim_add_systemT_outputs(VALUE mod, VALUE systemTV, VALUE sigVs) {
825
828
  long old_num = systemT->num_outputs;
826
829
  systemT->num_outputs += num;
827
830
  // printf("first systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
828
- // systemT->outputs =realloc(systemT->outputs,
829
- // sizeof(SignalI[systemT->num_outputs]));
830
- systemT->outputs =(SignalI*)my_realloc(systemT->outputs,
831
- sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_outputs]));
831
+ systemT->outputs =realloc(systemT->outputs,
832
+ sizeof(SignalI[systemT->num_outputs]));
833
+ // systemT->outputs =(SignalI*)my_realloc(systemT->outputs,
834
+ // sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_outputs]));
832
835
  // printf("now systemT->outputs=%p\n",systemT->outputs); fflush(stdout);
833
836
  // printf("access test: %p\n",systemT->outputs[0]); fflush(stdout);
834
837
  /* Get and add the signals from the Ruby value. */
@@ -852,10 +855,10 @@ VALUE rcsim_add_systemT_inouts(VALUE mod, VALUE systemTV, VALUE sigVs) {
852
855
  long old_num = systemT->num_inouts;
853
856
  systemT->num_inouts += num;
854
857
  // printf("first systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
855
- // systemT->inouts =realloc(systemT->inouts,
856
- // sizeof(SignalI[systemT->num_inouts]));
857
- systemT->inouts =(SignalI*)my_realloc(systemT->inouts,
858
- sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_inouts]));
858
+ systemT->inouts =realloc(systemT->inouts,
859
+ sizeof(SignalI[systemT->num_inouts]));
860
+ // systemT->inouts =(SignalI*)my_realloc(systemT->inouts,
861
+ // sizeof(SignalI[old_num]), sizeof(SignalI[systemT->num_inouts]));
859
862
  // printf("now systemT->inouts=%p\n",systemT->inouts); fflush(stdout);
860
863
  // printf("access test: %p\n",systemT->inouts[0]); fflush(stdout);
861
864
  /* Get and add the signals from the Ruby value. */
@@ -879,10 +882,10 @@ VALUE rcsim_add_scope_inners(VALUE mod, VALUE scopeV, VALUE sigVs) {
879
882
  long old_num = scope->num_inners;
880
883
  scope->num_inners += num;
881
884
  // printf("first scope->inners=%p\n",scope->inners); fflush(stdout);
882
- // scope->inners = realloc(scope->inners,
883
- // sizeof(SignalI[scope->num_inners]));
884
- scope->inners = (SignalI*)my_realloc(scope->inners,
885
- sizeof(SignalI[old_num]), sizeof(SignalI[scope->num_inners]));
885
+ scope->inners = realloc(scope->inners,
886
+ sizeof(SignalI[scope->num_inners]));
887
+ // scope->inners = (SignalI*)my_realloc(scope->inners,
888
+ // sizeof(SignalI[old_num]), sizeof(SignalI[scope->num_inners]));
886
889
  // printf("now scope->inners=%p\n",scope->inners); fflush(stdout);
887
890
  // printf("access test: %p\n",scope->inners[0]); fflush(stdout);
888
891
  /* Get and add the signals from the Ruby value. */
@@ -909,10 +912,10 @@ VALUE rcsim_add_scope_behaviors(VALUE mod, VALUE scopeV, VALUE behVs) {
909
912
  // printf("scope->behaviors=%p\n",scope->behaviors);
910
913
  scope->num_behaviors += num;
911
914
  // printf("first scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
912
- // scope->behaviors = realloc(scope->behaviors,
913
- // sizeof(Behavior[scope->num_behaviors]));
914
- scope->behaviors = (Behavior*)my_realloc(scope->behaviors,
915
- sizeof(Behavior[old_num]), sizeof(Behavior[scope->num_behaviors]));
915
+ scope->behaviors = realloc(scope->behaviors,
916
+ sizeof(Behavior[scope->num_behaviors]));
917
+ // scope->behaviors = (Behavior*)my_realloc(scope->behaviors,
918
+ // sizeof(Behavior[old_num]), sizeof(Behavior[scope->num_behaviors]));
916
919
  // printf("now scope->behaviors=%p\n",scope->behaviors); fflush(stdout);
917
920
  // printf("access test: %p\n",scope->behaviors[0]); fflush(stdout);
918
921
  /* Get and add the behaviors from the Ruby value. */
@@ -936,10 +939,10 @@ VALUE rcsim_add_scope_systemIs(VALUE mod, VALUE scopeV, VALUE sysVs) {
936
939
  long old_num = scope->num_systemIs;
937
940
  scope->num_systemIs += num;
938
941
  // printf("first scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
939
- // scope->systemIs = realloc(scope->systemIs,
940
- // sizeof(SystemI[scope->num_systemIs]));
941
- scope->systemIs = (SystemI*)my_realloc(scope->systemIs,
942
- sizeof(SystemI[old_num]), sizeof(SystemI[scope->num_systemIs]));
942
+ scope->systemIs = realloc(scope->systemIs,
943
+ sizeof(SystemI[scope->num_systemIs]));
944
+ // scope->systemIs = (SystemI*)my_realloc(scope->systemIs,
945
+ // sizeof(SystemI[old_num]), sizeof(SystemI[scope->num_systemIs]));
943
946
  // printf("now scope->systemIs=%p\n",scope->systemIs); fflush(stdout);
944
947
  // printf("access test: %p\n",scope->systemIs[0]); fflush(stdout);
945
948
  /* Get and add the system instances from the Ruby value. */
@@ -963,10 +966,10 @@ VALUE rcsim_add_scope_scopes(VALUE mod, VALUE scopeV, VALUE scpVs) {
963
966
  long old_num = scope->num_scopes;
964
967
  scope->num_scopes += num;
965
968
  // printf("first scope->scopes=%p\n",scope->scopes); fflush(stdout);
966
- // scope->scopes = realloc(scope->scopes,
967
- // sizeof(Scope[scope->num_scopes]));
968
- scope->scopes = (Scope*)my_realloc(scope->scopes,
969
- sizeof(Scope[old_num]), sizeof(Scope[scope->num_scopes]));
969
+ scope->scopes = realloc(scope->scopes,
970
+ sizeof(Scope[scope->num_scopes]));
971
+ // scope->scopes = (Scope*)my_realloc(scope->scopes,
972
+ // sizeof(Scope[old_num]), sizeof(Scope[scope->num_scopes]));
970
973
  // printf("now scope->scopes=%p\n",scope->scopes); fflush(stdout);
971
974
  // printf("access test: %p\n",scope->scopes[0]); fflush(stdout);
972
975
  /* Get and add the sub scopes from the Ruby value. */
@@ -990,10 +993,10 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
990
993
  long old_num = behavior->num_events;
991
994
  behavior->num_events += num;
992
995
  // printf("first behavior->events=%p\n",behavior->events); fflush(stdout);
993
- // behavior->events = realloc(behavior->events,
994
- // sizeof(Event[behavior->num_events]));
995
- behavior->events = (Event*)my_realloc(behavior->events,
996
- sizeof(Event[old_num]), sizeof(Event[behavior->num_events]));
996
+ behavior->events = realloc(behavior->events,
997
+ sizeof(Event[behavior->num_events]));
998
+ // behavior->events = (Event*)my_realloc(behavior->events,
999
+ // sizeof(Event[old_num]), sizeof(Event[behavior->num_events]));
997
1000
  // printf("now behavior->events=%p\n",behavior->events); fflush(stdout);
998
1001
  // printf("access test: %p\n",behavior->events[0]); fflush(stdout);
999
1002
  /* Get and add the events from the Ruby value. */
@@ -1008,9 +1011,9 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
1008
1011
  case ANYEDGE:
1009
1012
  sig->num_any++;
1010
1013
  // printf("first sig->any=%p\n",sig->any); fflush(stdout);
1011
- // sig->any = realloc(sig->any,sizeof(Object[sig->num_any]));
1012
- sig->any = (Object*)my_realloc(sig->any,
1013
- sizeof(Object[sig->num_any-1]),sizeof(Object[sig->num_any]));
1014
+ sig->any = realloc(sig->any,sizeof(Object[sig->num_any]));
1015
+ // sig->any = (Object*)my_realloc(sig->any,
1016
+ // sizeof(Object[sig->num_any-1]),sizeof(Object[sig->num_any]));
1014
1017
  // printf("now sig->any=%p\n",sig->any); fflush(stdout);
1015
1018
  // printf("access test: %p\n",sig->any[0]); fflush(stdout);
1016
1019
  // show_access(sig->any,sig->num_any-1);
@@ -1020,9 +1023,9 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
1020
1023
  case POSEDGE:
1021
1024
  sig->num_pos++;
1022
1025
  // printf("first sig->pos=%p\n",sig->pos); fflush(stdout);
1023
- // sig->pos = realloc(sig->pos,sizeof(Object[sig->num_pos]));
1024
- sig->pos = (Object*)my_realloc(sig->pos,
1025
- sizeof(Object[sig->num_pos-1]),sizeof(Object[sig->num_pos]));
1026
+ sig->pos = realloc(sig->pos,sizeof(Object[sig->num_pos]));
1027
+ // sig->pos = (Object*)my_realloc(sig->pos,
1028
+ // sizeof(Object[sig->num_pos-1]),sizeof(Object[sig->num_pos]));
1026
1029
  // printf("now sig->pos=%p\n",sig->pos); fflush(stdout);
1027
1030
  // printf("access test: %p\n",sig->pos[0]); fflush(stdout);
1028
1031
  // show_access(sig->pos,sig->num_pos-1);
@@ -1032,9 +1035,9 @@ VALUE rcsim_add_behavior_events(VALUE mod, VALUE behaviorV, VALUE eventVs) {
1032
1035
  case NEGEDGE:
1033
1036
  sig->num_neg++;
1034
1037
  // printf("first sig->neg=%p\n",sig->neg); fflush(stdout);
1035
- // sig->neg = realloc(sig->neg,sizeof(Object[sig->num_neg]));
1036
- sig->neg = (Object*)my_realloc(sig->neg,
1037
- sizeof(Object[sig->num_neg-1]),sizeof(Object[sig->num_neg]));
1038
+ sig->neg = realloc(sig->neg,sizeof(Object[sig->num_neg]));
1039
+ // sig->neg = (Object*)my_realloc(sig->neg,
1040
+ // sizeof(Object[sig->num_neg-1]),sizeof(Object[sig->num_neg]));
1038
1041
  // printf("now sig->neg=%p\n",sig->neg); fflush(stdout);
1039
1042
  // printf("access test: %p\n",sig->neg[0]); fflush(stdout);
1040
1043
  // show_access(sig->neg,sig->num_neg-1);
@@ -1059,10 +1062,10 @@ VALUE rcsim_add_systemI_systemTs(VALUE mod, VALUE systemIV, VALUE sysVs) {
1059
1062
  long old_num = systemI->num_systems;
1060
1063
  systemI->num_systems += num;
1061
1064
  // printf("first systemI->systems=%p\n",systemI->systems); fflush(stdout);
1062
- // systemI->systems=realloc(systemI->systems,
1063
- // sizeof(SystemT[systemI->num_systems]));
1064
- systemI->systems = (SystemT*)my_realloc(systemI->systems,
1065
- sizeof(SystemT[old_num]), sizeof(SystemT[systemI->num_systems]));
1065
+ systemI->systems=realloc(systemI->systems,
1066
+ sizeof(SystemT[systemI->num_systems]));
1067
+ // systemI->systems = (SystemT*)my_realloc(systemI->systems,
1068
+ // sizeof(SystemT[old_num]), sizeof(SystemT[systemI->num_systems]));
1066
1069
  // printf("now systemI->systems=%p\n",systemI->systems); fflush(stdout);
1067
1070
  // printf("access test: %p\n",systemI->systems[0]); fflush(stdout);
1068
1071
  /* Get and add the alternate system types from the Ruby value. */
@@ -1075,6 +1078,29 @@ VALUE rcsim_add_systemI_systemTs(VALUE mod, VALUE systemIV, VALUE sysVs) {
1075
1078
  return systemIV;
1076
1079
  }
1077
1080
 
1081
+ /* Adds sub signals a C signal. */
1082
+ VALUE rcsim_add_signal_signals(VALUE mod, VALUE signalIV, VALUE sigVs) {
1083
+ /* Get the C signal from the Ruby value. */
1084
+ SignalI signalI;
1085
+ value_to_rcsim(SignalIS,signalIV,signalI);
1086
+ // printf("rcsim_add_signal_signals with signalI=%p\n",signalI);
1087
+ /* Prepare the size for the alternate system types. */
1088
+ long num = RARRAY_LEN(sigVs);
1089
+ long old_num = signalI->num_signals;
1090
+ signalI->num_signals += num;
1091
+ signalI->signals=realloc(signalI->signals,
1092
+ sizeof(SignalI[signalI->num_signals]));
1093
+ // signalI->signals = (SignalI*)my_realloc(signalI->signals,
1094
+ // sizeof(SignalI[old_num]), sizeof(SignalI[signalI->num_signals]));
1095
+ /* Get and add the alternate system types from the Ruby value. */
1096
+ for(long i=0; i< num; ++i) {
1097
+ SignalI sig;
1098
+ value_to_rcsim(SignalIS,rb_ary_entry(sigVs,i),sig);
1099
+ signalI->signals[old_num + i] = sig;
1100
+ }
1101
+ return signalIV;
1102
+ }
1103
+
1078
1104
  /* Adds arguments to a C print. */
1079
1105
  VALUE rcsim_add_print_args(VALUE mod, VALUE printV, VALUE argVs) {
1080
1106
  /* Get the C print from the Ruby value. */
@@ -1086,10 +1112,10 @@ VALUE rcsim_add_print_args(VALUE mod, VALUE printV, VALUE argVs) {
1086
1112
  long old_num = print->num_args;
1087
1113
  print->num_args += num;
1088
1114
  // printf("first print->args=%p\n",print->args); fflush(stdout);
1089
- // print->args = realloc(print->args,
1090
- // sizeof(Expression[print->num_args]));
1091
- print->args = (Expression*)my_realloc(print->args,
1092
- sizeof(Expression[old_num]), sizeof(Expression[print->num_args]));
1115
+ print->args = realloc(print->args,
1116
+ sizeof(Expression[print->num_args]));
1117
+ // print->args = (Expression*)my_realloc(print->args,
1118
+ // sizeof(Expression[old_num]), sizeof(Expression[print->num_args]));
1093
1119
  // printf("now print->args=%p\n",print->args); fflush(stdout);
1094
1120
  // printf("access test: %p\n",print->args[0]); fflush(stdout);
1095
1121
  /* Get and add the arguments from the Ruby value. */
@@ -1114,14 +1140,14 @@ VALUE rcsim_add_hif_noifs(VALUE mod, VALUE hifV, VALUE condVs, VALUE stmntVs) {
1114
1140
  hif->num_noifs += num;
1115
1141
  // printf("first hif->noconds=%p\n",hif->noconds); fflush(stdout);
1116
1142
  // printf("first hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
1117
- // hif->noconds = realloc(hif->noconds,sizeof(Expression[hif->num_noifs]));
1118
- hif->noconds = (Expression*)my_realloc(hif->noconds,
1119
- sizeof(Expression[old_num]),sizeof(Expression[hif->num_noifs]));
1143
+ hif->noconds = realloc(hif->noconds,sizeof(Expression[hif->num_noifs]));
1144
+ // hif->noconds = (Expression*)my_realloc(hif->noconds,
1145
+ // sizeof(Expression[old_num]),sizeof(Expression[hif->num_noifs]));
1120
1146
  // printf("now hif->noconds=%p\n",hif->noconds); fflush(stdout);
1121
1147
  // printf("access test: %p\n",hif->noconds[0]); fflush(stdout);
1122
- // hif->nostmnts = realloc(hif->nostmnts,sizeof(Statement[hif->num_noifs]));
1123
- hif->nostmnts = (Statement*)my_realloc(hif->nostmnts,
1124
- sizeof(Statement[old_num]),sizeof(Statement[hif->num_noifs]));
1148
+ hif->nostmnts = realloc(hif->nostmnts,sizeof(Statement[hif->num_noifs]));
1149
+ // hif->nostmnts = (Statement*)my_realloc(hif->nostmnts,
1150
+ // sizeof(Statement[old_num]),sizeof(Statement[hif->num_noifs]));
1125
1151
  // printf("now hif->nostmnts=%p\n",hif->nostmnts); fflush(stdout);
1126
1152
  // printf("access test: %p\n",hif->nostmnts[0]); fflush(stdout);
1127
1153
  /* Get and add the noifs from the Ruby value. */
@@ -1150,16 +1176,16 @@ VALUE rcsim_add_hcase_whens(VALUE mod, VALUE hcaseV, VALUE matchVs, VALUE stmntV
1150
1176
  hcase->num_whens += num;
1151
1177
  // printf("first hcase->matches=%p\n",hcase->matches); fflush(stdout);
1152
1178
  // printf("first hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
1153
- // hcase->matches = realloc(hcase->matches,
1154
- // sizeof(Expression[hcase->num_whens]));
1155
- hcase->matches = (Expression*)my_realloc(hcase->matches,
1156
- sizeof(Expression[old_num]), sizeof(Expression[hcase->num_whens]));
1179
+ hcase->matches = realloc(hcase->matches,
1180
+ sizeof(Expression[hcase->num_whens]));
1181
+ // hcase->matches = (Expression*)my_realloc(hcase->matches,
1182
+ // sizeof(Expression[old_num]), sizeof(Expression[hcase->num_whens]));
1157
1183
  // printf("now hcase->matches=%p\n",hcase->matches); fflush(stdout);
1158
1184
  // printf("access test: %p\n",hcase->matches[0]); fflush(stdout);
1159
- // hcase->stmnts = realloc(hcase->stmnts,
1160
- // sizeof(Statement[hcase->num_whens]));
1161
- hcase->stmnts = (Statement*)my_realloc(hcase->stmnts,
1162
- sizeof(Statement[old_num]), sizeof(Statement[hcase->num_whens]));
1185
+ hcase->stmnts = realloc(hcase->stmnts,
1186
+ sizeof(Statement[hcase->num_whens]));
1187
+ // hcase->stmnts = (Statement*)my_realloc(hcase->stmnts,
1188
+ // sizeof(Statement[old_num]), sizeof(Statement[hcase->num_whens]));
1163
1189
  // printf("now hcase->stmnts=%p\n",hcase->stmnts); fflush(stdout);
1164
1190
  // printf("access test: %p\n",hcase->stmnts[0]); fflush(stdout);
1165
1191
  /* Get and add the whens from the Ruby value. */
@@ -1187,10 +1213,10 @@ VALUE rcsim_add_block_inners(VALUE mod, VALUE blockV, VALUE sigVs) {
1187
1213
  long old_num = block->num_inners;
1188
1214
  block->num_inners += num;
1189
1215
  // printf("first block->inners=%p\n",block->inners); fflush(stdout);
1190
- // block->inners = realloc(block->inners,
1191
- // sizeof(SignalI[block->num_inners]));
1192
- block->inners = (SignalI*)my_realloc(block->inners,
1193
- sizeof(SignalI[old_num]), sizeof(SignalI[block->num_inners]));
1216
+ block->inners = realloc(block->inners,
1217
+ sizeof(SignalI[block->num_inners]));
1218
+ // block->inners = (SignalI*)my_realloc(block->inners,
1219
+ // sizeof(SignalI[old_num]), sizeof(SignalI[block->num_inners]));
1194
1220
  // printf("now block->inners=%p\n",block->inners); fflush(stdout);
1195
1221
  // printf("access test: %p\n",block->inners[0]); fflush(stdout);
1196
1222
  /* Get and add the signals from the Ruby value. */
@@ -1214,10 +1240,10 @@ VALUE rcsim_add_block_statements(VALUE mod, VALUE blockV, VALUE stmntVs) {
1214
1240
  long old_num = block->num_stmnts;
1215
1241
  block->num_stmnts += num;
1216
1242
  // printf("first block->stmnts=%p\n",block->stmnts); fflush(stdout);
1217
- // block->stmnts = realloc(block->stmnts,
1218
- // sizeof(Statement[block->num_stmnts]));
1219
- block->stmnts = (Statement*)my_realloc(block->stmnts,
1220
- sizeof(Statement[old_num]), sizeof(Statement[block->num_stmnts]));
1243
+ block->stmnts = realloc(block->stmnts,
1244
+ sizeof(Statement[block->num_stmnts]));
1245
+ // block->stmnts = (Statement*)my_realloc(block->stmnts,
1246
+ // sizeof(Statement[old_num]), sizeof(Statement[block->num_stmnts]));
1221
1247
  // printf("now block->stmnts=%p\n",block->stmnts); fflush(stdout);
1222
1248
  // printf("access test: %p\n",block->stmnts[0]); fflush(stdout);
1223
1249
  /* Get and add the statements from the Ruby value. */
@@ -1241,10 +1267,10 @@ VALUE rcsim_add_select_choices(VALUE mod, VALUE selectV, VALUE choiceVs) {
1241
1267
  long old_num = select->num_choices;
1242
1268
  select->num_choices += num;
1243
1269
  // printf("first select->choices=%p\n",select->choices); fflush(stdout);
1244
- // select->choices = realloc(select->choices,
1245
- // sizeof(Expression[select->num_choices]));
1246
- select->choices = (Expression*)my_realloc(select->choices,
1247
- sizeof(Expression[old_num]),sizeof(Expression[select->num_choices]));
1270
+ select->choices = realloc(select->choices,
1271
+ sizeof(Expression[select->num_choices]));
1272
+ // Select->choices = (Expression*)my_realloc(select->choices,
1273
+ // sizeof(Expression[old_num]),sizeof(Expression[select->num_choices]));
1248
1274
  // printf("now select->choices=%p\n",select->choices); fflush(stdout);
1249
1275
  // printf("access test: %p\n",select->choices[0]); fflush(stdout);
1250
1276
  /* Get and add the choices from the Ruby value. */
@@ -1269,10 +1295,10 @@ VALUE rcsim_add_concat_expressions(VALUE mod, VALUE concatV, VALUE exprVs) {
1269
1295
  // printf("add_concat_expressions with num=%li old_num=%li\n",num,old_num);
1270
1296
  concat->num_exprs += num;
1271
1297
  // printf("first concat->exprs=%p\n",concat->exprs); fflush(stdout);
1272
- // concat->exprs = realloc(concat->exprs,
1273
- // sizeof(Expression[concat->num_exprs]));
1274
- concat->exprs = (Expression*)my_realloc(concat->exprs,
1275
- sizeof(Expression[old_num]), sizeof(Expression[concat->num_exprs]));
1298
+ concat->exprs = realloc(concat->exprs,
1299
+ sizeof(Expression[concat->num_exprs]));
1300
+ // concat->exprs = (Expression*)my_realloc(concat->exprs,
1301
+ // sizeof(Expression[old_num]), sizeof(Expression[concat->num_exprs]));
1276
1302
  // printf("now concat->exprs=%p\n",concat->exprs); fflush(stdout);
1277
1303
  // printf("access test: %p\n",concat->exprs[0]); fflush(stdout);
1278
1304
  /* Get and add the expressions from the Ruby value. */
@@ -1296,10 +1322,10 @@ VALUE rcsim_add_refConcat_refs(VALUE mod, VALUE refConcatV, VALUE refVs) {
1296
1322
  long old_num = refConcat->num_refs;
1297
1323
  refConcat->num_refs += num;
1298
1324
  // printf("first refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
1299
- // refConcat->refs = realloc(refConcat->refs,
1300
- // sizeof(Reference[refConcat->num_refs]));
1301
- refConcat->refs = (Reference*)my_realloc(refConcat->refs,
1302
- sizeof(Reference[old_num]), sizeof(Reference[refConcat->num_refs]));
1325
+ refConcat->refs = realloc(refConcat->refs,
1326
+ sizeof(Reference[refConcat->num_refs]));
1327
+ // refConcat->refs = (Reference*)my_realloc(refConcat->refs,
1328
+ // sizeof(Reference[old_num]), sizeof(Reference[refConcat->num_refs]));
1303
1329
  // printf("now refConcat->refs=%p\n",refConcat->refs); fflush(stdout);
1304
1330
  // printf("access test: %p\n",refConcat->refs[0]); fflush(stdout);
1305
1331
  /* Get and add the references from the Ruby value. */
@@ -1459,6 +1485,7 @@ void Init_hruby_sim() {
1459
1485
  rb_define_singleton_method(mod,"rcsim_add_scope_scopes",rcsim_add_scope_scopes,2);
1460
1486
  rb_define_singleton_method(mod,"rcsim_add_behavior_events",rcsim_add_behavior_events,2);
1461
1487
  rb_define_singleton_method(mod,"rcsim_add_systemI_systemTs",rcsim_add_systemI_systemTs,2);
1488
+ rb_define_singleton_method(mod,"rcsim_add_signal_signals",rcsim_add_signal_signals,2);
1462
1489
  rb_define_singleton_method(mod,"rcsim_add_print_args",rcsim_add_print_args,2);
1463
1490
  rb_define_singleton_method(mod,"rcsim_add_hif_noifs",rcsim_add_hif_noifs,3);
1464
1491
  rb_define_singleton_method(mod,"rcsim_add_hcase_whens",rcsim_add_hcase_whens,3);
@@ -530,6 +530,9 @@ typedef struct SignalIS_ {
530
530
  Value c_value; /* The current value of the signal. */
531
531
  Value f_value; /* The future (next) value of the signal. */
532
532
 
533
+ int num_signals; /* The number of sub signals. */
534
+ SignalI* signals; /* The sub signals. */
535
+
533
536
  int fading; /* Tell if the signal can be overwritten by Z. */
534
537
 
535
538
  int num_any; /* The number of behavior activated on any edge. */
@@ -83,7 +83,7 @@ static void add_hash_type(Type type) {
83
83
  List entry = hash_type[hvalue];
84
84
  if (!entry) {
85
85
  /* No entry, create a new one. */
86
- entry = malloc(sizeof(List));
86
+ entry = (List)malloc(sizeof(ListS));
87
87
  entry = build_list(entry);
88
88
  }
89
89
  /* Adds the type to the entry. */
@@ -201,16 +201,24 @@ 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(1,sizeof(ValueS));
204
+ // Value res = calloc(1,sizeof(ValueS));
205
+ Value res = malloc(sizeof(ValueS));
206
+ #ifdef RCSIM
207
+ res->kind = VALUEE;
208
+ res->owner = 0;
209
+ #endif
205
210
  /* Allocates the data of the value. */
206
211
  if (!numeric) {
207
212
  /* Allocate the bit string and fill it with u (undefined) by default. */
208
- res->data_str = malloc(sizeof(char)*width);
213
+ // res->data_str = malloc(sizeof(char)*width);
214
+ res->data_str = malloc(sizeof(char)*width+1);
209
215
  memset(res->data_str,'x',width);
216
+ res->data_str[width] = 0;
210
217
  /* And set its capacity to the type width. */
211
- res->capacity = width;
218
+ res->capacity = width+1;
212
219
  } else {
213
220
  res->capacity = 0;
221
+ res->data_str = 0;
214
222
  }
215
223
 
216
224
  /* Initialize it. */
@@ -229,8 +237,8 @@ void resize_value(Value value, unsigned long long size) {
229
237
  if (value->capacity < size) {
230
238
  /* Resizing required, to limit frequent resize, double the
231
239
  * required new capacity. */
232
- /* Free the former data. */
233
- free(value->data_str);
240
+ /* Free the former data if required. */
241
+ if (value->capacity > 0) free(value->data_str);
234
242
  /* Reallocate it. */
235
243
  value->data_str = calloc(size*2,sizeof(char));
236
244
  /* Update the size. */
@@ -86,8 +86,8 @@ void register_timed_behavior(Behavior behavior) {
86
86
  } else {
87
87
  /* Need to increase the capacity. */
88
88
  Behavior* behaviors = calloc(cap_timed_behaviors*2,sizeof(Behavior));
89
- // memcpy(behaviors,timed_behaviors,sizeof(Behavior)*cap_timed_behaviors);
90
89
  memcpy(behaviors,timed_behaviors,sizeof(Behavior[cap_timed_behaviors]));
90
+ free(timed_behaviors);
91
91
  timed_behaviors = behaviors;
92
92
  cap_timed_behaviors *= 2;
93
93
  }
@@ -110,6 +110,7 @@ void register_init_behavior(Behavior beh) {
110
110
  Behavior* new_behs = calloc(cap_init_behaviors*2,sizeof(Behavior));
111
111
  memcpy(new_behs,init_behaviors,sizeof(Behavior[cap_init_behaviors]));
112
112
  cap_init_behaviors *= 2;
113
+ free(init_behaviors);
113
114
  init_behaviors=new_behs;
114
115
  }
115
116
  }
@@ -129,9 +130,9 @@ void register_signal(SignalI signal) {
129
130
  } else {
130
131
  /* Need to increase the capacity. */
131
132
  SignalI* new_signals = calloc(cap_all_signals*2,sizeof(SignalI));
132
- // memcpy(new_signals,all_signals,sizeof(SignalI)*cap_all_signals);
133
133
  memcpy(new_signals,all_signals,sizeof(SignalI[cap_all_signals]));
134
134
  cap_all_signals *= 2;
135
+ free(all_signals);
135
136
  all_signals=new_signals;
136
137
  }
137
138
  }
@@ -728,14 +729,26 @@ void transmit_to_signal_range_seq(Value value, RefRangeS ref) {
728
729
  SignalI signal = ref.signal;
729
730
  unsigned long long first = ref.first;
730
731
  unsigned long long last = ref.last;
731
- // printf("Tansmit to signal range: %s(%p) [%llu,%llu]\n",signal->name,signal,first,last);
732
+ // printf("Tansmit to signal range seq: %s(%p) [%llu,%llu]\n",signal->name,signal,first,last);
733
+ // /* Can transmit, copy the content. */
734
+ // if (signal->fading)
735
+ // // write_range(value,first,last,signal->f_value->type,signal->f_value);
736
+ // write_range(value,first,last,ref.type,signal->f_value);
737
+ // else
738
+ // // write_range_no_z(value,first,last,signal->f_value->type,signal->f_value);
739
+ // write_range_no_z(value,first,last,ref.type,signal->f_value);
740
+ /* The base type is stored here to avoid allocating a new type each time.
741
+ * It have an arbitrary base size a single element. */
742
+ static TypeS baseT = { 1, 1 };
743
+ baseT.base = signal->f_value->type->base;
744
+ // printf("Tansmit to signal range: %s(%p) [%lld:%lld]\n",signal->name,signal,first,last);
732
745
  /* Can transmit, copy the content. */
733
746
  if (signal->fading)
734
- // write_range(value,first,last,signal->f_value->type,signal->f_value);
735
- write_range(value,first,last,ref.type,signal->f_value);
747
+ signal->f_value = write_range(value,first,last,&baseT,
748
+ signal->f_value);
736
749
  else
737
- // write_range_no_z(value,first,last,signal->f_value->type,signal->f_value);
738
- write_range_no_z(value,first,last,ref.type,signal->f_value);
750
+ signal->f_value = write_range_no_z(value,first,last,&baseT,
751
+ signal->f_value);
739
752
  /* And touch the signal. */
740
753
  touch_signal_seq(signal);
741
754
  }