HDLRuby 2.11.12 → 3.1.0

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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.html +3274 -0
  3. data/README.md +660 -128
  4. data/ext/hruby_sim/hruby_sim_calc.c +2 -0
  5. data/lib/HDLRuby/backend/hruby_allocator.rb +2 -2
  6. data/lib/HDLRuby/backend/hruby_c_allocator.rb +7 -7
  7. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +2 -1
  8. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  9. data/lib/HDLRuby/hdr_samples/with_bram.rb +3 -3
  10. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +105 -0
  11. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +69 -0
  12. data/lib/HDLRuby/hdr_samples/with_ref_expr.rb +30 -0
  13. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +185 -0
  14. data/lib/HDLRuby/hdr_samples/with_sequencer_deep.rb +91 -0
  15. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +439 -0
  16. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +89 -0
  17. data/lib/HDLRuby/hdr_samples/with_sequencer_func.rb +63 -0
  18. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +120 -0
  19. data/lib/HDLRuby/hdrcc.rb +16 -3
  20. data/lib/HDLRuby/hdrlib.rb +1 -1
  21. data/lib/HDLRuby/hruby_db.rb +2 -2
  22. data/lib/HDLRuby/hruby_high.rb +61 -25
  23. data/lib/HDLRuby/hruby_high_fullname.rb +3 -1
  24. data/lib/HDLRuby/hruby_low.rb +2 -2
  25. data/lib/HDLRuby/hruby_low2c.rb +58 -43
  26. data/lib/HDLRuby/hruby_low2hdr.rb +66 -40
  27. data/lib/HDLRuby/hruby_low2high.rb +86 -44
  28. data/lib/HDLRuby/hruby_low2seq.rb +26 -18
  29. data/lib/HDLRuby/hruby_low2sym.rb +14 -13
  30. data/lib/HDLRuby/hruby_low2vhd.rb +78 -43
  31. data/lib/HDLRuby/hruby_low_bool2select.rb +61 -46
  32. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +56 -44
  33. data/lib/HDLRuby/hruby_low_cleanup.rb +18 -16
  34. data/lib/HDLRuby/hruby_low_fix_types.rb +64 -32
  35. data/lib/HDLRuby/hruby_low_mutable.rb +53 -118
  36. data/lib/HDLRuby/hruby_low_resolve.rb +26 -31
  37. data/lib/HDLRuby/hruby_low_with_bool.rb +33 -16
  38. data/lib/HDLRuby/hruby_low_with_port.rb +3 -3
  39. data/lib/HDLRuby/hruby_low_with_var.rb +23 -9
  40. data/lib/HDLRuby/hruby_low_without_concat.rb +19 -13
  41. data/lib/HDLRuby/hruby_low_without_namespace.rb +47 -32
  42. data/lib/HDLRuby/hruby_low_without_parinseq.rb +18 -12
  43. data/lib/HDLRuby/hruby_low_without_select.rb +36 -23
  44. data/lib/HDLRuby/hruby_low_without_subsignals.rb +79 -39
  45. data/lib/HDLRuby/hruby_rcsim.rb +79 -64
  46. data/lib/HDLRuby/hruby_rsim.rb +64 -15
  47. data/lib/HDLRuby/hruby_rsim_mute.rb +2 -3
  48. data/lib/HDLRuby/hruby_rsim_vcd.rb +28 -25
  49. data/lib/HDLRuby/hruby_types.rb +5 -5
  50. data/lib/HDLRuby/hruby_values.rb +19 -8
  51. data/lib/HDLRuby/hruby_verilog.rb +191 -65
  52. data/lib/HDLRuby/hruby_verilog_name.rb +49 -42
  53. data/lib/HDLRuby/soft/stacks.rb +219 -0
  54. data/lib/HDLRuby/std/bram.rb +9 -5
  55. data/lib/HDLRuby/std/clocks.rb +1 -1
  56. data/lib/HDLRuby/std/fsm.rb +39 -10
  57. data/lib/HDLRuby/std/sequencer.rb +2085 -0
  58. data/lib/HDLRuby/std/sequencer_func.rb +533 -0
  59. data/lib/HDLRuby/std/sequencer_sync.rb +400 -0
  60. data/lib/HDLRuby/std/std.rb +13 -0
  61. data/lib/HDLRuby/version.rb +1 -1
  62. data/tuto/adder_sat_flags_vcd.png +0 -0
  63. data/tuto/addsub_vcd.png +0 -0
  64. data/tuto/alu_vcd.png +0 -0
  65. data/tuto/bit_pong_vcd.png +0 -0
  66. data/tuto/checksum_vcd.png +0 -0
  67. data/tuto/circuit_hdr.odg +0 -0
  68. data/tuto/circuit_hdr.png +0 -0
  69. data/tuto/circuit_hie.odg +0 -0
  70. data/tuto/circuit_hie.png +0 -0
  71. data/tuto/circuit_view.odg +0 -0
  72. data/tuto/circuit_view.png +0 -0
  73. data/tuto/clock_counter_vcd.png +0 -0
  74. data/tuto/counter_ext_vcd.png +0 -0
  75. data/tuto/fact_vcd.png +0 -0
  76. data/tuto/hw_flow.odg +0 -0
  77. data/tuto/hw_flow.png +0 -0
  78. data/tuto/maxxer_vcd.png +0 -0
  79. data/tuto/pingpong0_vcd.png +0 -0
  80. data/tuto/pingpong1_vcd.png +0 -0
  81. data/tuto/pingpong2_vcd.png +0 -0
  82. data/tuto/ram_vcd.png +0 -0
  83. data/tuto/serializer_vcd.png +0 -0
  84. data/tuto/sw_flow.odg +0 -0
  85. data/tuto/sw_flow.png +0 -0
  86. data/tuto/the_counter_vcd.png +0 -0
  87. data/tuto/tutorial_sw.html +2359 -0
  88. data/tuto/tutorial_sw.md +2890 -0
  89. data/tuto/tutorial_sw.pdf +0 -0
  90. data/tuto/tutorial_sw_jp.md +417 -0
  91. metadata +46 -2
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -263,6 +263,9 @@ module HDLRuby
263
263
  # Initialize the environment for processing the hdr file.
264
264
  bind = TOPLEVEL_BINDING.clone
265
265
  eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind)
266
+ if $options[:std] then
267
+ eval("require 'std/std.rb'\n\ninclude HDLRuby::High::Std\n\n",bind)
268
+ end
266
269
  # Process it.
267
270
  eval(@texts[0],bind,@top_file_name,1)
268
271
  # Get the resulting instance
@@ -280,8 +283,8 @@ module HDLRuby
280
283
  end
281
284
 
282
285
 
283
- # Extend the Code class with generation of file for the content.
284
286
  class HDLRuby::Low::Code
287
+ ## Extends the Code class with generation of file for the content.
285
288
 
286
289
  ## Creates a file in +path+ containing the content of the code.
287
290
  def to_file(path = "")
@@ -337,6 +340,9 @@ end
337
340
  require 'optparse'
338
341
  # Process the command line options
339
342
  $options = {}
343
+ # By default the std libraries are loaded.
344
+ $options[:std] = true
345
+ # Parse the options
340
346
  $optparse = OptionParser.new do |opts|
341
347
  opts.banner = "Usage: hdrcc.rb [options] <input file> [<output directory or file>]"
342
348
 
@@ -435,6 +441,9 @@ $optparse = OptionParser.new do |opts|
435
441
  opts.on("--testall","Compile all the available unit tests.") do |t|
436
442
  $options[:testall] = t
437
443
  end
444
+ opts.on("--no-std", "Compile without the standard library.") do |t|
445
+ $options[:std] = false
446
+ end
438
447
  opts.on("-t", "--top system", "Specify the top system to process") do|t|
439
448
  $options[:top] = t
440
449
  end
@@ -445,7 +454,11 @@ $optparse = OptionParser.new do |opts|
445
454
  $options[:dump] = v
446
455
  $options[:multiple] = v
447
456
  end
448
- opts.on("--version", "Shows the version of HDLRuby.") do |v|
457
+ opts.on("--get-samples", "Copy the sample directory (hdr_samples) to current one, the exit") do
458
+ FileUtils.copy_entry(File.dirname(__FILE__) + "/hdr_samples","./hdr_samples")
459
+ exit
460
+ end
461
+ opts.on("--version", "Show the version of HDLRuby, then exit") do |v|
449
462
  puts VERSION
450
463
  exit
451
464
  end
@@ -808,7 +821,7 @@ elsif $options[:verilog] then
808
821
  $top_system.each_systemT_deep do |systemT|
809
822
  HDLRuby.show? "signal2subs step..."
810
823
  # Ensure there is not implicit assign to sub signals.
811
- systemT.signal2subs!
824
+ systemT.signal2subs!(true)
812
825
  # HDLRuby.show "casts_without_expression! step..."
813
826
  # systemT.casts_without_expression!
814
827
  # HDLRuby.show Time.now
@@ -226,8 +226,8 @@ module HDLRuby
226
226
  end
227
227
 
228
228
 
229
- # Extend the Code class with generation of file for the content.
230
229
  class HDLRuby::Low::Code
230
+ ## Extends the Code class with generation of file for the content.
231
231
 
232
232
  ## Creates a file in +path+ containing the content of the code.
233
233
  def to_file(path = "")
@@ -9,7 +9,7 @@ warn "hruby_db.rb (former hruby_low.rb) is deprecated."
9
9
  ##
10
10
  # Low-level libraries for describing digital hardware.
11
11
  #######################################################
12
- module HDLRuby::Low
12
+ module HDLRuby::LowDB
13
13
 
14
14
  Base = HDLRuby::Base
15
15
 
@@ -151,7 +151,7 @@ module HDLRuby::Low
151
151
  end
152
152
 
153
153
  ##
154
- # Describes a unsigned integer data type.
154
+ # Describes an unsigned integer data type.
155
155
  class TypeUnsigned < Base::TypeUnsigned
156
156
  include Ltype
157
157
  end
@@ -2044,7 +2044,7 @@ module HDLRuby::High
2044
2044
  end
2045
2045
 
2046
2046
  ##
2047
- # Describes a unsigned integer data type.
2047
+ # Describes an unsigned integer data type.
2048
2048
  class TypeUnsigned < TypeVector
2049
2049
 
2050
2050
  # Creates a new vector type named +name+ from +base+ type and with
@@ -2198,29 +2198,48 @@ module HDLRuby::High
2198
2198
  #
2199
2199
  # NOTE: a function is a short-cut for a method that creates a scope.
2200
2200
  def function(name, &ruby_block)
2201
+ warn("Construct 'function' is deprecated, use 'hdef' instead.")
2201
2202
  # Ensure there is a block.
2202
2203
  ruby_block = proc {} unless block_given?
2203
2204
  if HDLRuby::High.in_system? then
2204
2205
  define_singleton_method(name.to_sym) do |*args,&other_block|
2205
- # sub do
2206
2206
  sub(HDLRuby.uniq_name(name)) do
2207
2207
  HDLRuby::High.top_user.instance_exec(*args,*other_block,
2208
2208
  &ruby_block)
2209
- # ruby_block.call(*args)
2210
2209
  end
2211
2210
  end
2212
2211
  else
2213
2212
  define_method(name.to_sym) do |*args,&other_block|
2214
- # sub do
2215
2213
  sub(HDLRuby.uniq_name(name)) do
2216
2214
  HDLRuby::High.top_user.instance_exec(*args,*other_block,
2217
2215
  &ruby_block)
2218
- # ruby_block.call(*args,*other_block)
2219
2216
  end
2220
2217
  end
2221
2218
  end
2222
2219
  end
2223
2220
 
2221
+ # Declares a function named +name+ using +ruby_block+ as body.
2222
+ #
2223
+ # NOTE: a function is a short-cut for a method that creates a scope.
2224
+ def hdef(name, &ruby_block)
2225
+ # Ensure there is a block.
2226
+ ruby_block = proc {} unless block_given?
2227
+ if HDLRuby::High.in_system? then
2228
+ define_singleton_method(name.to_sym) do |*args,&other_block|
2229
+ sub(HDLRuby.uniq_name(name)) do
2230
+ HDLRuby::High.top_user.instance_exec(*args,*other_block,
2231
+ &ruby_block)
2232
+ end
2233
+ end
2234
+ else
2235
+ define_method(name.to_sym) do |*args,&other_block|
2236
+ sub(HDLRuby.uniq_name(name)) do
2237
+ HDLRuby::High.top_user.instance_exec(*args,*other_block,
2238
+ &ruby_block)
2239
+ end
2240
+ end
2241
+ end
2242
+ end
2224
2243
 
2225
2244
 
2226
2245
 
@@ -2855,17 +2874,17 @@ module HDLRuby::High
2855
2874
 
2856
2875
  # Casts to a bit vector type.
2857
2876
  def to_bit
2858
- return self.as(bit[self.width])
2877
+ return self.as(HDLRuby::High.top_user.bit[self.type.width])
2859
2878
  end
2860
2879
 
2861
2880
  # Casts to an unsigned bit vector type.
2862
2881
  def to_unsigned
2863
- return self.as(unsigned[self.width])
2882
+ return self.as(HDLRuby::High.top_user.unsigned[self.type.width])
2864
2883
  end
2865
2884
 
2866
2885
  # Casts to a signed bit vector type.
2867
- def to_unsigned
2868
- return self.as(signed[self.width])
2886
+ def to_signed
2887
+ return self.as(HDLRuby::High.top_user.signed[self.type.width])
2869
2888
  end
2870
2889
 
2871
2890
  # Extends on the left to +n+ bits filling with +v+ bit values.
@@ -2997,6 +3016,12 @@ module HDLRuby::High
2997
3016
  define_method(orig_operator(operator),&meth)
2998
3017
  end
2999
3018
 
3019
+ # The <=> operator is also supported by is transformed into a sub
3020
+ # with a signed result.
3021
+ def <=>(expr)
3022
+ return (self.as(self.type.base[self.type.width+1])-expr).to_signed
3023
+ end
3024
+
3000
3025
 
3001
3026
  # Creates an access to elements of range +rng+ of the signal.
3002
3027
  #
@@ -3128,7 +3153,6 @@ module HDLRuby::High
3128
3153
 
3129
3154
  # Converts the unary expression to HDLRuby::Low.
3130
3155
  def to_low
3131
- # return HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
3132
3156
  castL =HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
3133
3157
  # # For debugging: set the source high object
3134
3158
  # castL.properties[:low2high] = self.hdr_id
@@ -3188,7 +3212,7 @@ module HDLRuby::High
3188
3212
 
3189
3213
 
3190
3214
  ##
3191
- # Describes a section operation (generalization of the ternary operator).
3215
+ # Describes a selection operation (generalization of the ternary operator).
3192
3216
  #
3193
3217
  # NOTE: choice is using the value of +select+ as an index.
3194
3218
  class Select < Low::Select
@@ -3344,6 +3368,12 @@ module HDLRuby::High
3344
3368
  end
3345
3369
  end
3346
3370
 
3371
+ # Get the refered objects.
3372
+ def objects
3373
+ return [ self.object] if self.is_a?(RefObject)
3374
+ return self.each.map { |ref| ref.objects }.flatten
3375
+ end
3376
+
3347
3377
  # Reference can be used like enumerator
3348
3378
  include Enumerable
3349
3379
  end
@@ -4410,14 +4440,14 @@ module HDLRuby::High
4410
4440
  super(nil)
4411
4441
  # # Save the Location for debugging information
4412
4442
  # @location = caller_locations
4413
- # Sets the current behavior
4414
- @@cur_behavior = self
4443
+ # # Sets the current behavior
4444
+ # @@cur_behavior = self
4415
4445
  # Add the events (they may be hierarchical to flatten)
4416
4446
  events.flatten.each { |event| self.add_event(event) }
4417
4447
  # Create and add the block.
4418
4448
  self.block = High.make_block(mode,&ruby_block)
4419
- # Unset the current behavior
4420
- @@cur_behavior = nil
4449
+ # # Unset the current behavior
4450
+ # @@cur_behavior = nil
4421
4451
  end
4422
4452
 
4423
4453
  # Sets an event to the behavior.
@@ -4584,12 +4614,21 @@ module HDLRuby::High
4584
4614
  end
4585
4615
  end
4586
4616
 
4587
- # The current behavior: by default none.
4588
- @@cur_behavior = nil
4617
+ # # The current behavior: by default none.
4618
+ # @@cur_behavior = nil
4589
4619
 
4590
4620
  # Gets the enclosing behavior if any.
4591
4621
  def self.cur_behavior
4592
- return @@cur_behavior
4622
+ # return @@cur_behavior
4623
+ if in_behavior? then
4624
+ user = top_user
4625
+ while(user && !user.is_a?(Behavior)) do
4626
+ user = user.parent
4627
+ end
4628
+ return user
4629
+ else
4630
+ return nil
4631
+ end
4593
4632
  end
4594
4633
 
4595
4634
  # Tell if we are in a behavior.
@@ -4765,13 +4804,10 @@ module HDLRuby::High
4765
4804
  return Value.new(TypeSigned.new(:"",self.bit_length..0),self)
4766
4805
  end
4767
4806
  end
4768
- end
4769
-
4770
- # Extends the Float class for computing for conversion to expression.
4771
- class ::Float
4772
- # Converts to a new high-level expression.
4773
- def to_expr
4774
- return Value.new(Float,self)
4807
+
4808
+ # Gets the bit width
4809
+ def width
4810
+ return self.bit_length
4775
4811
  end
4776
4812
  end
4777
4813
 
@@ -5,10 +5,11 @@ require "HDLRuby/hruby_high"
5
5
  module HDLRuby::High
6
6
 
7
7
  ##
8
- # Library for describing adding the fullname method to HDLRuby::High objects.
8
+ # Library for adding the fullname method to HDLRuby::High objects.
9
9
  #
10
10
  ########################################################################
11
11
 
12
+
12
13
  class SystemT
13
14
 
14
15
  ## Returns the name of the signal with its hierarchy.
@@ -32,6 +33,7 @@ module HDLRuby::High
32
33
 
33
34
  end
34
35
 
36
+
35
37
  class Scope
36
38
  include WithFullname
37
39
  end
@@ -1919,7 +1919,7 @@ module HDLRuby::Low
1919
1919
  end
1920
1920
 
1921
1921
  ##
1922
- # Describes a unsigned integer data type.
1922
+ # Describes an unsigned integer data type.
1923
1923
  class TypeUnsigned < TypeVector
1924
1924
 
1925
1925
  # Creates a new vector type named +name+ from +base+ type and with
@@ -6117,7 +6117,7 @@ module HDLRuby::Low
6117
6117
 
6118
6118
 
6119
6119
  ##
6120
- # Describe a this reference.
6120
+ # Describes a this reference.
6121
6121
  #
6122
6122
  # This is the current system.
6123
6123
  class RefThis < Ref