HDLRuby 3.3.4 → 3.5.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.
@@ -420,6 +420,7 @@ module HDLRuby::High
420
420
  #
421
421
  # NOTE: a name can also be a signal, is which case it is duplicated.
422
422
  def make_inputs(type, *names)
423
+ # puts "for inputs=#{names} top_user=#{High.top_user}(#{High.top_user.name}) @scope=#{@scope}(#{@scope.name})"
423
424
  # Check if called within the top scope of the block.
424
425
  if High.top_user != @scope then
425
426
  # No, cannot make an input from here.
@@ -874,6 +875,7 @@ module HDLRuby::High
874
875
 
875
876
  # Converts the system to HDLRuby::Low and set its +name+.
876
877
  def to_low(name = self.name)
878
+ # puts "to_low for system=#{name}"
877
879
  name = name.to_s
878
880
  if name.empty? then
879
881
  raise AnyError,
@@ -1235,8 +1237,10 @@ module HDLRuby::High
1235
1237
  end
1236
1238
 
1237
1239
  # Declares a high-level sequential behavior activated on a list of
1238
- # +events+, and built by executing +ruby_block+.
1239
- def seq(*events, &ruby_block)
1240
+ # +events+, with possible name +name+ and built by executing
1241
+ # +ruby_block+.
1242
+ # def seq(*events, &ruby_block)
1243
+ def seq(*events, name: nil, &ruby_block)
1240
1244
  # Ensure there is a block.
1241
1245
  ruby_block = proc {} unless block_given?
1242
1246
  # Preprocess the events.
@@ -1244,12 +1248,16 @@ module HDLRuby::High
1244
1248
  event.respond_to?(:to_event) ? event.to_event : event
1245
1249
  end
1246
1250
  # Create and add the resulting behavior.
1247
- self.add_behavior(Behavior.new(:seq,*events,&ruby_block))
1251
+ # self.add_behavior(Behavior.new(:seq,*events,&ruby_block))
1252
+ self.add_behavior(Behavior.new(:seq,*events,name: name,
1253
+ &ruby_block))
1248
1254
  end
1249
1255
 
1250
1256
  # Declares a high-level parallel behavior activated on a list of
1251
- # +events+, and built by executing +ruby_block+.
1252
- def par(*events, &ruby_block)
1257
+ # +events+, with possible name +name+ and built by executing
1258
+ # +ruby_block+.
1259
+ # def par(*events, &ruby_block)
1260
+ def par(*events, name: nil, &ruby_block)
1253
1261
  # Ensure there is a block.
1254
1262
  ruby_block = proc {} unless block_given?
1255
1263
  # Preprocess the events.
@@ -1257,7 +1265,8 @@ module HDLRuby::High
1257
1265
  event.respond_to?(:to_event) ? event.to_event : event
1258
1266
  end
1259
1267
  # Create and add the resulting behavior.
1260
- self.add_behavior(Behavior.new(:par,*events,&ruby_block))
1268
+ self.add_behavior(Behavior.new(:par,*events,name: name,
1269
+ &ruby_block))
1261
1270
  end
1262
1271
 
1263
1272
  # Declares a high-level timed behavior built by executing +ruby_block+.
@@ -2271,6 +2280,22 @@ module HDLRuby::High
2271
2280
  end
2272
2281
 
2273
2282
 
2283
+ ## Methods for loading external files.
2284
+
2285
+ # Require a verilog file.
2286
+ def require_verilog(filename)
2287
+ # Converts the file to HDLRuby.
2288
+ if Kernel.system("v2hdr", "#{filename}", "#{filename}.rb") then
2289
+ # Success, require the resulting file.
2290
+ require "#{Dir.pwd}/#{filename}.rb"
2291
+ else
2292
+ # Failure.
2293
+ raise AnyError,
2294
+ "Could not load Verilog HDL file: #{filename}."
2295
+ end
2296
+ end
2297
+
2298
+
2274
2299
 
2275
2300
  # Classes describing harware instances.
2276
2301
 
@@ -2284,6 +2309,11 @@ module HDLRuby::High
2284
2309
 
2285
2310
  # Creates a new system instance of system type +systemT+ named +name+.
2286
2311
  def initialize(name, systemT)
2312
+ # Check the validity of the name.
2313
+ unless name.is_a?(String) or name.is_a?(Symbol)
2314
+ raise AnyError,
2315
+ "Missing instance name for system instantiation."
2316
+ end
2287
2317
  # Initialize the system instance structure.
2288
2318
  super(name,systemT)
2289
2319
 
@@ -2338,7 +2368,16 @@ module HDLRuby::High
2338
2368
  end
2339
2369
  else
2340
2370
  # No, perform a connection is order of declaration
2371
+ # But first check if there are not too many of them.
2372
+ if connects.size >
2373
+ self.systemT.each_signal_with_included.to_a.size then
2374
+ raise AnyError, "Too many connections to instance " +
2375
+ "#{self.name}: got #{connects.size} " +
2376
+ "but expecting at most " +
2377
+ "#{self.systemT.each_signal_with_included.to_a.size}"
2378
+ end
2341
2379
  connects.each.with_index do |csig,i|
2380
+ # Now do the connection.
2342
2381
  # puts "systemT inputs=#{systemT.each_input.to_a.size}"
2343
2382
  # Gets i-est signal to connect
2344
2383
  ssig = self.systemT.get_interface_with_included(i)
@@ -3540,12 +3579,21 @@ module HDLRuby::High
3540
3579
 
3541
3580
  # Converts the name reference to a HDLRuby::Low::RefName.
3542
3581
  def to_low
3543
- # puts "to_low with base=#{@base} @object=#{@object}"
3544
- # puts "@object.name=#{@object.name} @object.parent=#{@object.parent.name}"
3582
+ # puts "to_low with base=#{@base} @object=#{@object} @object.parent=#{@object.parent} High.cur_system=#{High.cur_system}"
3583
+ # puts "@object.name=#{@object.name}"
3584
+ # puts "@object.parent.name=#{@object.parent.name}" if @object.parent
3585
+ # Check if a direct access is possible or not.
3586
+ # It is possible if the object parent is the top level,
3587
+ # or if it is a system or the first scope of a system.
3588
+ # (NOTE: previously we ensured that it was only for the
3589
+ # current system, however, this did not support the case
3590
+ # of object within included systems).
3545
3591
  if @base.is_a?(RefThis) &&
3546
3592
  (@object.parent != High.top_user) &&
3547
- (@object.parent != High.cur_system) &&
3548
- (@object.parent != High.cur_system.scope) then # &&
3593
+ # (@object.parent != High.cur_system) &&
3594
+ (!@object.parent.is_a?(SystemT)) &&
3595
+ # (@object.parent != High.cur_system.scope) then # &&
3596
+ (!(@object.parent.is_a?(Scope) && @object.parent.parent.is_a?(SystemT))) then
3549
3597
  # (!@object.parent.name.empty?) then
3550
3598
  # Need to have a hierachical access.
3551
3599
  if @object.respond_to?(:low_object) && @object.low_object then
@@ -4474,17 +4522,16 @@ module HDLRuby::High
4474
4522
  self.add_statement(TimeWait.new(delay))
4475
4523
  end
4476
4524
 
4477
- # # Adds a loop until +delay+ statement in the block in +mode+ whose
4478
- # # loop content is built using +ruby_block+.
4479
- # def repeat(delay, mode = nil, &ruby_block)
4480
- # Adds a +number+ times loop statement in the block in +mode+ whose
4525
+ # # Adds a +number+ times loop statement in the block in +mode+ whose
4526
+ # def repeat(number = -1, mode = nil, &ruby_block)
4527
+ # Adds a +number+ times loop statement in the block whose
4481
4528
  # loop content is built using +ruby_block+.
4482
4529
  # NOTE: if +number+ is negative, the number of iteration is infinite.
4483
- def repeat(number = -1, mode = nil, &ruby_block)
4530
+ def repeat(number = -1, &ruby_block)
4484
4531
  # Ensure there is a block.
4485
4532
  ruby_block = proc {} unless block_given?
4486
- # Build the content block.
4487
- content = High.make_block(mode,&ruby_block)
4533
+ # Build the content block: necessarily seq since timed.
4534
+ content = High.make_block(:seq,&ruby_block)
4488
4535
  # Create and add the statement.
4489
4536
  # self.add_statement(TimeRepeat.new(content,delay))
4490
4537
  self.add_statement(TimeRepeat.new(number,content))
@@ -4558,20 +4605,19 @@ module HDLRuby::High
4558
4605
  High = HDLRuby::High
4559
4606
 
4560
4607
  # Creates a new behavior executing +block+ activated on a list of
4561
- # +events+, and built by executing +ruby_block+.
4608
+ # +events+, possible name (of main block) +name+ and built by
4609
+ # executing +ruby_block+.
4562
4610
  # +mode+ can be either :seq or :par for respectively sequential or
4563
4611
  # parallel.
4564
- def initialize(mode,*events,&ruby_block)
4612
+ # def initialize(mode, *events, &ruby_block)
4613
+ def initialize(mode, *events, name: nil, &ruby_block)
4565
4614
  # Initialize the behavior with it.
4566
4615
  super(nil)
4567
- # # Save the Location for debugging information
4568
- # @location = caller_locations
4569
- # # Sets the current behavior
4570
- # @@cur_behavior = self
4571
4616
  # Add the events (they may be hierarchical to flatten)
4572
4617
  events.flatten.each { |event| self.add_event(event) }
4573
4618
  # Create and add the block.
4574
- self.block = High.make_block(mode,&ruby_block)
4619
+ # self.block = High.make_block(mode,&ruby_block)
4620
+ self.block = High.make_block(mode,*name,&ruby_block)
4575
4621
  # # Unset the current behavior
4576
4622
  # @@cur_behavior = nil
4577
4623
  end
@@ -4813,6 +4859,11 @@ module HDLRuby::High
4813
4859
  # Registers hardware referencing method +name+ to the current namespace.
4814
4860
  def self.space_reg(name,&ruby_block)
4815
4861
  # print "registering #{name} in #{Namespaces[-1]}\n"
4862
+ # Check the name class.
4863
+ unless name.is_a?(String) or name.is_a?(Symbol) then
4864
+ raise AnyError,
4865
+ "Invalid class for a name, string or symbol expected but got: #{name.class}"
4866
+ end
4816
4867
  Namespaces[-1].add_method(name,&ruby_block)
4817
4868
  end
4818
4869
 
@@ -4866,6 +4917,11 @@ module HDLRuby::High
4866
4917
  to_expr
4867
4918
  end
4868
4919
 
4920
+ # Converts to a new dealy in fentoseconds.
4921
+ def fs
4922
+ return Delay.new(self,:fs)
4923
+ end
4924
+
4869
4925
  # Converts to a new delay in picoseconds.
4870
4926
  def ps
4871
4927
  return Delay.new(self,:ps)
@@ -6194,6 +6194,10 @@ module HDLRuby::Low
6194
6194
  # Create a new named reference with +type+ accessing +ref+ with +name+.
6195
6195
  # def initialize(ref,name)
6196
6196
  def initialize(type,ref,name)
6197
+ # puts "new RefName with name=#{name}"
6198
+ if !name or name.empty? then
6199
+ raise "Internal error: Creating a RefName without a name."
6200
+ end
6197
6201
  super(type)
6198
6202
  # Check and set the accessed reference.
6199
6203
  unless ref.is_a?(Ref) then
@@ -7,7 +7,6 @@ module HDLRuby
7
7
  # General tools for handling HDLRuby objects
8
8
  #######################################################
9
9
 
10
-
11
10
  # Method and attribute for generating an absolute uniq name.
12
11
  # Such names cannot be used in HDLRuby::High code, but can be used
13
12
  # to generate such code.