HDLRuby 2.11.0 → 2.11.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  }
@@ -946,7 +946,7 @@ Value reduce_or_value_bitstring(Value src, Value dst) {
946
946
 
947
947
  /* Performs the reduce or. */
948
948
  unsigned long long count;
949
- char res;
949
+ char res = 0;
950
950
  for(count = 0; count < width; ++count) {
951
951
  /* Performs the reduce or. */
952
952
  char d = src_data[count] - '0'; /* Get and convert to bit. */
@@ -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,13 @@ 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(timed_behaviors,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]));
81
+ timed_behaviors = behaviors;
80
82
  cap_timed_behaviors *= 2;
81
83
  }
82
84
  }
@@ -92,11 +94,12 @@ void register_signal(SignalI signal) {
92
94
  if (cap_all_signals == 0) {
93
95
  /* Need to create the array containing the timed behaviors. */
94
96
  cap_all_signals = 100;
95
- all_signals = calloc(sizeof(SignalI),cap_all_signals);
97
+ all_signals = calloc(cap_all_signals,sizeof(SignalI));
96
98
  } else {
97
99
  /* Need to increase the capacity. */
98
- SignalI* new_signals = calloc(sizeof(SignalI),cap_all_signals*2);
99
- 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]));
100
103
  cap_all_signals *= 2;
101
104
  all_signals=new_signals;
102
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,11 +33,16 @@ 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]));
38
+ if (pool_values == NULL) {
39
+ perror("Internal error with the pool of values.");
40
+ exit(1);
41
+ }
36
42
  /* Allocate the new values. */
37
43
  /* Note: now pool_pos is the old pool_cap and is also the number
38
44
  * of new values to allocate. */
39
- ValueS* new_values = (ValueS*)calloc(sizeof(ValueS),pool_pos);
45
+ ValueS* new_values = (ValueS*)calloc(pool_pos,sizeof(ValueS));
40
46
  /* Assign them to the pool. */
41
47
  unsigned int i;
42
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.0"
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.0
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-09-23 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