HDLRuby 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/HDLRuby.gemspec +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +2774 -0
- data/README.pdf +0 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/hdrcc +3 -0
- data/lib/HDLRuby/alcc.rb +137 -0
- data/lib/HDLRuby/backend/hruby_allocator.rb +69 -0
- data/lib/HDLRuby/backend/hruby_c_allocator.rb +76 -0
- data/lib/HDLRuby/hdr_samples/adder.rb +7 -0
- data/lib/HDLRuby/hdr_samples/adder_assign_error.rb +11 -0
- data/lib/HDLRuby/hdr_samples/adder_bench.rb +27 -0
- data/lib/HDLRuby/hdr_samples/adder_gen.rb +7 -0
- data/lib/HDLRuby/hdr_samples/adder_nodef_error.rb +7 -0
- data/lib/HDLRuby/hdr_samples/addsub.rb +19 -0
- data/lib/HDLRuby/hdr_samples/addsubz.rb +22 -0
- data/lib/HDLRuby/hdr_samples/alu.rb +47 -0
- data/lib/HDLRuby/hdr_samples/calculator.rb +48 -0
- data/lib/HDLRuby/hdr_samples/counter_bench.rb +83 -0
- data/lib/HDLRuby/hdr_samples/dff.rb +9 -0
- data/lib/HDLRuby/hdr_samples/dff_bench.rb +66 -0
- data/lib/HDLRuby/hdr_samples/dff_counter.rb +20 -0
- data/lib/HDLRuby/hdr_samples/include.rb +14 -0
- data/lib/HDLRuby/hdr_samples/instance_open.rb +23 -0
- data/lib/HDLRuby/hdr_samples/mei8.rb +256 -0
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +309 -0
- data/lib/HDLRuby/hdr_samples/multer_gen.rb +8 -0
- data/lib/HDLRuby/hdr_samples/multer_seq.rb +29 -0
- data/lib/HDLRuby/hdr_samples/neural/a.rb +9 -0
- data/lib/HDLRuby/hdr_samples/neural/a_sub.rb +5 -0
- data/lib/HDLRuby/hdr_samples/neural/bw.rb +23 -0
- data/lib/HDLRuby/hdr_samples/neural/counter.rb +16 -0
- data/lib/HDLRuby/hdr_samples/neural/dadz.rb +9 -0
- data/lib/HDLRuby/hdr_samples/neural/dadz_sub.rb +4 -0
- data/lib/HDLRuby/hdr_samples/neural/forward.rb +153 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub.rb +62 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand.rb +41 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand_typedef.rb +47 -0
- data/lib/HDLRuby/hdr_samples/neural/mem.rb +30 -0
- data/lib/HDLRuby/hdr_samples/neural/random.rb +23 -0
- data/lib/HDLRuby/hdr_samples/neural/selector.rb +29 -0
- data/lib/HDLRuby/hdr_samples/neural/sigmoid.rb +20 -0
- data/lib/HDLRuby/hdr_samples/neural/z.rb +33 -0
- data/lib/HDLRuby/hdr_samples/prog.obj +256 -0
- data/lib/HDLRuby/hdr_samples/ram.rb +18 -0
- data/lib/HDLRuby/hdr_samples/register_with_code_bench.rb +98 -0
- data/lib/HDLRuby/hdr_samples/rom.rb +10 -0
- data/lib/HDLRuby/hdr_samples/struct.rb +14 -0
- data/lib/HDLRuby/hdr_samples/sumprod.rb +29 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_bench.rb +103 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb +261 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_cpusim_bench.rb +302 -0
- data/lib/HDLRuby/hdr_samples/system_open.rb +11 -0
- data/lib/HDLRuby/hdr_samples/tuple.rb +16 -0
- data/lib/HDLRuby/hdr_samples/with_channel.rb +118 -0
- data/lib/HDLRuby/hdr_samples/with_class.rb +199 -0
- data/lib/HDLRuby/hdr_samples/with_decoder.rb +17 -0
- data/lib/HDLRuby/hdr_samples/with_fsm.rb +34 -0
- data/lib/HDLRuby/hdr_samples/with_reconf.rb +103 -0
- data/lib/HDLRuby/hdrcc.rb +623 -0
- data/lib/HDLRuby/high_samples/_adder_fault.rb +23 -0
- data/lib/HDLRuby/high_samples/_generic_transmission2.rb +146 -0
- data/lib/HDLRuby/high_samples/adder.rb +21 -0
- data/lib/HDLRuby/high_samples/adder_common_errors.rb +25 -0
- data/lib/HDLRuby/high_samples/addsub.rb +33 -0
- data/lib/HDLRuby/high_samples/addsubz.rb +37 -0
- data/lib/HDLRuby/high_samples/after.rb +28 -0
- data/lib/HDLRuby/high_samples/all_signals.rb +29 -0
- data/lib/HDLRuby/high_samples/alu.rb +61 -0
- data/lib/HDLRuby/high_samples/anonymous.rb +41 -0
- data/lib/HDLRuby/high_samples/before.rb +28 -0
- data/lib/HDLRuby/high_samples/blockblock.rb +26 -0
- data/lib/HDLRuby/high_samples/bugs/dadz.rb +22 -0
- data/lib/HDLRuby/high_samples/bugs/misample_instan.rb +20 -0
- data/lib/HDLRuby/high_samples/bugs/misample_updown.rb +22 -0
- data/lib/HDLRuby/high_samples/bugs/sample_add.rb +16 -0
- data/lib/HDLRuby/high_samples/bugs/sample_barrel.rb +13 -0
- data/lib/HDLRuby/high_samples/bugs/sample_daice.rb +57 -0
- data/lib/HDLRuby/high_samples/bugs/sample_kumiawase.rb +52 -0
- data/lib/HDLRuby/high_samples/bugs/sample_multi.rb +18 -0
- data/lib/HDLRuby/high_samples/bugs/sample_sub.rb +14 -0
- data/lib/HDLRuby/high_samples/bugs/z2.rb +32 -0
- data/lib/HDLRuby/high_samples/case.rb +32 -0
- data/lib/HDLRuby/high_samples/case2.rb +30 -0
- data/lib/HDLRuby/high_samples/change.rb +23 -0
- data/lib/HDLRuby/high_samples/clocks.rb +35 -0
- data/lib/HDLRuby/high_samples/comparer.rb +21 -0
- data/lib/HDLRuby/high_samples/conditionals.rb +29 -0
- data/lib/HDLRuby/high_samples/dff.rb +23 -0
- data/lib/HDLRuby/high_samples/each.rb +28 -0
- data/lib/HDLRuby/high_samples/exporter.rb +42 -0
- data/lib/HDLRuby/high_samples/functions.rb +60 -0
- data/lib/HDLRuby/high_samples/if_seq.rb +26 -0
- data/lib/HDLRuby/high_samples/inherit_as_dff.rb +32 -0
- data/lib/HDLRuby/high_samples/inherit_dff.rb +36 -0
- data/lib/HDLRuby/high_samples/instance.rb +37 -0
- data/lib/HDLRuby/high_samples/memory.rb +64 -0
- data/lib/HDLRuby/high_samples/multi_file.rb +27 -0
- data/lib/HDLRuby/high_samples/overload.rb +32 -0
- data/lib/HDLRuby/high_samples/paper_after.rb +49 -0
- data/lib/HDLRuby/high_samples/ram.rb +27 -0
- data/lib/HDLRuby/high_samples/registers.rb +139 -0
- data/lib/HDLRuby/high_samples/rom.rb +23 -0
- data/lib/HDLRuby/high_samples/scopeblockname.rb +37 -0
- data/lib/HDLRuby/high_samples/scopescope.rb +26 -0
- data/lib/HDLRuby/high_samples/shift.rb +31 -0
- data/lib/HDLRuby/high_samples/shift2.rb +40 -0
- data/lib/HDLRuby/high_samples/simple_instance.rb +31 -0
- data/lib/HDLRuby/high_samples/test_all.sh +10 -0
- data/lib/HDLRuby/high_samples/typedef.rb +24 -0
- data/lib/HDLRuby/high_samples/values.rb +70 -0
- data/lib/HDLRuby/high_samples/vector.rb +22 -0
- data/lib/HDLRuby/high_samples/with_decoder.rb +30 -0
- data/lib/HDLRuby/high_samples/with_fsm.rb +46 -0
- data/lib/HDLRuby/high_samples/with_pipe.rb +43 -0
- data/lib/HDLRuby/high_samples/with_seq.rb +25 -0
- data/lib/HDLRuby/hruby_bstr.rb +1085 -0
- data/lib/HDLRuby/hruby_check.rb +317 -0
- data/lib/HDLRuby/hruby_db.rb +432 -0
- data/lib/HDLRuby/hruby_error.rb +44 -0
- data/lib/HDLRuby/hruby_high.rb +4103 -0
- data/lib/HDLRuby/hruby_low.rb +4735 -0
- data/lib/HDLRuby/hruby_low2c.rb +1986 -0
- data/lib/HDLRuby/hruby_low2high.rb +738 -0
- data/lib/HDLRuby/hruby_low2seq.rb +248 -0
- data/lib/HDLRuby/hruby_low2sym.rb +126 -0
- data/lib/HDLRuby/hruby_low2vhd.rb +1437 -0
- data/lib/HDLRuby/hruby_low_bool2select.rb +295 -0
- data/lib/HDLRuby/hruby_low_cleanup.rb +193 -0
- data/lib/HDLRuby/hruby_low_fix_types.rb +437 -0
- data/lib/HDLRuby/hruby_low_mutable.rb +1803 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +165 -0
- data/lib/HDLRuby/hruby_low_skeleton.rb +129 -0
- data/lib/HDLRuby/hruby_low_with_bool.rb +141 -0
- data/lib/HDLRuby/hruby_low_with_port.rb +167 -0
- data/lib/HDLRuby/hruby_low_with_var.rb +302 -0
- data/lib/HDLRuby/hruby_low_without_bit2vector.rb +88 -0
- data/lib/HDLRuby/hruby_low_without_concat.rb +162 -0
- data/lib/HDLRuby/hruby_low_without_connection.rb +113 -0
- data/lib/HDLRuby/hruby_low_without_namespace.rb +718 -0
- data/lib/HDLRuby/hruby_low_without_outread.rb +107 -0
- data/lib/HDLRuby/hruby_low_without_select.rb +206 -0
- data/lib/HDLRuby/hruby_serializer.rb +398 -0
- data/lib/HDLRuby/hruby_tools.rb +37 -0
- data/lib/HDLRuby/hruby_types.rb +239 -0
- data/lib/HDLRuby/hruby_values.rb +64 -0
- data/lib/HDLRuby/hruby_verilog.rb +1888 -0
- data/lib/HDLRuby/hruby_verilog_name.rb +52 -0
- data/lib/HDLRuby/low_samples/adder.yaml +97 -0
- data/lib/HDLRuby/low_samples/after.yaml +228 -0
- data/lib/HDLRuby/low_samples/before.yaml +223 -0
- data/lib/HDLRuby/low_samples/blockblock.yaml +48 -0
- data/lib/HDLRuby/low_samples/bugs/sample_add.yaml +97 -0
- data/lib/HDLRuby/low_samples/bugs/sample_daice.yaml +444 -0
- data/lib/HDLRuby/low_samples/bugs/sample_kumiawase.yaml +332 -0
- data/lib/HDLRuby/low_samples/bugs/sample_sub.yaml +97 -0
- data/lib/HDLRuby/low_samples/bugs/seqpar.yaml +184 -0
- data/lib/HDLRuby/low_samples/case.yaml +327 -0
- data/lib/HDLRuby/low_samples/change.yaml +135 -0
- data/lib/HDLRuby/low_samples/clocks.yaml +674 -0
- data/lib/HDLRuby/low_samples/cloner.rb +22 -0
- data/lib/HDLRuby/low_samples/comparer.yaml +85 -0
- data/lib/HDLRuby/low_samples/conditionals.yaml +133 -0
- data/lib/HDLRuby/low_samples/dff.yaml +107 -0
- data/lib/HDLRuby/low_samples/each.yaml +1328 -0
- data/lib/HDLRuby/low_samples/exporter.yaml +226 -0
- data/lib/HDLRuby/low_samples/functions.yaml +298 -0
- data/lib/HDLRuby/low_samples/generic_transmission.yaml +597 -0
- data/lib/HDLRuby/low_samples/inherit_as_dff.yaml +125 -0
- data/lib/HDLRuby/low_samples/inherit_dff.yaml +107 -0
- data/lib/HDLRuby/low_samples/load_yaml.rb +11 -0
- data/lib/HDLRuby/low_samples/memory.yaml +678 -0
- data/lib/HDLRuby/low_samples/namespace_extractor.rb +23 -0
- data/lib/HDLRuby/low_samples/overload.yaml +226 -0
- data/lib/HDLRuby/low_samples/paper_after.yaml +431 -0
- data/lib/HDLRuby/low_samples/port_maker.rb +14 -0
- data/lib/HDLRuby/low_samples/ram.yaml +207 -0
- data/lib/HDLRuby/low_samples/registers.yaml +228 -0
- data/lib/HDLRuby/low_samples/rom.yaml +2950 -0
- data/lib/HDLRuby/low_samples/shift.yaml +230 -0
- data/lib/HDLRuby/low_samples/shift2.yaml +2095 -0
- data/lib/HDLRuby/low_samples/simple_instance.yaml +102 -0
- data/lib/HDLRuby/low_samples/test_all.sh +43 -0
- data/lib/HDLRuby/low_samples/typedef.yaml +115 -0
- data/lib/HDLRuby/low_samples/values.yaml +577 -0
- data/lib/HDLRuby/low_samples/variable_maker.rb +14 -0
- data/lib/HDLRuby/low_samples/vector.yaml +56 -0
- data/lib/HDLRuby/low_samples/with_seq.yaml +188 -0
- data/lib/HDLRuby/low_samples/yaml2hdr.rb +10 -0
- data/lib/HDLRuby/low_samples/yaml2vhd.rb +19 -0
- data/lib/HDLRuby/sim/Makefile +19 -0
- data/lib/HDLRuby/sim/hruby_sim.h +590 -0
- data/lib/HDLRuby/sim/hruby_sim_calc.c +2362 -0
- data/lib/HDLRuby/sim/hruby_sim_core.c +589 -0
- data/lib/HDLRuby/sim/hruby_sim_list.c +93 -0
- data/lib/HDLRuby/sim/hruby_sim_vizualize.c +91 -0
- data/lib/HDLRuby/sim/hruby_value_pool.c +64 -0
- data/lib/HDLRuby/std/channel.rb +354 -0
- data/lib/HDLRuby/std/clocks.rb +165 -0
- data/lib/HDLRuby/std/counters.rb +82 -0
- data/lib/HDLRuby/std/decoder.rb +214 -0
- data/lib/HDLRuby/std/fsm.rb +516 -0
- data/lib/HDLRuby/std/pipeline.rb +220 -0
- data/lib/HDLRuby/std/reconf.rb +309 -0
- data/lib/HDLRuby/test_hruby_bstr.rb +2259 -0
- data/lib/HDLRuby/test_hruby_high.rb +594 -0
- data/lib/HDLRuby/test_hruby_high_low.rb +99 -0
- data/lib/HDLRuby/test_hruby_low.rb +934 -0
- data/lib/HDLRuby/v_samples/adder.v +10 -0
- data/lib/HDLRuby/v_samples/dff.v +12 -0
- data/lib/HDLRuby/v_samples/ram.v +20 -0
- data/lib/HDLRuby/v_samples/rom.v +270 -0
- data/lib/HDLRuby/version.rb +3 -0
- data/lib/HDLRuby.rb +11 -0
- data/makedoc +1 -0
- data/metadata.yaml +4 -0
- metadata +299 -0
@@ -0,0 +1,437 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'HDLRuby'
|
3
|
+
require 'HDLRuby/hruby_low_mutable'
|
4
|
+
|
5
|
+
|
6
|
+
module HDLRuby::Low
|
7
|
+
|
8
|
+
|
9
|
+
##
|
10
|
+
# Make explicit all the type conversions and convert the constants accordingly.
|
11
|
+
#
|
12
|
+
########################################################################
|
13
|
+
|
14
|
+
|
15
|
+
## Extends the SystemT class with fixing of types and constants.
|
16
|
+
class SystemT
|
17
|
+
# Explicit the types conversions in the system.
|
18
|
+
def explicit_types!
|
19
|
+
# No direct fix required in the system, recurse on the scope.
|
20
|
+
self.scope.explicit_types!
|
21
|
+
return self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
## Extends the Scope class with fixing of types and constants.
|
27
|
+
class Scope
|
28
|
+
# Explicit the types conversions in the scope.
|
29
|
+
def explicit_types!
|
30
|
+
# Recurse on the sub scopes.
|
31
|
+
self.each_scope(&:explicit_types!)
|
32
|
+
# Fix the types of the declarations.
|
33
|
+
self.each_inner(&:explicit_types!)
|
34
|
+
# Fix the types of the connections.
|
35
|
+
self.each_connection(&:explicit_types!)
|
36
|
+
# Fix the types of the behaviors.
|
37
|
+
self.each_behavior(&:explicit_types!)
|
38
|
+
return self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
## Extends the Behavior class with fixing of types and constants.
|
44
|
+
class Behavior
|
45
|
+
# Explicit the types conversions in the scope.
|
46
|
+
def explicit_types!
|
47
|
+
# Fix the types of the block.
|
48
|
+
self.block.explicit_types!
|
49
|
+
return self
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
## Extends the SignalI class with fixing of types and constants.
|
55
|
+
class SignalI
|
56
|
+
# Explicit the types conversions in the signal.
|
57
|
+
def explicit_types!
|
58
|
+
# Is there a value?
|
59
|
+
value = self.value
|
60
|
+
if value then
|
61
|
+
# Yes recurse on it.
|
62
|
+
self.set_value!(value.explicit_types(self.type))
|
63
|
+
end
|
64
|
+
# No, nothing to do.
|
65
|
+
return self
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
## Extends the Statement class with fixing of types and constants.
|
71
|
+
class Statement
|
72
|
+
# Explicit the types conversions in the statement.
|
73
|
+
def explicit_types!
|
74
|
+
raise "Should implement explicit_types for class #{self.class}."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
## Extends the Transmit class with fixing of types and constants.
|
80
|
+
class Transmit
|
81
|
+
# Explicit the types conversions in the statement.
|
82
|
+
def explicit_types!
|
83
|
+
# Recurse on the left and the right.
|
84
|
+
self.set_left!(self.left.explicit_types)
|
85
|
+
# The right have to match the left type.
|
86
|
+
self.set_right!(self.right.explicit_types(self.left.type))
|
87
|
+
return self
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
## Extends the If class with fixing of types and constants.
|
94
|
+
class If
|
95
|
+
# Explicit the types conversions in the if.
|
96
|
+
def explicit_types!
|
97
|
+
# Recurse on the condition: it must be a Bit.
|
98
|
+
self.set_condition!(self.condition.explicit_types(Bit))
|
99
|
+
# Recurse on the yes block.
|
100
|
+
self.yes.explicit_types!
|
101
|
+
# Recruse on the alternative ifs, the conditions must be Bit.
|
102
|
+
self.map_noifs! do |cond,block|
|
103
|
+
[ cond.explicit_types(Bit), block.explicit_types! ]
|
104
|
+
end
|
105
|
+
# Recurse on the no block.
|
106
|
+
self.no.explicit_types! if self.no
|
107
|
+
return self
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
## Extends the When class with fixing of types and constants.
|
113
|
+
class When
|
114
|
+
# Explicit the types conversions in the when where +type+ is the
|
115
|
+
# type of the selecting value.
|
116
|
+
def explicit_types!(type)
|
117
|
+
# Recurse on the match, it must be of type.
|
118
|
+
self.set_match!(self.match.explicit_types(type))
|
119
|
+
# Recurse on the statement.
|
120
|
+
self.statement.explicit_types!
|
121
|
+
return self
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
## Extends the Case class with fixing of types and constants.
|
127
|
+
class Case
|
128
|
+
# Explicit the types conversions in the case.
|
129
|
+
def explicit_types!
|
130
|
+
# Recurse on the value.
|
131
|
+
self.set_value!(self.value.explicit_types)
|
132
|
+
# Recurse on the whens, the match of each when must be of the
|
133
|
+
# type of the value.
|
134
|
+
self.each_when { |w| w.explicit_types!(self.value.type) }
|
135
|
+
return self
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# Describes a wait statement: not synthesizable!
|
141
|
+
class TimeWait
|
142
|
+
# Explicit the types conversions in the time wait.
|
143
|
+
def explicit_types!
|
144
|
+
# Nothing to do.
|
145
|
+
return self
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
## Extends the TimeRepeat class with fixing of types and constants.
|
150
|
+
class TimeRepeat
|
151
|
+
# Explicit the types conversions in the time repeat.
|
152
|
+
def explicit_types!
|
153
|
+
# Recurse on the statement.
|
154
|
+
self.statement.explicit_types!
|
155
|
+
return self
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
## Extends the Block class with fixing of types and constants.
|
161
|
+
class Block
|
162
|
+
# Explicit the types conversions in the block.
|
163
|
+
def explicit_types!
|
164
|
+
# Recurse on the statements.
|
165
|
+
self.each_statement(&:explicit_types!)
|
166
|
+
return self
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
## Extends the Connection class with fixing of types and constants.
|
172
|
+
class Connection
|
173
|
+
# Nothing required, Transmit is generated identically.
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
## Extends the Expression class with fixing of types and constants.
|
178
|
+
class Expression
|
179
|
+
# Explicit the types conversions in the expression where
|
180
|
+
# +type+ is the expected type of the condition if any.
|
181
|
+
def explicit_types(type = nil)
|
182
|
+
raise "Should implement explicit_types for class #{self.class}."
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
## Extends the Value class with fixing of types and constants.
|
188
|
+
class Value
|
189
|
+
# Explicit the types conversions in the value where
|
190
|
+
# +type+ is the expected type of the condition if any.
|
191
|
+
def explicit_types(type = nil)
|
192
|
+
# Does the type match the value?
|
193
|
+
if type && !self.type.eql?(type) then
|
194
|
+
# No, update the type of the value.
|
195
|
+
return Value.new(type,self.content)
|
196
|
+
else
|
197
|
+
# yes, return the value as is.
|
198
|
+
return self.clone
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
## Extends the Cast class with fixing of types and constants.
|
205
|
+
class Cast
|
206
|
+
# Explicit the types conversions in the cast where
|
207
|
+
# +type+ is the expected type of the condition if any.
|
208
|
+
def explicit_types(type = nil)
|
209
|
+
# Does the type match the cast?
|
210
|
+
if type && !self.type.eql?(type) then
|
211
|
+
# No, Recurse on the child tomatch the type.
|
212
|
+
return self.child.explicit_types(type)
|
213
|
+
else
|
214
|
+
# No simply recurse on the child with the cast's type.
|
215
|
+
return self.child.explicit_types(self.type)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
|
221
|
+
## Extends the Operation class with fixing of types and constants.
|
222
|
+
class Operation
|
223
|
+
# Explicit the types conversions in the operation where
|
224
|
+
# +type+ is the expected type of the condition if any.
|
225
|
+
def explicit_types(type = nil)
|
226
|
+
raise "Should implement explicit_types for class #{self.class}."
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
|
231
|
+
## Extends the Unary class with fixing of types and constants.
|
232
|
+
class Unary
|
233
|
+
# Explicit the types conversions in the unary operation where
|
234
|
+
# +type+ is the expected type of the condition if any.
|
235
|
+
def explicit_types(type = nil)
|
236
|
+
# Recurse on the child (no type to specify here, unary operations
|
237
|
+
# preserve the type of their child).
|
238
|
+
op = Unary.new(self.type,self.operator,self.child.explicit_types)
|
239
|
+
# Does the type match the operation?
|
240
|
+
if type && !self.type.eql?(type) then
|
241
|
+
# No create a cast.
|
242
|
+
return Cast.new(type,op)
|
243
|
+
else
|
244
|
+
# Yes, return the operation as is.
|
245
|
+
return op
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
## Extends the Binary class with fixing of types and constants.
|
252
|
+
class Binary
|
253
|
+
# Explicit the types conversions in the binary operation where
|
254
|
+
# +type+ is the expected type of the condition if any.
|
255
|
+
def explicit_types(type = nil)
|
256
|
+
# Find the larger child type.
|
257
|
+
ctype = self.left.type.width > self.right.type.width ?
|
258
|
+
self.left.type : self.right.type
|
259
|
+
# Recurse on the children: match the larger type.
|
260
|
+
op = Binary.new(self.type,self.operator,
|
261
|
+
self.left.explicit_types(ctype),
|
262
|
+
self.right.explicit_types(ctype))
|
263
|
+
# Does the type match the operation?
|
264
|
+
if type && !self.type.eql?(type) then
|
265
|
+
# No create a cast.
|
266
|
+
return Cast.new(type,op)
|
267
|
+
else
|
268
|
+
# Yes, return the operation as is.
|
269
|
+
return op
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
|
275
|
+
## Extends the Select class with fixing of types and constants.
|
276
|
+
class Select
|
277
|
+
# Explicit the types conversions in the selection where
|
278
|
+
# +type+ is the expected type of the condition if any.
|
279
|
+
def explicit_types(type = nil)
|
280
|
+
# If there is no type to match, use the one of the selection.
|
281
|
+
type = self.type unless type
|
282
|
+
# Each choice child must match the type.
|
283
|
+
return Select.new(type,self.operator,self.select.clone,
|
284
|
+
*self.each_choice.map { |choice| choice.explicit_types(type)})
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
## Extends the Concat class with fixing of types and constants.
|
290
|
+
class Concat
|
291
|
+
# Explicit the types conversions in the concat where
|
292
|
+
# +type+ is the expected type of the condition if any.
|
293
|
+
def explicit_types(type = nil)
|
294
|
+
# Is there a type to match?
|
295
|
+
if type then
|
296
|
+
# Yes, update the concat to the type.
|
297
|
+
# Is it an array type?
|
298
|
+
if type.is_a?(TypeVector) then
|
299
|
+
# Yes, update the concat without subcasting.
|
300
|
+
return Concat.new(type,self.each_expression.map do |expr|
|
301
|
+
expr.explicit_types
|
302
|
+
end)
|
303
|
+
else
|
304
|
+
# No, it should be a tuple.
|
305
|
+
return Concat.new(type,self.expressions.map.with_index do
|
306
|
+
|expr,i|
|
307
|
+
expr.explicit_types(type.get_type(i))
|
308
|
+
end)
|
309
|
+
end
|
310
|
+
else
|
311
|
+
# No, recurse on the sub expressions.
|
312
|
+
return Concat.new(self.type,self.expressions.map do |expr|
|
313
|
+
expr.explicit_types
|
314
|
+
end)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
|
320
|
+
## Extends the Ref class with fixing of types and constants.
|
321
|
+
class Ref
|
322
|
+
# Explicit the types conversions in the reference where
|
323
|
+
# +type+ is the expected type of the condition if any.
|
324
|
+
def explicit_types(type = nil)
|
325
|
+
raise "Should implement explicit_types for class #{self.class}."
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
## Extends the RefConcat class with fixing of types and constants.
|
331
|
+
class RefConcat
|
332
|
+
# Explicit the types conversions in the concat ref where
|
333
|
+
# +type+ is the expected type of the condition if any.
|
334
|
+
def explicit_types(type = nil)
|
335
|
+
# Is there a type to match?
|
336
|
+
if type then
|
337
|
+
# Yes, update the concat to the type.
|
338
|
+
# Is it an array type?
|
339
|
+
if type.is_a?(TypeVector) then
|
340
|
+
# Yes, update the concat accordingly.
|
341
|
+
return RefConcat.new(type,self.each_ref.map do |ref|
|
342
|
+
ref.explicit_types(type.base)
|
343
|
+
end)
|
344
|
+
else
|
345
|
+
# No, it should be a tuple.
|
346
|
+
return RefConcat.new(type,self.each_ref.map.with_index do
|
347
|
+
|ref,i|
|
348
|
+
ref.explicit_types(type.get_type(i))
|
349
|
+
end)
|
350
|
+
end
|
351
|
+
else
|
352
|
+
# No, recurse on the sub expressions.
|
353
|
+
return RefConcat.new(self.type,self.each_ref.map.with_index do
|
354
|
+
|ref,i|
|
355
|
+
ref.explicit_types(self.type.get_type(i))
|
356
|
+
end)
|
357
|
+
end
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
## Extends the RefIndex class with fixing of types and constants.
|
363
|
+
class RefIndex
|
364
|
+
# Explicit the types conversions in the index ref where
|
365
|
+
# +type+ is the expected type of the condition if any.
|
366
|
+
def explicit_types(type = nil)
|
367
|
+
# Is there a type to match ?
|
368
|
+
if type then
|
369
|
+
# Regenerate the reference and cast it
|
370
|
+
return Cast.new(type,
|
371
|
+
RefIndex.new(self.type,self.ref.explicit_types,
|
372
|
+
self.index.explicit_types))
|
373
|
+
else
|
374
|
+
# No, recurse with the type of the current index ref.
|
375
|
+
return RefIndex.new(self.type,
|
376
|
+
self.ref.explicit_types,
|
377
|
+
self.index.explicit_types)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
## Extends the RefRange class with fixing of types and constants.
|
384
|
+
class RefRange
|
385
|
+
# Explicit the types conversions in the range ref where
|
386
|
+
# +type+ is the expected type of the condition if any.
|
387
|
+
def explicit_types(type = nil)
|
388
|
+
# Is there a type to match ?
|
389
|
+
if type then
|
390
|
+
# Regenerate the reference and cast it.
|
391
|
+
return Cast.new(type,
|
392
|
+
RefRange.new(self.type,self.ref.explicit_types,
|
393
|
+
self.range.first.explicit_types ..
|
394
|
+
self.range.last.explicit_types))
|
395
|
+
else
|
396
|
+
# No, recurse with the type of the current range ref.
|
397
|
+
return RefRange.new(self.type,
|
398
|
+
self.ref.explicit_types,
|
399
|
+
self.range.first.explicit_types ..
|
400
|
+
self.range.last.explicit_types)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
|
406
|
+
## Extends the RefName class with fixing of types and constants.
|
407
|
+
class RefName
|
408
|
+
# Explicit the types conversions in the index ref where
|
409
|
+
# +type+ is the expected type of the condition if any.
|
410
|
+
def explicit_types(type = nil)
|
411
|
+
# Is there a type to match, if not use current one.
|
412
|
+
type = self.type unless type
|
413
|
+
# Cast if required and return the new reference.
|
414
|
+
if self.type.eql?(type) then
|
415
|
+
# No need to cast.
|
416
|
+
return RefName.new(type,self.ref.explicit_types,self.name)
|
417
|
+
else
|
418
|
+
# Need a cast.
|
419
|
+
return Cast.new(type,
|
420
|
+
RefName.new(self.type,self.ref.explicit_types,self.name))
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
## Extends the RefThis class with fixing of types and constants.
|
427
|
+
class RefThis
|
428
|
+
# Explicit the types conversions in the index ref where
|
429
|
+
# +type+ is the expected type of the condition if any.
|
430
|
+
def explicit_types(type = nil)
|
431
|
+
# Simply duplicate.
|
432
|
+
return self.clone
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
|
437
|
+
end
|