HDLRuby 2.3.4 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1978,14 +1978,6 @@ module HDLRuby::Low
1978
1978
 
1979
1979
  include Hparent
1980
1980
 
1981
- # # Creates a new behavior.
1982
- # def initialize
1983
- # # Initialize the sensitivity list.
1984
- # @events = []
1985
- # # Initialize the block list.
1986
- # @blocks = []
1987
- # end
1988
-
1989
1981
  # The block executed by the behavior.
1990
1982
  attr_reader :block
1991
1983
 
@@ -2074,6 +2066,11 @@ module HDLRuby::Low
2074
2066
  return !@events.empty?
2075
2067
  end
2076
2068
 
2069
+ # Tells if it is activated on one of +events+.
2070
+ def on_event?(*events)
2071
+ @events.any? { |ev0| events.any? { |ev1| ev0.eql?(ev1) } }
2072
+ end
2073
+
2077
2074
  # Tells if there is a positive or negative edge event.
2078
2075
  def on_edge?
2079
2076
  @events.each do |event|
@@ -2619,6 +2616,15 @@ module HDLRuby::Low
2619
2616
  end
2620
2617
  end
2621
2618
 
2619
+ # Gets the behavior the statement is in.
2620
+ def behavior
2621
+ if self.parent.is_a?(Behavior) then
2622
+ return self.parent
2623
+ else
2624
+ return self.parent.behavior
2625
+ end
2626
+ end
2627
+
2622
2628
  # Gets the top block, i.e. the first block of the current behavior.
2623
2629
  def top_block
2624
2630
  return self.parent.is_a?(Behavior) ? self : self.parent.top_block
@@ -2633,6 +2639,11 @@ module HDLRuby::Low
2633
2639
  def parent_system
2634
2640
  return self.top_scope.parent
2635
2641
  end
2642
+
2643
+ # Tell if the statement includes a signal whose name is one of +names+.
2644
+ def use_name?(*names)
2645
+ # By default, nothing to do.
2646
+ end
2636
2647
  end
2637
2648
 
2638
2649
 
@@ -2747,6 +2758,11 @@ module HDLRuby::Low
2747
2758
  # A ruby block?
2748
2759
  # Nothing to do.
2749
2760
  end
2761
+
2762
+ # Tell if the statement includes a signal whose name is one of +names+.
2763
+ def use_name?(*names)
2764
+ return @left.use_name?(*names) || @right.use_name?(*names)
2765
+ end
2750
2766
  end
2751
2767
 
2752
2768
 
@@ -2925,6 +2941,12 @@ module HDLRuby::Low
2925
2941
  @no.each_block_deep(&ruby_block) if @no
2926
2942
  end
2927
2943
 
2944
+ # Tell if the statement includes a signal whose name is one of +names+.
2945
+ # NOTE: for the if check only the condition.
2946
+ def use_name?(*names)
2947
+ return @condition.use_name?(*name)
2948
+ end
2949
+
2928
2950
  # Clones the If (deeply)
2929
2951
  def clone
2930
2952
  # Duplicate the if.
@@ -3038,6 +3060,12 @@ module HDLRuby::Low
3038
3060
  def top_block
3039
3061
  return self.parent.is_a?(Behavior) ? self : self.parent.top_block
3040
3062
  end
3063
+
3064
+ # Tell if the statement includes a signal whose name is one of +names+.
3065
+ # NOTE: for the when check only the match.
3066
+ def use_name?(*names)
3067
+ return @match.use_name?(*name)
3068
+ end
3041
3069
  end
3042
3070
 
3043
3071
 
@@ -3186,6 +3214,12 @@ module HDLRuby::Low
3186
3214
  @default.each_statement_deep(&ruby_block) if @default
3187
3215
  end
3188
3216
 
3217
+ # Tell if the statement includes a signal whose name is one of +names+.
3218
+ # NOTE: for the case check only the value.
3219
+ def use_name?(*names)
3220
+ return @value.use_name?(*name)
3221
+ end
3222
+
3189
3223
  # Clones the Case (deeply)
3190
3224
  def clone
3191
3225
  # Clone the default if any.
@@ -3838,6 +3872,12 @@ module HDLRuby::Low
3838
3872
  end
3839
3873
  end
3840
3874
 
3875
+ # Tell if the expression includes a signal whose name is one of +names+.
3876
+ def use_name?(*names)
3877
+ # By default nothing.
3878
+ return false
3879
+ end
3880
+
3841
3881
  # Clones the expression (deeply)
3842
3882
  def clone
3843
3883
  raise AnyError,
@@ -3991,6 +4031,12 @@ module HDLRuby::Low
3991
4031
  @child.each_ref_deep(&ruby_block)
3992
4032
  end
3993
4033
 
4034
+ # Tell if the expression includes a signal whose name is one of +names+.
4035
+ def use_name?(*names)
4036
+ # Recurse on the child.
4037
+ return @child.use_name?(*names)
4038
+ end
4039
+
3994
4040
  # Clones the value (deeply)
3995
4041
  def clone
3996
4042
  return Cast.new(@type,@child.clone)
@@ -4101,6 +4147,12 @@ module HDLRuby::Low
4101
4147
  @child.each_ref_deep(&ruby_block)
4102
4148
  end
4103
4149
 
4150
+ # Tell if the expression includes a signal whose name is one of +names+.
4151
+ def use_name?(*names)
4152
+ # Recurse on the child.
4153
+ return @child.use_name?(*names)
4154
+ end
4155
+
4104
4156
  # Clones the unary operator (deeply)
4105
4157
  def clone
4106
4158
  return Unary.new(@type,self.operator,@child.clone)
@@ -4187,6 +4239,12 @@ module HDLRuby::Low
4187
4239
  @right.each_ref_deep(&ruby_block)
4188
4240
  end
4189
4241
 
4242
+ # Tell if the expression includes a signal whose name is one of +names+.
4243
+ def use_name?(*names)
4244
+ # Recurse on the left and the right.
4245
+ return @left.use_name?(*names) || @right.use_name?(*names)
4246
+ end
4247
+
4190
4248
  # Clones the binary operator (deeply)
4191
4249
  def clone
4192
4250
  return Binary.new(@type, self.operator,
@@ -4311,6 +4369,14 @@ module HDLRuby::Low
4311
4369
  end
4312
4370
  end
4313
4371
 
4372
+ # Tell if the expression includes a signal whose name is one of +names+.
4373
+ def use_name?(*names)
4374
+ # Recurse on the select.
4375
+ return true if @select.use_name?(*names)
4376
+ # Recurse on the choices.
4377
+ return @choices.any? { |choice| choice.use_name?(*names) }
4378
+ end
4379
+
4314
4380
  # Clones the select (deeply)
4315
4381
  def clone
4316
4382
  return Select.new(@type, self.operator, @select.clone,
@@ -4390,6 +4456,12 @@ module HDLRuby::Low
4390
4456
  end
4391
4457
  end
4392
4458
 
4459
+ # Tell if the expression includes a signal whose name is one of +names+.
4460
+ def use_name?(*names)
4461
+ # Recurse on the expressions.
4462
+ return @expressions.any? { |expr| expr.use_name?(*names) }
4463
+ end
4464
+
4393
4465
  # Clones the concatenated expression (deeply)
4394
4466
  def clone
4395
4467
  return Concat.new(@type,
@@ -4532,6 +4604,12 @@ module HDLRuby::Low
4532
4604
  end
4533
4605
  end
4534
4606
 
4607
+ # Tell if the expression includes a signal whose name is one of +names+.
4608
+ def use_name?(*names)
4609
+ # Recurse on the references.
4610
+ return @refs.any? { |expr| expr.use_name?(*names) }
4611
+ end
4612
+
4535
4613
  # Clones the concatenated references (deeply)
4536
4614
  def clone
4537
4615
  return RefConcat.new(@type, @refs.map { |ref| ref.clone } )
@@ -4615,6 +4693,12 @@ module HDLRuby::Low
4615
4693
  @ref.each_node_deep(&ruby_block)
4616
4694
  end
4617
4695
 
4696
+ # Tell if the expression includes a signal whose name is one of +names+.
4697
+ def use_name?(*names)
4698
+ # Recurse on the index and the reference.
4699
+ return @index.use_name?(names) || @ref.use_name?(*names)
4700
+ end
4701
+
4618
4702
  # Clones the indexed references (deeply)
4619
4703
  def clone
4620
4704
  return RefIndex.new(@type, @ref.clone, @index.clone)
@@ -4710,6 +4794,13 @@ module HDLRuby::Low
4710
4794
  @ref.each_node_deep(&ruby_block)
4711
4795
  end
4712
4796
 
4797
+ # Tell if the expression includes a signal whose name is one of +names+.
4798
+ def use_name?(*names)
4799
+ # Recurse on the range and the reference.
4800
+ return @range.first.use_name?(names) ||
4801
+ @range.last.use_name?(names) || @ref.use_name?(*names)
4802
+ end
4803
+
4713
4804
  # Clones the range references (deeply)
4714
4805
  def clone
4715
4806
  return RefRange.new(@type, @ref.clone,
@@ -4797,6 +4888,14 @@ module HDLRuby::Low
4797
4888
  @ref.each_node_deep(&ruby_block)
4798
4889
  end
4799
4890
 
4891
+ # Tell if the expression includes a signal whose name is one of +names+.
4892
+ def use_name?(*names)
4893
+ # Is the named used here?
4894
+ return true if names.include?(@name)
4895
+ # No, recurse the reference.
4896
+ return @ref.use_name?(*names)
4897
+ end
4898
+
4800
4899
  # Clones the name references (deeply)
4801
4900
  def clone
4802
4901
  return RefName.new(@type, @ref.clone, @name)
@@ -106,13 +106,13 @@ module HDLRuby::Low
106
106
 
107
107
  ## Generates the main for making the objects of +objs+ and
108
108
  # for starting the simulation and including the files from +hnames+
109
- def self.main(top,objs,hnames)
109
+ def self.main(name,init_visualizer,top,objs,hnames)
110
110
  res = Low2C.includes(*hnames)
111
111
  res << "int main(int argc, char* argv[]) {\n"
112
112
  # Build the objects.
113
113
  objs.each { |obj| res << " #{Low2C.make_name(obj)}();\n" }
114
114
  # Starts the simulation.
115
- res << " hruby_sim_core(-1);\n"
115
+ res<< " hruby_sim_core(\"#{name}\",#{init_visualizer},-1);\n"
116
116
  # Close the main.
117
117
  res << "}\n"
118
118
  return res
@@ -1612,7 +1612,9 @@ module HDLRuby::Low
1612
1612
  # return "equal_value(#{self.left.to_c(level)}," +
1613
1613
  # "#{self.right.to_c(level)})"
1614
1614
  # when :!= then
1615
- # return "not_equal_value(#{self.left.to_c(level)}," +
1615
+ # # return "not_equal_value(#{self.left.to_c(level)}," +
1616
+ # # "#{self.right.to_c(level)})"
1617
+ # return "xor_value(#{self.left.to_c(level)}," +
1616
1618
  # "#{self.right.to_c(level)})"
1617
1619
  # when :> then
1618
1620
  # return "greater_value(#{self.left.to_c(level)}," +
@@ -1681,9 +1683,12 @@ module HDLRuby::Low
1681
1683
  when :rr then
1682
1684
  res += "dst = rotate_right_value(src0,src1,dst);\n"
1683
1685
  when :== then
1684
- res += "dst = equal_value(src0,src1,dst);\n"
1686
+ res += "dst = equal_value(src0,src1,dst);\n" +
1687
+ "dst = reduce_or_value(dst,dst);"
1685
1688
  when :!= then
1686
- res += "dst = not_equal_value(src0,src1,dst);\n"
1689
+ # res += "dst = not_equal_value(src0,src1,dst);\n"
1690
+ res += "dst = xor_value(src0,src1,dst);\n" +
1691
+ "dst = reduce_or_value(dst,dst);"
1687
1692
  when :> then
1688
1693
  res += "dst = greater_value(src0,src1,dst);\n"
1689
1694
  when :< then
@@ -156,7 +156,7 @@ module HDLRuby::Low
156
156
  end
157
157
  end
158
158
 
159
- # Deletes an type.
159
+ # Deletes a type.
160
160
  def delete_type!(type)
161
161
  if @types.key?(type.name) then
162
162
  # The type is present, delete it.
@@ -167,7 +167,7 @@ module HDLRuby::Low
167
167
  type
168
168
  end
169
169
 
170
- # Deletes an systemT.
170
+ # Deletes a systemT.
171
171
  def delete_systemT!(systemT)
172
172
  if @systemTs.key?(systemT.name) then
173
173
  # The systemT is present, delete it.
@@ -230,6 +230,33 @@ module HDLRuby::Low
230
230
  behavior.parent = nil
231
231
  end
232
232
  end
233
+
234
+ # Deletes the elements related to one of +names+: either they have
235
+ # one of the names or they use an element with these names.
236
+ # NOTE: only delete actual instantiated elements, types or
237
+ # systemTs are left as is.
238
+ def delete_related!(*names)
239
+ # Delete the sub scopes whose name are in names.
240
+ @scopes.delete_if { |scope| names.include?(scope.name) }
241
+ # Delete the inner signals whose name are in names.
242
+ @inners.delete_if { |sig| names.include?(sig.name) }
243
+ # Delete the connections that contain signals whose name are
244
+ # in names.
245
+ @connections.delete_if { |connection| connection.use_name?(*names) }
246
+ # Delete the behaviors whose block name or events' name are in
247
+ # names.
248
+ @behaviors.delete_if do |behavior|
249
+ names.include?(behavior.block.name) or
250
+ behavior.each_event.include? do |event|
251
+ event.ref.use_name?(*names)
252
+ end
253
+ end
254
+
255
+ # Recurse on the sub scopes.
256
+ @scopes.each { |scope| scope.delete_related!(names) }
257
+ # Recurse on the behaviors.
258
+ @behaviors.each { |behavior| behavior.block.delete_related!(names) }
259
+ end
233
260
  end
234
261
 
235
262
 
@@ -514,6 +541,14 @@ module HDLRuby::Low
514
541
  # By default: nothing to do.
515
542
  return {}
516
543
  end
544
+
545
+ # Deletes the elements related to one of +names+: either they have
546
+ # one of the names or they use an element with these names.
547
+ # NOTE: only delete actual instantiated elements, types or
548
+ # systemTs are left as is.
549
+ def delete_related!(*names)
550
+ # Nothing to do by default.
551
+ end
517
552
  end
518
553
 
519
554
 
@@ -694,6 +729,21 @@ module HDLRuby::Low
694
729
 
695
730
  return res
696
731
  end
732
+
733
+ # Deletes the elements related to one of +names+: either they have
734
+ # one of the names or they use an element with these names.
735
+ # NOTE: only delete actual instantiated elements, types or
736
+ # systemTs are left as is.
737
+ def delete_related!(*names)
738
+ # Delete the noifs if their condition uses one of names.
739
+ @noifs.delete_if { |noif| noif[0].use_names?(names) }
740
+ # Recurse on the yes.
741
+ @yes.delete_related!(*names)
742
+ # Recurse on the no.
743
+ @no.delete_related!(*names)
744
+ # Recruse one the no ifs statements.
745
+ @noifs.each { |noif| noif[1].delete_related!(*names) }
746
+ end
697
747
  end
698
748
 
699
749
  ##
@@ -758,6 +808,15 @@ module HDLRuby::Low
758
808
 
759
809
  return res
760
810
  end
811
+
812
+ # Deletes the elements related to one of +names+: either they have
813
+ # one of the names or they use an element with these names.
814
+ # NOTE: only delete actual instantiated elements, types or
815
+ # systemTs are left as is.
816
+ def delete_related!(*names)
817
+ # Recurse on the statement.
818
+ @statement.delete_related!(*names)
819
+ end
761
820
  end
762
821
 
763
822
 
@@ -833,6 +892,18 @@ module HDLRuby::Low
833
892
 
834
893
  return res
835
894
  end
895
+
896
+ # Deletes the elements related to one of +names+: either they have
897
+ # one of the names or they use an element with these names.
898
+ # NOTE: only delete actual instantiated elements, types or
899
+ # systemTs are left as is.
900
+ def delete_related!(*names)
901
+ # Delete the whens whose match contains a signal whoses name is
902
+ # in names.
903
+ @whens.delete_if { |w| w.match.use_name?(*names) }
904
+ # Recurse on the whens.
905
+ @whens.each { |w| w.delete_related!(*names) }
906
+ end
836
907
  end
837
908
 
838
909
 
@@ -1091,8 +1162,25 @@ module HDLRuby::Low
1091
1162
  end
1092
1163
  end
1093
1164
  end
1165
+
1166
+ # Deletes the elements related to one of +names+: either they have
1167
+ # one of the names or they use an element with these names.
1168
+ # NOTE: only delete actual instantiated elements, types or
1169
+ # systemTs are left as is.
1170
+ def delete_related!(*names)
1171
+ # Delete the inner signals whose name are in names.
1172
+ @inners.delete_if { |sig| names.include?(sig.name) }
1173
+ # Recurse on the statements.
1174
+ @statements.each do |statement|
1175
+ statement.delete_related!(*names)
1176
+ end
1177
+ # Delete the statements that contain signals whose name are
1178
+ # in names.
1179
+ @statements.delete_if { |statement| statement.use_name?(*names) }
1180
+ end
1094
1181
  end
1095
1182
 
1183
+
1096
1184
  # Describes a timed block.
1097
1185
  #
1098
1186
  # NOTE:
@@ -145,6 +145,7 @@ module HDLRuby::Low
145
145
  # puts "Resolve with #{self} and name=#{self.name}"
146
146
  # First resolve the sub reference if possible.
147
147
  if self.ref.is_a?(RefName) then
148
+ # puts "ref name=#{self.ref.name}"
148
149
  obj = self.ref.resolve
149
150
  # Look into the object for the name.
150
151
  return obj.get_by_name(self.name)
@@ -29,7 +29,9 @@ module HDLRuby::Low
29
29
  if scope.each_connection.to_a.any? then
30
30
  inputs_blk = Block.new(:par)
31
31
  outputs_blk = Block.new(:par)
32
+ timed_blk = TimeBlock.new(:seq)
32
33
  scope.each_connection do |connection|
34
+ # puts "For connection: #{connection}"
33
35
  # Check the left and right of the connection
34
36
  # for input or output port.
35
37
  left = connection.left
@@ -40,6 +42,15 @@ module HDLRuby::Low
40
42
  right_r = right.resolve if right.respond_to?(:resolve)
41
43
  # puts "right_r=#{right_r.name}" if right_r
42
44
  # puts "right_r.parent=#{right_r.parent.name}" if right_r && right_r.parent
45
+ if right.is_a?(Value) then
46
+ # Right is value, the new transmit is to add
47
+ # to the timed block.
48
+ timed_blk.add_statement(
49
+ Transmit.new(left.clone,right.clone))
50
+ # No more process for this connection.
51
+ next
52
+ end
53
+
43
54
  # Check if left is an input or an output.
44
55
  left_is_i = left_is_o = false
45
56
  if left_r && left_r.parent.is_a?(SystemT) then
@@ -118,6 +129,9 @@ module HDLRuby::Low
118
129
  if outputs_blk.each_statement.any? then
119
130
  scope.add_behavior(Behavior.new(outputs_blk))
120
131
  end
132
+ if timed_blk.each_statement.any? then
133
+ scope.add_behavior(TimeBehavior.new(timed_blk))
134
+ end
121
135
  end
122
136
  end
123
137
  end