HDLRuby 2.9.0 → 2.10.5

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.
@@ -38,7 +38,7 @@ module HDLRuby::High
38
38
  # puts "eigen_extend for #{self} class=#{self.class}"
39
39
  obj.singleton_methods.each do |name|
40
40
  next if name == :yaml_tag # Do not know why we need to skip
41
- # puts "name=#{name}"
41
+ puts "name=#{name}"
42
42
  self.define_singleton_method(name, &obj.singleton_method(name))
43
43
  end
44
44
  end
@@ -87,10 +87,11 @@ module HDLRuby::High
87
87
  raise AnyError,
88
88
  "Resevered name #{name} cannot be overridden."
89
89
  end
90
- if self.respond_to?(name) then
91
- raise AnyError,
92
- "Symbol #{name} is already defined."
93
- end
90
+ # Deactivated: overriding is now accepted.
91
+ # if self.respond_to?(name) then
92
+ # raise AnyError,
93
+ # "Symbol #{name} is already defined."
94
+ # end
94
95
  define_singleton_method(name,&ruby_block)
95
96
  end
96
97
  end
@@ -441,9 +442,9 @@ module HDLRuby::High
441
442
  res = self.add_output(SignalI.new(name,type,:output))
442
443
  elsif name.is_a?(Hash) then
443
444
  # Names associated with values.
444
- names.each do |name,value|
445
- res = self.add_inner(
446
- SignalI.new(name,type,:inner,value))
445
+ name.each do |key,value|
446
+ res = self.add_output(
447
+ SignalI.new(key,type,:output,value))
447
448
  end
448
449
  else
449
450
  raise AnyError, "Invalid class for a name: #{name.class}"
@@ -474,6 +475,21 @@ module HDLRuby::High
474
475
  end
475
476
 
476
477
 
478
+ # Gets an input signal by +name+ considering also the included
479
+ # systems
480
+ def get_input_with_included(name)
481
+ # Look in self.
482
+ found = self.get_input(name)
483
+ return found if found
484
+ # Not in self, look in the included systems.
485
+ self.scope.each_included do |included|
486
+ found = included.get_input_with_included(name)
487
+ return found if found
488
+ end
489
+ # Not found
490
+ return nil
491
+ end
492
+
477
493
  # Gets an output signal by +name+ considering also the included
478
494
  # systems
479
495
  def get_output_with_included(name)
@@ -489,6 +505,36 @@ module HDLRuby::High
489
505
  return nil
490
506
  end
491
507
 
508
+ # Gets an inout signal by +name+ considering also the included
509
+ # systems
510
+ def get_inout_with_included(name)
511
+ # Look in self.
512
+ found = self.get_inout(name)
513
+ return found if found
514
+ # Not in self, look in the included systems.
515
+ self.scope.each_included do |included|
516
+ found = included.get_inout_with_included(name)
517
+ return found if found
518
+ end
519
+ # Not found
520
+ return nil
521
+ end
522
+
523
+ # Iterates over the all signals (input, output, inout, inner, constant),
524
+ # i.e, also the ones of the included systems.
525
+ #
526
+ # Returns an enumerator if no ruby block is given.
527
+ def each_signal_all_with_included(&ruby_block)
528
+ # No ruby block? Return an enumerator.
529
+ return to_enum(:each_signal_all_with_included) unless ruby_block
530
+ # Iterate on all the signals of the current system.
531
+ self.each_signal_all(&ruby_block)
532
+ # Recurse on the included systems.
533
+ self.scope.each_included do |included|
534
+ included.each_signal_all_with_included(&ruby_block)
535
+ end
536
+ end
537
+
492
538
  # Iterates over the all interface signals, i.e, also the ones of
493
539
  # the included systems.
494
540
  #
@@ -496,7 +542,7 @@ module HDLRuby::High
496
542
  def each_signal_with_included(&ruby_block)
497
543
  # No ruby block? Return an enumerator.
498
544
  return to_enum(:each_signal_with_included) unless ruby_block
499
- # Iterate on the signals of the current system.
545
+ # Iterate on all the signals of the current system.
500
546
  self.each_signal(&ruby_block)
501
547
  # Recurse on the included systems.
502
548
  self.scope.each_included do |included|
@@ -510,6 +556,14 @@ module HDLRuby::High
510
556
  return each_signal_with_included.to_a[i]
511
557
  end
512
558
 
559
+ # Gets a signal by +name+ considering also the included
560
+ # systems
561
+ def get_signal_with_included(name)
562
+ return get_input_with_included(name) ||
563
+ get_output_with_included(name) ||
564
+ get_inout_with_included(name)
565
+ end
566
+
513
567
  # Iterates over the exported constructs
514
568
  #
515
569
  # NOTE: look into the scope.
@@ -616,7 +670,6 @@ module HDLRuby::High
616
670
  # Fill the public namespace
617
671
  space = self.public_namespace
618
672
  # Interface signals
619
- # puts "i_name=#{i_name} @to_includes=#{@to_includes.size}"
620
673
  self.each_signal do |signal|
621
674
  # puts "signal=#{signal.name}"
622
675
  space.send(:define_singleton_method,signal.name) do
@@ -869,7 +922,8 @@ module HDLRuby::High
869
922
  # Initialize the set of exported inner signals and instances
870
923
  @exports = {}
871
924
  # Initialize the set of included systems.
872
- @includes = {}
925
+ # @includes = {}
926
+ @includes = []
873
927
 
874
928
  # Builds the scope if a ruby block is provided.
875
929
  self.build(&ruby_block) if block_given?
@@ -956,7 +1010,8 @@ module HDLRuby::High
956
1010
  # No ruby block? Return an enumerator.
957
1011
  return to_enum(:each_included) unless ruby_block
958
1012
  # A block? Apply it on each included system.
959
- @includes.each_value(&ruby_block)
1013
+ # @includes.each_value(&ruby_block)
1014
+ @includes.each(&ruby_block)
960
1015
  # And apply on the sub scopes if any.
961
1016
  @scopes.each {|scope| scope.each_included(&ruby_block) }
962
1017
  end
@@ -1126,6 +1181,8 @@ module HDLRuby::High
1126
1181
 
1127
1182
  # Declares a sub scope with possible +name+ and built from +ruby_block+.
1128
1183
  def sub(name = :"", &ruby_block)
1184
+ # Ensure there is a block.
1185
+ ruby_block = proc {} unless block_given?
1129
1186
  # Creates the new scope.
1130
1187
  # scope = Scope.new(name,&ruby_block)
1131
1188
  scope = Scope.new(name)
@@ -1142,6 +1199,8 @@ module HDLRuby::High
1142
1199
  # Declares a high-level sequential behavior activated on a list of
1143
1200
  # +events+, and built by executing +ruby_block+.
1144
1201
  def seq(*events, &ruby_block)
1202
+ # Ensure there is a block.
1203
+ ruby_block = proc {} unless block_given?
1145
1204
  # Preprocess the events.
1146
1205
  events.map! do |event|
1147
1206
  event.respond_to?(:to_event) ? event.to_event : event
@@ -1153,6 +1212,8 @@ module HDLRuby::High
1153
1212
  # Declares a high-level parallel behavior activated on a list of
1154
1213
  # +events+, and built by executing +ruby_block+.
1155
1214
  def par(*events, &ruby_block)
1215
+ # Ensure there is a block.
1216
+ ruby_block = proc {} unless block_given?
1156
1217
  # Preprocess the events.
1157
1218
  events.map! do |event|
1158
1219
  event.respond_to?(:to_event) ? event.to_event : event
@@ -1164,6 +1225,8 @@ module HDLRuby::High
1164
1225
  # Declares a high-level timed behavior built by executing +ruby_block+.
1165
1226
  # By default, timed behavior are sequential.
1166
1227
  def timed(&ruby_block)
1228
+ # Ensure there is a block.
1229
+ ruby_block = proc {} unless block_given?
1167
1230
  # Create and add the resulting behavior.
1168
1231
  self.add_behavior(TimeBehavior.new(:seq,&ruby_block))
1169
1232
  end
@@ -1177,6 +1240,8 @@ module HDLRuby::High
1177
1240
  # * the else part is defined through the helse method.
1178
1241
  # * a behavior is created to enclose the hif.
1179
1242
  def hif(condition, mode = nil, &ruby_block)
1243
+ # Ensure there is a block.
1244
+ ruby_block = proc {} unless block_given?
1180
1245
  self.par do
1181
1246
  hif(condition,mode,&ruby_block)
1182
1247
  end
@@ -1189,6 +1254,8 @@ module HDLRuby::High
1189
1254
  #
1190
1255
  # NOTE: added to the hif of the last behavior.
1191
1256
  def helse(mode = nil, &ruby_block)
1257
+ # Ensure there is a block.
1258
+ ruby_block = proc {} unless block_given?
1192
1259
  # There is a ruby_block: the helse is assumed to be with
1193
1260
  # the last statement of the last behavior.
1194
1261
  statement = self.last_behavior.last_statement
@@ -1203,6 +1270,8 @@ module HDLRuby::High
1203
1270
  # with a +condition+ that when met lead
1204
1271
  # to the execution of the block in +mode+ generated by the +ruby_block+.
1205
1272
  def helsif(condition, mode = nil, &ruby_block)
1273
+ # Ensure there is a block.
1274
+ ruby_block = proc {} unless block_given?
1206
1275
  # There is a ruby_block: the helse is assumed to be with
1207
1276
  # the last statement of the last behavior.
1208
1277
  statement = self.last_behavior.last_statement
@@ -1230,6 +1299,8 @@ module HDLRuby::High
1230
1299
  #
1231
1300
  # Can only be used once.
1232
1301
  def hwhen(match, mode = nil, &ruby_block)
1302
+ # Ensure there is a block.
1303
+ ruby_block = proc {} unless block_given?
1233
1304
  # There is a ruby_block: the helse is assumed to be with
1234
1305
  # the last statement of the last behavior.
1235
1306
  statement = @behaviors.last.last_statement
@@ -1249,13 +1320,16 @@ module HDLRuby::High
1249
1320
  # Include a +system+ type with possible +args+ instanciation
1250
1321
  # arguments.
1251
1322
  def include(system,*args)
1252
- if @includes.key?(system.name) then
1253
- raise AnyError, "Cannot include twice the same system."
1323
+ # if @includes.key?(system.name) then
1324
+ # raise AnyError, "Cannot include twice the same system: #{system}"
1325
+ # end
1326
+ if @includes.include?(system) then
1327
+ raise AnyError, "Cannot include twice the same system: #{system}"
1254
1328
  end
1255
- # puts "Include system=#{system.name}"
1256
- # Save the name of the included system, it will serve as key
1257
- # for looking for the included expanded version.
1258
- include_name = system.name
1329
+ # # puts "Include system=#{system.name}"
1330
+ # # Save the name of the included system, it will serve as key
1331
+ # # for looking for the included expanded version.
1332
+ # include_name = system.name
1259
1333
  # Expand the system to include
1260
1334
  system = system.expand(:"",*args)
1261
1335
  # Add the included system interface to the current one.
@@ -1263,7 +1337,8 @@ module HDLRuby::High
1263
1337
  space = self.namespace
1264
1338
  # Interface signals
1265
1339
  # puts "i_name=#{i_name} @to_includes=#{@to_includes.size}"
1266
- system.each_signal_with_included do |signal|
1340
+ # system.each_signal_with_included do |signal|
1341
+ system.each_signal_all_with_included do |signal|
1267
1342
  # puts "signal=#{signal.name}"
1268
1343
  space.send(:define_singleton_method,signal.name) do
1269
1344
  signal
@@ -1282,18 +1357,20 @@ module HDLRuby::High
1282
1357
  end
1283
1358
  end
1284
1359
  # Adds it the list of includeds
1285
- @includes[include_name] = system
1360
+ # @includes[include_name] = system
1361
+ @includes << system
1362
+
1286
1363
  # puts "@includes=#{@includes}"
1287
1364
 
1288
1365
  end
1289
1366
 
1290
- # Casts as an included +system+.
1291
- def as(system)
1292
- # puts "as with name: #{system.name}"
1293
- system = system.name if system.respond_to?(:name)
1294
- # puts "includes are: #{@includes.keys}"
1295
- return @includes[system].namespace
1296
- end
1367
+ # Obsolete
1368
+ # # Casts as an included +system+.
1369
+ # def as(system)
1370
+ # # puts "as with name: #{system.name}"
1371
+ # system = system.name if system.respond_to?(:name)
1372
+ # return @includes[system].namespace
1373
+ # end
1297
1374
 
1298
1375
 
1299
1376
  # Gets the current system.
@@ -1308,7 +1385,8 @@ module HDLRuby::High
1308
1385
  # NOTE: name conflicts are treated in the current NameStack state.
1309
1386
  def fill_low(scopeL)
1310
1387
  # Adds the content of its included systems.
1311
- @includes.each_value {|system| system.scope.fill_low(scopeL) }
1388
+ # @includes.each_value {|system| system.scope.fill_low(scopeL) }
1389
+ @includes.each {|system| system.scope.fill_low(scopeL) }
1312
1390
  # Adds the declared local system types.
1313
1391
  # NOTE: in the current version of HDLRuby::High, there should not
1314
1392
  # be any of them (only eigen systems are real system types).
@@ -1545,6 +1623,8 @@ module HDLRuby::High
1545
1623
 
1546
1624
  # Redefinition of +operator+.
1547
1625
  def define_operator(operator,&ruby_block)
1626
+ # Ensure there is a block.
1627
+ ruby_block = proc {} unless block_given?
1548
1628
  # Register the operator as overloaded.
1549
1629
  @overloads ||= {}
1550
1630
  @overloads[operator] = ruby_block
@@ -1941,6 +2021,8 @@ module HDLRuby::High
1941
2021
  # Declares a high-level generic type named +name+, and using +ruby_block+
1942
2022
  # for construction.
1943
2023
  def typedef(name, &ruby_block)
2024
+ # Ensure there is a block.
2025
+ ruby_block = proc {} unless block_given?
1944
2026
  type = TypeGen.new(name,&ruby_block)
1945
2027
  if HDLRuby::High.in_system? then
1946
2028
  # Must be inside a scope.
@@ -1976,6 +2058,8 @@ module HDLRuby::High
1976
2058
  # Declares a high-level system type named +name+, with +includes+ mixins
1977
2059
  # system types and using +ruby_block+ for instantiating.
1978
2060
  def system(name = :"", *includes, &ruby_block)
2061
+ # Ensure there is a block.
2062
+ ruby_block = proc {} unless block_given?
1979
2063
  # print "system ruby_block=#{ruby_block}\n"
1980
2064
  # Creates the resulting system.
1981
2065
  return SystemT.new(name,*includes,&ruby_block)
@@ -1987,6 +2071,8 @@ module HDLRuby::High
1987
2071
  # NOTE: this is for generating directly an instance without declaring
1988
2072
  # it system type.
1989
2073
  def instance(name, *includes, &ruby_block)
2074
+ # Ensure there is a block.
2075
+ ruby_block = proc {} unless block_given?
1990
2076
  # Creates the system type.
1991
2077
  systemT = system(:"",*includes,&ruby_block)
1992
2078
  # Instantiate it with +name+.
@@ -1999,6 +2085,8 @@ module HDLRuby::High
1999
2085
  #
2000
2086
  # NOTE: a function is a short-cut for a method that creates a scope.
2001
2087
  def function(name, &ruby_block)
2088
+ # Ensure there is a block.
2089
+ ruby_block = proc {} unless block_given?
2002
2090
  if HDLRuby::High.in_system? then
2003
2091
  define_singleton_method(name.to_sym) do |*args,&other_block|
2004
2092
  # sub do
@@ -2074,26 +2162,28 @@ module HDLRuby::High
2074
2162
  # Performs the connections.
2075
2163
  connects.each do |key,value|
2076
2164
  # Gets the signal corresponding to connect.
2077
- signal = self.get_signal(key)
2078
- unless signal then
2079
- # Look into the included systems.
2080
- self.systemT.scope.each_included do |included|
2081
- signal = included.get_signal(key)
2082
- break if signal
2083
- end
2084
- end
2165
+ # signal = self.get_signal(key)
2166
+ # unless signal then
2167
+ # # Look into the included systems.
2168
+ # self.systemT.scope.each_included do |included|
2169
+ # signal = included.get_signal(key)
2170
+ # break if signal
2171
+ # end
2172
+ # end
2173
+ signal = self.systemT.get_signal_with_included(key)
2085
2174
  # Check if it is an output.
2086
- isout = self.get_output(key)
2087
- unless isout then
2088
- # Look into the inlucded systems.
2089
- self.systemT.scope.each_included do |included|
2090
- isout = included.get_output(key)
2091
- break if isout
2092
- end
2093
- end
2175
+ # isout = self.get_output(key)
2176
+ # unless isout then
2177
+ # # Look into the inlucded systems.
2178
+ # self.systemT.scope.each_included do |included|
2179
+ # isout = included.get_output(key)
2180
+ # break if isout
2181
+ # end
2182
+ # end
2183
+ isout = self.systemT.get_output_with_included(key)
2094
2184
  # Convert it to a reference.
2185
+ # puts "key=#{key} value=#{value} signal=#{signal}"
2095
2186
  ref = RefObject.new(self.to_ref,signal)
2096
- # puts "key=#{key} value=#{value} signal=#{signal} ref=#{ref}"
2097
2187
  # Make the connection.
2098
2188
  if isout then
2099
2189
  value <= ref
@@ -2135,6 +2225,8 @@ module HDLRuby::High
2135
2225
  # NOTE: actually executes +ruby_block+ in the context of the
2136
2226
  # systemT.
2137
2227
  def open(&ruby_block)
2228
+ # Ensure there is a block.
2229
+ ruby_block = proc {} unless block_given?
2138
2230
  # Extend the eigen system.
2139
2231
  @systemT.run(&ruby_block)
2140
2232
  # Update the methods.
@@ -2196,7 +2288,15 @@ module HDLRuby::High
2196
2288
  # system type.
2197
2289
  def method_missing(m, *args, &ruby_block)
2198
2290
  # print "method_missing in class=#{self.class} with m=#{m}\n"
2199
- self.public_namespace.send(m,*args,&ruby_block)
2291
+ # Maybe its a signal reference.
2292
+ signal = self.systemT.get_signal_with_included(m)
2293
+ if signal then
2294
+ # Yes, create the reference.
2295
+ return RefObject.new(self.to_ref,signal)
2296
+ else
2297
+ # No try elsewhere
2298
+ self.public_namespace.send(m,*args,&ruby_block)
2299
+ end
2200
2300
  end
2201
2301
 
2202
2302
 
@@ -2331,6 +2431,8 @@ module HDLRuby::High
2331
2431
  #
2332
2432
  # Can only be used once.
2333
2433
  def helse(mode = nil, &ruby_block)
2434
+ # Ensure there is a block.
2435
+ ruby_block = proc {} unless block_given?
2334
2436
  # If there is a no block, it is an error.
2335
2437
  raise AnyError, "Cannot have two helse for a single if statement." if self.no
2336
2438
  # Create the no block if required
@@ -2345,6 +2447,8 @@ module HDLRuby::High
2345
2447
  #
2346
2448
  # Can only be used if the no-block is not set yet.
2347
2449
  def helsif(next_cond, mode = nil, &ruby_block)
2450
+ # Ensure there is a block.
2451
+ ruby_block = proc {} unless block_given?
2348
2452
  # If there is a no block, it is an error.
2349
2453
  raise AnyError, "Cannot have an helsif after an helse." if self.no
2350
2454
  # Create the noif block if required
@@ -2413,6 +2517,8 @@ module HDLRuby::High
2413
2517
  #
2414
2518
  # Can only be used once for the given +match+.
2415
2519
  def hwhen(match, mode = nil, &ruby_block)
2520
+ # Ensure there is a block.
2521
+ ruby_block = proc {} unless block_given?
2416
2522
  # Create the nu block if required
2417
2523
  when_block = High.make_block(mode,&ruby_block)
2418
2524
  # Adds the case.
@@ -2424,6 +2530,8 @@ module HDLRuby::High
2424
2530
  #
2425
2531
  # Can only be used once.
2426
2532
  def helse(mode = nil, &ruby_block)
2533
+ # Ensure there is a block.
2534
+ ruby_block = proc {} unless block_given?
2427
2535
  # Create the nu block if required
2428
2536
  default_block = High.make_block(mode,&ruby_block)
2429
2537
  # Sets the default block.
@@ -3158,7 +3266,8 @@ module HDLRuby::High
3158
3266
 
3159
3267
  # Converts the name reference to a HDLRuby::Low::RefName.
3160
3268
  def to_low
3161
- # puts "to_low with base=#{@base} @object=#{@object.name}"
3269
+ # puts "to_low with base=#{@base} @object=#{@object}"
3270
+ # puts "@object.name=#{@object.name}"
3162
3271
  refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
3163
3272
  @base.to_ref.to_low,@object.name)
3164
3273
  # # For debugging: set the source high object
@@ -3794,11 +3903,15 @@ module HDLRuby::High
3794
3903
  # Creates a new block with the current mode with possible +name+ and
3795
3904
  # built from +ruby_block+.
3796
3905
  def sub(name = :"", &ruby_block)
3906
+ # Ensure there is a block.
3907
+ ruby_block = proc {} unless block_given?
3797
3908
  self.add_block(self.mode,name,&ruby_block)
3798
3909
  end
3799
3910
 
3800
3911
  # Adds statements at the top of the block.
3801
3912
  def unshift(&ruby_block)
3913
+ # Ensure there is a block.
3914
+ ruby_block = proc {} unless block_given?
3802
3915
  # Create a sub block for the statements.
3803
3916
  block = High.make_block(self.mode,:"",&ruby_block)
3804
3917
  # Unshifts it.
@@ -3843,6 +3956,8 @@ module HDLRuby::High
3843
3956
  #
3844
3957
  # NOTE: the else part is defined through the helse method.
3845
3958
  def hif(condition, mode = nil, &ruby_block)
3959
+ # Ensure there is a block.
3960
+ ruby_block = proc {} unless block_given?
3846
3961
  # Creates the if statement.
3847
3962
  self.add_statement(If.new(condition,mode,&ruby_block))
3848
3963
  end
@@ -3852,6 +3967,8 @@ module HDLRuby::High
3852
3967
  #
3853
3968
  # Can only be used once.
3854
3969
  def helse(mode = nil, &ruby_block)
3970
+ # Ensure there is a block.
3971
+ ruby_block = proc {} unless block_given?
3855
3972
  # There is a ruby_block: the helse is assumed to be with
3856
3973
  # the hif in the same block.
3857
3974
  # Completes the hif or the hcase statement.
@@ -3866,6 +3983,8 @@ module HDLRuby::High
3866
3983
  # with a +condition+ that when met lead
3867
3984
  # to the execution of the block in +mode+ generated by the +ruby_block+.
3868
3985
  def helsif(condition, mode = nil, &ruby_block)
3986
+ # Ensure there is a block.
3987
+ ruby_block = proc {} unless block_given?
3869
3988
  # There is a ruby_block: the helse is assumed to be with
3870
3989
  # the hif in the same block.
3871
3990
  # Completes the hif statement.
@@ -3893,6 +4012,8 @@ module HDLRuby::High
3893
4012
  #
3894
4013
  # Can only be used once.
3895
4014
  def hwhen(match, mode = nil, &ruby_block)
4015
+ # Ensure there is a block.
4016
+ ruby_block = proc {} unless block_given?
3896
4017
  # There is a ruby_block: the helse is assumed to be with
3897
4018
  # the hif in the same block.
3898
4019
  # Completes the hcase statement.
@@ -4008,6 +4129,8 @@ module HDLRuby::High
4008
4129
  # Adds a loop until +delay+ statement in the block in +mode+ whose
4009
4130
  # loop content is built using +ruby_block+.
4010
4131
  def repeat(delay, mode = nil, &ruby_block)
4132
+ # Ensure there is a block.
4133
+ ruby_block = proc {} unless block_given?
4011
4134
  # Build the content block.
4012
4135
  content = High.make_block(mode,&ruby_block)
4013
4136
  # Create and add the statement.
@@ -4666,6 +4789,8 @@ module HDLRuby::High
4666
4789
  # Creates a hcase statement executing +ruby_block+ on the element of
4667
4790
  # the array selected by +value+
4668
4791
  def hcase(value,&ruby_block)
4792
+ # Ensure there is a block.
4793
+ ruby_block = proc {} unless block_given?
4669
4794
  High.cur_block.hcase(value)
4670
4795
  self.each.with_index do |elem,i|
4671
4796
  High.cur_block.hwhen(i) { ruby_block.call(elem) }