HDLRuby 2.9.0 → 2.10.2

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.
@@ -441,9 +441,9 @@ module HDLRuby::High
441
441
  res = self.add_output(SignalI.new(name,type,:output))
442
442
  elsif name.is_a?(Hash) then
443
443
  # Names associated with values.
444
- names.each do |name,value|
445
- res = self.add_inner(
446
- SignalI.new(name,type,:inner,value))
444
+ name.each do |key,value|
445
+ res = self.add_output(
446
+ SignalI.new(key,type,:output,value))
447
447
  end
448
448
  else
449
449
  raise AnyError, "Invalid class for a name: #{name.class}"
@@ -474,6 +474,21 @@ module HDLRuby::High
474
474
  end
475
475
 
476
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
+
477
492
  # Gets an output signal by +name+ considering also the included
478
493
  # systems
479
494
  def get_output_with_included(name)
@@ -489,6 +504,36 @@ module HDLRuby::High
489
504
  return nil
490
505
  end
491
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
+
492
537
  # Iterates over the all interface signals, i.e, also the ones of
493
538
  # the included systems.
494
539
  #
@@ -496,7 +541,7 @@ module HDLRuby::High
496
541
  def each_signal_with_included(&ruby_block)
497
542
  # No ruby block? Return an enumerator.
498
543
  return to_enum(:each_signal_with_included) unless ruby_block
499
- # Iterate on the signals of the current system.
544
+ # Iterate on all the signals of the current system.
500
545
  self.each_signal(&ruby_block)
501
546
  # Recurse on the included systems.
502
547
  self.scope.each_included do |included|
@@ -510,6 +555,14 @@ module HDLRuby::High
510
555
  return each_signal_with_included.to_a[i]
511
556
  end
512
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
+
513
566
  # Iterates over the exported constructs
514
567
  #
515
568
  # NOTE: look into the scope.
@@ -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
@@ -1249,13 +1304,16 @@ module HDLRuby::High
1249
1304
  # Include a +system+ type with possible +args+ instanciation
1250
1305
  # arguments.
1251
1306
  def include(system,*args)
1252
- if @includes.key?(system.name) then
1253
- 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}"
1254
1312
  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
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
1259
1317
  # Expand the system to include
1260
1318
  system = system.expand(:"",*args)
1261
1319
  # Add the included system interface to the current one.
@@ -1263,7 +1321,8 @@ module HDLRuby::High
1263
1321
  space = self.namespace
1264
1322
  # Interface signals
1265
1323
  # puts "i_name=#{i_name} @to_includes=#{@to_includes.size}"
1266
- system.each_signal_with_included do |signal|
1324
+ # system.each_signal_with_included do |signal|
1325
+ system.each_signal_all_with_included do |signal|
1267
1326
  # puts "signal=#{signal.name}"
1268
1327
  space.send(:define_singleton_method,signal.name) do
1269
1328
  signal
@@ -1282,18 +1341,20 @@ module HDLRuby::High
1282
1341
  end
1283
1342
  end
1284
1343
  # Adds it the list of includeds
1285
- @includes[include_name] = system
1344
+ # @includes[include_name] = system
1345
+ @includes << system
1346
+
1286
1347
  # puts "@includes=#{@includes}"
1287
1348
 
1288
1349
  end
1289
1350
 
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
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
1297
1358
 
1298
1359
 
1299
1360
  # Gets the current system.
@@ -1308,7 +1369,8 @@ module HDLRuby::High
1308
1369
  # NOTE: name conflicts are treated in the current NameStack state.
1309
1370
  def fill_low(scopeL)
1310
1371
  # Adds the content of its included systems.
1311
- @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) }
1312
1374
  # Adds the declared local system types.
1313
1375
  # NOTE: in the current version of HDLRuby::High, there should not
1314
1376
  # be any of them (only eigen systems are real system types).
@@ -2074,26 +2136,28 @@ module HDLRuby::High
2074
2136
  # Performs the connections.
2075
2137
  connects.each do |key,value|
2076
2138
  # 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
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)
2085
2148
  # 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
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)
2094
2158
  # Convert it to a reference.
2159
+ # puts "key=#{key} value=#{value} signal=#{signal}"
2095
2160
  ref = RefObject.new(self.to_ref,signal)
2096
- # puts "key=#{key} value=#{value} signal=#{signal} ref=#{ref}"
2097
2161
  # Make the connection.
2098
2162
  if isout then
2099
2163
  value <= ref
@@ -3158,7 +3222,8 @@ module HDLRuby::High
3158
3222
 
3159
3223
  # Converts the name reference to a HDLRuby::Low::RefName.
3160
3224
  def to_low
3161
- # puts "to_low with base=#{@base} @object=#{@object.name}"
3225
+ # puts "to_low with base=#{@base} @object=#{@object}"
3226
+ # puts "@object.name=#{@object.name}"
3162
3227
  refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
3163
3228
  @base.to_ref.to_low,@object.name)
3164
3229
  # # For debugging: set the source high object
@@ -184,7 +184,7 @@ module HDLRuby::Low
184
184
 
185
185
  # Adds input +signal+.
186
186
  def add_input(signal)
187
- # print "add_input with signal: #{signal.name}\n"
187
+ # print "In #{self} add_input with signal: #{signal.name}\n"
188
188
  # Check and add the signal.
189
189
  unless signal.is_a?(SignalI)
190
190
  raise AnyError,
@@ -289,6 +289,8 @@ module HDLRuby::Low
289
289
  @inputs.each(&ruby_block)
290
290
  @outputs.each(&ruby_block)
291
291
  @inouts.each(&ruby_block)
292
+ # And each signal of the direct scope.
293
+ @scope.each_signal(&ruby_block)
292
294
  end
293
295
 
294
296
  # Iterates over all the signals of the system type and its scope.
@@ -297,7 +299,8 @@ module HDLRuby::Low
297
299
  return to_enum(:each_signal_deep) unless ruby_block
298
300
  # A ruby block?
299
301
  # First iterate over the current system type's signals.
300
- self.each_signal_all(&ruby_block)
302
+ # self.each_signal_all(&ruby_block)
303
+ self.each_signal(&ruby_block)
301
304
  # Then apply on the behaviors (since in HDLRuby:High, blocks can
302
305
  # include signals).
303
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.9.0"
2
+ VERSION = "2.10.2"
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.9.0
4
+ version: 2.10.2
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-05-15 00:00:00.000000000 Z
11
+ date: 2022-06-11 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
@@ -173,6 +175,7 @@ files:
173
175
  - lib/HDLRuby/hdr_samples/with_to_array.rb
174
176
  - lib/HDLRuby/hdr_samples/with_values.rb
175
177
  - lib/HDLRuby/hdrcc.rb
178
+ - lib/HDLRuby/hdrlib.rb
176
179
  - lib/HDLRuby/high_samples/_adder_fault.rb
177
180
  - lib/HDLRuby/high_samples/_generic_transmission2.rb
178
181
  - lib/HDLRuby/high_samples/adder.rb
@@ -324,9 +327,11 @@ files:
324
327
  - lib/HDLRuby/std/connector.rb
325
328
  - lib/HDLRuby/std/counters.rb
326
329
  - lib/HDLRuby/std/decoder.rb
330
+ - lib/HDLRuby/std/delays.rb
327
331
  - lib/HDLRuby/std/fixpoint.rb
328
332
  - lib/HDLRuby/std/fsm.rb
329
333
  - lib/HDLRuby/std/function_generator.rb
334
+ - lib/HDLRuby/std/handshakes.rb
330
335
  - lib/HDLRuby/std/hruby_unit.rb
331
336
  - lib/HDLRuby/std/linear.rb
332
337
  - lib/HDLRuby/std/loop.rb