HDLRuby 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/HDLRuby.gemspec +1 -0
  3. data/README.md +149 -79
  4. data/ext/hruby_sim/hruby_rcsim_build.c +2 -0
  5. data/ext/hruby_sim/hruby_sim_calc.c +33 -6
  6. data/ext/hruby_sim/hruby_sim_tree_calc.c +111 -22
  7. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +2 -2
  8. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +2 -1
  9. data/lib/HDLRuby/hdr_samples/counter_bench.rb +1 -1
  10. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +8 -7
  11. data/lib/HDLRuby/hdr_samples/dff_properties.rb +2 -0
  12. data/lib/HDLRuby/hdr_samples/enum_as_param.rb +52 -0
  13. data/lib/HDLRuby/hdr_samples/linear_test.rb +2 -0
  14. data/lib/HDLRuby/hdr_samples/logic_bench.rb +6 -0
  15. data/lib/HDLRuby/hdr_samples/mei8.rb +6 -6
  16. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +6 -6
  17. data/lib/HDLRuby/hdr_samples/memory_test.rb +2 -0
  18. data/lib/HDLRuby/hdr_samples/named_sub.rb +9 -5
  19. data/lib/HDLRuby/hdr_samples/ram.rb +7 -6
  20. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +2 -0
  21. data/lib/HDLRuby/hdr_samples/struct.rb +15 -3
  22. data/lib/HDLRuby/hdr_samples/with_bram.rb +1 -1
  23. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +1 -1
  24. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +1 -1
  25. data/lib/HDLRuby/hdr_samples/with_channel.rb +2 -0
  26. data/lib/HDLRuby/hdr_samples/with_channel_other.rb +2 -0
  27. data/lib/HDLRuby/hdr_samples/with_class.rb +3 -1
  28. data/lib/HDLRuby/hdr_samples/with_connector.rb +2 -0
  29. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -0
  30. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +6 -0
  31. data/lib/HDLRuby/hdr_samples/with_fixpoint_adv.rb +73 -0
  32. data/lib/HDLRuby/hdr_samples/with_leftright.rb +1 -1
  33. data/lib/HDLRuby/hdr_samples/with_ref_expr.rb +30 -0
  34. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +49 -37
  35. data/lib/HDLRuby/hdr_samples/with_sequencer_channel.rb +58 -0
  36. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +113 -69
  37. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +28 -14
  38. data/lib/HDLRuby/hdr_samples/with_sequencer_func.rb +63 -0
  39. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +2 -1
  40. data/lib/HDLRuby/hdrcc.rb +13 -1
  41. data/lib/HDLRuby/hruby_high.rb +105 -31
  42. data/lib/HDLRuby/hruby_low.rb +127 -3
  43. data/lib/HDLRuby/hruby_low2programs.rb +47 -0
  44. data/lib/HDLRuby/hruby_low_resolve.rb +3 -2
  45. data/lib/HDLRuby/hruby_low_without_namespace.rb +133 -5
  46. data/lib/HDLRuby/hruby_low_without_subsignals.rb +51 -12
  47. data/lib/HDLRuby/hruby_rcsim.rb +24 -1
  48. data/lib/HDLRuby/hruby_serializer.rb +2 -1
  49. data/lib/HDLRuby/hruby_types.rb +5 -5
  50. data/lib/HDLRuby/hruby_values.rb +7 -7
  51. data/lib/HDLRuby/hruby_verilog.rb +193 -35
  52. data/lib/HDLRuby/hruby_verilog_name.rb +35 -42
  53. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  54. data/lib/HDLRuby/std/fsm.rb +10 -1
  55. data/lib/HDLRuby/std/function_generator.rb +1 -1
  56. data/lib/HDLRuby/std/linear.rb +7 -7
  57. data/lib/HDLRuby/std/sequencer.rb +538 -60
  58. data/lib/HDLRuby/std/sequencer_channel.rb +90 -0
  59. data/lib/HDLRuby/std/sequencer_func.rb +546 -0
  60. data/lib/HDLRuby/std/std.rb +2 -0
  61. data/lib/HDLRuby/version.rb +1 -1
  62. data/tuto/tutorial_sw.md +267 -61
  63. metadata +25 -4
  64. data/lib/HDLRuby/hdr_samples/with_register_stack.rb +0 -150
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -84,6 +84,10 @@ require 'HDLRuby/backend/hruby_c_allocator'
84
84
 
85
85
  require 'HDLRuby/version.rb'
86
86
 
87
+ # Global flags
88
+ $sim = false # Tells if hdrcc is in simulation mode
89
+ $gen = false # Tells if hdrcc is in hardware generation mode
90
+
87
91
 
88
92
  ##
89
93
  # HDLRuby compiler interface program
@@ -373,19 +377,23 @@ $optparse = OptionParser.new do |opts|
373
377
  opts.on("-S","--sim","Default simulator (hybrid C-Ruby)") do |v|
374
378
  $options[:rcsim] = v
375
379
  $options[:multiple] = v
380
+ $sim = true
376
381
  end
377
382
  opts.on("--csim","Standalone C-based simulator") do |v|
378
383
  $options[:clang] = v
379
384
  $options[:multiple] = v
380
385
  $options[:csim] = v
386
+ $sim = true
381
387
  end
382
388
  opts.on("--rsim","Ruby-based simulator") do |v|
383
389
  $options[:rsim] = v
384
390
  $options[:multiple] = v
391
+ $sim = true
385
392
  end
386
393
  opts.on("--rcsim","Hybrid C-Ruby-based simulator") do |v|
387
394
  $options[:rcsim] = v
388
395
  $options[:multiple] = v
396
+ $sim = true
389
397
  end
390
398
  opts.on("--mute", "The simulator will not generate any output") do |v|
391
399
  $options[:mute] = v
@@ -396,12 +404,14 @@ $optparse = OptionParser.new do |opts|
396
404
  opts.on("-v", "--verilog","Output in Verlog HDL format") do |v|
397
405
  $options[:verilog] = v
398
406
  $options[:multiple] = v
407
+ $gen = true
399
408
  end
400
409
  opts.on("-V", "--vhdl","Output in VHDL format") do |v|
401
410
  HDLRuby::Low::Low2VHDL.vhdl08 = false
402
411
  $options[:vhdl] = v
403
412
  $options[:multiple] = v
404
413
  $options[:vhdl08] = false
414
+ $gen = true
405
415
  end
406
416
  opts.on("-A", "--alliance","Output in Alliance-compatible VHDL format") do |v|
407
417
  HDLRuby::Low::Low2VHDL.vhdl08 = false
@@ -410,12 +420,14 @@ $optparse = OptionParser.new do |opts|
410
420
  $options[:alliance] = v
411
421
  $options[:multiple] = v
412
422
  $options[:vhdl08] = false
423
+ $gen = true
413
424
  end
414
425
  opts.on("-U", "--vhdl08","Output in VHDL'08 format") do |v|
415
426
  HDLRuby::Low::Low2VHDL.vhdl08 = true
416
427
  $options[:vhdl] = v
417
428
  $options[:multiple] = v
418
429
  $options[:vhdl08] = true
430
+ $gen = true
419
431
  end
420
432
  opts.on("-s", "--syntax","Output the Ruby syntax tree") do |s|
421
433
  $options[:syntax] = s
@@ -821,7 +833,7 @@ elsif $options[:verilog] then
821
833
  $top_system.each_systemT_deep do |systemT|
822
834
  HDLRuby.show? "signal2subs step..."
823
835
  # Ensure there is not implicit assign to sub signals.
824
- systemT.signal2subs!
836
+ systemT.signal2subs!(true)
825
837
  # HDLRuby.show "casts_without_expression! step..."
826
838
  # systemT.casts_without_expression!
827
839
  # HDLRuby.show Time.now
@@ -880,9 +880,11 @@ module HDLRuby::High
880
880
  "Cannot convert a system without a name to HDLRuby::Low."
881
881
  end
882
882
  # Create the resulting low system type.
883
- # systemTL = HDLRuby::Low::SystemT.new(High.names_create(name),
884
- systemTL = HDLRuby::Low::SystemT.new(HDLRuby.uniq_name(name),
885
- self.scope.to_low)
883
+ # systemTL = HDLRuby::Low::SystemT.new(HDLRuby.uniq_name(name),
884
+ # self.scope.to_low)
885
+ systemTLN = HDLRuby.uniq_name(name)
886
+ systemTL = HDLRuby::Low::SystemT.new(systemTLN,
887
+ self.scope.to_low(systemTLN))
886
888
  # puts "New low from system #{self.name}: #{systemTL.name}"
887
889
  # # For debugging: set the source high object
888
890
  # systemTL.properties[:low2high] = self.hdr_id
@@ -1168,6 +1170,17 @@ module HDLRuby::High
1168
1170
  self.parent.inout(*names)
1169
1171
  end
1170
1172
 
1173
+ # Declares a program in language +lang+ with start function named +func+
1174
+ # and accessed expressions an code given in +args+.
1175
+ def program(lang, func, *args)
1176
+ # Create the program.
1177
+ prog = Program.new(lang, func, *args)
1178
+ # Adds the resulting program to the current scope.
1179
+ HDLRuby::High.top_user.add_program(prog)
1180
+ # Return the resulting program
1181
+ return prog
1182
+ end
1183
+
1171
1184
  # Declares a non-HDLRuby set of code chunks described by +content+ and
1172
1185
  # completed from +ruby_block+ execution result.
1173
1186
  # NOTE: content includes the events to activate the code on and
@@ -1512,6 +1525,8 @@ module HDLRuby::High
1512
1525
  scopeL.add_systemT(systemI_low.systemT)
1513
1526
  }
1514
1527
  end
1528
+ # Adds the programs.
1529
+ self.each_program { |prog| scopeL.add_program(prog.to_low) }
1515
1530
  # Adds the code chunks.
1516
1531
  self.each_code { |code| scopeL.add_code(code.to_low) }
1517
1532
  # Adds the connections.
@@ -1526,10 +1541,15 @@ module HDLRuby::High
1526
1541
  end
1527
1542
 
1528
1543
  # Converts the scope to HDLRuby::Low.
1529
- def to_low()
1544
+ # +name+ is the name of the system containing the new low scope in case
1545
+ # of top scope, should be used as name for it.
1546
+ # NOTE: by convention, the name of the top scope is the name of the
1547
+ # system.
1548
+ def to_low(low_name = nil)
1530
1549
  # Create the resulting low scope.
1531
1550
  # scopeL = HDLRuby::Low::Scope.new()
1532
- scopeL = HDLRuby::Low::Scope.new(self.name)
1551
+ low_name = self.name unless low_name
1552
+ scopeL = HDLRuby::Low::Scope.new(low_name)
1533
1553
  # # For debugging: set the source high object
1534
1554
  # scopeL.properties[:low2high] = self.hdr_id
1535
1555
  # self.properties[:high2low] = scopeL
@@ -1974,7 +1994,7 @@ module HDLRuby::High
1974
1994
  raise AnyError, "Generic type #{self.name} did not produce a valid type: #{gtype.class}"
1975
1995
  end
1976
1996
  # Create a new type definition from it.
1977
- gtype = TypeDef.new(self.name.to_s + "_#{args.join(":")}",
1997
+ gtype = TypeDef.new(self.name.to_s + "_#{args.join(':')}",
1978
1998
  gtype)
1979
1999
  # Adds the possible overloaded operators.
1980
2000
  self.each_overload do |op,ruby_block|
@@ -2168,6 +2188,7 @@ module HDLRuby::High
2168
2188
 
2169
2189
  # Methods for declaring systems
2170
2190
 
2191
+
2171
2192
  # Declares a high-level system type named +name+, with +includes+ mixins
2172
2193
  # system types and using +ruby_block+ for instantiating.
2173
2194
  def system(name = :"", *includes, &ruby_block)
@@ -2198,29 +2219,48 @@ module HDLRuby::High
2198
2219
  #
2199
2220
  # NOTE: a function is a short-cut for a method that creates a scope.
2200
2221
  def function(name, &ruby_block)
2222
+ warn("Construct 'function' is deprecated, use 'hdef' instead.")
2201
2223
  # Ensure there is a block.
2202
2224
  ruby_block = proc {} unless block_given?
2203
2225
  if HDLRuby::High.in_system? then
2204
2226
  define_singleton_method(name.to_sym) do |*args,&other_block|
2205
- # sub do
2206
2227
  sub(HDLRuby.uniq_name(name)) do
2207
2228
  HDLRuby::High.top_user.instance_exec(*args,*other_block,
2208
2229
  &ruby_block)
2209
- # ruby_block.call(*args)
2210
2230
  end
2211
2231
  end
2212
2232
  else
2213
2233
  define_method(name.to_sym) do |*args,&other_block|
2214
- # sub do
2215
2234
  sub(HDLRuby.uniq_name(name)) do
2216
2235
  HDLRuby::High.top_user.instance_exec(*args,*other_block,
2217
2236
  &ruby_block)
2218
- # ruby_block.call(*args,*other_block)
2219
2237
  end
2220
2238
  end
2221
2239
  end
2222
2240
  end
2223
2241
 
2242
+ # Declares a function named +name+ using +ruby_block+ as body.
2243
+ #
2244
+ # NOTE: a function is a short-cut for a method that creates a scope.
2245
+ def hdef(name, &ruby_block)
2246
+ # Ensure there is a block.
2247
+ ruby_block = proc {} unless block_given?
2248
+ if HDLRuby::High.in_system? then
2249
+ define_singleton_method(name.to_sym) do |*args,&other_block|
2250
+ sub(HDLRuby.uniq_name(name)) do
2251
+ HDLRuby::High.top_user.instance_exec(*args,*other_block,
2252
+ &ruby_block)
2253
+ end
2254
+ end
2255
+ else
2256
+ define_method(name.to_sym) do |*args,&other_block|
2257
+ sub(HDLRuby.uniq_name(name)) do
2258
+ HDLRuby::High.top_user.instance_exec(*args,*other_block,
2259
+ &ruby_block)
2260
+ end
2261
+ end
2262
+ end
2263
+ end
2224
2264
 
2225
2265
 
2226
2266
 
@@ -2275,24 +2315,8 @@ module HDLRuby::High
2275
2315
  # Performs the connections.
2276
2316
  connects.each do |key,value|
2277
2317
  # Gets the signal corresponding to connect.
2278
- # signal = self.get_signal(key)
2279
- # unless signal then
2280
- # # Look into the included systems.
2281
- # self.systemT.scope.each_included do |included|
2282
- # signal = included.get_signal(key)
2283
- # break if signal
2284
- # end
2285
- # end
2286
2318
  signal = self.systemT.get_signal_with_included(key)
2287
2319
  # Check if it is an output.
2288
- # isout = self.get_output(key)
2289
- # unless isout then
2290
- # # Look into the inlucded systems.
2291
- # self.systemT.scope.each_included do |included|
2292
- # isout = included.get_output(key)
2293
- # break if isout
2294
- # end
2295
- # end
2296
2320
  isout = self.systemT.get_output_with_included(key)
2297
2321
  # Convert it to a reference.
2298
2322
  # puts "key=#{key} value=#{value} signal=#{signal}"
@@ -2422,7 +2446,6 @@ module HDLRuby::High
2422
2446
 
2423
2447
  # Gets the private namespace.
2424
2448
  def namespace
2425
- # self.systemT.scope.namespace
2426
2449
  self.systemT.namespace
2427
2450
  end
2428
2451
 
@@ -2473,6 +2496,25 @@ module HDLRuby::High
2473
2496
  end
2474
2497
  end
2475
2498
 
2499
+
2500
+
2501
+
2502
+ ##
2503
+ # Describes a program.
2504
+ class Program < HDLRuby::Low::Program
2505
+ # Converts the if to HDLRuby::Low.
2506
+ def to_low
2507
+ # Create the resulting program.
2508
+ progL = HDLRuby::Low::Program.new(self.lang,self.function,
2509
+ *self.each_expression.map(&:to_low),
2510
+ *self.each_event.map(&:to_low),
2511
+ *self.each_code)
2512
+ # Return the resulting program.
2513
+ return progL
2514
+ end
2515
+ end
2516
+
2517
+
2476
2518
  ##
2477
2519
  # Decribes a set of non-HDLRuby code chunks.
2478
2520
  class Code < HDLRuby::Low::Code
@@ -3134,7 +3176,6 @@ module HDLRuby::High
3134
3176
 
3135
3177
  # Converts the unary expression to HDLRuby::Low.
3136
3178
  def to_low
3137
- # return HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
3138
3179
  castL =HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
3139
3180
  # # For debugging: set the source high object
3140
3181
  # castL.properties[:low2high] = self.hdr_id
@@ -3318,6 +3359,24 @@ module HDLRuby::High
3318
3359
  include HExpression
3319
3360
  include HArrow
3320
3361
 
3362
+ # Update the initialize to handle struct types accesses if
3363
+ # it is not a RefObject, this latter being a proxy to a
3364
+ # real component.
3365
+ if klass != RefObject then
3366
+ original_initialize = instance_method(:initialize)
3367
+ define_method(:initialize) do |*args, &block|
3368
+ original_initialize.bind(self).call(*args,&block)
3369
+ # Now process it if it is a structured type.
3370
+ if self.type.struct? then
3371
+ self.type.each do |name,typ|
3372
+ self.define_singleton_method(name) do
3373
+ RefName.new(typ,self,name)
3374
+ end
3375
+ end
3376
+ end
3377
+ end
3378
+ end
3379
+
3321
3380
  # Converts to a new expression.
3322
3381
  def to_expr
3323
3382
  self.to_ref
@@ -3418,15 +3477,22 @@ module HDLRuby::High
3418
3477
  # Converts the name reference to a HDLRuby::Low::RefName.
3419
3478
  def to_low
3420
3479
  # puts "to_low with base=#{@base} @object=#{@object}"
3421
- # puts "@object.name=#{@object.name}"
3480
+ # puts "@object.name=#{@object.name} @object.parent=#{@object.parent.name}"
3422
3481
  if @base.is_a?(RefThis) &&
3423
3482
  (@object.parent != High.top_user) &&
3424
3483
  (@object.parent != High.cur_system) &&
3484
+ (@object.parent != High.cur_system.scope) &&
3425
3485
  (!@object.parent.name.empty?) then
3426
3486
  # Need to have a hierachical access.
3427
- # puts "Indirect access for #{self.object.name}: #{self.object.parent.name}(#{self.object.parent.class}) != #{High.cur_system.name}(#{High.top_user.class})"
3428
- refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
3487
+ if @object.respond_to?(:low_object) && @object.low_object then
3488
+ # There where already a low object, create the ref from it.
3489
+ # puts "absolute ref!"
3490
+ refNameL = @object.low_object.absolute_ref
3491
+ else
3492
+ # No create the indirect reference.
3493
+ refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
3429
3494
  @object.parent.to_ref.to_low,@object.name)
3495
+ end
3430
3496
  else
3431
3497
  # Direct access is enough.
3432
3498
  refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
@@ -3954,11 +4020,19 @@ module HDLRuby::High
3954
4020
  return [obj,self.to_expr]
3955
4021
  end
3956
4022
 
4023
+ # Get the low version off the object.
4024
+ # NOTE: only useful for Signals and SystemIs since they can be accessed
4025
+ # from outside the module they have been defined in.
4026
+ def low_object
4027
+ return @low_object
4028
+ end
4029
+
3957
4030
  # Converts the system to HDLRuby::Low and set its +name+.
3958
4031
  def to_low(name = self.name)
3959
4032
  # return HDLRuby::Low::SignalI.new(name,self.type.to_low)
3960
4033
  valueL = self.value ? self.value.to_low : nil
3961
4034
  signalIL = HDLRuby::Low::SignalI.new(name,self.type.to_low,valueL)
4035
+ @low_object = signalIL
3962
4036
  # Recurse on the sub signals if any.
3963
4037
  self.each_signal do |sig|
3964
4038
  signalIL.add_signal(sig.to_low)
@@ -79,6 +79,24 @@ module HDLRuby::Low
79
79
  end
80
80
  return res
81
81
  end
82
+
83
+ # Get an absolute reference to the object.
84
+ def absolute_ref
85
+ # Get the full hierarchy up to the object.
86
+ path = self.hierarchy
87
+ # Create the reference.
88
+ # return path.reduce(RefThis.new) do |ref,node|
89
+ return path.reverse_each.reduce(RefThis.new) do |ref,node|
90
+ # puts "node=#{node}"
91
+ # puts "name=#{node.name}" if node.respond_to?(:name)
92
+ if node.respond_to?(:name) then
93
+ typ = node.respond_to?(:type) ? node.type : void
94
+ RefName.new(typ,ref,node.name)
95
+ else
96
+ ref
97
+ end
98
+ end
99
+ end
82
100
  end
83
101
 
84
102
 
@@ -98,7 +116,8 @@ module HDLRuby::Low
98
116
  attr_reader :scope
99
117
 
100
118
  # Creates a new system type named +name+ with +scope+.
101
- def initialize(name,scope)
119
+ # def initialize(name,scope)
120
+ def initialize(name,scope = nil)
102
121
  # Set the name as a symbol.
103
122
  @name = name.to_sym
104
123
 
@@ -109,6 +128,13 @@ module HDLRuby::Low
109
128
  @interface = [] # The interface signals in order of
110
129
  # declaration
111
130
 
131
+ # self.set_scope(scope) if scope
132
+ # end
133
+
134
+ # # Set the scope of the systemT to +scope+.
135
+ # # Note: cannot override an existing scope.
136
+ # def set_scope(scope)
137
+ # raise(AnyError,"Scope already present") if @scope
112
138
  # Check the scope
113
139
  unless scope.is_a?(Scope)
114
140
  raise AnyError,
@@ -313,7 +339,7 @@ module HDLRuby::Low
313
339
  # Returns an enumerator if no ruby block is given.
314
340
  def each_signal_all(&ruby_block)
315
341
  # No ruby block? Return an enumerator.
316
- return to_enum(:each_signal) unless ruby_block
342
+ return to_enum(:each_signal_all) unless ruby_block
317
343
  # A ruby block? Apply it on each signal instance.
318
344
  @inputs.each(&ruby_block)
319
345
  @outputs.each(&ruby_block)
@@ -526,6 +552,8 @@ module HDLRuby::Low
526
552
  @inners = HashName.new
527
553
  # Initialize the system instances list.
528
554
  @systemIs = HashName.new
555
+ # Initialize the programs list.
556
+ @programs = []
529
557
  # Initialize the non-HDLRuby code chunks list.
530
558
  @codes = []
531
559
  # Initialize the connections list.
@@ -804,7 +832,40 @@ module HDLRuby::Low
804
832
  # end
805
833
  # systemI
806
834
  # end
835
+
836
+
837
+ # Handling the programs.
838
+
839
+ # Adds program +prog+.
840
+ def add_program(prog)
841
+ # Check and add the program.
842
+ unless prog.is_a?(Program)
843
+ raise AnyError,
844
+ "Invalid class for a program: #{prog.class}"
845
+ end
846
+ # Set the parent of the program.
847
+ program.parent = self
848
+ # Add the program.
849
+ @programs << program
850
+ program
851
+ end
852
+
853
+ # Iterates over the programs.
807
854
  #
855
+ # Returns an enumerator if no ruby block is given.
856
+ def each_program(&ruby_block)
857
+ # puts "each_program from scope=#{self}"
858
+ # No ruby block? Return an enumerator.
859
+ return to_enum(:each_program) unless ruby_block
860
+ # A ruby block? Apply it on each program.
861
+ @programs.each(&ruby_block)
862
+ end
863
+
864
+ # Tells if there is any program.
865
+ def has_program?
866
+ return !@programs.empty?
867
+ end
868
+
808
869
  # Handling the non-HDLRuby code chunks.
809
870
 
810
871
  # Adds code chunk +code+.
@@ -832,7 +893,7 @@ module HDLRuby::Low
832
893
  # puts "each_code from scope=#{self}"
833
894
  # No ruby block? Return an enumerator.
834
895
  return to_enum(:each_code) unless ruby_block
835
- # A ruby block? Apply it on each system instance.
896
+ # A ruby block? Apply it on each code.
836
897
  @codes.each(&ruby_block)
837
898
  end
838
899
 
@@ -2936,6 +2997,69 @@ module HDLRuby::Low
2936
2997
  end
2937
2998
 
2938
2999
 
3000
+ ##
3001
+ # Describes a program.
3002
+ class Program
3003
+
3004
+ include Hparent
3005
+
3006
+ attr_reader :language, :function
3007
+
3008
+ # Creates a new program in language +lang+ with start function
3009
+ # named +func+ accessed expressions, events and code files given in
3010
+ # +args+.
3011
+ def initialize(lang,func,*args)
3012
+ # Sets the language.
3013
+ @language = lang.to_sym
3014
+ # Sets the start function.
3015
+ @function = func.to_s
3016
+ # Process the expressions and code files arguments.
3017
+ @exprs = []
3018
+ @events = []
3019
+ @codes = []
3020
+ args.each do |arg|
3021
+ if arg.is_a?(String) then
3022
+ @codes << arg
3023
+ elsif arg.is_a?(Event) then
3024
+ @events << arg
3025
+ else
3026
+ @exprs << arg.to_expr
3027
+ end
3028
+ end
3029
+ end
3030
+
3031
+ # Iterates over each accessed expression.
3032
+ #
3033
+ # Returns an enumerator if no ruby block is given.
3034
+ def each_expression(&ruby_block)
3035
+ # No block? Return an enumerator.
3036
+ return to_enum(:each_expression) unless ruby_block
3037
+ # A block is given, apply it.
3038
+ @exprs.each(&ruby_block)
3039
+ end
3040
+
3041
+ # Iterates over each accessed event.
3042
+ #
3043
+ # Returns an enumerator if no ruby block is given.
3044
+ def each_event(&ruby_block)
3045
+ # No block? Return an enumerator.
3046
+ return to_enum(:each_event) unless ruby_block
3047
+ # A block is given, apply it.
3048
+ @events.each(&ruby_block)
3049
+ end
3050
+
3051
+ # Iterates over each code files.
3052
+ #
3053
+ # Returns an enumerator if no ruby block is given.
3054
+ def each_code(&ruby_block)
3055
+ # No block? Return an enumerator.
3056
+ return to_enum(:each_code) unless ruby_block
3057
+ # A block is given, apply it.
3058
+ @codes.each(&ruby_block)
3059
+ end
3060
+ end
3061
+
3062
+
2939
3063
  ##
2940
3064
  # Decribes a set of non-HDLRuby code chunks.
2941
3065
  class Code
@@ -0,0 +1,47 @@
1
+ require 'HDLRuby'
2
+ require 'HDLRuby/hruby_low_with_bool'
3
+ require 'HDLRuby/hruby_low_without_namespace'
4
+ require 'HDLRuby/hruby_low_with_var'
5
+
6
+
7
+ module HDLRuby::Low
8
+
9
+
10
+ ##
11
+ # Converts a HDLRuby::Low description to descriptions of software programs.
12
+ #
13
+ ########################################################################
14
+
15
+ ## Provides tools for extracting software from HDLRuby description.
16
+ module Low2Programs
17
+
18
+ class SystemT
19
+ ## Extends the SystemT class with extraction of software.
20
+
21
+ # Extract the information about the software in the system and put it
22
+ # into +target+ directory.
23
+ def extract_programs(target)
24
+ # Gather the programs descriptions.
25
+ programs = self.scope.each_scope_deep.map do |scope|
26
+ scope.each_program.to_a
27
+ end
28
+ programs.flatten!
29
+ # Sort the programs by language.
30
+ lang2prog = Hash.new([])
31
+ programs.each { |prog| lang2prog[prog.language] << prog }
32
+ # Copy the programs in the corresponding subdirectories.
33
+ lang2prog.each do |lang,progs|
34
+ dir = target + "/" + lang
35
+ Dir.mkdir(dir)
36
+ progs.each do |prog|
37
+ prog.each_code { |code| FileUtils.cp(code,dir) }
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ class Scope
45
+ end
46
+
47
+ end
@@ -233,6 +233,7 @@ module HDLRuby::Low
233
233
  if self.ref.is_a?(RefName) then
234
234
  obj = self.ref.resolve
235
235
  # puts "obj=#{obj}"
236
+ return obj if obj.name == self.name
236
237
  # Look into the object for the name.
237
238
  return obj.get_by_name(self.name)
238
239
  else
@@ -242,9 +243,9 @@ module HDLRuby::Low
242
243
  while parent
243
244
  # puts "parent=#{parent}"
244
245
  if parent.respond_to?(:get_by_name) then
245
- # puts "get_by_name"
246
+ # puts "Going get_by_name with name=#{self.name}"
246
247
  found = parent.get_by_name(self.name)
247
- # puts "found" if found
248
+ # puts "found=#{found}" if found
248
249
  return found if found
249
250
  end
250
251
  parent = parent.parent