HDLRuby 2.8.1 → 2.10.3

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.
@@ -344,6 +344,7 @@ module HDLRuby::High
344
344
  def initialize(name, *mixins, &ruby_block)
345
345
  # Initialize the system type structure.
346
346
  super(name,Scope.new(name,self))
347
+ # puts "new systemT=#{self}"
347
348
 
348
349
  # Initialize the set of extensions to transmit to the instances'
349
350
  # eigen class
@@ -373,6 +374,28 @@ module HDLRuby::High
373
374
  make_instantiater(name,SystemI,&ruby_block)
374
375
  end
375
376
 
377
+
378
+ # Tell if the current system is a descedent of +system+
379
+ def of?(system)
380
+ # Maybe self is system.
381
+ if (self == system) then
382
+ # Yes, consider it is adescendent of system.
383
+ return true
384
+ else
385
+ # Look into the generators.
386
+ @generators.each do |generator|
387
+ return true if generator.of?(system)
388
+ end
389
+ # Look into the included systems.
390
+ @to_includes.each do |included|
391
+ return true if included.of?(system)
392
+ end
393
+ end
394
+ # Not found.
395
+ return false
396
+ end
397
+
398
+
376
399
  # Converts to a namespace user.
377
400
  def to_user
378
401
  # Returns the scope.
@@ -418,9 +441,9 @@ module HDLRuby::High
418
441
  res = self.add_output(SignalI.new(name,type,:output))
419
442
  elsif name.is_a?(Hash) then
420
443
  # Names associated with values.
421
- names.each do |name,value|
422
- res = self.add_inner(
423
- SignalI.new(name,type,:inner,value))
444
+ name.each do |key,value|
445
+ res = self.add_output(
446
+ SignalI.new(key,type,:output,value))
424
447
  end
425
448
  else
426
449
  raise AnyError, "Invalid class for a name: #{name.class}"
@@ -451,6 +474,21 @@ module HDLRuby::High
451
474
  end
452
475
 
453
476
 
477
+ # Gets an input signal by +name+ considering also the included
478
+ # systems
479
+ def get_input_with_included(name)
480
+ # Look in self.
481
+ found = self.get_input(name)
482
+ return found if found
483
+ # Not in self, look in the included systems.
484
+ self.scope.each_included do |included|
485
+ found = included.get_input_with_included(name)
486
+ return found if found
487
+ end
488
+ # Not found
489
+ return nil
490
+ end
491
+
454
492
  # Gets an output signal by +name+ considering also the included
455
493
  # systems
456
494
  def get_output_with_included(name)
@@ -466,6 +504,36 @@ module HDLRuby::High
466
504
  return nil
467
505
  end
468
506
 
507
+ # Gets an inout signal by +name+ considering also the included
508
+ # systems
509
+ def get_inout_with_included(name)
510
+ # Look in self.
511
+ found = self.get_inout(name)
512
+ return found if found
513
+ # Not in self, look in the included systems.
514
+ self.scope.each_included do |included|
515
+ found = included.get_inout_with_included(name)
516
+ return found if found
517
+ end
518
+ # Not found
519
+ return nil
520
+ end
521
+
522
+ # Iterates over the all signals (input, output, inout, inner, constant),
523
+ # i.e, also the ones of the included systems.
524
+ #
525
+ # Returns an enumerator if no ruby block is given.
526
+ def each_signal_all_with_included(&ruby_block)
527
+ # No ruby block? Return an enumerator.
528
+ return to_enum(:each_signal_all_with_included) unless ruby_block
529
+ # Iterate on all the signals of the current system.
530
+ self.each_signal_all(&ruby_block)
531
+ # Recurse on the included systems.
532
+ self.scope.each_included do |included|
533
+ included.each_signal_all_with_included(&ruby_block)
534
+ end
535
+ end
536
+
469
537
  # Iterates over the all interface signals, i.e, also the ones of
470
538
  # the included systems.
471
539
  #
@@ -473,7 +541,7 @@ module HDLRuby::High
473
541
  def each_signal_with_included(&ruby_block)
474
542
  # No ruby block? Return an enumerator.
475
543
  return to_enum(:each_signal_with_included) unless ruby_block
476
- # Iterate on the signals of the current system.
544
+ # Iterate on all the signals of the current system.
477
545
  self.each_signal(&ruby_block)
478
546
  # Recurse on the included systems.
479
547
  self.scope.each_included do |included|
@@ -487,6 +555,14 @@ module HDLRuby::High
487
555
  return each_signal_with_included.to_a[i]
488
556
  end
489
557
 
558
+ # Gets a signal by +name+ considering also the included
559
+ # systems
560
+ def get_signal_with_included(name)
561
+ return get_input_with_included(name) ||
562
+ get_output_with_included(name) ||
563
+ get_inout_with_included(name)
564
+ end
565
+
490
566
  # Iterates over the exported constructs
491
567
  #
492
568
  # NOTE: look into the scope.
@@ -571,6 +647,7 @@ module HDLRuby::High
571
647
 
572
648
  # Sets the generators of the expanded result.
573
649
  expanded.add_generator(self)
650
+ # puts "expanded=#{expanded}"
574
651
  @to_includes.each { |system| expanded.add_generator(system) }
575
652
  # Also for the previously includeds. */
576
653
  self.scope.each_included.each { |system| expanded.add_generator(system) }
@@ -634,9 +711,8 @@ module HDLRuby::High
634
711
 
635
712
  # Create the instance and sets its eigen system to +eigen+.
636
713
  instance = @instance_class.new(i_name,eigen)
714
+ # puts "instance=#{instance}"
637
715
  eigen.eigenize(instance)
638
- # puts "instance interface=#{instance.each_signal.to_a.size}"
639
- # puts "eigen interface=#{eigen.each_signal.to_a.size}"
640
716
 
641
717
  # Extend the instance.
642
718
  instance.eigen_extend(@singleton_instanceO)
@@ -846,7 +922,8 @@ module HDLRuby::High
846
922
  # Initialize the set of exported inner signals and instances
847
923
  @exports = {}
848
924
  # Initialize the set of included systems.
849
- @includes = {}
925
+ # @includes = {}
926
+ @includes = []
850
927
 
851
928
  # Builds the scope if a ruby block is provided.
852
929
  self.build(&ruby_block) if block_given?
@@ -933,7 +1010,8 @@ module HDLRuby::High
933
1010
  # No ruby block? Return an enumerator.
934
1011
  return to_enum(:each_included) unless ruby_block
935
1012
  # A block? Apply it on each included system.
936
- @includes.each_value(&ruby_block)
1013
+ # @includes.each_value(&ruby_block)
1014
+ @includes.each(&ruby_block)
937
1015
  # And apply on the sub scopes if any.
938
1016
  @scopes.each {|scope| scope.each_included(&ruby_block) }
939
1017
  end
@@ -1226,13 +1304,16 @@ module HDLRuby::High
1226
1304
  # Include a +system+ type with possible +args+ instanciation
1227
1305
  # arguments.
1228
1306
  def include(system,*args)
1229
- if @includes.key?(system.name) then
1230
- raise AnyError, "Cannot include twice the same system."
1307
+ # if @includes.key?(system.name) then
1308
+ # raise AnyError, "Cannot include twice the same system: #{system}"
1309
+ # end
1310
+ if @includes.include?(system) then
1311
+ raise AnyError, "Cannot include twice the same system: #{system}"
1231
1312
  end
1232
- # puts "Include system=#{system.name}"
1233
- # Save the name of the included system, it will serve as key
1234
- # for looking for the included expanded version.
1235
- include_name = system.name
1313
+ # # puts "Include system=#{system.name}"
1314
+ # # Save the name of the included system, it will serve as key
1315
+ # # for looking for the included expanded version.
1316
+ # include_name = system.name
1236
1317
  # Expand the system to include
1237
1318
  system = system.expand(:"",*args)
1238
1319
  # Add the included system interface to the current one.
@@ -1240,7 +1321,8 @@ module HDLRuby::High
1240
1321
  space = self.namespace
1241
1322
  # Interface signals
1242
1323
  # puts "i_name=#{i_name} @to_includes=#{@to_includes.size}"
1243
- system.each_signal_with_included do |signal|
1324
+ # system.each_signal_with_included do |signal|
1325
+ system.each_signal_all_with_included do |signal|
1244
1326
  # puts "signal=#{signal.name}"
1245
1327
  space.send(:define_singleton_method,signal.name) do
1246
1328
  signal
@@ -1259,18 +1341,20 @@ module HDLRuby::High
1259
1341
  end
1260
1342
  end
1261
1343
  # Adds it the list of includeds
1262
- @includes[include_name] = system
1344
+ # @includes[include_name] = system
1345
+ @includes << system
1346
+
1263
1347
  # puts "@includes=#{@includes}"
1264
1348
 
1265
1349
  end
1266
1350
 
1267
- # Casts as an included +system+.
1268
- def as(system)
1269
- # puts "as with name: #{system.name}"
1270
- system = system.name if system.respond_to?(:name)
1271
- # puts "includes are: #{@includes.keys}"
1272
- return @includes[system].namespace
1273
- end
1351
+ # Obsolete
1352
+ # # Casts as an included +system+.
1353
+ # def as(system)
1354
+ # # puts "as with name: #{system.name}"
1355
+ # system = system.name if system.respond_to?(:name)
1356
+ # return @includes[system].namespace
1357
+ # end
1274
1358
 
1275
1359
 
1276
1360
  # Gets the current system.
@@ -1285,7 +1369,8 @@ module HDLRuby::High
1285
1369
  # NOTE: name conflicts are treated in the current NameStack state.
1286
1370
  def fill_low(scopeL)
1287
1371
  # Adds the content of its included systems.
1288
- @includes.each_value {|system| system.scope.fill_low(scopeL) }
1372
+ # @includes.each_value {|system| system.scope.fill_low(scopeL) }
1373
+ @includes.each {|system| system.scope.fill_low(scopeL) }
1289
1374
  # Adds the declared local system types.
1290
1375
  # NOTE: in the current version of HDLRuby::High, there should not
1291
1376
  # be any of them (only eigen systems are real system types).
@@ -2051,26 +2136,28 @@ module HDLRuby::High
2051
2136
  # Performs the connections.
2052
2137
  connects.each do |key,value|
2053
2138
  # Gets the signal corresponding to connect.
2054
- signal = self.get_signal(key)
2055
- unless signal then
2056
- # Look into the included systems.
2057
- self.systemT.scope.each_included do |included|
2058
- signal = included.get_signal(key)
2059
- break if signal
2060
- end
2061
- end
2139
+ # signal = self.get_signal(key)
2140
+ # unless signal then
2141
+ # # Look into the included systems.
2142
+ # self.systemT.scope.each_included do |included|
2143
+ # signal = included.get_signal(key)
2144
+ # break if signal
2145
+ # end
2146
+ # end
2147
+ signal = self.systemT.get_signal_with_included(key)
2062
2148
  # Check if it is an output.
2063
- isout = self.get_output(key)
2064
- unless isout then
2065
- # Look into the inlucded systems.
2066
- self.systemT.scope.each_included do |included|
2067
- isout = included.get_output(key)
2068
- break if isout
2069
- end
2070
- end
2149
+ # isout = self.get_output(key)
2150
+ # unless isout then
2151
+ # # Look into the inlucded systems.
2152
+ # self.systemT.scope.each_included do |included|
2153
+ # isout = included.get_output(key)
2154
+ # break if isout
2155
+ # end
2156
+ # end
2157
+ isout = self.systemT.get_output_with_included(key)
2071
2158
  # Convert it to a reference.
2159
+ # puts "key=#{key} value=#{value} signal=#{signal}"
2072
2160
  ref = RefObject.new(self.to_ref,signal)
2073
- # puts "key=#{key} value=#{value} signal=#{signal} ref=#{ref}"
2074
2161
  # Make the connection.
2075
2162
  if isout then
2076
2163
  value <= ref
@@ -3135,7 +3222,8 @@ module HDLRuby::High
3135
3222
 
3136
3223
  # Converts the name reference to a HDLRuby::Low::RefName.
3137
3224
  def to_low
3138
- # puts "to_low with base=#{@base} @object=#{@object.name}"
3225
+ # puts "to_low with base=#{@base} @object=#{@object}"
3226
+ # puts "@object.name=#{@object.name}"
3139
3227
  refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
3140
3228
  @base.to_ref.to_low,@object.name)
3141
3229
  # # For debugging: set the source high object
@@ -164,7 +164,6 @@ module HDLRuby::Low
164
164
  end
165
165
 
166
166
 
167
-
168
167
  # Handling the (re)configuration.
169
168
 
170
169
  # Gets the configuration wrapper if any.
@@ -185,7 +184,7 @@ module HDLRuby::Low
185
184
 
186
185
  # Adds input +signal+.
187
186
  def add_input(signal)
188
- # print "add_input with signal: #{signal.name}\n"
187
+ # print "In #{self} add_input with signal: #{signal.name}\n"
189
188
  # Check and add the signal.
190
189
  unless signal.is_a?(SignalI)
191
190
  raise AnyError,
@@ -290,6 +289,8 @@ module HDLRuby::Low
290
289
  @inputs.each(&ruby_block)
291
290
  @outputs.each(&ruby_block)
292
291
  @inouts.each(&ruby_block)
292
+ # And each signal of the direct scope.
293
+ @scope.each_signal(&ruby_block)
293
294
  end
294
295
 
295
296
  # Iterates over all the signals of the system type and its scope.
@@ -298,7 +299,8 @@ module HDLRuby::Low
298
299
  return to_enum(:each_signal_deep) unless ruby_block
299
300
  # A ruby block?
300
301
  # First iterate over the current system type's signals.
301
- self.each_signal_all(&ruby_block)
302
+ # self.each_signal_all(&ruby_block)
303
+ self.each_signal(&ruby_block)
302
304
  # Then apply on the behaviors (since in HDLRuby:High, blocks can
303
305
  # include signals).
304
306
  @scope.each_signal_deep(&ruby_block)
@@ -2082,11 +2082,11 @@ module HDLRuby::Low
2082
2082
  if str =~ /^[01]+$/ && str.length <= 64 then
2083
2083
  # Yes, generate a numeral value.
2084
2084
  res << " " * (level+1)*3
2085
- # res << "static unsigned long long data[] = { "
2086
2085
  res << "static unsigned int data[] = { "
2087
2086
  res << str.scan(/.{1,#{Low2C.int_width}}/m).reverse.map do |sub|
2088
2087
  sub.to_i(2).to_s # + "ULL"
2089
2088
  end.join(",")
2089
+ res << ", 0" if (str.length <= 32)
2090
2090
  res << " };\n"
2091
2091
  # Create the value.
2092
2092
  res << " " * (level+1)*3
@@ -92,6 +92,7 @@ module HDLRuby::Low
92
92
  inputs_blk.add_statement(
93
93
  Transmit.new(right.clone,left.clone))
94
94
  elsif (left_is_o) then
95
+ # puts "left=#{left} right=#{right}"
95
96
  outputs_blk.add_statement(
96
97
  Transmit.new(right.clone,left.clone))
97
98
  elsif (right_is_o) then
@@ -1871,10 +1871,11 @@ static Value equal_value_numeric(Value src0, Value src1, Value dst) {
1871
1871
  dst->type = src0->type;
1872
1872
  dst->numeric = 1;
1873
1873
 
1874
- // /* Perform the !XOR. */
1875
- // dst->data_int = ~(src0->data_int ^ src1->data_int);
1876
1874
  /* Perform the comparison. */
1877
1875
  dst->data_int = (src0->data_int == src1->data_int) ? 1 : 0;
1876
+ printf("scr0->data_int=%lld\n",src0->data_int);
1877
+ printf("scr1->data_int=%lld\n",src1->data_int);
1878
+ printf("dst->data_int=%lld\n",dst->data_int);
1878
1879
  return dst;
1879
1880
  }
1880
1881
 
@@ -0,0 +1,92 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: delays
5
+ #
6
+ ########################################################################
7
+
8
+
9
+ ## Module describing a simple delay using handshake for working.
10
+ # @param num the number of clock cycles to delay.
11
+ system :delay do |num|
12
+ # Checks and process the number of clock to wait.
13
+ num = num.to_i
14
+ raise "The delay generic argument must be positive: #{num}" if (num < 0)
15
+
16
+ input :clk # The clock to make the delay on.
17
+ input :req # The handshake request.
18
+ output :ack # The handshake acknoledgment.
19
+
20
+ # The process of the delay.
21
+ if (num == 0) then
22
+ # No delay case.
23
+ ack <= req
24
+ else
25
+ # The is a delay.
26
+ inner run: 0 # Tell if the deayl is running.
27
+ [num.width+1].inner :count # The counter for computing the delay.
28
+ par(clk.posedge) do
29
+ # Is there a request to treat?
30
+ hif(req & ~run) do
31
+ # Yes, intialize the delay.
32
+ run <= 1
33
+ count <= 0
34
+ ack <= 0
35
+ end
36
+ # No, maybe there is a request in processing.
37
+ helsif(run) do
38
+ # Yes, increase the counter.
39
+ count <= count + 1
40
+ # Check if the delay is reached.
41
+ hif(count == num-1) do
42
+ # Yes, tells it and stop the count.
43
+ ack <= 1
44
+ run <= 0
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+
53
+ ## Module describing a pipeline delay (supporting multiple successive delays)
54
+ # using handshake for working.
55
+ # @param num the number of clock cycles to delay.
56
+ system :delayp do |num|
57
+ # Checks and process the number of clock to wait.
58
+ num = num.to_i
59
+ raise "The delay generic argument must be positive: #{num}" if (num < 0)
60
+
61
+ input :clk # The clock to make the delay on.
62
+ input :req # The handshake request.
63
+ output :ack # The handshake acknoledgment.
64
+
65
+ if (num==0) then
66
+ # No delay.
67
+ ack <= req
68
+ else
69
+ # There is a delay.
70
+
71
+ [num].inner state: 0 # The shift register containing the progression
72
+ # of each requested delay.
73
+
74
+ # The acknoledgment is directly the last bit of the state register.
75
+ ack <= state[-1]
76
+
77
+
78
+ # The process controlling the delay.
79
+ seq(clk.posedge) do
80
+ # Update the state.
81
+ if (num > 1) then
82
+ state <= state << 1
83
+ else
84
+ state <= 0
85
+ end
86
+ # Handle the input.
87
+ ( state[0] <= 1 ).hif(req)
88
+ end
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,60 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: handshake protocols.
5
+ #
6
+ ########################################################################
7
+
8
+
9
+ ## Module describing a simple client handshake for working.
10
+ # @param event the event to synchronize the handshake.
11
+ # @param req the signal telling a request is there.
12
+ # @param cond the condition allowing the protocol.
13
+ system :hs_client do |event, req, cond=_1|
14
+ input :reqI
15
+ output ackI: 0
16
+
17
+ # A each synchronization event.
18
+ par(event) do
19
+ # Is the protocol is allowed and a request is present.
20
+ hif(cond & reqI) do
21
+ # Yes perform the action and tell the request has been treated.
22
+ req <= 1 if req
23
+ ackI <= 1
24
+ end
25
+ helse do
26
+ # No, do not perform the action, and do not acknowledge.
27
+ req <= 0 if req
28
+ ackI <= 0
29
+ end
30
+ end
31
+ end
32
+
33
+
34
+ ## Module describing a simple server handshake for working.
35
+ # @param event the event to synchronize the handshake.
36
+ # @param req the signal for asking a new request.
37
+ system :hs_server do |event, req|
38
+ output reqO: 0
39
+ input :ackO
40
+
41
+ # A each synchronization event.
42
+ par(event) do
43
+ # Shall we start the output?
44
+ hif(ackO) { reqO <= 0 }
45
+ hif(req) { reqO <= 1 }
46
+ end
47
+ end
48
+
49
+
50
+ ## Module describing a pipeline with handshakes.
51
+ # @param event the event to synchronize the handshakes.
52
+ # @param read the signal telling there is a request from the client side
53
+ # @param write the signal used for asking the server to issue a request
54
+ system :hs_pipe do |event,read,write|
55
+ inner :cond
56
+ include(hs_client(event,read,cond))
57
+ include(hs_server(event,write))
58
+ cond <= ~reqO
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.8.1"
2
+ VERSION = "2.10.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.8.1
4
+ version: 2.10.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-03-22 00:00:00.000000000 Z
11
+ date: 2022-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -152,9 +152,11 @@ files:
152
152
  - lib/HDLRuby/hdr_samples/with_connector_memory.rb
153
153
  - lib/HDLRuby/hdr_samples/with_decoder.rb
154
154
  - lib/HDLRuby/hdr_samples/with_def.rb
155
+ - lib/HDLRuby/hdr_samples/with_delay.rb
155
156
  - lib/HDLRuby/hdr_samples/with_fixpoint.rb
156
157
  - lib/HDLRuby/hdr_samples/with_fsm.rb
157
158
  - lib/HDLRuby/hdr_samples/with_function_generator.rb
159
+ - lib/HDLRuby/hdr_samples/with_handshake.rb
158
160
  - lib/HDLRuby/hdr_samples/with_init.rb
159
161
  - lib/HDLRuby/hdr_samples/with_instance.rb
160
162
  - lib/HDLRuby/hdr_samples/with_linear.rb
@@ -162,6 +164,7 @@ files:
162
164
  - lib/HDLRuby/hdr_samples/with_memory.rb
163
165
  - lib/HDLRuby/hdr_samples/with_memory_rom.rb
164
166
  - lib/HDLRuby/hdr_samples/with_multi_channels.rb
167
+ - lib/HDLRuby/hdr_samples/with_of.rb
165
168
  - lib/HDLRuby/hdr_samples/with_reconf.rb
166
169
  - lib/HDLRuby/hdr_samples/with_reduce.rb
167
170
  - lib/HDLRuby/hdr_samples/with_ref_array.rb
@@ -172,6 +175,7 @@ files:
172
175
  - lib/HDLRuby/hdr_samples/with_to_array.rb
173
176
  - lib/HDLRuby/hdr_samples/with_values.rb
174
177
  - lib/HDLRuby/hdrcc.rb
178
+ - lib/HDLRuby/hdrlib.rb
175
179
  - lib/HDLRuby/high_samples/_adder_fault.rb
176
180
  - lib/HDLRuby/high_samples/_generic_transmission2.rb
177
181
  - lib/HDLRuby/high_samples/adder.rb
@@ -323,9 +327,11 @@ files:
323
327
  - lib/HDLRuby/std/connector.rb
324
328
  - lib/HDLRuby/std/counters.rb
325
329
  - lib/HDLRuby/std/decoder.rb
330
+ - lib/HDLRuby/std/delays.rb
326
331
  - lib/HDLRuby/std/fixpoint.rb
327
332
  - lib/HDLRuby/std/fsm.rb
328
333
  - lib/HDLRuby/std/function_generator.rb
334
+ - lib/HDLRuby/std/handshakes.rb
329
335
  - lib/HDLRuby/std/hruby_unit.rb
330
336
  - lib/HDLRuby/std/linear.rb
331
337
  - lib/HDLRuby/std/loop.rb