HDLRuby 2.11.4 → 2.11.7
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/ext/hruby_sim/hruby_rcsim_build.c +87 -48
- data/ext/hruby_sim/hruby_sim.h +67 -1
- data/ext/hruby_sim/hruby_sim_calc.c +211 -28
- data/ext/hruby_sim/hruby_sim_core.c +140 -52
- data/ext/hruby_sim/hruby_sim_mute.c +65 -0
- data/ext/hruby_sim/hruby_sim_stack_calc.c +10 -0
- data/ext/hruby_sim/hruby_sim_tree_calc.c +36 -9
- data/ext/hruby_sim/hruby_sim_vcd.c +41 -23
- data/lib/HDLRuby/hdr_samples/arith_bench.rb +92 -0
- data/lib/HDLRuby/hdr_samples/constant_prop_bench.rb +58 -0
- data/lib/HDLRuby/hdrcc.rb +15 -6
- data/lib/HDLRuby/hruby_bstr.rb +15 -3
- data/lib/HDLRuby/hruby_high.rb +8 -4
- data/lib/HDLRuby/hruby_low.rb +14 -5
- data/lib/HDLRuby/hruby_low2c.rb +184 -68
- data/lib/HDLRuby/hruby_low_without_connection.rb +6 -2
- data/lib/HDLRuby/hruby_rcsim.rb +25 -15
- data/lib/HDLRuby/hruby_rsim.rb +201 -85
- data/lib/HDLRuby/hruby_rsim_mute.rb +35 -0
- data/lib/HDLRuby/hruby_rsim_vcd.rb +168 -12
- data/lib/HDLRuby/hruby_values.rb +19 -2
- data/lib/HDLRuby/hruby_verilog.rb +67 -17
- data/lib/HDLRuby/std/fsm.rb +3 -3
- data/lib/HDLRuby/version.rb +1 -1
- metadata +6 -2
@@ -0,0 +1,92 @@
|
|
1
|
+
|
2
|
+
# A benchmark for the arithmetic operations.
|
3
|
+
system :arith_bench do
|
4
|
+
signed[8].inner :x8,:y8,:z8,:s8
|
5
|
+
signed[10].inner :s10
|
6
|
+
signed[16].inner :x16,:y16,:z16,:s16
|
7
|
+
signed[18].inner :s18
|
8
|
+
signed[32].inner :x32,:y32,:z32,:s32
|
9
|
+
signed[34].inner :s34
|
10
|
+
|
11
|
+
s8 <= x8+y8+z8
|
12
|
+
s10 <= x8.as(signed[10])+y8+z8
|
13
|
+
|
14
|
+
s16 <= x16+y16+z16
|
15
|
+
s18 <= x16.as(signed[18])+y16+z16
|
16
|
+
|
17
|
+
s32 <= x32+y32+z32
|
18
|
+
s34 <= x32.as(signed[34])+y32+z32
|
19
|
+
|
20
|
+
timed do
|
21
|
+
x8 <= 0
|
22
|
+
y8 <= 0
|
23
|
+
z8 <= 0
|
24
|
+
x16 <= 0
|
25
|
+
y16 <= 0
|
26
|
+
z16 <= 0
|
27
|
+
x32 <= 0
|
28
|
+
y32 <= 0
|
29
|
+
z32 <= 0
|
30
|
+
!10.ns
|
31
|
+
x8 <= 1
|
32
|
+
y8 <= 1
|
33
|
+
z8 <= 1
|
34
|
+
x16 <= 1
|
35
|
+
y16 <= 1
|
36
|
+
z16 <= 1
|
37
|
+
x32 <= 1
|
38
|
+
y32 <= 1
|
39
|
+
z32 <= 1
|
40
|
+
!10.ns
|
41
|
+
x8 <= 2
|
42
|
+
y8 <= 2
|
43
|
+
z8 <= 2
|
44
|
+
x16 <= 4
|
45
|
+
y16 <= 4
|
46
|
+
z16 <= 4
|
47
|
+
x32 <= 8
|
48
|
+
y32 <= 8
|
49
|
+
z32 <= 8
|
50
|
+
!10.ns
|
51
|
+
x8 <= 0x7F
|
52
|
+
y8 <= 0x7F
|
53
|
+
z8 <= 0x7F
|
54
|
+
x16 <= 0x7FFF
|
55
|
+
y16 <= 0x7FFF
|
56
|
+
z16 <= 0x7FFF
|
57
|
+
x32 <= 0x7FFFFFFF
|
58
|
+
y32 <= 0x7FFFFFFF
|
59
|
+
z32 <= 0x7FFFFFFF
|
60
|
+
!10.ns
|
61
|
+
x8 <= -1
|
62
|
+
y8 <= -1
|
63
|
+
z8 <= -1
|
64
|
+
x16 <= -1
|
65
|
+
y16 <= -1
|
66
|
+
z16 <= -1
|
67
|
+
x32 <= -1
|
68
|
+
y32 <= -1
|
69
|
+
z32 <= -1
|
70
|
+
!10.ns
|
71
|
+
x8 <= -2
|
72
|
+
y8 <= -2
|
73
|
+
z8 <= -2
|
74
|
+
x16 <= -4
|
75
|
+
y16 <= -4
|
76
|
+
z16 <= -4
|
77
|
+
x32 <= -8
|
78
|
+
y32 <= -8
|
79
|
+
z32 <= -8
|
80
|
+
!10.ns
|
81
|
+
x8 <= -0x80
|
82
|
+
y8 <= -0x80
|
83
|
+
z8 <= -0x80
|
84
|
+
x16 <= -0x8000
|
85
|
+
y16 <= -0x8000
|
86
|
+
z16 <= -0x8000
|
87
|
+
x32 <= -0x80000000
|
88
|
+
y32 <= -0x80000000
|
89
|
+
z32 <= -0x80000000
|
90
|
+
!10.ns
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# A simple counter
|
2
|
+
system :counter do
|
3
|
+
input :clk, :rst
|
4
|
+
[8].input :inc
|
5
|
+
[8].output :count
|
6
|
+
|
7
|
+
par(clk.posedge) do
|
8
|
+
hif(rst) { count <= 0 }
|
9
|
+
helse { count <= count + inc }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# A benchmark for the counter using a constant as the inc input.
|
14
|
+
system :dff_bench do
|
15
|
+
inner :clk, :rst
|
16
|
+
[8].inner :count
|
17
|
+
[8].constant inc: 5
|
18
|
+
|
19
|
+
# counter(:my_counter).(clk,rst,inc,count)
|
20
|
+
counter(:my_counter).(clk,rst,5,count)
|
21
|
+
|
22
|
+
# par do
|
23
|
+
# my_counter.inc <= 5
|
24
|
+
# count <= my_counter.count
|
25
|
+
# end
|
26
|
+
|
27
|
+
timed do
|
28
|
+
clk <= 0
|
29
|
+
rst <= 0
|
30
|
+
!10.ns
|
31
|
+
clk <= 1
|
32
|
+
rst <= 0
|
33
|
+
!10.ns
|
34
|
+
clk <= 0
|
35
|
+
rst <= 1
|
36
|
+
!10.ns
|
37
|
+
clk <= 1
|
38
|
+
rst <= 1
|
39
|
+
!10.ns
|
40
|
+
clk <= 0
|
41
|
+
rst <= 0
|
42
|
+
!10.ns
|
43
|
+
clk <= 1
|
44
|
+
!10.ns
|
45
|
+
clk <= 0
|
46
|
+
!10.ns
|
47
|
+
clk <= 1
|
48
|
+
!10.ns
|
49
|
+
clk <= 0
|
50
|
+
!10.ns
|
51
|
+
clk <= 1
|
52
|
+
!10.ns
|
53
|
+
clk <= 0
|
54
|
+
!10.ns
|
55
|
+
clk <= 1
|
56
|
+
!10.ns
|
57
|
+
end
|
58
|
+
end
|
data/lib/HDLRuby/hdrcc.rb
CHANGED
@@ -380,6 +380,9 @@ $optparse = OptionParser.new do |opts|
|
|
380
380
|
$options[:rcsim] = v
|
381
381
|
$options[:multiple] = v
|
382
382
|
end
|
383
|
+
opts.on("--mute", "The simulator will not generate any output") do |v|
|
384
|
+
$options[:mute] = v
|
385
|
+
end
|
383
386
|
opts.on("--vcd", "The simulator will generate a vcd file") do |v|
|
384
387
|
$options[:vcd] = v
|
385
388
|
end
|
@@ -712,8 +715,9 @@ elsif $options[:clang] then
|
|
712
715
|
$main = File.open($name,"w")
|
713
716
|
|
714
717
|
# Select the vizualizer depending on the options.
|
715
|
-
init_visualizer = $options[:
|
716
|
-
|
718
|
+
init_visualizer = $options[:mute] ? "init_mute_visualizer" :
|
719
|
+
$options[:vcd] ? "init_vcd_visualizer" :
|
720
|
+
"init_default_visualizer"
|
717
721
|
|
718
722
|
# Gather the system to generate and sort them in the right order
|
719
723
|
# to ensure references are generated before being used.
|
@@ -857,9 +861,13 @@ elsif $options[:rsim] then
|
|
857
861
|
HDLRuby.show "#{Time.now}#{show_mem}"
|
858
862
|
# Ruby-level simulation.
|
859
863
|
require 'HDLRuby/hruby_rsim.rb'
|
860
|
-
# Is VCD output is required.
|
861
|
-
if $options[:
|
862
|
-
# Yes
|
864
|
+
# Is mute or VCD output is required.
|
865
|
+
if $options[:mute] then
|
866
|
+
# Yes for mute.
|
867
|
+
require "HDLRuby/hruby_rsim_mute.rb"
|
868
|
+
$top_system.sim($stdout)
|
869
|
+
elsif $options[:vcd] then
|
870
|
+
# Yes for VCD
|
863
871
|
require "HDLRuby/hruby_rsim_vcd.rb"
|
864
872
|
vcdout = File.open($output+"/hruby_simulator.vcd","w")
|
865
873
|
$top_system.sim(vcdout)
|
@@ -881,7 +889,8 @@ elsif $options[:rcsim] then
|
|
881
889
|
$top_system.to_rcsim
|
882
890
|
HDLRuby.show "Executing the hybrid C-Ruby-level simulator..."
|
883
891
|
HDLRuby.show "#{Time.now}#{show_mem}"
|
884
|
-
HDLRuby::High.rcsim($top_system,"hruby_simulator",$output
|
892
|
+
HDLRuby::High.rcsim($top_system,"hruby_simulator",$output,
|
893
|
+
($options[:mute] && 1) || ($options[:vcd] && 2) || 0)
|
885
894
|
HDLRuby.show "End of hybrid C-Ruby-level simulation..."
|
886
895
|
HDLRuby.show "#{Time.now}#{show_mem}"
|
887
896
|
elsif $options[:vhdl] then
|
data/lib/HDLRuby/hruby_bstr.rb
CHANGED
@@ -51,7 +51,9 @@ module HDLRuby
|
|
51
51
|
elsif val.is_a?(Numeric) then
|
52
52
|
# Content is a numeric.
|
53
53
|
@content = []
|
54
|
-
if val
|
54
|
+
if val == 0 then
|
55
|
+
@content << 0
|
56
|
+
elsif val > 0 then
|
55
57
|
while val > 0 do
|
56
58
|
@content << (val & 1)
|
57
59
|
val /= 2
|
@@ -110,6 +112,11 @@ module HDLRuby
|
|
110
112
|
return @content
|
111
113
|
end
|
112
114
|
|
115
|
+
# Hash comparison.
|
116
|
+
def eql?(bstr)
|
117
|
+
return @content.eql?(bstr.raw_content)
|
118
|
+
end
|
119
|
+
|
113
120
|
# Tells if the bit string is strictly.
|
114
121
|
#
|
115
122
|
# NOTE: return false if the sign is undefined of if it is unknown
|
@@ -180,10 +187,14 @@ module HDLRuby
|
|
180
187
|
if right >= left then
|
181
188
|
# puts "left=#{left} right=#{right}"
|
182
189
|
# Get the corresponding bits as a BitString
|
183
|
-
return BitString.new(@content[left..right],:raw)
|
190
|
+
# return BitString.new(@content[left..right],:raw)
|
191
|
+
# set to positive.
|
192
|
+
return BitString.new(@content[left..right]+[0],:raw)
|
184
193
|
else
|
185
194
|
# Get the corresponding bits as a BitString
|
186
|
-
return BitString.new(@content[right..left].reverse,:raw)
|
195
|
+
# return BitString.new(@content[right..left].reverse,:raw)
|
196
|
+
# set to positive.
|
197
|
+
return BitString.new(@content[right..left].reverse+[0],:raw)
|
187
198
|
end
|
188
199
|
else
|
189
200
|
# Process the index.
|
@@ -532,6 +543,7 @@ module HDLRuby
|
|
532
543
|
val = BitString.new(val)
|
533
544
|
end
|
534
545
|
vcontent = val.raw_content
|
546
|
+
# puts "vcontent=#{vcontent}"
|
535
547
|
width = vcontent.size > @content.size ? vcontent.size : @content.size
|
536
548
|
res_content = width.times.map do |i|
|
537
549
|
# Get the bits to compute with
|
data/lib/HDLRuby/hruby_high.rb
CHANGED
@@ -4213,7 +4213,7 @@ module HDLRuby::High
|
|
4213
4213
|
# Creates a new +type+ sort of block with possible +name+
|
4214
4214
|
# and build it by executing +ruby_block+.
|
4215
4215
|
def initialize(type, name = :"", &ruby_block)
|
4216
|
-
# Initialize the
|
4216
|
+
# Initialize the behavior.
|
4217
4217
|
super(type,name)
|
4218
4218
|
|
4219
4219
|
unless name.empty? then
|
@@ -4674,7 +4674,11 @@ module HDLRuby::High
|
|
4674
4674
|
class ::Integer
|
4675
4675
|
# Converts to a new high-level expression.
|
4676
4676
|
def to_expr
|
4677
|
-
|
4677
|
+
if (self.bit_length <= 63) then
|
4678
|
+
return Value.new(Integer,self)
|
4679
|
+
else
|
4680
|
+
return Value.new(TypeSigned.new(:"",self.bit_length..0),self)
|
4681
|
+
end
|
4678
4682
|
end
|
4679
4683
|
end
|
4680
4684
|
|
@@ -5168,9 +5172,9 @@ module HDLRuby::High
|
|
5168
5172
|
|
5169
5173
|
|
5170
5174
|
# Standard vector types.
|
5171
|
-
Integer = TypeSigned.new(:integer)
|
5175
|
+
Integer = TypeSigned.new(:integer,63..0)
|
5172
5176
|
Char = TypeSigned.new(:char,7..0)
|
5173
|
-
Natural = TypeUnsigned.new(:natural)
|
5177
|
+
Natural = TypeUnsigned.new(:natural,63..0)
|
5174
5178
|
Bignum = TypeSigned.new(:bignum,HDLRuby::Infinity..0)
|
5175
5179
|
Real = TypeFloat.new(:float)
|
5176
5180
|
|
data/lib/HDLRuby/hruby_low.rb
CHANGED
@@ -4615,8 +4615,8 @@ module HDLRuby::Low
|
|
4615
4615
|
# Yes so it is also a left value if it is a sub ref.
|
4616
4616
|
if parent.respond_to?(:ref) then
|
4617
4617
|
# It might nor be a sub ref.
|
4618
|
-
# return parent.ref
|
4619
|
-
return parent.ref.
|
4618
|
+
# return parent.ref.eql?(self)
|
4619
|
+
return parent.ref.equal?(self)
|
4620
4620
|
else
|
4621
4621
|
# It is necessarily a sub ref (case of RefConcat for now).
|
4622
4622
|
return true
|
@@ -4624,8 +4624,8 @@ module HDLRuby::Low
|
|
4624
4624
|
end
|
4625
4625
|
# No, therefore maybe it is directly a left value.
|
4626
4626
|
return (parent.is_a?(Transmit) || parent.is_a?(Connection)) &&
|
4627
|
-
|
4628
|
-
parent.left.
|
4627
|
+
# parent.left.eql?(self)
|
4628
|
+
parent.left.equal?(self)
|
4629
4629
|
end
|
4630
4630
|
|
4631
4631
|
# Tells if the expression is a right value.
|
@@ -4715,9 +4715,18 @@ module HDLRuby::Low
|
|
4715
4715
|
# converted to BitString.
|
4716
4716
|
unless content.is_a?(Numeric) or
|
4717
4717
|
content.is_a?(HDLRuby::BitString)
|
4718
|
-
content = HDLRuby::BitString.new(content.to_s)
|
4718
|
+
# content = HDLRuby::BitString.new(content.to_s)
|
4719
|
+
content = content.to_s
|
4720
|
+
if self.type.unsigned? && content[0] != 0 then
|
4721
|
+
content = "0" + content.rjust(self.type.width,content[0])
|
4722
|
+
end
|
4723
|
+
content = HDLRuby::BitString.new(content)
|
4719
4724
|
end
|
4720
4725
|
@content = content
|
4726
|
+
if (@content.is_a?(Numeric) && self.type.unsigned?) then
|
4727
|
+
# Adjust the bits for unsigned.
|
4728
|
+
@content = @content & (2**self.type.width-1)
|
4729
|
+
end
|
4721
4730
|
end
|
4722
4731
|
end
|
4723
4732
|
|
data/lib/HDLRuby/hruby_low2c.rb
CHANGED
@@ -20,6 +20,7 @@ module HDLRuby::Low
|
|
20
20
|
# h files.
|
21
21
|
def self.includes(*names)
|
22
22
|
res = '#include <stdlib.h>' + "\n" +
|
23
|
+
'#include <string.h>' + "\n" +
|
23
24
|
'#include "hruby_sim.h"' + "\n"
|
24
25
|
names.each { |name| res << "#include \"#{name}\"\n" }
|
25
26
|
res << "\n"
|
@@ -687,6 +688,10 @@ module HDLRuby::Low
|
|
687
688
|
if time then
|
688
689
|
res << " " * (level+1)*3
|
689
690
|
res << "register_timed_behavior(behavior);\n"
|
691
|
+
else
|
692
|
+
# Otherwise register it as a behavior to initialize. */
|
693
|
+
res << " " * (level+1)*3
|
694
|
+
res << "register_init_behavior(behavior);\n"
|
690
695
|
end
|
691
696
|
|
692
697
|
# Set the owner if any.
|
@@ -724,12 +729,39 @@ module HDLRuby::Low
|
|
724
729
|
refs = self.block.each_node_deep.select do |node|
|
725
730
|
node.is_a?(RefName) && !node.leftvalue? &&
|
726
731
|
!node.parent.is_a?(RefName)
|
732
|
+
# node.is_a?(RefName) && !node.parent.is_a?(RefName)
|
727
733
|
end.to_a
|
728
734
|
# Keep only one ref per signal.
|
729
|
-
refs.uniq! { |
|
735
|
+
refs.uniq! { |ref| ref.full_name }
|
736
|
+
# # Remove the intermediate left values if sequential.
|
737
|
+
# self.each_block_deep do |blk|
|
738
|
+
# if blk.mode == :seq && !blk.parent.is_a?(Behavior) then
|
739
|
+
# blk.each_node_deep do |node|
|
740
|
+
# if node.is_a?(RefName) && node.leftvalue? &&
|
741
|
+
# !node.parent.is_a?(RefName) then
|
742
|
+
# puts "removing ref=#{node.full_name}"
|
743
|
+
# refs.delete_if {|ref| ref.full_name == node.full_name }
|
744
|
+
# end
|
745
|
+
# end
|
746
|
+
# end
|
747
|
+
# end
|
748
|
+
# # Remove left values.
|
749
|
+
# lefts = refs.select {|ref| ref.leftvalue? }.map do |ref|
|
750
|
+
# ref.full_name
|
751
|
+
# end
|
752
|
+
# puts "lefts=#{lefts}"
|
753
|
+
# puts "first refs.size=#{refs.size}"
|
754
|
+
# refs.delete_if { |ref| lefts.include?(ref.full_name) }
|
755
|
+
# puts "now refs.size=#{refs.size}"
|
756
|
+
# puts "refs=#{refs.map {|r| r.full_name}}"
|
730
757
|
# Remove the inner signals from the list.
|
731
|
-
self.block.each_inner do |inner|
|
732
|
-
|
758
|
+
# self.block.each_inner do |inner|
|
759
|
+
# refs.delete_if {|r| r.name == inner.name }
|
760
|
+
# end
|
761
|
+
self.each_block_deep do |blk|
|
762
|
+
blk.each_inner do |inner|
|
763
|
+
refs.delete_if {|r| r.name == inner.name }
|
764
|
+
end
|
733
765
|
end
|
734
766
|
# Generate the event.
|
735
767
|
events = refs.map {|ref| Event.new(:anyedge,ref.clone) }
|
@@ -843,6 +875,9 @@ module HDLRuby::Low
|
|
843
875
|
## Extends the SignalI class with generation of C text.
|
844
876
|
class SignalI
|
845
877
|
|
878
|
+
# The id of a signal in the simulator.
|
879
|
+
@@signal_id = 0
|
880
|
+
|
846
881
|
## Generates the C text for an access to the signal.
|
847
882
|
# +level+ is the hierachical level of the object.
|
848
883
|
# def to_c_signal(level = 0)
|
@@ -881,6 +916,8 @@ module HDLRuby::Low
|
|
881
916
|
res << "SignalI signalI = malloc(sizeof(SignalIS));\n"
|
882
917
|
res << " " * (level+1)*3
|
883
918
|
res << "signalI->kind = SIGNALI;\n";
|
919
|
+
res << "signalI->id = #{@@signal_id};\n"
|
920
|
+
@@signal_id = @@signal_id+1;
|
884
921
|
|
885
922
|
# Sets the global variable of the signal.
|
886
923
|
res << "\n"
|
@@ -918,9 +955,9 @@ module HDLRuby::Low
|
|
918
955
|
if self.value then
|
919
956
|
# There is an initial value.
|
920
957
|
res << " " * (level+1)*3
|
921
|
-
|
922
|
-
|
923
|
-
|
958
|
+
res << "copy_value("
|
959
|
+
self.value.to_c_expr(res,level+2)
|
960
|
+
res << ",signalI->c_value);\n"
|
924
961
|
res << "copy_value("
|
925
962
|
self.value.to_c_expr(res,level+2)
|
926
963
|
res << ",signalI->f_value);\n"
|
@@ -1720,26 +1757,49 @@ module HDLRuby::Low
|
|
1720
1757
|
res << "if (is_defined()) {\n"
|
1721
1758
|
# The condition is testable.
|
1722
1759
|
# Generate the case as a succession of if statements.
|
1723
|
-
self.each_when do |w|
|
1760
|
+
# self.each_when do |w|
|
1761
|
+
# res << " " * ((level+2)*3)
|
1762
|
+
# res << "dup();\n"
|
1763
|
+
# res << " " * ((level+2)*3)
|
1764
|
+
# w.match.to_c(res,level+2)
|
1765
|
+
# res << "if (to_integer() == to_integer()) { \n"
|
1766
|
+
# w.statement.to_c(res,level+3)
|
1767
|
+
# res << " " * (level+2)*3
|
1768
|
+
# res << "}\n"
|
1769
|
+
# end
|
1770
|
+
# if self.default then
|
1771
|
+
# res << " " * (level+2)*3
|
1772
|
+
# res << "else {\n"
|
1773
|
+
# self.default.to_c(res,level+3)
|
1774
|
+
# res << " " * (level+2)*3
|
1775
|
+
# res << "}\n"
|
1776
|
+
# end
|
1777
|
+
res << " " * ((level+2)*3)
|
1778
|
+
res << "int val=to_integer(), done=0;\n"
|
1779
|
+
self.each_when.with_index do |w,i|
|
1724
1780
|
res << " " * ((level+2)*3)
|
1725
|
-
res << "
|
1781
|
+
res << "if (!done) {\n" unless i == 0
|
1726
1782
|
res << " " * ((level+2)*3)
|
1727
1783
|
w.match.to_c(res,level+2)
|
1728
|
-
res << "if (
|
1784
|
+
res << "if (val == to_integer()) {\n"
|
1729
1785
|
w.statement.to_c(res,level+3)
|
1786
|
+
res << " " * (level+3)*3
|
1787
|
+
res << "done = 1;\n"
|
1730
1788
|
res << " " * (level+2)*3
|
1789
|
+
res << "}" unless i == 0
|
1731
1790
|
res << "}\n"
|
1732
1791
|
end
|
1733
1792
|
if self.default then
|
1734
1793
|
res << " " * (level+2)*3
|
1735
|
-
res << "
|
1794
|
+
res << "if(!done) {\n"
|
1736
1795
|
self.default.to_c(res,level+3)
|
1737
1796
|
res << " " * (level+2)*3
|
1738
1797
|
res << "}\n"
|
1739
1798
|
end
|
1799
|
+
|
1740
1800
|
# Close the case.
|
1741
1801
|
res << " " * (level+1)*3
|
1742
|
-
res << "pop();\n" # Remove the testing value.
|
1802
|
+
# res << "pop();\n" # Remove the testing value.
|
1743
1803
|
res << " " * (level+1)*3
|
1744
1804
|
res << "}\n"
|
1745
1805
|
res << " " * (level)*3
|
@@ -1827,7 +1887,7 @@ module HDLRuby::Low
|
|
1827
1887
|
def to_c(res,level = 0)
|
1828
1888
|
# The resulting string.
|
1829
1889
|
res << " " * level*3
|
1830
|
-
if (number < 0) then
|
1890
|
+
if (self.number < 0) then
|
1831
1891
|
# Generate an infinite loop executing the block and waiting.
|
1832
1892
|
res << "for(;;) {\n"
|
1833
1893
|
else
|
@@ -2053,8 +2113,6 @@ module HDLRuby::Low
|
|
2053
2113
|
## Generates the content of the h file.
|
2054
2114
|
# def to_ch
|
2055
2115
|
def to_ch(res)
|
2056
|
-
# res = ""
|
2057
|
-
# return "extern Value #{Low2C.make_name(self)}();"
|
2058
2116
|
res << "extern Value " << Low2C.make_name(self) << "();"
|
2059
2117
|
return res
|
2060
2118
|
end
|
@@ -2067,74 +2125,131 @@ module HDLRuby::Low
|
|
2067
2125
|
def to_c_make(res,level = 0)
|
2068
2126
|
# Check is the value maker is already present.
|
2069
2127
|
maker = Low2C.make_name(self);
|
2070
|
-
# return "" if @@made_values.include?(maker)
|
2071
2128
|
return res if @@made_values.include?(maker)
|
2072
2129
|
@@made_values.add(maker)
|
2073
2130
|
|
2074
|
-
# The resulting string.
|
2075
|
-
# res = ""
|
2076
|
-
|
2077
2131
|
# The header of the value generation.
|
2078
2132
|
res << " " * level*3
|
2079
|
-
# res << "Value " << Low2C.make_name(self) << "() {\n"
|
2080
2133
|
res << "Value " << maker << "() {\n"
|
2081
2134
|
|
2135
|
+
# # Declares the data.
|
2136
|
+
# # Create the bit string.
|
2137
|
+
# # str = self.content.is_a?(BitString) ?
|
2138
|
+
# # self.content.to_s : self.content.to_s(2).rjust(32,"0")
|
2139
|
+
# if self.content.is_a?(BitString) then
|
2140
|
+
# str = self.content.is_a?(BitString) ?
|
2141
|
+
# self.content.to_s : self.content.to_s(2).rjust(32,"0")
|
2142
|
+
# else
|
2143
|
+
# # sign = self.content>=0 ? "0" : "1"
|
2144
|
+
# # str = self.content.abs.to_s(2).rjust(width,sign).upcase
|
2145
|
+
# if self.content >= 0 then
|
2146
|
+
# str = self.content.to_s(2).rjust(width,"0").upcase
|
2147
|
+
# else
|
2148
|
+
# # Compute the extension to the next multiple
|
2149
|
+
# # of int_width
|
2150
|
+
# ext_width = (((width-1) / Low2C.int_width)+1)*Low2C.int_width
|
2151
|
+
# # Convert the string.
|
2152
|
+
# str = (2**ext_width+self.content).to_s(2).upcase
|
2153
|
+
# end
|
2154
|
+
# # puts "content=#{self.content} str=#{str}"
|
2155
|
+
# end
|
2156
|
+
# # Is it a fully defined number?
|
2157
|
+
# # NOTE: bignum values are not supported by the simulation engine
|
2158
|
+
# # yet, therefore numeric values are limited to 64 max.
|
2159
|
+
# if str =~ /^[01]+$/ && str.length <= 64 then
|
2160
|
+
# # Yes, generate a numeral value.
|
2161
|
+
# res << " " * (level+1)*3
|
2162
|
+
# res << "static unsigned int data[] = { "
|
2163
|
+
# res << str.scan(/.{1,#{Low2C.int_width}}/m).reverse.map do |sub|
|
2164
|
+
# sub.to_i(2).to_s # + "ULL"
|
2165
|
+
# end.join(",")
|
2166
|
+
# res << ", 0" if (str.length <= 32)
|
2167
|
+
# res << " };\n"
|
2168
|
+
# # Create the value.
|
2169
|
+
# res << " " * (level+1)*3
|
2170
|
+
# # puts "str=#{str} type width=#{self.type.width} signed? #{type.signed?}"
|
2171
|
+
# # res << "return make_set_value(#{self.type.to_c(level+1)},1," +
|
2172
|
+
# # "data);\n"
|
2173
|
+
# res << "return make_set_value("
|
2174
|
+
# self.type.to_c(res,level+1)
|
2175
|
+
# res << ",1,data);\n"
|
2176
|
+
# else
|
2177
|
+
# # No, generate a bit string value.
|
2178
|
+
# res << " " * (level+1)*3
|
2179
|
+
# # res << "static unsigned char data[] = \"#{str}\";\n"
|
2180
|
+
# res << "static unsigned char data[] = \"#{str.reverse}\";\n"
|
2181
|
+
# # Create the value.
|
2182
|
+
# res << " " * (level+1)*3
|
2183
|
+
# # res << "return make_set_value(#{self.type.to_c(level+1)},0," +
|
2184
|
+
# # "data);\n"
|
2185
|
+
# res << "return make_set_value("
|
2186
|
+
# self.type.to_c(res,level+1)
|
2187
|
+
# res << ",0,data);\n"
|
2188
|
+
# end
|
2189
|
+
|
2082
2190
|
# Declares the data.
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2191
|
+
if self.content.is_a?(::Integer) then
|
2192
|
+
if self.type.width <= 64 then
|
2193
|
+
res << " " * (level+1)*3
|
2194
|
+
res << "Value value = make_value("
|
2195
|
+
self.type.to_c(res,level+1)
|
2196
|
+
res << ",1);\n"
|
2197
|
+
# res << " " * (level+1)*3
|
2198
|
+
# res << "value->numeric = 1;\n"
|
2199
|
+
res << " " * (level+1)*3
|
2200
|
+
res << "value->capacity = 0;\n"
|
2201
|
+
res << " " * (level+1)*3
|
2202
|
+
res << "value->data_str = NULL;\n"
|
2203
|
+
res << " " * (level+1)*3
|
2204
|
+
if self.content.bit_length <= 63 then
|
2205
|
+
res << "value->data_int = #{self.content}LLU;\n"
|
2206
|
+
else
|
2207
|
+
res << "value->data_int = "
|
2208
|
+
res << "#{self.content & 0xFFFFFFFFFFFF}LLU;\n"
|
2209
|
+
end
|
2210
|
+
# Close the value.
|
2211
|
+
res << " " * (level+1)*3
|
2212
|
+
res << "return value;\n"
|
2213
|
+
res << " " * level*3
|
2214
|
+
res << "}\n\n"
|
2215
|
+
# Return the result.
|
2216
|
+
return res
|
2094
2217
|
else
|
2095
|
-
|
2096
|
-
#
|
2097
|
-
|
2098
|
-
#
|
2099
|
-
str =
|
2218
|
+
str = self.content.to_s(2)
|
2219
|
+
# if str[-1] == "-" then
|
2220
|
+
# str[-1] = "1"
|
2221
|
+
# elsif str[-1] == "1" then
|
2222
|
+
# str = "0" + str
|
2223
|
+
# end
|
2224
|
+
if self.content < 0 then
|
2225
|
+
str = (2**self.type.width + self.content).to_s(2)
|
2226
|
+
str = "1" * (self.type.width-str.length) + str
|
2227
|
+
else
|
2228
|
+
str = self.content.to_s(2)
|
2229
|
+
str = "0" * (self.type.width-str.length) + str
|
2230
|
+
end
|
2231
|
+
str.reverse!
|
2100
2232
|
end
|
2101
|
-
# puts "content=#{self.content} str=#{str}"
|
2102
|
-
end
|
2103
|
-
# Is it a fully defined number?
|
2104
|
-
# NOTE: bignum values are not supported by the simulation engine
|
2105
|
-
# yet, therefore numeric values are limited to 64 max.
|
2106
|
-
if str =~ /^[01]+$/ && str.length <= 64 then
|
2107
|
-
# Yes, generate a numeral value.
|
2108
|
-
res << " " * (level+1)*3
|
2109
|
-
res << "static unsigned int data[] = { "
|
2110
|
-
res << str.scan(/.{1,#{Low2C.int_width}}/m).reverse.map do |sub|
|
2111
|
-
sub.to_i(2).to_s # + "ULL"
|
2112
|
-
end.join(",")
|
2113
|
-
res << ", 0" if (str.length <= 32)
|
2114
|
-
res << " };\n"
|
2115
|
-
# Create the value.
|
2116
|
-
res << " " * (level+1)*3
|
2117
|
-
# puts "str=#{str} type width=#{self.type.width} signed? #{type.signed?}"
|
2118
|
-
# res << "return make_set_value(#{self.type.to_c(level+1)},1," +
|
2119
|
-
# "data);\n"
|
2120
|
-
res << "return make_set_value("
|
2121
|
-
self.type.to_c(res,level+1)
|
2122
|
-
res << ",1,data);\n"
|
2123
2233
|
else
|
2124
|
-
|
2125
|
-
res << " " * (level+1)*3
|
2126
|
-
# res << "static unsigned char data[] = \"#{str}\";\n"
|
2127
|
-
res << "static unsigned char data[] = \"#{str.reverse}\";\n"
|
2128
|
-
# Create the value.
|
2129
|
-
res << " " * (level+1)*3
|
2130
|
-
# res << "return make_set_value(#{self.type.to_c(level+1)},0," +
|
2131
|
-
# "data);\n"
|
2132
|
-
res << "return make_set_value("
|
2133
|
-
self.type.to_c(res,level+1)
|
2134
|
-
res << ",0,data);\n"
|
2234
|
+
str = content.to_s.reverse
|
2135
2235
|
end
|
2236
|
+
str = str.ljust(self.type.width,str[-1])
|
2237
|
+
res << " " * (level+1)*3
|
2238
|
+
res << "Value value = make_value("
|
2239
|
+
self.type.to_c(res,level+1)
|
2240
|
+
res << ",1);\n"
|
2241
|
+
res << " " * (level+1)*3
|
2242
|
+
res << "value->numeric = 0;\n"
|
2243
|
+
res << " " * (level+1)*3
|
2244
|
+
res << "value->capacity = #{str.length+1};"
|
2245
|
+
res << " " * (level+1)*3
|
2246
|
+
res << "value->data_str = calloc(value->capacity,sizeof(char));\n"
|
2247
|
+
res << " " * (level+1)*3
|
2248
|
+
res << "strcpy(value->data_str,\"#{str}\");\n"
|
2136
2249
|
|
2137
2250
|
# Close the value.
|
2251
|
+
res << " " * (level+1)*3
|
2252
|
+
res << "return value;\n"
|
2138
2253
|
res << " " * level*3
|
2139
2254
|
res << "}\n\n"
|
2140
2255
|
# Return the result.
|
@@ -2142,6 +2257,7 @@ module HDLRuby::Low
|
|
2142
2257
|
end
|
2143
2258
|
end
|
2144
2259
|
|
2260
|
+
|
2145
2261
|
## Extends the Cast class with generation of C text.
|
2146
2262
|
class Cast
|
2147
2263
|
|