HDLRuby 3.9.3 → 3.9.6

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.
@@ -777,7 +777,6 @@ module HDLRuby::High
777
777
  # registered in the namespace stack, and one for creating an
778
778
  # array of instances being registered in the Array class.
779
779
  def make_instantiater(name,klass,&ruby_block)
780
- # puts "make_instantiater with name=#{name}"
781
780
  # Set the instanciater.
782
781
  @instance_procs = [ ruby_block ]
783
782
  # Set the target instantiation class.
@@ -794,7 +793,8 @@ module HDLRuby::High
794
793
  # If no arguments, return the system as is
795
794
  return obj if args.empty?
796
795
  # Are there any generic arguments?
797
- if ruby_block.arity > 0 then
796
+ if ruby_block.arity > 0 or args.size > 1 or args[0].is_a?(Hash) then
797
+ # if ruby_block.parameters.size > 0 then
798
798
  # Yes, must specialize the system with the arguments.
799
799
  # If arguments, create a new system specialized with them
800
800
  return SystemT.new(:"") { include(obj,*args) }
@@ -1435,7 +1435,8 @@ module HDLRuby::High
1435
1435
  return if self.metaif(condition,&ruby_block)
1436
1436
  # Ensure there is a block.
1437
1437
  ruby_block = proc {} unless block_given?
1438
- self.par do
1438
+ # self.par do
1439
+ self.seq do # Seq for combinatorial is good practice
1439
1440
  hif(condition,mode,&ruby_block)
1440
1441
  end
1441
1442
  end
@@ -1491,11 +1492,40 @@ module HDLRuby::High
1491
1492
  # * a new behavior is created to enclose the hcase.
1492
1493
  def hcase(value)
1493
1494
  return if self.metacase(value)
1494
- self.par do
1495
+ # self.par do
1496
+ self.seq do # Seq for combinatorial is good practice
1495
1497
  hcase(value)
1496
1498
  end
1497
1499
  end
1498
1500
 
1501
+ # Creates a new case statement taking z was wildcard with a +value+ used for deciding which
1502
+ # block to execute.
1503
+ #
1504
+ # NOTE:
1505
+ # * the when part is defined through the hwhen method.
1506
+ # * a new behavior is created to enclose the hcase.
1507
+ def hcasez(value)
1508
+ return if self.metacase(value)
1509
+ # self.par do
1510
+ self.seq do # Seq for combinatorial is good practice
1511
+ hcasez(value)
1512
+ end
1513
+ end
1514
+
1515
+ # Creates a new case statement taking z as wildcards with a +value+ used for deciding which
1516
+ # block to execute.
1517
+ #
1518
+ # NOTE:
1519
+ # * the when part is defined through the hwhen method.
1520
+ # * a new behavior is created to enclose the hcase.
1521
+ def hcasez(value)
1522
+ return if self.metacase(value)
1523
+ # self.par do
1524
+ self.seq do # Seq for combinatorial is good practice
1525
+ hcasez(value)
1526
+ end
1527
+ end
1528
+
1499
1529
  # Sets the block of a case structure executed when the +match+ is met
1500
1530
  # to the block in +mode+ generated by the execution of +ruby_block+.
1501
1531
  #
@@ -2337,6 +2367,7 @@ module HDLRuby::High
2337
2367
  end
2338
2368
  define_singleton_method(name.to_sym) do |*args|
2339
2369
  if (args.size < ruby_block.arity) then
2370
+ # if (args.size < ruby_block.parameters.size) then
2340
2371
  # Not enough arguments get generic type as is.
2341
2372
  type
2342
2373
  else
@@ -2350,6 +2381,7 @@ module HDLRuby::High
2350
2381
  else
2351
2382
  define_method(name.to_sym) do |*args|
2352
2383
  if (args.size < ruby_block.arity) then
2384
+ # if (args.size < ruby_block.parameters.size) then
2353
2385
  # Not enough arguments, get generic type as is.
2354
2386
  type
2355
2387
  else
@@ -2368,7 +2400,7 @@ module HDLRuby::High
2368
2400
  def system(name = :"", *includes, &ruby_block)
2369
2401
  # Ensure there is a block.
2370
2402
  ruby_block = proc {} unless block_given?
2371
- # print "system ruby_block=#{ruby_block}\n"
2403
+ # print "system name=#{name} ruby_block=#{ruby_block}\n"
2372
2404
  # Creates the resulting system.
2373
2405
  return SystemT.new(name,*includes,&ruby_block)
2374
2406
  end
@@ -2523,6 +2555,9 @@ module HDLRuby::High
2523
2555
  connects.each do |key,value|
2524
2556
  # Gets the signal corresponding to connect.
2525
2557
  signal = self.systemT.get_signal_with_included(key)
2558
+ unless signal then
2559
+ raise AnyError, "Invalid parameter: #{key}"
2560
+ end
2526
2561
  # Check if it is an output.
2527
2562
  isout = self.systemT.get_output_with_included(key)
2528
2563
  # Convert it to a reference.
@@ -2826,7 +2861,7 @@ module HDLRuby::High
2826
2861
  obj = self
2827
2862
  ::HDLRuby::High.cur_block.delete_statement!(obj)
2828
2863
  # Handles the metaprogramming.
2829
- return obj if self.metaif(condition,proc { add_statement(obj) })
2864
+ return obj if self.metaif(condition) { add_statement(obj) }
2830
2865
  # Creates the if statement.
2831
2866
  stmnt = If.new(condition) { add_statement(obj) }
2832
2867
  # Add it to the current block.
@@ -2935,9 +2970,11 @@ module HDLRuby::High
2935
2970
 
2936
2971
  # Creates a new case statement with a +value+ that decides which
2937
2972
  # block to execute.
2938
- def initialize(value)
2973
+ # +mode+ is the mode the case should run in. For now there are
2974
+ # only two possiblities: normal case :"", and casez :casez
2975
+ def initialize(value, mode = :"")
2939
2976
  # Create the yes block.
2940
- super(value.to_expr)
2977
+ super(value.to_expr, mode)
2941
2978
  end
2942
2979
 
2943
2980
  # Sets the block executed in +mode+ when the value matches +match+.
@@ -2969,7 +3006,7 @@ module HDLRuby::High
2969
3006
  # Converts the case to HDLRuby::Low.
2970
3007
  def to_low
2971
3008
  # Create the low level case.
2972
- caseL = HDLRuby::Low::Case.new(@value.to_low)
3009
+ caseL = HDLRuby::Low::Case.new(@value.to_low,@mode)
2973
3010
  # # For debugging: set the source high object
2974
3011
  # caseL.properties[:low2high] = self.hdr_id
2975
3012
  # self.properties[:high2low] = caseL
@@ -3185,12 +3222,12 @@ module HDLRuby::High
3185
3222
 
3186
3223
  # Extends on the left to +n+ bits filling with +v+ bit values.
3187
3224
  def ljust(n,v)
3188
- return [(v.to_s * (n-self.width)).to_expr, self]
3225
+ return [(v.to_s * (n-self.width)).to_value, self].to_expr
3189
3226
  end
3190
3227
 
3191
3228
  # Extends on the right to +n+ bits filling with +v+ bit values.
3192
3229
  def rjust(n,v)
3193
- return [self, (v.to_s * (n-self.width)).to_expr]
3230
+ return [self, (v.to_s * (n-self.width)).to_value].to_expr
3194
3231
  end
3195
3232
 
3196
3233
  # Extends on the left to +n+ bits filling with 0.
@@ -3200,7 +3237,8 @@ module HDLRuby::High
3200
3237
 
3201
3238
  # Extends on the left to +n+ bits preserving the signe.
3202
3239
  def sext(n)
3203
- return self.ljust(self[-1])
3240
+ # return self.ljust(n,self[-1])
3241
+ return self.as(HDLRuby::High.top_user.signed[self.type.width]).as(HDLRuby::High.top_user.signed[n])
3204
3242
  end
3205
3243
 
3206
3244
  # # Match the type with +typ+:
@@ -3741,6 +3779,9 @@ module HDLRuby::High
3741
3779
  # Creates a new reference from a +base+ reference and named +object+.
3742
3780
  def initialize(base,object)
3743
3781
  # puts "New RefObjet with base=#{base}, object=#{object}"
3782
+ unless object
3783
+ raise AnyError, "Empty object for reference."
3784
+ end
3744
3785
  if object.respond_to?(:type) then
3745
3786
  # Typed object, so typed reference.
3746
3787
  super(object.type)
@@ -4636,6 +4677,16 @@ module HDLRuby::High
4636
4677
  self.add_statement(Case.new(value))
4637
4678
  end
4638
4679
 
4680
+ # Creates a new case statement taking z as wildcard with a +value+ used for deciding which
4681
+ # block to execute.
4682
+ #
4683
+ # NOTE: the when part is defined through the hwhen method.
4684
+ def hcasez(value)
4685
+ return if self.metacase(value)
4686
+ # Creates the case statement.
4687
+ self.add_statement(Case.new(value, :casez))
4688
+ end
4689
+
4639
4690
  # Sets the block of a case structure executed when the +match+ is met
4640
4691
  # to the block in +mode+ generated by the execution of +ruby_block+.
4641
4692
  #
@@ -5247,6 +5298,7 @@ module HDLRuby::High
5247
5298
  class ::Float
5248
5299
  # Converts to a new high-level expression.
5249
5300
  def to_expr
5301
+ raise "Float not supported yet."
5250
5302
  return Value.new(Real,self)
5251
5303
  end
5252
5304
 
@@ -5399,6 +5451,38 @@ module HDLRuby::High
5399
5451
  expr
5400
5452
  end
5401
5453
 
5454
+ # Casts to +typ+.
5455
+ def as(typ)
5456
+ return self.to_expr.as(typ)
5457
+ end
5458
+
5459
+ # Converts to a bit vector.
5460
+ def to_bit
5461
+ return self.to_expr.to_bit
5462
+ end
5463
+
5464
+ # Casts to an unsigned bit vector type.
5465
+ def to_unsigned
5466
+ return self.to_bit.to_unsigned
5467
+ end
5468
+
5469
+ # Casts to a signed bit vector type.
5470
+ def to_signed
5471
+ return self.to_bit_to_signed
5472
+ end
5473
+
5474
+ # Extends on the left to +n+ bits filling with 0.
5475
+ def zext(n)
5476
+ return self.to_bit.zext(n)
5477
+ end
5478
+
5479
+ # Extends on the left to +n+ bits preserving the signe.
5480
+ def sext(n)
5481
+ return self.to_bit.sext(n)
5482
+ end
5483
+
5484
+ # Add the methods of HExpression
5485
+
5402
5486
  # Converts to a new high-level reference.
5403
5487
  def to_ref
5404
5488
  expr = RefConcat.new(TypeTuple.new(:"",:little,*self.map do |elem|
@@ -5467,6 +5551,17 @@ module HDLRuby::High
5467
5551
  end
5468
5552
  end
5469
5553
 
5554
+ # Creates a hcase statement taking z as wildcard executing +ruby_block+ on the element of
5555
+ # the array selected by +value+
5556
+ def hcasez(value,&ruby_block)
5557
+ # Ensure there is a block.
5558
+ ruby_block = proc {} unless block_given?
5559
+ High.cur_block.hcasez(value)
5560
+ self.each.with_index do |elem,i|
5561
+ High.cur_block.hwhen(i) { ruby_block.call(elem) }
5562
+ end
5563
+ end
5564
+
5470
5565
  # Moved to HArrow.
5471
5566
  # # Add support of the left arrow operator.
5472
5567
  # def <=(expr)
@@ -5604,7 +5699,7 @@ module HDLRuby::High
5604
5699
  # Check the value
5605
5700
  return nil unless value.match(/^[0-9]+$/)
5606
5701
  # Compute it (base 10 values cannot be 4-state!)
5607
- value = value.to_i.to_s(2)
5702
+ value = value.to_i.to_s(2).rjust(width,"0")
5608
5703
  when "h" then
5609
5704
  # base 16, compute the width
5610
5705
  width = width ? width.to_i : value.size * 4
@@ -5792,6 +5887,20 @@ def self.configure_high
5792
5887
  end
5793
5888
 
5794
5889
 
5890
+
5891
+ ## Handling the properties that can be added to HDLRuby objects.
5892
+
5893
+ ## Add to object +obj+, property +prop+.
5894
+ def self.add_property(obj,prop)
5895
+ HDLRuby::Low.add_property(obj,prop)
5896
+ end
5897
+
5898
+ ## Iterate on the properties of object +obj+.
5899
+ def self.each_property(obj,&ruby_block)
5900
+ HDLRuby::Low.each_property(obj,&ruby_block)
5901
+ end
5902
+
5903
+
5795
5904
  end
5796
5905
 
5797
5906
 
@@ -36,8 +36,6 @@ module HDLRuby::Low
36
36
  end
37
37
 
38
38
 
39
- # Hdecorator = HDLRuby::Hdecorator
40
-
41
39
  ##
42
40
  # Gives parent definition and access properties to an hardware object.
43
41
  module Hparent
@@ -162,9 +160,6 @@ module HDLRuby::Low
162
160
  end
163
161
  end
164
162
 
165
- # # Add decorator capability (modifies intialize to put after).
166
- # include Hdecorator
167
-
168
163
  # Comparison for hash: structural comparison.
169
164
  def eql?(obj)
170
165
  return false unless obj.is_a?(SystemT)
@@ -529,9 +524,6 @@ module HDLRuby::Low
529
524
  @behaviors = []
530
525
  end
531
526
 
532
- # # Add decorator capability (modifies intialize to put after).
533
- # include Hdecorator
534
-
535
527
  # Comparison for hash: structural comparison.
536
528
  def eql?(obj)
537
529
  return false unless obj.is_a?(Scope)
@@ -1293,8 +1285,11 @@ module HDLRuby::Low
1293
1285
  @name = name.to_sym
1294
1286
  end
1295
1287
 
1296
- # # Add decorator capability (modifies intialize to put after).
1297
- # include Hdecorator
1288
+ # Converts the system to HDLRuby::Low.
1289
+ # Here already low.
1290
+ def to_low
1291
+ return self
1292
+ end
1298
1293
 
1299
1294
  # Comparison for hash: structural comparison.
1300
1295
  def eql?(obj)
@@ -1989,6 +1984,11 @@ module HDLRuby::Low
1989
1984
  return true
1990
1985
  end
1991
1986
 
1987
+ # Gets thebitwidth
1988
+ def width
1989
+ return self.reduce(0) {|sum,elem| sum + elem.width }
1990
+ end
1991
+
1992
1992
  # Hash function.
1993
1993
  def hash
1994
1994
  return [super,@types].hash
@@ -2330,9 +2330,6 @@ module HDLRuby::Low
2330
2330
  # @block = block
2331
2331
  end
2332
2332
 
2333
- # # Add decorator capability (modifies intialize to put after).
2334
- # include Hdecorator
2335
-
2336
2333
  # Sets the block if not already set.
2337
2334
  def block=(block)
2338
2335
  # Check the block.
@@ -2561,9 +2558,6 @@ module HDLRuby::Low
2561
2558
  ref.parent = self
2562
2559
  end
2563
2560
 
2564
- # # Add decorator capability (modifies intialize to put after).
2565
- # include Hdecorator
2566
-
2567
2561
  # Comparison for hash: structural comparison.
2568
2562
  def eql?(obj)
2569
2563
  return false unless obj.is_a?(Event)
@@ -2698,9 +2692,6 @@ module HDLRuby::Low
2698
2692
  @signals.each(&ruby_block) if @signals
2699
2693
  end
2700
2694
 
2701
- # # Add decorator capability (modifies intialize to put after).
2702
- # include Hdecorator
2703
-
2704
2695
  # Iterates over each object deeply.
2705
2696
  #
2706
2697
  # Returns an enumerator if no ruby block is given.
@@ -2783,9 +2774,6 @@ module HDLRuby::Low
2783
2774
  @systemTs = [ @systemT ]
2784
2775
  end
2785
2776
 
2786
- # # Add decorator capability (modifies intialize to put after).
2787
- # include Hdecorator
2788
-
2789
2777
  # Iterates over each object deeply.
2790
2778
  #
2791
2779
  # Returns an enumerator if no ruby block is given.
@@ -2919,9 +2907,6 @@ module HDLRuby::Low
2919
2907
  lumps.each { |lump| self.add_lump(lump) }
2920
2908
  end
2921
2909
 
2922
- # # Add decorator capability (modifies intialize to put after).
2923
- # include Hdecorator
2924
-
2925
2910
  # Adds a +lump+ of code, it is ment to become an expression or
2926
2911
  # some text.
2927
2912
  def add_lump(lump)
@@ -3101,9 +3086,6 @@ module HDLRuby::Low
3101
3086
  @chunks = HashName.new
3102
3087
  end
3103
3088
 
3104
- # # Add decorator capability (modifies intialize to put after).
3105
- # include Hdecorator
3106
-
3107
3089
  # Adds a +chunk+ to the sensitivity list.
3108
3090
  def add_chunk(chunk)
3109
3091
  # Check and add the chunk.
@@ -3212,7 +3194,6 @@ module HDLRuby::Low
3212
3194
  # NOTE: this is an abstract class which is not to be used directly.
3213
3195
  class Statement
3214
3196
  include Hparent
3215
- # include Hdecorator
3216
3197
 
3217
3198
  # Clones (deeply)
3218
3199
  def clone
@@ -3700,9 +3681,6 @@ module HDLRuby::Low
3700
3681
  match.parent = statement.parent = self
3701
3682
  end
3702
3683
 
3703
- # # Add decorator capability (modifies intialize to put after).
3704
- # include Hdecorator
3705
-
3706
3684
  # Iterates over each object deeply.
3707
3685
  #
3708
3686
  # Returns an enumerator if no ruby block is given.
@@ -3818,15 +3796,18 @@ module HDLRuby::Low
3818
3796
  attr_reader :default
3819
3797
 
3820
3798
  # Creates a new case statement whose excution flow is decided from
3821
- # +value+ with a possible cases given in +whens+ and +default
3822
- # + (can be set later)
3823
- def initialize(value, default = nil, whens = [])
3799
+ # +value+ with a possible cases given in +whens+ and +default+
3800
+ # (can be set later)
3801
+ # +mode+ is the mode the case should run in. For now there are two
3802
+ # possible modes: normal case :"", and in a mode where z are taken as wildcards :casez.
3803
+ def initialize(value, mode = :"", default = nil, whens = [])
3824
3804
  # Check and set the value.
3825
3805
  unless value.is_a?(Expression)
3826
3806
  raise AnyError, "Invalid class for a value: #{value.class}"
3827
3807
  end
3828
3808
  super()
3829
3809
  @value = value
3810
+ @mode = mode.to_sym
3830
3811
  # And set its parent.
3831
3812
  value.parent = self
3832
3813
  # Checks and set the default case if any.
@@ -3994,7 +3975,7 @@ module HDLRuby::Low
3994
3975
  # Clone the default if any.
3995
3976
  default = @default ? @default.clone : nil
3996
3977
  # Clone the case.
3997
- return Case.new(@value.clone,default,(@whens.map do |w|
3978
+ return Case.new(@value.clone,@mode,default,(@whens.map do |w|
3998
3979
  w.clone
3999
3980
  end) )
4000
3981
  end
@@ -4025,9 +4006,6 @@ module HDLRuby::Low
4025
4006
  @unit = unit.to_sym
4026
4007
  end
4027
4008
 
4028
- # # Add decorator capability (modifies intialize to put after).
4029
- # include Hdecorator
4030
-
4031
4009
  # Iterates over each object deeply.
4032
4010
  #
4033
4011
  # Returns an enumerator if no ruby block is given.
@@ -4918,8 +4896,10 @@ module HDLRuby::Low
4918
4896
  end
4919
4897
  end
4920
4898
 
4921
- # # Add decorator capability (modifies intialize to put after).
4922
- # include Hdecorator
4899
+ # Gets the bit width of the expression.
4900
+ def width
4901
+ return @type.width
4902
+ end
4923
4903
 
4924
4904
  # Comparison for hash: structural comparison.
4925
4905
  def eql?(obj)
@@ -5023,6 +5003,7 @@ module HDLRuby::Low
5023
5003
 
5024
5004
  # Creates a new value typed +type+ and containing +content+.
5025
5005
  def initialize(type,content)
5006
+ # puts "New value with content=#{content} (content.class=#{content.class})"
5026
5007
  super(type)
5027
5008
  if content.nil? then
5028
5009
  # Handle the nil content case.
@@ -5041,7 +5022,11 @@ module HDLRuby::Low
5041
5022
  unless content.is_a?(Numeric) or
5042
5023
  content.is_a?(HDLRuby::BitString)
5043
5024
  # content = HDLRuby::BitString.new(content.to_s)
5044
- content = content.to_s
5025
+ if content.is_a?(Array) then
5026
+ content = content.map(&:to_s).join
5027
+ else
5028
+ content = content.to_s
5029
+ end
5045
5030
  if self.type.unsigned? && content[0] != "0" then
5046
5031
  # content = "0" + content.rjust(self.type.width,content[0])
5047
5032
  if content[0] == "1" then
@@ -5108,10 +5093,10 @@ module HDLRuby::Low
5108
5093
  return self.content <=> value
5109
5094
  end
5110
5095
 
5111
- # Gets the bit width of the value.
5112
- def width
5113
- return @type.width
5114
- end
5096
+ # # Gets the bit width of the value.
5097
+ # def width
5098
+ # return @type.width
5099
+ # end
5115
5100
 
5116
5101
  # Tells if the value is even.
5117
5102
  def even?
@@ -6449,4 +6434,23 @@ module HDLRuby::Low
6449
6434
  end
6450
6435
 
6451
6436
  end
6437
+
6438
+
6439
+ ## Handling the properties that can be added to HDLRuby objects.
6440
+
6441
+ Properties = Hash.new
6442
+
6443
+ ## Add to object +obj+, property +prop+.
6444
+ def self.add_property(obj,prop)
6445
+ Properties[obj] ||= Set.new
6446
+ Properties[obj] << prop
6447
+ obj
6448
+ end
6449
+
6450
+ ## Iterate on the properties of object +obj+.
6451
+ def self.each_property(obj,&ruby_block)
6452
+ Properties[obj].each(&ruby_block)
6453
+ end
6454
+
6455
+
6452
6456
  end
@@ -156,7 +156,7 @@ module HDLRuby::Low
156
156
  blk = self.block
157
157
  sig = blk ? blk.get_signal_up(expr.ref.name) :
158
158
  self.scope.get_signal_up(expr.ref.name)
159
- sig.split_to_index(expr,expr.index,res)
159
+ sig.split_to_index(expr,expr.index,res) if sig
160
160
  elsif expr.is_a?(RefRange) and expr.ref.is_a?(RefName) and
161
161
  expr.range.first.is_a?(Value) and
162
162
  expr.range.last.is_a?(Value) then
@@ -164,7 +164,7 @@ module HDLRuby::Low
164
164
  blk = self.block
165
165
  sig = blk ? blk.get_signal_up(expr.ref.name) :
166
166
  self.scope.get_signal_up(expr.ref.name)
167
- sig.split_to_range(expr,expr.range,res)
167
+ sig.split_to_range(expr,expr.range,res) if sig
168
168
  end
169
169
  end
170
170
  end
@@ -719,8 +719,13 @@ module HDLRuby::High
719
719
  # Generate the C description of the hardware case.
720
720
  def to_rcsim
721
721
  # Create the hardware case C object.
722
- @rcstatement = RCSim.rcsim_make_hcase(self.value.to_rcsim,
723
- self.default ? self.default.to_rcsim : nil)
722
+ if(@mode == :casez) then
723
+ @rcstatement = RCSim.rcsim_make_hcasez(self.value.to_rcsim,
724
+ self.default ? self.default.to_rcsim : nil)
725
+ else
726
+ @rcstatement = RCSim.rcsim_make_hcase(self.value.to_rcsim,
727
+ self.default ? self.default.to_rcsim : nil)
728
+ end
724
729
 
725
730
  # Add the hardware whens.
726
731
  rcsim_matches = self.each_when.map {|wh| wh.match.to_rcsim }
@@ -904,8 +909,13 @@ module HDLRuby::High
904
909
  return RCSim.rcsim_make_value_numeric(self.type.to_rcsim,
905
910
  self.content)
906
911
  else
912
+ if (self.content >= 0 and self.content & 0x8000_0000_0000_0000 == 0) then
907
913
  return RCSim.rcsim_make_value_numeric(self.type.to_rcsim,
908
- self.content & 0xFFFFFFFFFFFF)
914
+ self.content & 0x7FFF_FFFF_FFFF_FFFF)
915
+ else
916
+ return RCSim.rcsim_make_value_numeric_63one(self.type.to_rcsim,
917
+ self.content & 0x7FFF_FFFF_FFFF_FFFF)
918
+ end
909
919
  end
910
920
  else
911
921
  if self.content < 0 then
@@ -1562,10 +1562,14 @@ module HDLRuby::Low
1562
1562
  # Converts the system to Verilog code.
1563
1563
  def to_verilog
1564
1564
  # if self.base.name.to_s != "bit"
1565
+ first = self.range.first
1566
+ first = first.to_verilog if first.is_a?(Expression)
1567
+ last = self.range.last
1568
+ last = last.to_verilog if last.is_a?(Expression)
1565
1569
  if VERILOG_BASE_TYPES.include?(self.base.name.to_s)
1566
- return " #{self.base.name.to_s}[#{self.range.first}:#{self.range.last}]"
1570
+ return " #{self.base.name.to_s}[#{first}:#{last}]"
1567
1571
  end
1568
- return " [#{self.range.first}:#{self.range.last}]"
1572
+ return " [#{first}:#{last}]"
1569
1573
  end
1570
1574
  end
1571
1575
 
@@ -1630,9 +1634,9 @@ module HDLRuby::Low
1630
1634
  res = ""
1631
1635
  sels = self.select.to_verilog
1632
1636
  @choices[0..-2].each_with_index do |choice,i|
1633
- res << "#{sels} == #{i} ? #{choice.to_verilog} : "
1637
+ res << "(#{sels} == #{i} ? #{choice.to_verilog} : "
1634
1638
  end
1635
- res << @choices[-1].to_verilog
1639
+ res << @choices[-1].to_verilog + (")" * @choices[0..-2].size)
1636
1640
  return res
1637
1641
  end
1638
1642
  end
@@ -1676,6 +1680,9 @@ module HDLRuby::Low
1676
1680
  # return "#{self.type.width}'b#{str}"
1677
1681
  else
1678
1682
  str = self.content.to_verilog
1683
+ if str.length > self.type.width then
1684
+ str = str[str.length-self.type.width..-1]
1685
+ end
1679
1686
  if self.content.negative? then
1680
1687
  return "#{str.length}'sb#{str}"
1681
1688
  else
@@ -1738,7 +1745,11 @@ module HDLRuby::Low
1738
1745
 
1739
1746
  result = " " * spc # Indented based on space_count.
1740
1747
 
1741
- result << "case(#{self.value.to_verilog})\n"
1748
+ if @mode == :casez then
1749
+ result << "casez(#{self.value.to_verilog})\n"
1750
+ else
1751
+ result << "case(#{self.value.to_verilog})\n"
1752
+ end
1742
1753
 
1743
1754
  # n the case statement, each branch is partitioned by when. Process each time when.
1744
1755
  self.each_when do |whens|
@@ -2150,7 +2161,7 @@ module HDLRuby::Low
2150
2161
  inout = self.each_inout.to_a
2151
2162
 
2152
2163
  # Spelling necessary for simulation.
2153
- code = "`timescale 1ps/1ps\n\n"
2164
+ code = "`timescale 10ps/1ps\n\n"
2154
2165
 
2155
2166
  # self.properties[:verilog_name] = vname
2156
2167
  # Output the module name.