HDLRuby 2.6.25 → 2.7.11
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/case_bench.rb +23 -18
- data/lib/HDLRuby/hdr_samples/parseq_bench.rb +61 -0
- data/lib/HDLRuby/hdr_samples/range_bench.rb +4 -1
- data/lib/HDLRuby/hdr_samples/rom_nest.rb +27 -0
- data/lib/HDLRuby/hdr_samples/with_channel_other.rb +128 -0
- data/lib/HDLRuby/hdr_samples/with_init.rb +18 -0
- data/lib/HDLRuby/hdr_samples/with_instance.rb +42 -0
- data/lib/HDLRuby/hdr_samples/with_ref_array.rb +26 -0
- data/lib/HDLRuby/hdr_samples/with_subsums.rb +33 -0
- data/lib/HDLRuby/hdr_samples/with_values.rb +61 -0
- data/lib/HDLRuby/hruby_high.rb +87 -27
- data/lib/HDLRuby/hruby_low.rb +4 -1
- data/lib/HDLRuby/hruby_low2c.rb +98 -72
- data/lib/HDLRuby/hruby_low_resolve.rb +30 -1
- data/lib/HDLRuby/hruby_tools.rb +1 -0
- data/lib/HDLRuby/sim/hruby_sim.h +9 -1
- data/lib/HDLRuby/sim/hruby_sim_core.c +5 -2
- data/lib/HDLRuby/sim/hruby_sim_stack_calc.c +80 -33
- data/lib/HDLRuby/version.rb +1 -1
- metadata +10 -2
data/lib/HDLRuby/hruby_high.rb
CHANGED
@@ -133,6 +133,8 @@ module HDLRuby::High
|
|
133
133
|
module Hmissing
|
134
134
|
High = HDLRuby::High
|
135
135
|
|
136
|
+
NAMES = { }
|
137
|
+
|
136
138
|
# Missing methods may be immediate values, if not, they are looked up
|
137
139
|
# in the upper level of the namespace if any.
|
138
140
|
def method_missing(m, *args, &ruby_block)
|
@@ -140,6 +142,20 @@ module HDLRuby::High
|
|
140
142
|
# Is the missing method an immediate value?
|
141
143
|
value = m.to_value
|
142
144
|
return value if value and args.empty?
|
145
|
+
# Or is it a uniq name generator?
|
146
|
+
if (m[-1] == '?') then
|
147
|
+
# Yes
|
148
|
+
m = m[0..-2]
|
149
|
+
return NAMES[m] = HDLRuby.uniq_name(m)
|
150
|
+
end
|
151
|
+
# Is in a previous uniq name?
|
152
|
+
if (m[-1] == '!') then
|
153
|
+
pm = m[0..-2]
|
154
|
+
if NAMES.key?(pm) then
|
155
|
+
# Yes, returns the current corresponding uniq name.
|
156
|
+
return self.send(NAMES[pm],*args,&ruby_block)
|
157
|
+
end
|
158
|
+
end
|
143
159
|
# No, is there an upper namespace, i.e. is the current object
|
144
160
|
# present in the space?
|
145
161
|
if High.space_index(self) then
|
@@ -256,9 +272,9 @@ module HDLRuby::High
|
|
256
272
|
SignalI.new(name,type,:inner))
|
257
273
|
elsif name.is_a?(Hash) then
|
258
274
|
# Names associated with values.
|
259
|
-
|
275
|
+
name.each do |key,value|
|
260
276
|
res = self.add_inner(
|
261
|
-
SignalI.new(
|
277
|
+
SignalI.new(key,type,:inner,value))
|
262
278
|
end
|
263
279
|
else
|
264
280
|
raise AnyError,
|
@@ -550,10 +566,14 @@ module HDLRuby::High
|
|
550
566
|
expanded = self.class.new(name.to_s) {}
|
551
567
|
# Include the mixin systems given when declaring the system.
|
552
568
|
@to_includes.each { |system| expanded.scope.include(system) }
|
569
|
+
# Include the previously includeds. */
|
570
|
+
self.scope.each_included { |system| expanded.scope.include(system) }
|
553
571
|
|
554
572
|
# Sets the generators of the expanded result.
|
555
573
|
expanded.add_generator(self)
|
556
574
|
@to_includes.each { |system| expanded.add_generator(system) }
|
575
|
+
# Also for the previously includeds. */
|
576
|
+
self.scope.each_included.each { |system| expanded.add_generator(system) }
|
557
577
|
|
558
578
|
# Fills the scope of the expanded class.
|
559
579
|
# puts "Build top with #{self.name} for #{name}"
|
@@ -828,8 +848,7 @@ module HDLRuby::High
|
|
828
848
|
# Initialize the set of included systems.
|
829
849
|
@includes = {}
|
830
850
|
|
831
|
-
# Builds the scope if a ruby block is provided
|
832
|
-
# (which means the scope is not the top of a system).
|
851
|
+
# Builds the scope if a ruby block is provided.
|
833
852
|
self.build(&ruby_block) if block_given?
|
834
853
|
end
|
835
854
|
|
@@ -940,18 +959,20 @@ module HDLRuby::High
|
|
940
959
|
# Set the namespace for buidling the scope.
|
941
960
|
High.space_push(@namespace)
|
942
961
|
# Build the scope.
|
943
|
-
|
944
|
-
res = High.top_user.instance_eval(&ruby_block)
|
962
|
+
@return_value = High.top_user.instance_eval(&ruby_block)
|
963
|
+
# res = High.top_user.instance_eval(&ruby_block)
|
945
964
|
High.space_pop
|
946
|
-
# Now gain access to the result within the sub scope.
|
947
|
-
if (res.is_a?(HRef)) then
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
965
|
+
# # Now gain access to the result within the sub scope.
|
966
|
+
# # if (res.is_a?(HRef)) then
|
967
|
+
# if (res.is_a?(HExpression)) then
|
968
|
+
# High.space_push(@namespace)
|
969
|
+
# @return_value = res.type.inner(HDLRuby.uniq_name)
|
970
|
+
# @return_value <= res
|
971
|
+
# High.space_pop
|
972
|
+
# @return_value = RefObject.new(self,@return_value)
|
973
|
+
# else
|
974
|
+
# @return_value = res
|
975
|
+
# end
|
955
976
|
# This will be the return value.
|
956
977
|
@return_value
|
957
978
|
end
|
@@ -1083,10 +1104,12 @@ module HDLRuby::High
|
|
1083
1104
|
# Declares a sub scope with possible +name+ and built from +ruby_block+.
|
1084
1105
|
def sub(name = :"", &ruby_block)
|
1085
1106
|
# Creates the new scope.
|
1086
|
-
scope = Scope.new(name,&ruby_block)
|
1087
|
-
|
1107
|
+
# scope = Scope.new(name,&ruby_block)
|
1108
|
+
scope = Scope.new(name)
|
1088
1109
|
# Add it
|
1089
1110
|
self.add_scope(scope)
|
1111
|
+
# Build it.
|
1112
|
+
scope.build(&ruby_block)
|
1090
1113
|
# puts "self=#{self}"
|
1091
1114
|
# puts "self scopes=#{self.each_scope.to_a.join(",")}"
|
1092
1115
|
# Use its return value
|
@@ -1237,6 +1260,7 @@ module HDLRuby::High
|
|
1237
1260
|
end
|
1238
1261
|
# Adds it the list of includeds
|
1239
1262
|
@includes[include_name] = system
|
1263
|
+
# puts "@includes=#{@includes}"
|
1240
1264
|
|
1241
1265
|
end
|
1242
1266
|
|
@@ -1960,9 +1984,6 @@ module HDLRuby::High
|
|
1960
1984
|
&ruby_block)
|
1961
1985
|
# ruby_block.call(*args)
|
1962
1986
|
end
|
1963
|
-
# sub do
|
1964
|
-
# ruby_block.call(*args,*other_block)
|
1965
|
-
# end
|
1966
1987
|
end
|
1967
1988
|
else
|
1968
1989
|
define_method(name.to_sym) do |*args,&other_block|
|
@@ -1970,10 +1991,8 @@ module HDLRuby::High
|
|
1970
1991
|
sub(HDLRuby.uniq_name(name)) do
|
1971
1992
|
HDLRuby::High.top_user.instance_exec(*args,*other_block,
|
1972
1993
|
&ruby_block)
|
1994
|
+
# ruby_block.call(*args,*other_block)
|
1973
1995
|
end
|
1974
|
-
# sub do
|
1975
|
-
# ruby_block.call(*args,*other_block)
|
1976
|
-
# end
|
1977
1996
|
end
|
1978
1997
|
end
|
1979
1998
|
end
|
@@ -2033,10 +2052,25 @@ module HDLRuby::High
|
|
2033
2052
|
connects.each do |key,value|
|
2034
2053
|
# Gets the signal corresponding to connect.
|
2035
2054
|
signal = self.get_signal(key)
|
2055
|
+
unless signal then
|
2056
|
+
# Look into the included systems.
|
2057
|
+
self.systemT.scope.each_included do |included|
|
2058
|
+
signal = included.get_signal(key)
|
2059
|
+
break if signal
|
2060
|
+
end
|
2061
|
+
end
|
2036
2062
|
# Check if it is an output.
|
2037
2063
|
isout = self.get_output(key)
|
2064
|
+
unless isout then
|
2065
|
+
# Look into the inlucded systems.
|
2066
|
+
self.systemT.scope.each_included do |included|
|
2067
|
+
isout = included.get_output(key)
|
2068
|
+
break if isout
|
2069
|
+
end
|
2070
|
+
end
|
2038
2071
|
# Convert it to a reference.
|
2039
2072
|
ref = RefObject.new(self.to_ref,signal)
|
2073
|
+
# puts "key=#{key} value=#{value} signal=#{signal} ref=#{ref}"
|
2040
2074
|
# Make the connection.
|
2041
2075
|
if isout then
|
2042
2076
|
value <= ref
|
@@ -2651,6 +2685,20 @@ module HDLRuby::High
|
|
2651
2685
|
#
|
2652
2686
|
# NOTE: +rng+ can be a single expression in which case it is an index.
|
2653
2687
|
def [](rng)
|
2688
|
+
if rng.is_a?(::Range) then
|
2689
|
+
first = rng.first
|
2690
|
+
if (first.is_a?(::Integer)) then
|
2691
|
+
first = self.type.size+first if first < 0
|
2692
|
+
end
|
2693
|
+
last = rng.last
|
2694
|
+
if (last.is_a?(::Integer)) then
|
2695
|
+
last = self.type.size+last if last < 0
|
2696
|
+
end
|
2697
|
+
rng = first..last
|
2698
|
+
end
|
2699
|
+
if rng.is_a?(::Integer) && rng < 0 then
|
2700
|
+
rng = self.type.size+rng
|
2701
|
+
end
|
2654
2702
|
if rng.respond_to?(:to_expr) then
|
2655
2703
|
# Number range: convert it to an expression.
|
2656
2704
|
rng = rng.to_expr
|
@@ -2987,6 +3035,7 @@ module HDLRuby::High
|
|
2987
3035
|
|
2988
3036
|
# Creates a new reference from a +base+ reference and named +object+.
|
2989
3037
|
def initialize(base,object)
|
3038
|
+
# puts "New RefObjet with base=#{base}, object=#{object.name}"
|
2990
3039
|
if object.respond_to?(:type) then
|
2991
3040
|
# Typed object, so typed reference.
|
2992
3041
|
super(object.type)
|
@@ -3023,7 +3072,7 @@ module HDLRuby::High
|
|
3023
3072
|
|
3024
3073
|
# Converts the name reference to a HDLRuby::Low::RefName.
|
3025
3074
|
def to_low
|
3026
|
-
# puts "to_low with base=#{@base} @object=#{@object}"
|
3075
|
+
# puts "to_low with base=#{@base} @object=#{@object.name}"
|
3027
3076
|
refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
|
3028
3077
|
@base.to_ref.to_low,@object.name)
|
3029
3078
|
# # For debugging: set the source high object
|
@@ -3081,7 +3130,8 @@ module HDLRuby::High
|
|
3081
3130
|
# Converts to a new reference.
|
3082
3131
|
def to_ref
|
3083
3132
|
return RefIndex.new(self.type,
|
3084
|
-
self.ref.to_ref,self.index.to_expr)
|
3133
|
+
# self.ref.to_ref,self.index.to_expr)
|
3134
|
+
self.ref.to_expr,self.index.to_expr)
|
3085
3135
|
end
|
3086
3136
|
|
3087
3137
|
# Converts the index reference to HDLRuby::Low.
|
@@ -3496,7 +3546,8 @@ module HDLRuby::High
|
|
3496
3546
|
# Converts the system to HDLRuby::Low and set its +name+.
|
3497
3547
|
def to_low(name = self.name)
|
3498
3548
|
# return HDLRuby::Low::SignalI.new(name,self.type.to_low)
|
3499
|
-
|
3549
|
+
valueL = self.value ? self.value.to_low : nil
|
3550
|
+
signalIL = HDLRuby::Low::SignalI.new(name,self.type.to_low,valueL)
|
3500
3551
|
# # For debugging: set the source high object
|
3501
3552
|
# signalIL.properties[:low2high] = self.hdr_id
|
3502
3553
|
# self.properties[:high2low] = signalIL
|
@@ -3586,6 +3637,15 @@ module HDLRuby::High
|
|
3586
3637
|
High.space_push(@namespace)
|
3587
3638
|
@return_value = High.top_user.instance_eval(&ruby_block)
|
3588
3639
|
High.space_pop
|
3640
|
+
# if @return_value.is_a?(HExpression) then
|
3641
|
+
# res = @return_value
|
3642
|
+
# High.space_push(@namespace)
|
3643
|
+
# @return_value = res.type.inner(HDLRuby.uniq_name)
|
3644
|
+
# puts "@return_value name=#{@return_value.name}"
|
3645
|
+
# @return_value <= res
|
3646
|
+
# High.space_pop
|
3647
|
+
# @return_value = RefObject.new(self,@return_value)
|
3648
|
+
# end
|
3589
3649
|
@return_value
|
3590
3650
|
end
|
3591
3651
|
|
@@ -3775,7 +3835,7 @@ module HDLRuby::High
|
|
3775
3835
|
# Converts the block to HDLRuby::Low.
|
3776
3836
|
def to_low
|
3777
3837
|
# Create the resulting block
|
3778
|
-
blockL = HDLRuby::Low::Block.new(self.mode)
|
3838
|
+
blockL = HDLRuby::Low::Block.new(self.mode,self.name)
|
3779
3839
|
# # For debugging: set the source high object
|
3780
3840
|
# blockL.properties[:low2high] = self.hdr_id
|
3781
3841
|
# self.properties[:high2low] = blockL
|
data/lib/HDLRuby/hruby_low.rb
CHANGED
@@ -4058,6 +4058,7 @@ module HDLRuby::Low
|
|
4058
4058
|
|
4059
4059
|
# Adds inner signal +signal+.
|
4060
4060
|
def add_inner(signal)
|
4061
|
+
# puts "add inner=#{signal.name} in block=#{self}"
|
4061
4062
|
# Check and add the signal.
|
4062
4063
|
unless signal.is_a?(SignalI)
|
4063
4064
|
raise AnyError,
|
@@ -4087,6 +4088,7 @@ module HDLRuby::Low
|
|
4087
4088
|
|
4088
4089
|
## Gets an inner signal by +name+.
|
4089
4090
|
def get_inner(name)
|
4091
|
+
# puts "name=#{name}, inners=#{@inners.each_key.to_a}"
|
4090
4092
|
return @inners[name.to_sym]
|
4091
4093
|
end
|
4092
4094
|
alias_method :get_signal, :get_inner
|
@@ -5342,7 +5344,8 @@ module HDLRuby::Low
|
|
5342
5344
|
def initialize(type,ref,index)
|
5343
5345
|
super(type)
|
5344
5346
|
# Check and set the accessed reference.
|
5345
|
-
unless ref.is_a?(Ref) then
|
5347
|
+
# unless ref.is_a?(Ref) then
|
5348
|
+
unless ref.is_a?(Expression) then
|
5346
5349
|
raise AnyError, "Invalid class for a reference: #{ref.class}."
|
5347
5350
|
end
|
5348
5351
|
@ref = ref
|
data/lib/HDLRuby/hruby_low2c.rb
CHANGED
@@ -356,8 +356,13 @@ module HDLRuby::Low
|
|
356
356
|
end
|
357
357
|
self.scope.each_block_deep do |block|
|
358
358
|
block.each_inner do |signal|
|
359
|
-
#
|
360
|
-
|
359
|
+
# signal.value.to_ch(res) if signal.value
|
360
|
+
if signal.value then
|
361
|
+
signal.value.each_node_deep do |node|
|
362
|
+
# res << node.to_ch if node.is_a?(Value)
|
363
|
+
node.to_ch(res) if node.is_a?(Value)
|
364
|
+
end
|
365
|
+
end
|
361
366
|
end
|
362
367
|
block.each_node_deep do |node|
|
363
368
|
# res << node.to_ch if node.is_a?(Value)
|
@@ -702,6 +707,10 @@ module HDLRuby::Low
|
|
702
707
|
end.to_a
|
703
708
|
# Keep only one ref per signal.
|
704
709
|
refs.uniq! { |node| node.full_name }
|
710
|
+
# Remove the inner signals from the list.
|
711
|
+
self.block.each_inner do |inner|
|
712
|
+
refs.delete_if {|r| r.name == inner.name }
|
713
|
+
end
|
705
714
|
# Generate the event.
|
706
715
|
events = refs.map {|ref| Event.new(:anyedge,ref.clone) }
|
707
716
|
# Add them to the behavior for further processing.
|
@@ -891,11 +900,12 @@ module HDLRuby::Low
|
|
891
900
|
if self.value then
|
892
901
|
# There is an initial value.
|
893
902
|
res << " " * (level+1)*3
|
894
|
-
# res << "copy_value(
|
895
|
-
#
|
903
|
+
# res << "copy_value("
|
904
|
+
# self.value.to_c_expr(res,level+2)
|
905
|
+
# res << ",signalI->c_value);\n"
|
896
906
|
res << "copy_value("
|
897
907
|
self.value.to_c_expr(res,level+2)
|
898
|
-
res << ",signalI->
|
908
|
+
res << ",signalI->f_value);\n"
|
899
909
|
end
|
900
910
|
|
901
911
|
# Initially the signal can be overwritten by anything.
|
@@ -1360,7 +1370,7 @@ module HDLRuby::Low
|
|
1360
1370
|
# def to_c(level = 0)
|
1361
1371
|
def to_c(res,level = 0)
|
1362
1372
|
# Save the value pool state.
|
1363
|
-
res << (" " * (level*3)) << "
|
1373
|
+
res << (" " * (level*3)) << "PV;\n"
|
1364
1374
|
# Generate the print for each argument.
|
1365
1375
|
self.each_arg do |arg|
|
1366
1376
|
if (arg.is_a?(StringE)) then
|
@@ -1610,26 +1620,18 @@ module HDLRuby::Low
|
|
1610
1620
|
res << "{\n"
|
1611
1621
|
self.value.to_c(res,level+1)
|
1612
1622
|
res << " " * ((level+1)*3)
|
1613
|
-
res << "
|
1623
|
+
res << "dup();\n"
|
1614
1624
|
# Ensure the selection value is testable.
|
1615
1625
|
res << " " * ((level+1)*3)
|
1616
|
-
res << "if (
|
1626
|
+
res << "if (is_defined()) {\n"
|
1617
1627
|
# The condition is testable.
|
1618
1628
|
# Generate the case as a succession of if statements.
|
1619
|
-
first = true
|
1620
1629
|
self.each_when do |w|
|
1621
1630
|
res << " " * ((level+2)*3)
|
1622
|
-
|
1623
|
-
first = false
|
1624
|
-
else
|
1625
|
-
res << "else "
|
1626
|
-
end
|
1627
|
-
res << "if (value2integer(v) == "
|
1628
|
-
res << "value2integer(({\n"
|
1631
|
+
res << "dup();\n"
|
1629
1632
|
res << " " * ((level+2)*3)
|
1630
1633
|
w.match.to_c(res,level+2)
|
1631
|
-
res << "
|
1632
|
-
res << ")) {\n"
|
1634
|
+
res << "if (to_integer() == to_integer()) {\n"
|
1633
1635
|
w.statement.to_c(res,level+3)
|
1634
1636
|
res << " " * (level+2)*3
|
1635
1637
|
res << "}\n"
|
@@ -1643,6 +1645,8 @@ module HDLRuby::Low
|
|
1643
1645
|
end
|
1644
1646
|
# Close the case.
|
1645
1647
|
res << " " * (level+1)*3
|
1648
|
+
res << "pop();\n" # Remove the testing value.
|
1649
|
+
res << " " * (level+1)*3
|
1646
1650
|
res << "}\n"
|
1647
1651
|
res << " " * (level)*3
|
1648
1652
|
res << "}\n"
|
@@ -1899,6 +1903,16 @@ module HDLRuby::Low
|
|
1899
1903
|
# Should never be here.
|
1900
1904
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1901
1905
|
end
|
1906
|
+
|
1907
|
+
## Generates the C text for an expression access to the expression,
|
1908
|
+
# default case.
|
1909
|
+
# +level+ is the hierachical level of the object.
|
1910
|
+
def to_c_expr(res,level = 0)
|
1911
|
+
res << "({"
|
1912
|
+
self.to_c(res,level+1)
|
1913
|
+
res << (" " * ((level+1)*3))
|
1914
|
+
res << "pop();})"
|
1915
|
+
end
|
1902
1916
|
end
|
1903
1917
|
|
1904
1918
|
|
@@ -1981,7 +1995,7 @@ module HDLRuby::Low
|
|
1981
1995
|
res << " " * (level+1)*3
|
1982
1996
|
# res << "static unsigned long long data[] = { "
|
1983
1997
|
res << "static unsigned int data[] = { "
|
1984
|
-
res << str.scan(/.{1,#{Low2C.int_width}}/m).map do |sub|
|
1998
|
+
res << str.scan(/.{1,#{Low2C.int_width}}/m).reverse.map do |sub|
|
1985
1999
|
sub.to_i(2).to_s # + "ULL"
|
1986
2000
|
end.join(",")
|
1987
2001
|
res << " };\n"
|
@@ -2056,7 +2070,7 @@ module HDLRuby::Low
|
|
2056
2070
|
# def to_c(level = 0)
|
2057
2071
|
def to_c(res,level = 0)
|
2058
2072
|
# Save the value pool state.
|
2059
|
-
res << (" " * (level*3)) << "
|
2073
|
+
res << (" " * (level*3)) << "PV;\n"
|
2060
2074
|
# Generate the child.
|
2061
2075
|
self.child.to_c(res,level)
|
2062
2076
|
res << (" " * (level*3))
|
@@ -2144,7 +2158,7 @@ module HDLRuby::Low
|
|
2144
2158
|
end
|
2145
2159
|
# Some computation required.
|
2146
2160
|
# Save the value pool state.
|
2147
|
-
res << (" " * (level*3)) << "
|
2161
|
+
res << (" " * (level*3)) << "PV;\n"
|
2148
2162
|
# Generate the child.
|
2149
2163
|
self.child.to_c(res,level)
|
2150
2164
|
res << (" " * (level*3))
|
@@ -2256,7 +2270,7 @@ module HDLRuby::Low
|
|
2256
2270
|
# def to_c(level = 0)
|
2257
2271
|
def to_c(res, level = 0)
|
2258
2272
|
# Save the value pool state.
|
2259
|
-
res << (" " * (level*3)) << "
|
2273
|
+
res << (" " * (level*3)) << "PV;\n"
|
2260
2274
|
# Generate the left computation.
|
2261
2275
|
self.left.to_c(res,level)
|
2262
2276
|
# Generate the right computation.
|
@@ -2375,7 +2389,7 @@ module HDLRuby::Low
|
|
2375
2389
|
# +level+ is the hierachical level of the object.
|
2376
2390
|
def to_c(res,level = 0)
|
2377
2391
|
# Save the value pool state.
|
2378
|
-
res << (" " * (level*3)) << "
|
2392
|
+
res << (" " * (level*3)) << "PV;\n"
|
2379
2393
|
# Gather the possible selection choices.
|
2380
2394
|
expressions = self.each_choice.to_a
|
2381
2395
|
# Create the resulting string.
|
@@ -2444,7 +2458,7 @@ module HDLRuby::Low
|
|
2444
2458
|
# +level+ is the hierachical level of the object.
|
2445
2459
|
def to_c(res,level = 0)
|
2446
2460
|
# Save the value pool state.
|
2447
|
-
res << (" " * (level*3)) << "
|
2461
|
+
res << (" " * (level*3)) << "PV;\n"
|
2448
2462
|
# Gather the content to concat.
|
2449
2463
|
expressions = self.each_expression.to_a
|
2450
2464
|
# Compute each sub expression.
|
@@ -2461,46 +2475,64 @@ module HDLRuby::Low
|
|
2461
2475
|
return res
|
2462
2476
|
end
|
2463
2477
|
|
2464
|
-
# Generates the C text of expression for the equivalent HDLRuby code.
|
2465
|
-
# +level+ is the hierachical level of the object.
|
2466
|
-
def to_c_expr(res,level = 0)
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
end
|
2478
|
+
# # # Generates the C text of expression for the equivalent HDLRuby code.
|
2479
|
+
# # # +level+ is the hierachical level of the object.
|
2480
|
+
# # def to_c_expr(res,level = 0)
|
2481
|
+
# # # Gather the content to concat.
|
2482
|
+
# # expressions = self.each_expression.to_a
|
2483
|
+
# # # Create the resulting string.
|
2484
|
+
# # res << "({\n"
|
2485
|
+
# # # Overrides the upper src0, src1, ..., and dst...
|
2486
|
+
# # # And allocates a new value for dst.
|
2487
|
+
# # res << (" " * ((level+1)*3))
|
2488
|
+
# # res << "Value "
|
2489
|
+
# # res << expressions.size.times.map do |i|
|
2490
|
+
# # "src#{i}"
|
2491
|
+
# # end.join(",")
|
2492
|
+
# # res << ";\n"
|
2493
|
+
# # res << (" " * ((level+1)*3))
|
2494
|
+
# # res << "Value dst = get_value();\n"
|
2495
|
+
# # # Save the value pool state.
|
2496
|
+
# # res << (" " * (level*3)) << "SV;\n"
|
2497
|
+
# # # Compute each sub expression.
|
2498
|
+
# # expressions.each_with_index do |expr,i|
|
2499
|
+
# # res << (" " * ((level+1)*3))
|
2500
|
+
# # res << "src#{i} = "
|
2501
|
+
# # expr.to_c_expr(res,level+2)
|
2502
|
+
# # res << ";\n"
|
2503
|
+
# # end
|
2504
|
+
# # # Compute the direction.
|
2505
|
+
# # # Compute the resulting concatenation.
|
2506
|
+
# # res << (" " * ((level+1)*3))
|
2507
|
+
# # res << "concat_value(#{expressions.size},"
|
2508
|
+
# # res << "#{self.type.direction == :little ? 1 : 0},dst,"
|
2509
|
+
# # res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
2510
|
+
# # res << ");\n"
|
2511
|
+
# # # Save the value pool state.
|
2512
|
+
# # res << (" " * (level*3)) << "SV;\n"
|
2513
|
+
# # # Close the computation.
|
2514
|
+
# # res << (" " * (level*3))
|
2515
|
+
# # res << "dst; })"
|
2516
|
+
# # return res
|
2517
|
+
# # end
|
2518
|
+
# def to_c_expr(res,level = 0)
|
2519
|
+
# # Save the value pool state.
|
2520
|
+
# res << "({ PV;"
|
2521
|
+
# # Gather the content to concat.
|
2522
|
+
# expressions = self.each_expression.to_a
|
2523
|
+
# # Compute each sub expression.
|
2524
|
+
# expressions.each_with_index do |expr,i|
|
2525
|
+
# expr.to_c(res,level+2)
|
2526
|
+
# end
|
2527
|
+
# # Compute the resulting concatenation.
|
2528
|
+
# res << (" " * ((level+1)*3))
|
2529
|
+
# res << "sconcat(#{expressions.size},"
|
2530
|
+
# res << (self.type.direction == :little ? "1" : "0")
|
2531
|
+
# res << ");\n"
|
2532
|
+
# # Restore the value pool state.
|
2533
|
+
# res << "RV; pop();})"
|
2534
|
+
# return res
|
2535
|
+
# end
|
2504
2536
|
end
|
2505
2537
|
|
2506
2538
|
|
@@ -2604,7 +2636,7 @@ module HDLRuby::Low
|
|
2604
2636
|
# +left+ tells if it is a left value or not.
|
2605
2637
|
def to_c(res,level = 0, left = false)
|
2606
2638
|
# Save the value pool state.
|
2607
|
-
res << (" " * (level*3)) << "
|
2639
|
+
res << (" " * (level*3)) << "PV;\n"
|
2608
2640
|
# Compute the reference.
|
2609
2641
|
self.ref.to_c(res,level)
|
2610
2642
|
# Compute the index.
|
@@ -2718,7 +2750,7 @@ module HDLRuby::Low
|
|
2718
2750
|
# end
|
2719
2751
|
def to_c(res,level = 0, left = false)
|
2720
2752
|
# Save the value pool state.
|
2721
|
-
res << (" " * (level*3)) << "
|
2753
|
+
res << (" " * (level*3)) << "PV;\n"
|
2722
2754
|
# Compute the reference.
|
2723
2755
|
self.ref.to_c(res,level)
|
2724
2756
|
# res << (" " * (level*3))
|
@@ -2784,17 +2816,11 @@ module HDLRuby::Low
|
|
2784
2816
|
# +left+ tells if it is a left value or not.
|
2785
2817
|
# def to_c(level = 0, left = false)
|
2786
2818
|
def to_c(res,level = 0, left = false)
|
2787
|
-
# # puts "RefName to_c for #{self.name}"
|
2788
|
-
# self.resolve.to_c_signal(res,level+1)
|
2789
|
-
# res << "->" << (left ? "f_value" : "c_value")
|
2790
|
-
# return res
|
2791
2819
|
# puts "RefName to_c for #{self.name}"
|
2792
2820
|
res << (" " * (level*3))
|
2793
|
-
# res << "d="
|
2794
2821
|
res << "push("
|
2795
2822
|
self.resolve.to_c_signal(res,level+1)
|
2796
2823
|
res << "->" << (left ? "f_value" : "c_value")
|
2797
|
-
# res << ";\n"
|
2798
2824
|
res << ");\n"
|
2799
2825
|
return res
|
2800
2826
|
end
|
@@ -50,9 +50,25 @@ module HDLRuby::Low
|
|
50
50
|
return found if found
|
51
51
|
# Maybe it is a sub scope.
|
52
52
|
return self.each_scope.find { |scope| scope.name == name }
|
53
|
+
# Maybe it in the behavior.
|
54
|
+
return self.behavior.get_by_name
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
58
|
+
##
|
59
|
+
# Extends Behavior with the capability of finding one of its inner object
|
60
|
+
# by name.
|
61
|
+
class Behavior
|
62
|
+
|
63
|
+
## Find an inner object by +name+.
|
64
|
+
# NOTE: return nil if not found.
|
65
|
+
def get_by_name(name)
|
66
|
+
if (self.block.name == name.to_sym) then
|
67
|
+
return self.block
|
68
|
+
end
|
69
|
+
return self.block.get_by_name(name)
|
70
|
+
end
|
71
|
+
end
|
56
72
|
|
57
73
|
##
|
58
74
|
# Extends SystemI with the capability of finding one of its inner object
|
@@ -79,7 +95,16 @@ module HDLRuby::Low
|
|
79
95
|
# Ensure the name is a symbol.
|
80
96
|
name = name.to_sym
|
81
97
|
# Look in the signals.
|
82
|
-
|
98
|
+
found = self.get_inner(name)
|
99
|
+
return found if found
|
100
|
+
# Check the sub blocks names.
|
101
|
+
self.each_block do |block|
|
102
|
+
# puts "block=#{block.name}"
|
103
|
+
if (block.name == name) then
|
104
|
+
return block
|
105
|
+
end
|
106
|
+
end
|
107
|
+
return nil
|
83
108
|
end
|
84
109
|
end
|
85
110
|
|
@@ -199,6 +224,7 @@ module HDLRuby::Low
|
|
199
224
|
if self.ref.is_a?(RefName) then
|
200
225
|
# puts "ref name=#{self.ref.name}"
|
201
226
|
obj = self.ref.resolve
|
227
|
+
# puts "obj=#{obj}"
|
202
228
|
# Look into the object for the name.
|
203
229
|
return obj.get_by_name(self.name)
|
204
230
|
else
|
@@ -208,12 +234,15 @@ module HDLRuby::Low
|
|
208
234
|
while parent
|
209
235
|
# puts "parent=#{parent}"
|
210
236
|
if parent.respond_to?(:get_by_name) then
|
237
|
+
# puts "get_by_name"
|
211
238
|
found = parent.get_by_name(self.name)
|
239
|
+
# puts "found" if found
|
212
240
|
return found if found
|
213
241
|
end
|
214
242
|
parent = parent.parent
|
215
243
|
end
|
216
244
|
# Not found.
|
245
|
+
# puts "Not found!"
|
217
246
|
return nil
|
218
247
|
end
|
219
248
|
end
|
data/lib/HDLRuby/hruby_tools.rb
CHANGED
data/lib/HDLRuby/sim/hruby_sim.h
CHANGED
@@ -410,7 +410,8 @@ extern void save_value_pos();
|
|
410
410
|
extern void restore_value_pos();
|
411
411
|
|
412
412
|
/** Macros for short control of the pool of values. */
|
413
|
-
#define SV
|
413
|
+
#define SV save_value_pos();
|
414
|
+
#define PV push(get_value());save_value_pos();
|
414
415
|
#define RV restore_value_pos();
|
415
416
|
|
416
417
|
|
@@ -753,10 +754,17 @@ extern Value write_range_no_z(Value src, long long first, long long last,
|
|
753
754
|
* @param val the value to push. */
|
754
755
|
extern void push(Value val);
|
755
756
|
|
757
|
+
/** Duplicates a value in the stack. */
|
758
|
+
extern void dup();
|
759
|
+
|
756
760
|
/** Pops a value.
|
757
761
|
* @return the value. */
|
758
762
|
extern Value pop();
|
759
763
|
|
764
|
+
/** Access the top value of the stack without removing it.
|
765
|
+
* @return the value. */
|
766
|
+
extern Value peek();
|
767
|
+
|
760
768
|
/** Unary calculation.
|
761
769
|
* @param oper the operator function
|
762
770
|
* @return the destination
|