HDLRuby 2.5.0 → 2.6.5
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 +4 -4
- data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
- data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
- data/lib/HDLRuby/hdr_samples/dff_unit.rb +54 -0
- data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
- data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
- data/lib/HDLRuby/hdr_samples/music.rb +79 -0
- data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
- data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
- data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
- data/lib/HDLRuby/hdrcc.rb +132 -24
- data/lib/HDLRuby/hruby_decorator.rb +3 -1
- data/lib/HDLRuby/hruby_high.rb +215 -27
- data/lib/HDLRuby/hruby_low.rb +402 -45
- data/lib/HDLRuby/hruby_low2c.rb +122 -168
- data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
- data/lib/HDLRuby/hruby_low2high.rb +331 -549
- data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
- data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
- data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
- data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
- data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
- data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
- data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
- data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
- data/lib/HDLRuby/hruby_tools.rb +11 -1
- data/lib/HDLRuby/hruby_verilog.rb +1572 -1723
- data/lib/HDLRuby/sim/hruby_sim.h +29 -3
- data/lib/HDLRuby/sim/hruby_sim_calc.c +63 -6
- data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
- data/lib/HDLRuby/sim/hruby_sim_vcd.c +7 -3
- data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
- data/lib/HDLRuby/std/fixpoint.rb +9 -0
- data/lib/HDLRuby/std/function_generator.rb +139 -0
- data/lib/HDLRuby/std/hruby_unit.rb +75 -0
- data/lib/HDLRuby/version.rb +1 -1
- metadata +16 -5
data/lib/HDLRuby/hruby_low.rb
CHANGED
@@ -1317,6 +1317,11 @@ module HDLRuby::Low
|
|
1317
1317
|
return false
|
1318
1318
|
end
|
1319
1319
|
|
1320
|
+
# Tells if the type is hierarchical.
|
1321
|
+
def hierarchical?
|
1322
|
+
return self.base? || self.types?
|
1323
|
+
end
|
1324
|
+
|
1320
1325
|
# Tell if +type+ is equivalent to current type.
|
1321
1326
|
#
|
1322
1327
|
# NOTE: type can be compatible while not being equivalent, please
|
@@ -1359,10 +1364,6 @@ module HDLRuby::Low
|
|
1359
1364
|
# The void type.
|
1360
1365
|
class << (Void = Type.new(:void) )
|
1361
1366
|
include LLeaf
|
1362
|
-
# # Get the base type, actually self for leaf types.
|
1363
|
-
# def base
|
1364
|
-
# self
|
1365
|
-
# end
|
1366
1367
|
end
|
1367
1368
|
|
1368
1369
|
##
|
@@ -1465,6 +1466,11 @@ module HDLRuby::Low
|
|
1465
1466
|
# end
|
1466
1467
|
end
|
1467
1468
|
|
1469
|
+
##
|
1470
|
+
# The void type.
|
1471
|
+
class << (StringT = Type.new(:string) )
|
1472
|
+
include LLeaf
|
1473
|
+
end
|
1468
1474
|
|
1469
1475
|
|
1470
1476
|
##
|
@@ -1473,9 +1479,6 @@ module HDLRuby::Low
|
|
1473
1479
|
# NOTE: type definition are actually type with a name refering to another
|
1474
1480
|
# type (and equivalent to it).
|
1475
1481
|
class TypeDef < Type
|
1476
|
-
# Moved to constructor
|
1477
|
-
# extend Forwardable
|
1478
|
-
|
1479
1482
|
# The definition of the type.
|
1480
1483
|
attr_reader :def
|
1481
1484
|
|
@@ -1533,15 +1536,6 @@ module HDLRuby::Low
|
|
1533
1536
|
|
1534
1537
|
alias_method :each_deep, :each_type_deep
|
1535
1538
|
|
1536
|
-
# Moved to constructor
|
1537
|
-
# # Delegate the type methods to the ref.
|
1538
|
-
# def_delegators :@def,
|
1539
|
-
# :signed?, :unsigned?, :fixed?, :float?, :leaf?,
|
1540
|
-
# :width, :range?, :range, :base?, :base, :types?,
|
1541
|
-
# :get_all_types, :get_type, :each, :each_type,
|
1542
|
-
# :regular?,
|
1543
|
-
# :each_name,
|
1544
|
-
# :equivalent?
|
1545
1539
|
end
|
1546
1540
|
|
1547
1541
|
|
@@ -2401,6 +2395,12 @@ module HDLRuby::Low
|
|
2401
2395
|
end
|
2402
2396
|
end
|
2403
2397
|
|
2398
|
+
# Tells if the signal is immutable (cannot be written.)
|
2399
|
+
def immutable?
|
2400
|
+
# By default, signals are not immutable.
|
2401
|
+
false
|
2402
|
+
end
|
2403
|
+
|
2404
2404
|
# Add decorator capability (modifies intialize to put after).
|
2405
2405
|
include Hdecorator
|
2406
2406
|
|
@@ -2445,6 +2445,11 @@ module HDLRuby::Low
|
|
2445
2445
|
##
|
2446
2446
|
# Describes a constant signal.
|
2447
2447
|
class SignalC < SignalI
|
2448
|
+
# Tells if the signal is immutable (cannot be written.)
|
2449
|
+
def immutable?
|
2450
|
+
# Constant signals are immutable.
|
2451
|
+
true
|
2452
|
+
end
|
2448
2453
|
end
|
2449
2454
|
|
2450
2455
|
##
|
@@ -2802,6 +2807,15 @@ module HDLRuby::Low
|
|
2802
2807
|
"Internal error: hash is not defined for class: #{self.class}"
|
2803
2808
|
end
|
2804
2809
|
|
2810
|
+
# Iterates over each sub statement if any.
|
2811
|
+
#
|
2812
|
+
# Returns an enumerator if no ruby block is given.
|
2813
|
+
def each_statement(&ruby_block)
|
2814
|
+
# No ruby statement? Return an enumerator.
|
2815
|
+
return to_enum(:each_statement) unless ruby_block
|
2816
|
+
# By default: nothing to do.
|
2817
|
+
end
|
2818
|
+
|
2805
2819
|
# Get the block of the statement.
|
2806
2820
|
def block
|
2807
2821
|
if self.is_a?(Block)
|
@@ -3114,7 +3128,24 @@ module HDLRuby::Low
|
|
3114
3128
|
end
|
3115
3129
|
end
|
3116
3130
|
|
3131
|
+
# Iterates over each sub statement if any.
|
3132
|
+
#
|
3133
|
+
# Returns an enumerator if no ruby block is given.
|
3134
|
+
def each_statement(&ruby_block)
|
3135
|
+
# No ruby block? Return an enumerator.
|
3136
|
+
return to_enum(:each_statement) unless ruby_block
|
3137
|
+
# A ruby block?
|
3138
|
+
# Appy it on the statement children.
|
3139
|
+
ruby_block.call(@yes)
|
3140
|
+
self.each_noif do |next_cond,next_yes|
|
3141
|
+
ruby_block.call(next_yes)
|
3142
|
+
end
|
3143
|
+
ruby_block.call(@no) if @no
|
3144
|
+
end
|
3145
|
+
|
3117
3146
|
# Iterates over the children (including the condition).
|
3147
|
+
#
|
3148
|
+
# Returns an enumerator if no ruby block is given.
|
3118
3149
|
def each_node(&ruby_block)
|
3119
3150
|
# No ruby block? Return an enumerator.
|
3120
3151
|
return to_enum(:each_node) unless ruby_block
|
@@ -3271,6 +3302,17 @@ module HDLRuby::Low
|
|
3271
3302
|
return When.new(@match.clone,@statement.clone)
|
3272
3303
|
end
|
3273
3304
|
|
3305
|
+
# Iterates over each sub statement if any.
|
3306
|
+
#
|
3307
|
+
# Returns an enumerator if no ruby block is given.
|
3308
|
+
def each_statement(&ruby_block)
|
3309
|
+
# No ruby block? Return an enumerator.
|
3310
|
+
return to_enum(:each_statement) unless ruby_block
|
3311
|
+
# A ruby block?
|
3312
|
+
# Appy it on the statement child.
|
3313
|
+
ruby_block.call(@statement)
|
3314
|
+
end
|
3315
|
+
|
3274
3316
|
# Iterates over the sub blocks.
|
3275
3317
|
def each_block(&ruby_block)
|
3276
3318
|
# No ruby block? Return an enumerator.
|
@@ -3321,7 +3363,8 @@ module HDLRuby::Low
|
|
3321
3363
|
|
3322
3364
|
# Gets the top block, i.e. the first block of the current behavior.
|
3323
3365
|
def top_block
|
3324
|
-
return self.parent.is_a?(Behavior) ? self : self.parent.top_block
|
3366
|
+
# return self.parent.is_a?(Behavior) ? self : self.parent.top_block
|
3367
|
+
return self.parent.top_block
|
3325
3368
|
end
|
3326
3369
|
|
3327
3370
|
# Tell if the statement includes a signal whose name is one of +names+.
|
@@ -3425,6 +3468,19 @@ module HDLRuby::Low
|
|
3425
3468
|
@default
|
3426
3469
|
end
|
3427
3470
|
|
3471
|
+
# Iterates over each sub statement if any.
|
3472
|
+
#
|
3473
|
+
# Returns an enumerator if no ruby block is given.
|
3474
|
+
def each_statement(&ruby_block)
|
3475
|
+
# No ruby block? Return an enumerator.
|
3476
|
+
return to_enum(:each_statement) unless ruby_block
|
3477
|
+
# A ruby block?
|
3478
|
+
# Apply on each when.
|
3479
|
+
@whens.each { |w| w.each_statement(&ruby_block) }
|
3480
|
+
# And on the default if any.
|
3481
|
+
ruby_block.call(@default) if @default
|
3482
|
+
end
|
3483
|
+
|
3428
3484
|
# Iterates over the match cases.
|
3429
3485
|
#
|
3430
3486
|
# Returns an enumerator if no ruby block is given.
|
@@ -3571,6 +3627,122 @@ module HDLRuby::Low
|
|
3571
3627
|
end
|
3572
3628
|
|
3573
3629
|
|
3630
|
+
##
|
3631
|
+
# Describes a print statement: not synthesizable!
|
3632
|
+
class Print < Statement
|
3633
|
+
|
3634
|
+
# Creates a new statement for printing +args+.
|
3635
|
+
def initialize(*args)
|
3636
|
+
super()
|
3637
|
+
# Process the arguments.
|
3638
|
+
@args = args.map do |arg|
|
3639
|
+
arg.parent = self
|
3640
|
+
arg
|
3641
|
+
end
|
3642
|
+
end
|
3643
|
+
|
3644
|
+
# Comparison for hash: structural comparison.
|
3645
|
+
def eql?(obj)
|
3646
|
+
return false unless obj.is_a?(Print)
|
3647
|
+
return false if @args.each.zip(obj.each_arg).any? do |a0,a1|
|
3648
|
+
!a0.eql?(a1)
|
3649
|
+
end
|
3650
|
+
return true
|
3651
|
+
end
|
3652
|
+
|
3653
|
+
# Iterates over each argument.
|
3654
|
+
#
|
3655
|
+
# Returns an enumerator if no ruby block is given.
|
3656
|
+
def each_arg(&ruby_block)
|
3657
|
+
# No ruby block? Return an enumerator.
|
3658
|
+
return to_enum(:each_arg) unless ruby_block
|
3659
|
+
# A ruby block? First apply it to each argument.
|
3660
|
+
@args.each(&ruby_block)
|
3661
|
+
end
|
3662
|
+
|
3663
|
+
# Iterates over each object deeply.
|
3664
|
+
#
|
3665
|
+
# Returns an enumerator if no ruby block is given.
|
3666
|
+
def each_deep(&ruby_block)
|
3667
|
+
# No ruby block? Return an enumerator.
|
3668
|
+
return to_enum(:each_deep) unless ruby_block
|
3669
|
+
# A ruby block? First apply it to current.
|
3670
|
+
ruby_block.call(self)
|
3671
|
+
# Then apply on the arguments.
|
3672
|
+
self.each_arg(&ruby_block)
|
3673
|
+
end
|
3674
|
+
|
3675
|
+
# Hash function.
|
3676
|
+
def hash
|
3677
|
+
return @args.hash
|
3678
|
+
end
|
3679
|
+
|
3680
|
+
# Clones the TimeWait (deeply)
|
3681
|
+
def clone
|
3682
|
+
return Print.new(*@args.map { |arg| arg.clone })
|
3683
|
+
end
|
3684
|
+
|
3685
|
+
# Iterates over the expression children if any.
|
3686
|
+
def each_node(&ruby_block)
|
3687
|
+
# No ruby block? Return an enumerator.
|
3688
|
+
return to_enum(:each_node) unless ruby_block
|
3689
|
+
# A ruby block?
|
3690
|
+
# Apply it on each argument.
|
3691
|
+
@args.each(&ruby_block)
|
3692
|
+
end
|
3693
|
+
|
3694
|
+
# Iterates over the nodes deeply if any.
|
3695
|
+
def each_node_deep(&ruby_block)
|
3696
|
+
# No ruby block? Return an enumerator.
|
3697
|
+
return to_enum(:each_node_deep) unless ruby_block
|
3698
|
+
# A ruby block? First apply it to current.
|
3699
|
+
ruby_block.call(self)
|
3700
|
+
# And apply it on each argument.
|
3701
|
+
@args.each(&ruby_block)
|
3702
|
+
end
|
3703
|
+
|
3704
|
+
# Iterates over the sub blocks.
|
3705
|
+
def each_block(&ruby_block)
|
3706
|
+
# No ruby block? Return an enumerator.
|
3707
|
+
return to_enum(:each_block) unless ruby_block
|
3708
|
+
# A ruby block?
|
3709
|
+
# Recurse on each argument.
|
3710
|
+
@args.each do |arg|
|
3711
|
+
arg.each_block(&ruby_block) if arg.respond_to?(:each_block)
|
3712
|
+
end
|
3713
|
+
end
|
3714
|
+
|
3715
|
+
# Iterates over all the blocks contained in the current block.
|
3716
|
+
def each_block_deep(&ruby_block)
|
3717
|
+
# No ruby block? Return an enumerator.
|
3718
|
+
return to_enum(:each_block_deep) unless ruby_block
|
3719
|
+
# A ruby block?
|
3720
|
+
# Recurse on each argument.
|
3721
|
+
@args.each do |arg|
|
3722
|
+
if arg.respond_to?(:each_block_deep) then
|
3723
|
+
arg.each_block_deep(&ruby_block)
|
3724
|
+
end
|
3725
|
+
end
|
3726
|
+
end
|
3727
|
+
|
3728
|
+
# Iterates over all the statements contained in the current block.
|
3729
|
+
def each_statement_deep(&ruby_block)
|
3730
|
+
# No ruby block? Return an enumerator.
|
3731
|
+
return to_enum(:each_statement_deep) unless ruby_block
|
3732
|
+
# A ruby block?
|
3733
|
+
# Apply it on self.
|
3734
|
+
ruby_block.call(self)
|
3735
|
+
# Recurse on each argument.
|
3736
|
+
@args.each do |arg|
|
3737
|
+
if arg.respond_to?(:each_statement_deep) then
|
3738
|
+
arg.each_statement_deep(&ruby_block)
|
3739
|
+
end
|
3740
|
+
end
|
3741
|
+
end
|
3742
|
+
|
3743
|
+
end
|
3744
|
+
|
3745
|
+
|
3574
3746
|
##
|
3575
3747
|
# Describes a wait statement: not synthesizable!
|
3576
3748
|
class TimeWait < Statement
|
@@ -3867,7 +4039,6 @@ module HDLRuby::Low
|
|
3867
4039
|
# No ruby block? Return an enumerator.
|
3868
4040
|
return to_enum(:each_inner) unless ruby_block
|
3869
4041
|
# A ruby block? Apply it on each inner signal instance.
|
3870
|
-
# @inners.each_value(&ruby_block)
|
3871
4042
|
@inners.each(&ruby_block)
|
3872
4043
|
end
|
3873
4044
|
alias_method :each_signal, :each_inner
|
@@ -3958,17 +4129,6 @@ module HDLRuby::Low
|
|
3958
4129
|
def last_statement
|
3959
4130
|
return @statements[-1]
|
3960
4131
|
end
|
3961
|
-
|
3962
|
-
# # Deletes +statement+.
|
3963
|
-
# def delete_statement(statement)
|
3964
|
-
# if @statements.include?(statement) then
|
3965
|
-
# # Statement is present, delete it.
|
3966
|
-
# @statements.delete(statement)
|
3967
|
-
# # And remove its parent.
|
3968
|
-
# statement.parent = nil
|
3969
|
-
# end
|
3970
|
-
# statement
|
3971
|
-
# end
|
3972
4132
|
|
3973
4133
|
# Iterates over the sub blocks.
|
3974
4134
|
def each_block(&ruby_block)
|
@@ -4180,6 +4340,11 @@ module HDLRuby::Low
|
|
4180
4340
|
return !self.leftvalue?
|
4181
4341
|
end
|
4182
4342
|
|
4343
|
+
# Tells if the expression is immutable (cannot be written.)
|
4344
|
+
def immutable?
|
4345
|
+
false
|
4346
|
+
end
|
4347
|
+
|
4183
4348
|
# Iterates over the expression children if any.
|
4184
4349
|
def each_node(&ruby_block)
|
4185
4350
|
# By default: no child.
|
@@ -4235,29 +4400,34 @@ module HDLRuby::Low
|
|
4235
4400
|
# Describes a value.
|
4236
4401
|
class Value < Expression
|
4237
4402
|
|
4238
|
-
# Moved to Expression
|
4239
|
-
# # The type of value.
|
4240
|
-
# attr_reader :type
|
4241
|
-
|
4242
4403
|
# The content of the value.
|
4243
4404
|
attr_reader :content
|
4244
4405
|
|
4245
4406
|
# Creates a new value typed +type+ and containing +content+.
|
4246
4407
|
def initialize(type,content)
|
4247
|
-
# Moved to Expression.
|
4248
|
-
# # Check and set the type.
|
4249
|
-
# if type.is_a?(Type) then
|
4250
|
-
# @type = type
|
4251
|
-
# else
|
4252
|
-
# raise AnyError, "Invalid class for a type: #{type.class}."
|
4253
|
-
# end
|
4254
4408
|
super(type)
|
4255
|
-
|
4256
|
-
|
4257
|
-
|
4258
|
-
|
4409
|
+
unless content then
|
4410
|
+
# Handle the nil content case.
|
4411
|
+
unless type.eql?(Void) then
|
4412
|
+
raise AnyError, "A value with nil content must have the Void type."
|
4413
|
+
end
|
4414
|
+
@content = content
|
4415
|
+
else
|
4416
|
+
# Checks and set the content: Ruby Numeric and HDLRuby
|
4417
|
+
# BitString are supported. Strings or equivalent are
|
4418
|
+
# converted to BitString.
|
4419
|
+
unless content.is_a?(Numeric) or
|
4420
|
+
content.is_a?(HDLRuby::BitString)
|
4421
|
+
content = HDLRuby::BitString.new(content.to_s)
|
4422
|
+
end
|
4423
|
+
@content = content
|
4259
4424
|
end
|
4260
|
-
|
4425
|
+
end
|
4426
|
+
|
4427
|
+
# Tells if the expression is immutable (cannot be written.)
|
4428
|
+
def immutable?
|
4429
|
+
# Values are always immutable.
|
4430
|
+
true
|
4261
4431
|
end
|
4262
4432
|
|
4263
4433
|
# Iterates over each object deeply.
|
@@ -4326,6 +4496,7 @@ module HDLRuby::Low
|
|
4326
4496
|
end
|
4327
4497
|
end
|
4328
4498
|
|
4499
|
+
|
4329
4500
|
##
|
4330
4501
|
# Describes a cast.
|
4331
4502
|
class Cast < Expression
|
@@ -4345,6 +4516,12 @@ module HDLRuby::Low
|
|
4345
4516
|
child.parent = self
|
4346
4517
|
end
|
4347
4518
|
|
4519
|
+
# Tells if the expression is immutable (cannot be written.)
|
4520
|
+
def immutable?
|
4521
|
+
# Immutable if the child is immutable.
|
4522
|
+
return child.immutable?
|
4523
|
+
end
|
4524
|
+
|
4348
4525
|
# Iterates over each object deeply.
|
4349
4526
|
#
|
4350
4527
|
# Returns an enumerator if no ruby block is given.
|
@@ -4475,6 +4652,12 @@ module HDLRuby::Low
|
|
4475
4652
|
child.parent = self
|
4476
4653
|
end
|
4477
4654
|
|
4655
|
+
# Tells if the expression is immutable (cannot be written.)
|
4656
|
+
def immutable?
|
4657
|
+
# Immutable if the child is immutable.
|
4658
|
+
return child.immutable?
|
4659
|
+
end
|
4660
|
+
|
4478
4661
|
# Iterates over each object deeply.
|
4479
4662
|
#
|
4480
4663
|
# Returns an enumerator if no ruby block is given.
|
@@ -4577,6 +4760,12 @@ module HDLRuby::Low
|
|
4577
4760
|
left.parent = right.parent = self
|
4578
4761
|
end
|
4579
4762
|
|
4763
|
+
# Tells if the expression is immutable (cannot be written.)
|
4764
|
+
def immutable?
|
4765
|
+
# Immutable if both children are immutable.
|
4766
|
+
return left.immutable? && right.immutable?
|
4767
|
+
end
|
4768
|
+
|
4580
4769
|
# Iterates over each object deeply.
|
4581
4770
|
#
|
4582
4771
|
# Returns an enumerator if no ruby block is given.
|
@@ -4688,6 +4877,15 @@ module HDLRuby::Low
|
|
4688
4877
|
end
|
4689
4878
|
end
|
4690
4879
|
|
4880
|
+
# Tells if the expression is immutable (cannot be written.)
|
4881
|
+
def immutable?
|
4882
|
+
# Immutable if children are all immutable.
|
4883
|
+
return self.select.constant &&
|
4884
|
+
self.each_choice.reduce(true) do |r,c|
|
4885
|
+
r && c.immutable?
|
4886
|
+
end
|
4887
|
+
end
|
4888
|
+
|
4691
4889
|
# Iterates over each object deeply.
|
4692
4890
|
#
|
4693
4891
|
# Returns an enumerator if no ruby block is given.
|
@@ -4822,6 +5020,14 @@ module HDLRuby::Low
|
|
4822
5020
|
expressions.each { |expression| self.add_expression(expression) }
|
4823
5021
|
end
|
4824
5022
|
|
5023
|
+
# Tells if the expression is immutable (cannot be written.)
|
5024
|
+
def immutable?
|
5025
|
+
# Immutable if children are all immutable.
|
5026
|
+
return self.each_expression.reduce(true) do |r,c|
|
5027
|
+
r && c.immutable?
|
5028
|
+
end
|
5029
|
+
end
|
5030
|
+
|
4825
5031
|
# Iterates over each object deeply.
|
4826
5032
|
#
|
4827
5033
|
# Returns an enumerator if no ruby block is given.
|
@@ -4985,6 +5191,14 @@ module HDLRuby::Low
|
|
4985
5191
|
refs.each { |ref| ref.parent = self }
|
4986
5192
|
end
|
4987
5193
|
|
5194
|
+
# Tells if the expression is immutable (cannot be written.)
|
5195
|
+
def immutable?
|
5196
|
+
# Immutable if children are all immutable.
|
5197
|
+
return self.each_ref.reduce(true) do |r,c|
|
5198
|
+
r && c.immutable?
|
5199
|
+
end
|
5200
|
+
end
|
5201
|
+
|
4988
5202
|
# Iterates over each object deeply.
|
4989
5203
|
#
|
4990
5204
|
# Returns an enumerator if no ruby block is given.
|
@@ -5102,6 +5316,12 @@ module HDLRuby::Low
|
|
5102
5316
|
index.parent = self
|
5103
5317
|
end
|
5104
5318
|
|
5319
|
+
# Tells if the expression is immutable (cannot be written.)
|
5320
|
+
def immutable?
|
5321
|
+
# Immutable if the ref is immutable.
|
5322
|
+
return self.ref.immutable?
|
5323
|
+
end
|
5324
|
+
|
5105
5325
|
# Iterates over each object deeply.
|
5106
5326
|
#
|
5107
5327
|
# Returns an enumerator if no ruby block is given.
|
@@ -5215,6 +5435,12 @@ module HDLRuby::Low
|
|
5215
5435
|
first.parent = last.parent = self
|
5216
5436
|
end
|
5217
5437
|
|
5438
|
+
# Tells if the expression is immutable (cannot be written.)
|
5439
|
+
def immutable?
|
5440
|
+
# Immutable if the ref is immutable.
|
5441
|
+
return self.ref.immutable?
|
5442
|
+
end
|
5443
|
+
|
5218
5444
|
# Iterates over each object deeply.
|
5219
5445
|
#
|
5220
5446
|
# Returns an enumerator if no ruby block is given.
|
@@ -5444,4 +5670,135 @@ module HDLRuby::Low
|
|
5444
5670
|
return super
|
5445
5671
|
end
|
5446
5672
|
end
|
5673
|
+
|
5674
|
+
|
5675
|
+
|
5676
|
+
##
|
5677
|
+
# Describes a string.
|
5678
|
+
#
|
5679
|
+
# NOTE: This is not synthesizable!
|
5680
|
+
class StringE < Expression
|
5681
|
+
|
5682
|
+
attr_reader :content
|
5683
|
+
|
5684
|
+
# Creates a new string whose content is +str+ and is modified using
|
5685
|
+
# the objects of +args+.
|
5686
|
+
def initialize(content,*args)
|
5687
|
+
super(StringT)
|
5688
|
+
# Checks and set the content.
|
5689
|
+
@content = content.to_s
|
5690
|
+
# Process the arguments.
|
5691
|
+
@args = args.map do |arg|
|
5692
|
+
arg.parent = self
|
5693
|
+
arg
|
5694
|
+
end
|
5695
|
+
end
|
5696
|
+
|
5697
|
+
# Tells if the expression is immutable (cannot be written.)
|
5698
|
+
def immutable?
|
5699
|
+
# String objects are always immutable.
|
5700
|
+
true
|
5701
|
+
end
|
5702
|
+
|
5703
|
+
# Comparison for hash: structural comparison.
|
5704
|
+
def eql?(obj)
|
5705
|
+
return false unless obj.is_a?(StringE)
|
5706
|
+
return false unless @content.eql?(obj.content)
|
5707
|
+
return false if @args.each.zip(obj.each_arg).any? do |a0,a1|
|
5708
|
+
!a0.eql?(a1)
|
5709
|
+
end
|
5710
|
+
return true
|
5711
|
+
end
|
5712
|
+
|
5713
|
+
# Iterates over each argument.
|
5714
|
+
#
|
5715
|
+
# Returns an enumerator if no ruby block is given.
|
5716
|
+
def each_arg(&ruby_block)
|
5717
|
+
# No ruby block? Return an enumerator.
|
5718
|
+
return to_enum(:each_arg) unless ruby_block
|
5719
|
+
# A ruby block? First apply it to each argument.
|
5720
|
+
@args.each(&ruby_block)
|
5721
|
+
end
|
5722
|
+
|
5723
|
+
# Iterates over each object deeply.
|
5724
|
+
#
|
5725
|
+
# Returns an enumerator if no ruby block is given.
|
5726
|
+
def each_deep(&ruby_block)
|
5727
|
+
# No ruby block? Return an enumerator.
|
5728
|
+
return to_enum(:each_deep) unless ruby_block
|
5729
|
+
# A ruby block? First apply it to current.
|
5730
|
+
ruby_block.call(self)
|
5731
|
+
# Then apply on the arguments.
|
5732
|
+
self.each_arg(&ruby_block)
|
5733
|
+
end
|
5734
|
+
|
5735
|
+
# Hash function.
|
5736
|
+
def hash
|
5737
|
+
return @args.hash
|
5738
|
+
end
|
5739
|
+
|
5740
|
+
# Clones the string.
|
5741
|
+
def clone
|
5742
|
+
return StringE.new(@content.clone,*@args.map {|arg| arg.clone})
|
5743
|
+
end
|
5744
|
+
|
5745
|
+
# Iterates over the expression children if any.
|
5746
|
+
def each_node(&ruby_block)
|
5747
|
+
# No ruby block? Return an enumerator.
|
5748
|
+
return to_enum(:each_node) unless ruby_block
|
5749
|
+
# A ruby block?
|
5750
|
+
# Apply it on each argument.
|
5751
|
+
@args.each(&ruby_block)
|
5752
|
+
end
|
5753
|
+
|
5754
|
+
# Iterates over the nodes deeply if any.
|
5755
|
+
def each_node_deep(&ruby_block)
|
5756
|
+
# No ruby block? Return an enumerator.
|
5757
|
+
return to_enum(:each_node_deep) unless ruby_block
|
5758
|
+
# A ruby block? First apply it to current.
|
5759
|
+
ruby_block.call(self)
|
5760
|
+
# And apply it on each argument.
|
5761
|
+
@args.each(&ruby_block)
|
5762
|
+
end
|
5763
|
+
|
5764
|
+
# Iterates over the sub blocks.
|
5765
|
+
def each_block(&ruby_block)
|
5766
|
+
# No ruby block? Return an enumerator.
|
5767
|
+
return to_enum(:each_block) unless ruby_block
|
5768
|
+
# A ruby block?
|
5769
|
+
# Recurse on each argument.
|
5770
|
+
@args.each do |arg|
|
5771
|
+
arg.each_block(&ruby_block) if arg.respond_to?(:each_block)
|
5772
|
+
end
|
5773
|
+
end
|
5774
|
+
|
5775
|
+
# Iterates over all the blocks contained in the current block.
|
5776
|
+
def each_block_deep(&ruby_block)
|
5777
|
+
# No ruby block? Return an enumerator.
|
5778
|
+
return to_enum(:each_block_deep) unless ruby_block
|
5779
|
+
# A ruby block?
|
5780
|
+
# Recurse on each argument.
|
5781
|
+
@args.each do |arg|
|
5782
|
+
if arg.respond_to?(:each_block_deep) then
|
5783
|
+
arg.each_block_deep(&ruby_block)
|
5784
|
+
end
|
5785
|
+
end
|
5786
|
+
end
|
5787
|
+
|
5788
|
+
# Iterates over all the statements contained in the current block.
|
5789
|
+
def each_statement_deep(&ruby_block)
|
5790
|
+
# No ruby block? Return an enumerator.
|
5791
|
+
return to_enum(:each_statement_deep) unless ruby_block
|
5792
|
+
# A ruby block?
|
5793
|
+
# Apply it on self.
|
5794
|
+
ruby_block.call(self)
|
5795
|
+
# Recurse on each argument.
|
5796
|
+
@args.each do |arg|
|
5797
|
+
if arg.respond_to?(:each_statement_deep) then
|
5798
|
+
arg.each_statement_deep(&ruby_block)
|
5799
|
+
end
|
5800
|
+
end
|
5801
|
+
end
|
5802
|
+
|
5803
|
+
end
|
5447
5804
|
end
|