HDLRuby 3.7.5 → 3.7.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af734e680200b79bc927ebf845cf13e712f5614a6f2188f23385f53f059442d1
4
- data.tar.gz: be3d20a777119fd87686749b798df6a9f27ac9a0e7101821b1ab5a64d186a3c4
3
+ metadata.gz: 15e4da96afaa32db3686dcbad0ea327db644719dadfdba4ed6dcef1464f1e391
4
+ data.tar.gz: 1d08ab446037ab8ae6b86e6394a209a03ef06e8bcf233d10d9af25d059873f47
5
5
  SHA512:
6
- metadata.gz: 14dd0ec35076907dddb6448965c6ce6a9ffc5e00d229760a0f3d2a30d0c8f3cf60b27567cac50abfe6c321db6e86a86ef3961c166372283eef55e273c8c85279
7
- data.tar.gz: c63ef648b2782b10b02afba2247ba782bc34e83617a5d5b1bb11524844f2036e6cf47f6c435159f505ce2ee99201bb7c2663d39a04c76dd654e411249593d485
6
+ metadata.gz: 444499b3dc4f0577f113630a521bf7de67186f8dc2936c8626b91fd1dc556fac9b5f361f7265dbe81123c6a8391054eca2d57076e3067653b41c9566125d5b65
7
+ data.tar.gz: 9284989cce6b6006c3551e6d5f8e40a29a8c16726d168cab4347f27b596eac1962f045cd260c072ad0be31665e69f2f84ce6406e28b65d378262bc7586c39fbb
data/README.md CHANGED
@@ -15,9 +15,15 @@ And if you want an html version the following command with create a `tuto` folde
15
15
  hdrcc --get-tuto
16
16
  ```
17
17
 
18
- __What's new__
18
+ __What's new_
19
19
 
20
- For HDLRuby version 3.7.4/3.7.5:
20
+ For HDLRuby version 3.7.6:
21
+
22
+ * Added initial value to signals for the software sequencers.
23
+
24
+ * Fixed hprint in software sequencer.
25
+
26
+ For HDLRuby versions 3.7.4/3.7.5:
21
27
 
22
28
  * Various bug fixes.
23
29
 
@@ -8,11 +8,11 @@ system :my_seqencer do
8
8
  inner :clk,:rst
9
9
  [65536].inner :count
10
10
 
11
- # sequencer(clk.posedge,rst) do
12
- # sloop do
13
- # # count <= count + 1
14
- # end
15
- # end
11
+ sequencer(clk.posedge,rst) do
12
+ sloop do
13
+ count <= count + 1
14
+ end
15
+ end
16
16
 
17
17
 
18
18
 
@@ -96,6 +96,12 @@ module RubyHDL::High
96
96
  type = type.to_type
97
97
  last_sig = nil
98
98
  names.each do |name|
99
+ init = nil
100
+ if name.is_a?(Hash) then
101
+ init = name.values[0]
102
+ name = name.keys[0]
103
+ # puts "init=#{init}"
104
+ end
99
105
  name = name.to_sym
100
106
  # Create and add the signal.
101
107
  sig = SignalI.new(name,type,:inner)
@@ -104,6 +110,9 @@ module RubyHDL::High
104
110
  # self.register(name) { puts("sig=",sig.inspect); sig }
105
111
  self.register(name) { sig }
106
112
  last_sig = sig
113
+
114
+ # Sets the initial value if any.
115
+ sig.value = init if init
107
116
  end
108
117
  return last_sig
109
118
  end
@@ -587,6 +596,11 @@ module RubyHDL::High
587
596
  end
588
597
  alias_method :to_expr, :to_value
589
598
 
599
+ def as(type)
600
+ # For now, cast is ignored.
601
+ return self
602
+ end
603
+
590
604
  def to_ruby
591
605
  return self
592
606
  end
@@ -1311,10 +1325,10 @@ module RubyHDL::High
1311
1325
  return @base.to_c + "[#{self.size.to_i}]"
1312
1326
  else
1313
1327
  # Simple vector type case.
1314
- if float? then
1328
+ if @base.float? then
1315
1329
  return @base.to_c
1316
1330
  else
1317
- return @base + " long long"
1331
+ return @base.to_c + " long long"
1318
1332
  end
1319
1333
  end
1320
1334
  end
@@ -1324,7 +1338,7 @@ module RubyHDL::High
1324
1338
  if @base.is_a?(TypeVector) then
1325
1339
  # Array type case.
1326
1340
  base_init = @base.to_c_init
1327
- return "[" + ([base_init] * self.size.to_i).join(",") + "]"
1341
+ return "{" + ([base_init] * self.size.to_i).join(",") + "}"
1328
1342
  else
1329
1343
  return "0"
1330
1344
  end
@@ -1905,7 +1919,13 @@ module RubyHDL::High
1905
1919
  end
1906
1920
 
1907
1921
  # Convert to C code.
1908
- alias_method :to_c, :to_ruby
1922
+ def to_c
1923
+ if @content.is_a?(::Array) then
1924
+ return "{" + @content.to_s[1..-2] + "}"
1925
+ else
1926
+ return @content.to_s
1927
+ end
1928
+ end
1909
1929
  end
1910
1930
 
1911
1931
 
@@ -1986,10 +2006,11 @@ module RubyHDL::High
1986
2006
 
1987
2007
  # Convert to C code.
1988
2008
  def to_c
1989
- return "switch(#{@sel.to_c}) {\n" +
1990
- @choices.map.with_index do |choice,i|
1991
- "case #{i}:\n#{choice.to_c}\nbreak;"
1992
- end.join("\n") + "\n}"
2009
+ # return "switch(#{@sel.to_c}) {\n" +
2010
+ # @choices.map.with_index do |choice,i|
2011
+ # "case #{i}:\n#{choice.to_c}\nbreak;"
2012
+ # end.join("\n") + "\n}"
2013
+ return "#{@sel.to_c} ? #{@choices[1].to_c} : #{@choices[0].to_c}"
1993
2014
  end
1994
2015
  end
1995
2016
 
@@ -2098,6 +2119,7 @@ module RubyHDL::High
2098
2119
 
2099
2120
  # Describes a SW implementation of an range reference.
2100
2121
  class RefRange < Ref
2122
+ using RubyHDL::High
2101
2123
  attr_reader :base
2102
2124
 
2103
2125
  # Create a new index reference with +type+ data type +base+ base
@@ -2151,7 +2173,8 @@ module RubyHDL::High
2151
2173
 
2152
2174
  # Convert to Ruby code.
2153
2175
  def to_ruby
2154
- return "#{@base.to_ruby}[#{@rng.first.to_ruby}..#{@rng.last.to_ruby}]"
2176
+ # return "#{@base.to_ruby}[#{@rng.first.to_ruby}..#{@rng.last.to_ruby}]"
2177
+ return "#{@base.to_ruby}[#{@rng.last.to_ruby}..#{@rng.first.to_ruby}]"
2155
2178
  end
2156
2179
 
2157
2180
  # Convert to C code.
@@ -2163,7 +2186,11 @@ module RubyHDL::High
2163
2186
  smask = (1.to_value<<(@rng.first+1-@rng.last))-1
2164
2187
  cmask = ~(smask << @rng.last)
2165
2188
  # Get the final base.
2166
- base = @base.final_base.to_c
2189
+ if @base.is_a?(Ref) then
2190
+ base = @base.final_base.to_c
2191
+ else
2192
+ base = @base.to_c
2193
+ end
2167
2194
  # Generate the ruby code.
2168
2195
  return "(#{base} & #{cmask.to_c}) >> (#{@rng.last.to_c})"
2169
2196
  end
@@ -2241,7 +2268,7 @@ module RubyHDL::High
2241
2268
  def to_c
2242
2269
  if (@left.is_a?(RefIndex) or @left.is_a?(RefRange)) then
2243
2270
  if @left.base.type.base.is_a?(TypeVector) then
2244
- return "#{@left.to_c} = #{@right.to_c}"
2271
+ return "#{@left.to_c} = #{@right.to_c};"
2245
2272
  else
2246
2273
  # Get the access range.
2247
2274
  rng = @left.range
@@ -2260,7 +2287,7 @@ module RubyHDL::High
2260
2287
  end
2261
2288
  end
2262
2289
 
2263
- # Describes a SW implementation of a if statement.
2290
+ # Describes a SW implementation of a sif statement.
2264
2291
  class Sif < Statement
2265
2292
  # Create a new if statement in sequencer +sequencer+
2266
2293
  # with +cond+ condition and +ruby_block+
@@ -2321,7 +2348,7 @@ module RubyHDL::High
2321
2348
 
2322
2349
  # Convert to C code.
2323
2350
  def to_c
2324
- res = @sequencer.clk_up + "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}"
2351
+ res = @sequencer.clk_up_c + "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}"
2325
2352
  @elsifs.each do |(cond,blk)|
2326
2353
  res << "\nelse if(#{cond.to_c}) {\n#{blk.to_c}\n}"
2327
2354
  end
@@ -2332,6 +2359,33 @@ module RubyHDL::High
2332
2359
  end
2333
2360
  end
2334
2361
 
2362
+ # Describes a SW implementation of a hif statement.
2363
+ class Hif < Sif
2364
+ # Convert to Ruby code.
2365
+ def to_ruby
2366
+ res = "\nif((#{@condition.to_ruby}) != 0)\n#{@yes_blk.to_ruby}\n"
2367
+ @elsifs.each do |(cond,blk)|
2368
+ res << "elsif((#{cond.to_ruby}) != 0)\n#{blk.to_ruby}\n"
2369
+ end
2370
+ if @else_blk then
2371
+ res << "else\n#{@else_blk.to_ruby}\n"
2372
+ end
2373
+ return res + "end\n"
2374
+ end
2375
+
2376
+ # Convert to C code.
2377
+ def to_c
2378
+ res = "\nif(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n}"
2379
+ @elsifs.each do |(cond,blk)|
2380
+ res << "\nelse if(#{cond.to_c}) {\n#{blk.to_c}\n}"
2381
+ end
2382
+ if @else_blk then
2383
+ res << "\nelse {\n#{@else_blk.to_c}\n}"
2384
+ end
2385
+ return res
2386
+ end
2387
+ end
2388
+
2335
2389
  # Describes a SW implementation of a loop statement.
2336
2390
  class Sloop < Statement
2337
2391
  # Create a new infinite loop statement in sequencer +sequencer+
@@ -2479,7 +2533,7 @@ module RubyHDL::High
2479
2533
 
2480
2534
  # Convert to Ruby code.
2481
2535
  def to_c
2482
- return @sequencer.clk_up_c + "\nreturn #{val.to_c};"
2536
+ return @sequencer.clk_up_c + "\nreturn #{@value.to_c};"
2483
2537
  end
2484
2538
  end
2485
2539
 
@@ -2627,7 +2681,7 @@ module RubyHDL::High
2627
2681
 
2628
2682
  # Convert to C code.
2629
2683
  def to_c
2630
- return "\n__#{name}(" + @args.map {|arg| arg.to_ruby}.join(",") + ");"
2684
+ return "\n__#{@name}(" + @args.map {|arg| arg.to_ruby}.join(",") + ");"
2631
2685
  end
2632
2686
 
2633
2687
  # Create an iterator for a given method +meth+.
@@ -2962,6 +3016,54 @@ module RubyHDL::High
2962
3016
  end
2963
3017
  end
2964
3018
 
3019
+ # Describes a SW implementation of a hardware print statement.
3020
+ class Print < Statement
3021
+ using RubyHDL::High
3022
+
3023
+ # Create a new hprint statement in sequencer +sequencer+
3024
+ # for displaying +args+.
3025
+ def initialize(sequencer,*args)
3026
+ @sequencer = sequencer
3027
+ @arguments = args
3028
+ end
3029
+
3030
+ # Convert to Ruby code.
3031
+ def to_ruby
3032
+ return "" if @arguments.empty?
3033
+ res = "print("
3034
+ @arguments.each do |arg|
3035
+ if arg.is_a?(::String) then
3036
+ res << "\"#{arg}\""
3037
+ else
3038
+ res << arg.to_ruby
3039
+ end
3040
+ end
3041
+ res << ")\n"
3042
+ return res
3043
+ end
3044
+
3045
+ # Convert to C code.
3046
+ def to_c
3047
+ return "" if @arguments.empty?
3048
+ # Create the format.
3049
+ format = @arguments.map do |arg|
3050
+ if arg.is_a?(Expression) then
3051
+ arg.type.signed? ? "%lld" : "%llu"
3052
+ else
3053
+ "%s"
3054
+ end
3055
+ end.join
3056
+ return "printf(\"#{format}\"," +
3057
+ @arguments.map do |arg|
3058
+ if arg.is_a?(::String) then
3059
+ "\"#{arg.gsub(/\n/,"\\n")}\""
3060
+ else
3061
+ arg.to_c
3062
+ end
3063
+ end.join(",") + ");"
3064
+ end
3065
+ end
3066
+
2965
3067
 
2966
3068
  # Describes a SW implementation of an iterator statement.
2967
3069
  class Siter < Statement
@@ -3396,7 +3498,9 @@ module RubyHDL::High
3396
3498
  end
3397
3499
 
3398
3500
  # Convert to C code.
3399
- alias_method :to_c, :to_ruby
3501
+ def to_c
3502
+ return "__" + self.name.to_s
3503
+ end
3400
3504
 
3401
3505
  # Check if a value is defined for the signal.
3402
3506
  def value?
@@ -3553,14 +3657,14 @@ module RubyHDL::High
3553
3657
  # Convert to C code.
3554
3658
  def to_c
3555
3659
  res = ""
3556
- # Generate the arguments if any.
3557
- if @args.any? then
3558
- res = "(#{@args.map(&:to_c).join(",")})\n"
3559
- end
3660
+ # # Generate the arguments if any.
3661
+ # if @args.any? then
3662
+ # res = "(#{@args.map(&:to_c).join(",")})\n"
3663
+ # end
3560
3664
  # Generate the statements.
3561
- res += "{" + @statements.map do |stmnt|
3562
- stmnt.to_ruby + "\n"
3563
- end.join + "}"
3665
+ res += "{\n" + @statements.map do |stmnt|
3666
+ stmnt.to_c + "\n"
3667
+ end.join + "\n}"
3564
3668
  return res
3565
3669
  end
3566
3670
 
@@ -3600,7 +3704,11 @@ module RubyHDL::High
3600
3704
  def sif(cond, &ruby_block)
3601
3705
  self << RubyHDL::High::Sif.new(@sequencer,cond,&ruby_block)
3602
3706
  end
3603
- alias_method :hif, :sif
3707
+
3708
+ # Create a sequential if statement on +cond+.
3709
+ def hif(cond, &ruby_block)
3710
+ self << RubyHDL::High::Hif.new(@sequencer,cond,&ruby_block)
3711
+ end
3604
3712
 
3605
3713
  # Create a sequential elsif statement on +cond+.
3606
3714
  def selsif(cond, &ruby_block)
@@ -3645,10 +3753,11 @@ module RubyHDL::High
3645
3753
 
3646
3754
  # Displays a string for debugging purpose.
3647
3755
  def hprint(*args)
3648
- args.each do |arg|
3649
- arg = arg.to_value if arg.is_a?(RubyHDL::High::Expression)
3650
- print arg
3651
- end
3756
+ # args.each do |arg|
3757
+ # arg = arg.to_value if arg.is_a?(RubyHDL::High::Expression)
3758
+ # print arg
3759
+ # end
3760
+ self << RubyHDL::High::Print.new(@sequencer,*args)
3652
3761
  end
3653
3762
 
3654
3763
  # The SW-specific statements and expressions.
@@ -3705,7 +3814,7 @@ module RubyHDL::High
3705
3814
 
3706
3815
  # Convert to C code.
3707
3816
  def to_c
3708
- return "unsigned long long __#{name}(#{@args.map {|arg| "unsigned long long " + arg.to_c}.join(",")} {\n#{@blk.sequencer.clk_up_c}\n#{@blk.to_c}\n}\n"
3817
+ return "unsigned long long __#{name}(#{@args.map {|arg| "unsigned long long __" + arg.to_c}.join(",")}) {\n#{@blk.sequencer.clk_up_c}\n#{@blk.to_c}\n}\n"
3709
3818
  end
3710
3819
  end
3711
3820
 
@@ -3771,7 +3880,7 @@ module RubyHDL::High
3771
3880
  signal.to_ruby + " = RubyHDL.#{signal.name}"
3772
3881
  else
3773
3882
  signal.to_ruby + " ||= " +
3774
- (signal.array? ? "[]" : signal.value? ? signal.value.inspect : "0")
3883
+ (signal.array? ? "[*#{signal.value? ? signal.value : "nil"}]" : signal.value? ? signal.value.inspect : "0")
3775
3884
  end
3776
3885
  end.join("\n")}
3777
3886
 
@@ -3794,11 +3903,29 @@ BUILD
3794
3903
  def to_c
3795
3904
  typ = nil
3796
3905
  res = <<-BUILDC
3906
+ #include <stdio.h>
3907
+
3797
3908
  #{RubyHDL::High.global_sblock.each_signal.map do |signal|
3798
3909
  typ = signal.type
3799
- typ.to_c + " " + signal.to_c + "=" + typ.to_c_init + ";"
3910
+ if signal.value? then
3911
+ if signal.array? then
3912
+ typ.base.to_c + " " + signal.to_c + "[#{typ.size}]" " = {" +
3913
+ signal.value.inspect[1..-2] + "};"
3914
+ else
3915
+ typ.to_c + " " + signal.to_c + "=" + signal.value.inspect + ";"
3916
+ end
3917
+ else
3918
+ if signal.array? then
3919
+ typ.base.to_c + " " + signal.to_c + "[#{typ.size}]" + " =" + typ.to_c_init + ";"
3920
+ else
3921
+ typ.to_c + " " + signal.to_c + "=" + typ.to_c_init + ";"
3922
+ end
3923
+ end
3800
3924
  end.join("\n")}
3801
- #{sblock.to_c}
3925
+
3926
+ #{@sfunctions.map {|n,f| f.to_c }.join("\n\n")}
3927
+
3928
+ void sequencer() #{@blk.to_c}
3802
3929
  BUILDC
3803
3930
  return res
3804
3931
  end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "3.7.5"
2
+ VERSION = "3.7.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HDLRuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.5
4
+ version: 3.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier