HDLRuby 2.4.29 → 2.6.4

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/HDLRuby/drivers/xcd.rb +79 -0
  3. data/lib/HDLRuby/drivers/xcd/dummy.xcd +4 -0
  4. data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
  5. data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
  6. data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
  7. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
  8. data/lib/HDLRuby/hdr_samples/dff_properties.rb +19 -0
  9. data/lib/HDLRuby/hdr_samples/dff_unit.rb +54 -0
  10. data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
  11. data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
  12. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  13. data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
  14. data/lib/HDLRuby/hdr_samples/music.rb +79 -0
  15. data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
  16. data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
  17. data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
  18. data/lib/HDLRuby/hdrcc.rb +162 -26
  19. data/lib/HDLRuby/hruby_decorator.rb +250 -0
  20. data/lib/HDLRuby/hruby_high.rb +468 -91
  21. data/lib/HDLRuby/hruby_low.rb +913 -45
  22. data/lib/HDLRuby/hruby_low2c.rb +122 -168
  23. data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
  24. data/lib/HDLRuby/hruby_low2high.rb +331 -549
  25. data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
  26. data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
  27. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
  28. data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
  29. data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
  30. data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
  31. data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
  32. data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
  33. data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
  34. data/lib/HDLRuby/hruby_tools.rb +11 -1
  35. data/lib/HDLRuby/hruby_verilog.rb +1577 -1709
  36. data/lib/HDLRuby/sim/hruby_sim.h +29 -3
  37. data/lib/HDLRuby/sim/hruby_sim_calc.c +63 -6
  38. data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
  39. data/lib/HDLRuby/sim/hruby_sim_vcd.c +5 -1
  40. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
  41. data/lib/HDLRuby/std/fixpoint.rb +9 -0
  42. data/lib/HDLRuby/std/function_generator.rb +139 -0
  43. data/lib/HDLRuby/std/hruby_unit.rb +75 -0
  44. data/lib/HDLRuby/template_expander.rb +61 -0
  45. data/lib/HDLRuby/version.rb +1 -1
  46. metadata +21 -5
@@ -5,734 +5,516 @@ module HDLRuby::Low
5
5
 
6
6
 
7
7
  ##
8
- # Converts a HDLRuby::Low description to a HDLRuby::High text
9
- # description
8
+ # Converts a HDLRuby::Low description to HDLRuby::High description.
10
9
  #
11
10
  ########################################################################
12
11
 
13
- ## Provides tools for converting HDLRuby::Low objects to HDLRuby::High.
14
- module Low2High
15
12
 
16
- ## Tells if an HDLRuby::Low +name+ syntax is compatible for
17
- # HDLRuby::High.
18
- def self.high_name?(name)
19
- return name =~ /^[a-zA-Z_][a-zA-Z_0-9]*$/
20
- end
21
13
 
22
- ## Converts a HDLRuby::Low +name+ for declaration to HDLRuby::High.
23
- def self.high_decl_name(name)
24
- if high_name?(name) then
25
- # Compatible name return it as is.
26
- return name.to_s
27
- else
28
- # Incompatible, use quotes.
29
- return "\"#{name}\""
30
- end
14
+ # Add the conversion to high.
15
+ class SystemT
16
+ # Creates a new high system type named +name+ with +scope+.
17
+ def to_high
18
+ # Create the high system type.
19
+ res = HDLRuby::High::SystemT.new(self.name,self.scope.to_high)
20
+ # Add the inputs.
21
+ self.each_input { |i| res.add_input(i.to_high) }
22
+ # Add the outputs.
23
+ self.each_output { |o| res.add_output(o.to_high) }
24
+ # Add the inouts.
25
+ self.each_inout { |io| res.add_inout(io.to_high) }
26
+ return res
31
27
  end
28
+ end
32
29
 
33
- ## Converts a HDLRuby::Low +name+ for usage to HDLRuby::High.
34
- def self.high_use_name(name)
35
- if high_name?(name) then
36
- # Compatible name return it as is.
37
- return name.to_s
38
- else
39
- # Incompatible, use the HDLRuby::High "send" operator.
40
- return "(+:\"#{name}\")"
41
- end
30
+
31
+ # Add the conversion to high.
32
+ class Scope
33
+ # Creates a new high scope.
34
+ def to_high
35
+ # Create the high scope.
36
+ res = new HDLRuby::High::Scope.new(self.name)
37
+ # Add the local types.
38
+ self.each_type { |t| res.add_type(t.to_high) }
39
+ # Add the local system types.
40
+ self.each_systemT { |s| res.add_systemT(s.to_high) }
41
+ # Add the sub scopes.
42
+ self.each_scope { |s| res.add_scope(s.to_high) }
43
+ # Add the inner signals.
44
+ self.each_inner { |i| res.add_inner(i.to_high) }
45
+ # Add the system instances.
46
+ self.each_systemI { |s| res.add_systemI(s.to_high) }
47
+ # Add the non-HDLRuby cofe chunks.
48
+ self.each_code { |c| res.add_code(c.to_high) }
49
+ # Add the connections.
50
+ self.each_connection { |c| res.add_connection(c.to_high) }
51
+ # Add the behaviors.
52
+ self.each_behavior { |b| res.add_behavior(b.to_high) }
53
+ return res
42
54
  end
55
+ end
43
56
 
44
- ## Convert a HDLRuby::Low +name+ for instantiation to HDLRuby::High
45
- # with args as argument.
46
- def self.high_call_name(name,args)
47
- if high_name?(name) then
48
- # Compatible name return it as is.
49
- return "#{name} #{[*args].join(",")}"
50
- else
51
- # Incompatible, use the HDLRuby::High "send" operator.
52
- return "send(:\"#{name}\",#{[*args].join(",")})"
53
- end
57
+
58
+ # Add the conversion to high.
59
+ class Type
60
+ # Creates a new high type.
61
+ def to_high
62
+ return HDLRuby::High::Type.new(self.name)
54
63
  end
55
64
  end
56
65
 
57
66
 
67
+ # Add the conversion to high.
68
+ class TypeDef
69
+ # Creates a new high type definition.
70
+ def to_high
71
+ return HDLRuby::High::Typdef.new(self.name,self.type.to_high)
72
+ end
73
+ end
58
74
 
59
- ## Extends the SystemT class with generation of HDLRuby::High text.
60
- class SystemT
61
75
 
62
- # Generates the text of the equivalent HDLRuby::High code.
63
- # +level+ is the hierachical level of the object.
64
- def to_high(level = 0)
65
- # The resulting string.
66
- res = ""
67
- # Generate the header.
68
- res << " " * (level*3)
69
- res << "system :#{Low2High.high_decl_name(self.name)} do\n"
70
- # Generate the interface.
71
- # Inputs.
72
- self.each_input do |input|
73
- res << " " * ((level+1)*3)
74
- res << input.type.to_high(level+1)
75
- res << ".input :" << Low2High.high_decl_name(input.name)
76
- res << "\n"
77
- end
78
- # Outputs.
79
- self.each_output do |output|
80
- res << " " * ((level+1)*3)
81
- res << output.type.to_high(level+1)
82
- res << ".output :" << Low2High.high_decl_name(output.name)
83
- res << "\n"
84
- end
85
- # Inouts.
86
- self.each_inout do |inout|
87
- res << " " * ((level+1)*3)
88
- res << inout.type.to_high(level+1)
89
- res << ".inout :" << Low2High.high_decl_name(inout.name)
90
- res << "\n"
91
- end
92
- # Generate the scope.
93
- res << " " * (level*3)
94
- res << "\n"
95
- res << self.scope.to_high(level+1,false)
96
- # End of the system.
97
- res << " " * (level*3)
98
- res << "end\n\n"
99
- # Return the result.
100
- return res
76
+ # Add the conversion to high.
77
+ class TypeVector
78
+ # Creates a new high type vector.
79
+ def to_high
80
+ return HDLRuby::High::TypeVector.new(self.name,
81
+ self.base.to_high,
82
+ self.range)
101
83
  end
102
84
  end
103
85
 
104
86
 
105
- ## Extends the Scope class with generation of HDLRuby::High text.
106
- class Scope
107
-
108
- # Generates the text of the equivalent HDLRuby::High code.
109
- # +level+ is the hierachical level of the object and
110
- # +header+ tells if the header is to generate or not.
111
- def to_high(level = 0,header = true)
112
- # The resulting string.
113
- res = ""
114
- # Generate the header if required.
115
- if header then
116
- res << (" " * (level*3)) << "sub "
117
- unless self.name.empty? then
118
- res << ":" << Low2High.high_decl_name(self.name) << " "
119
- end
120
- res << "do\n"
121
- end
122
- level = level + 1 if header
123
- # Generate the sub types.
124
- # Assume the types are TypeDef.
125
- self.each_type do |type|
126
- res << " " * (level*3)
127
- res << "typedef :#{type.name} do\n"
128
- res << " " * ((level+1)*3) << type.def.to_high(level)
129
- res << " " * (level*3) << "end\n"
130
- end
131
- # Generaste the sub system types.
132
- self.each_systemT { |systemT| res << systemT.to_high(level) }
133
- # Generate the inners declaration.
134
- self.each_inner do |inner|
135
- res << " " * (level*3)
136
- res << inner.type.to_high(level)
137
- res << ".inner :" << Low2High.high_decl_name(inner.name) << "\n"
138
- end
139
- # Generate the instances.
140
- res << "\n" if self.each_inner.any?
141
- self.each_systemI do |systemI|
142
- res << " " * (level*3)
143
- res << systemI.to_high(level) << "\n"
144
- end
145
- # Generate the sub scopes.
146
- self.each_scope do |scope|
147
- res << scope.to_high(level)
148
- end
149
- # Generate the connections.
150
- res << "\n" if self.each_scope.any?
151
- self.each_connection do |connection|
152
- res << connection.to_high(level)
153
- end
154
- # Generate the behaviors.
155
- res << "\n" if self.each_connection.any?
156
- self.each_behavior do |behavior|
157
- res << behavior.to_high(level)
158
- end
159
- # Close the scope if required.
160
- if header then
161
- res << " " * ((level-1)*3) << "end\n"
162
- end
163
- # Return the result.
164
- return res
87
+ # Add the conversion to high.
88
+ class TypeSigned
89
+ # Creates a new high type signed.
90
+ def to_high
91
+ return HDLRuby::High::TypeSigned.new(self.name,self.range)
165
92
  end
166
93
  end
167
94
 
168
95
 
169
- ## Extends the Type class with generation of HDLRuby::High text.
170
- class Type
171
-
172
- # Generates the text of the equivalent HDLRuby::High code.
173
- # +level+ is the hierachical level of the object.
174
- def to_high(level = 0)
175
- return Low2High.high_use_name(self.name)
96
+ # Add the conversion to high.
97
+ class TypeUnsigned
98
+ # Creates a new high type unsigned.
99
+ def to_high
100
+ return HDLRuby::High::TypeUnsigned.new(self.name,self.range)
176
101
  end
102
+
177
103
  end
178
104
 
179
- ## Extends the TypeDef class with generation of HDLRuby::High text.
180
- class TypeDef
181
105
 
182
- # Generates the text of the equivalent HDLRuby::High code.
183
- # +level+ is the hierachical level of the object.
184
- def to_high(level = 0)
185
- # Simply generates the redefined type.
186
- self.def.to_high(level)
106
+ # Add the conversion to high.
107
+ class TypeTuple
108
+ # Creates a new high type tuple.
109
+ def to_high
110
+ return HDLRuby::High::TypeTuple.new(self.name,self.direction,
111
+ *self.each_type.map { |typ| typ.to_high })
187
112
  end
188
113
  end
189
114
 
190
- ## Extends the TypeVector class with generation of HDLRuby::High text.
191
- class TypeVector
192
115
 
193
- # Generates the text of the equivalent HDLRuby::High code.
194
- # +level+ is the hierachical level of the object.
195
- def to_high(level = 0)
196
- # The resulting string.
197
- res = ""
198
- # Generate the base.
199
- res << self.base.to_high(level)
200
- # Generate the range.
201
- res << "[" << self.range.first.to_high(level) << ".." <<
202
- self.range.last.to_high(level) << "]"
203
- # Return the result.
204
- return res
116
+ # Add the conversion to high.
117
+ class TypeStruct
118
+ # Creates a new high type struct.
119
+ def to_high
120
+ return HDLRuby::High::TypeString.new(self.name,self.direction,
121
+ self.each {|name,typ| [name,typ.to_high]})
205
122
  end
206
123
  end
207
124
 
208
- ## Extends the TypeTuple class with generation of HDLRuby::High text.
209
- class TypeTuple
210
125
 
211
- # Generates the text of the equivalent HDLRuby::High code.
212
- # +level+ is the hierachical level of the object.
213
- def to_high(level = 0)
214
- # The resulting string.
215
- res = "["
216
- # Generate each sub type.
217
- res << self.each_type.map { |type| type.to_high(level) }.join(", ")
218
- # Close the tuple.
219
- res << "]"
220
- # Return the result.
126
+
127
+ # Add the conversion to high.
128
+ class Behavior
129
+ # Creates a new high behavior.
130
+ def to_high
131
+ # Create the resulting behavior.
132
+ res = HDLRuby::High::Behavior.new(self.block.to_high)
133
+ # Adds the events.
134
+ self.each_event { |ev| res.add_event(ev.to_high) }
221
135
  return res
222
136
  end
223
137
  end
224
138
 
225
- ## Extends the TypeStruct class with generation of HDLRuby::High text.
226
- class TypeStruct
227
139
 
228
- # Generates the text of the equivalent HDLRuby::High code.
229
- # +level+ is the hierachical level of the object.
230
- def to_high(level = 0)
231
- # The resulting string.
232
- res = "{ "
233
- # Generate each sub type.
234
- res << self.each.map do |key,type|
235
- "#{key}: " + type.to_high(level)
236
- end.join(", ")
237
- # Close the struct.
238
- res << " }"
239
- # Return the result.
140
+ # Add the conversion to high.
141
+ class TimeBehavior
142
+ # Creates a new high time behavior.
143
+ def to_high
144
+ # Create the resulting behavior.
145
+ res = HDLRuby::High::TimeBehavior.new(self.block.to_high)
146
+ # Adds the events.
147
+ self.each_event { |ev| res.add_event(ev.to_high) }
240
148
  return res
241
149
  end
242
150
  end
243
151
 
244
152
 
245
- ## Extends the Behavior class with generation of HDLRuby::High text.
246
- class Behavior
153
+ # Add the conversion to high.
154
+ class Event
155
+ # Creates a new high event.
156
+ def to_high
157
+ return HDLRuby::High::Event.new(self.type.to_high,self.ref.to_high)
158
+ end
159
+ end
247
160
 
248
- # Generates the text of the equivalent HDLRuby::High code.
249
- # +level+ is the hierachical level of the object and +timed+
250
- # tells if the behavior is a time behavior or not.
251
- def to_high(level = 0,timed = false)
252
- # The resulting string.
253
- res = " " * (level*3)
254
- # Generate the header.
255
- if timed then
256
- res << "timed"
161
+
162
+ # Add the conversion to high.
163
+ class SignalI
164
+ # Creates a new high signal.
165
+ def to_high
166
+ # Is there an initial value?
167
+ if (self.value) then
168
+ # Yes, create a new high signal with it.
169
+ return HDLRuby::High::SignalI.new(self.name,self.type.to_high,
170
+ self.val.to_high)
257
171
  else
258
- res << self.block.mode.to_s
259
- end
260
- if self.each_event.any? then
261
- res << "( "
262
- res << self.each_event.map do |event|
263
- event.to_high(level)
264
- end.join(", ")
265
- res << " )"
172
+ # No, create a new high signal with it.
173
+ return HDLRuby::High::SignalI.new(self.name,self.type.to_high)
266
174
  end
267
- res << " do\n"
268
- # Generate the content.
269
- res << self.block.to_high(level+1,false)
270
- # Close the behavior.
271
- res << " " * (level*3) << "end\n"
272
- # Return the result.
273
- return res
274
175
  end
275
176
  end
276
177
 
277
- ## Extends the TimeBehavior class with generation of HDLRuby::High text.
278
- class TimeBehavior
279
178
 
280
- # Generates the text of the equivalent HDLRuby::High code.
281
- # +level+ is the hierachical level of the object.
282
- def to_high(level = 0)
283
- super(level,true)
179
+ # Add the conversion to high.
180
+ class SignalC
181
+ # Creates a new high constant signal.
182
+ def to_high
183
+ # Is there an initial value?
184
+ if (self.value) then
185
+ # Yes, create a new high signal with it.
186
+ return HDLRuby::High::SignalC.new(self.name,self.type.to_high,
187
+ self.val.to_high)
188
+ else
189
+ # No, create a new high signal with it.
190
+ return HDLRuby::High::SignalC.new(self.name,self.type.to_high)
191
+ end
284
192
  end
285
193
  end
286
194
 
287
195
 
288
- ## Extends the Event class with generation of HDLRuby::High text.
289
- class Event
290
-
291
- # Generates the text of the equivalent HDLRuby::High code.
292
- # +level+ is the hierachical level of the object.
293
- def to_high(level = 0)
294
- return self.ref.to_high(level) + ".#{self.type}"
196
+ # Add the conversion to high.
197
+ class SystemI
198
+ # Creates a new high system instance.
199
+ def to_high
200
+ return HDLRuby::High::SystemI.new(self.name,self.systemT.to_high)
295
201
  end
296
202
  end
297
203
 
298
204
 
299
- ## Extends the SignalI class with generation of HDLRuby::High text.
300
- class SignalI
301
-
302
- # Generates the text of the equivalent HDLRuby::High code.
303
- # +level+ is the hierachical level of the object.
304
- def to_high(level = 0)
305
- return Low2High.high_use_name(self.name)
205
+ # Add the conversion to high.
206
+ class Chunk
207
+ # Creates a new high code chunk.
208
+ def to_high
209
+ return HDLRuby::High::Chunk.new(self.name,
210
+ *self.each_lump { |lump| lump.to_high })
306
211
  end
307
212
  end
308
213
 
309
214
 
310
- ## Extends the SystemI class with generation of HDLRuby::High text.
311
- class SystemI
312
-
313
- # Generates the text of the equivalent HDLRuby::High code.
314
- # +level+ is the hierachical level of the object.
315
- def to_high(level = 0)
316
- return Low2High.high_call_name(self.systemT.name,
317
- ":" + Low2High.high_decl_name(self.name))
215
+ # Add the conversion to high.
216
+ class Code
217
+ # Creates a new high code.
218
+ def to_high
219
+ # Create the new code.
220
+ res = HDLRuby::High::Code.new
221
+ # Add the events.
222
+ self.each_event { |ev| res.add_event(ev.to_high) }
223
+ # Add the code chunks.
224
+ self.each_chunk { |ch| res.add_chunk(ch.to_high) }
318
225
  end
319
226
  end
320
227
 
321
228
 
322
- ## Extends the Statement class with generation of HDLRuby::High text.
229
+ # Add the conversion to high.
323
230
  class Statement
324
-
325
- # Generates the text of the equivalent HDLRuby::High code.
326
- # +level+ is the hierachical level of the object.
327
- def to_high(level = 0)
328
- # Should never be here.
329
- raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
231
+ # Creates a new high statement.
232
+ def to_high
233
+ raise AnyError,
234
+ "Internal error: to_high is not defined for class: #{self.class}"
330
235
  end
331
236
  end
332
237
 
333
- ## Extends the Transmit class with generation of HDLRuby::High text.
334
- class Transmit
335
238
 
336
- # Generates the text of the equivalent HDLRuby::High code.
337
- # +level+ is the hierachical level of the object.
338
- def to_high(level = 0)
339
- return " " * (level*3) +
340
- self.left.to_high(level) + " <= " +
341
- self.right.to_high(level) + "\n"
239
+ # Add the conversion to high.
240
+ class Transmit
241
+ # Creates a new high transmit statement.
242
+ def to_high
243
+ return HDLRuby::High::Transmit.new(self.left.to_high,
244
+ self.right.to_high)
342
245
  end
343
246
  end
344
-
345
- ## Extends the If class with generation of HDLRuby::High text.
346
- class If
347
247
 
348
- # Generates the text of the equivalent HDLRuby::High code.
349
- # +level+ is the hierachical level of the object.
350
- def to_high(level = 0)
351
- # The result string.
352
- res = " " * (level*3)
353
- # Generate the test.
354
- res << "hif " << self.condition.to_high(level) << " do\n"
355
- # Generate the yes part.
356
- res << self.yes.to_high(level+1)
357
- res << " " * (level*3) << "end\n"
358
- # Generate the alternate if parts.
359
- self.each_noif do |cond,stmnt|
360
- res << " " * (level*3)
361
- res << "helsif " << cond.to_high(level) << " do\n"
362
- res << stmnt.to_high(level+1)
363
- res << " " * (level*3) << "end\n"
364
- end
365
- # Generate the no part if any.
248
+
249
+ # Add the conversion to high.
250
+ class If
251
+ # Creates a new high if statement.
252
+ def to_high
253
+ # Is there a no?
366
254
  if self.no then
367
- res << " " * (level*3)
368
- res << "helse do\n" << self.no.to_high(level+1)
369
- res << " " * (level*3) << "end\n"
255
+ # Yes, create a new if statement with it.
256
+ res = HDLRuby::High::If.new(self.condition.to_high,
257
+ self.yes.to_high,self.no.to_high)
258
+ else
259
+ # No, create a new if statement without it.
260
+ res = HDLRuby::High::If.new(self.condition.to_high,
261
+ self.yes.to_high)
262
+ end
263
+ # Add the noifs if any.
264
+ self.each_noif do |cond,stmnt|
265
+ res.add_noif(cond.to_high,stmt.to_high)
370
266
  end
371
- # Return the result.
372
267
  return res
373
268
  end
374
269
  end
375
270
 
376
- ## Extends the When class with generation of HDLRuby::High text.
377
- class When
378
271
 
379
- # Generates the text of the equivalent HDLRuby::High code.
380
- # +level+ is the hierachical level of the object.
381
- def to_high(level = 0)
382
- # The result string.
383
- res = " " * (level*3)
384
- # Generate the match.
385
- res << "hwhen " << self.match.to_high(level+1) << " do\n"
386
- # Generate the statement.
387
- res << self.statement.to_high(level+1)
388
- # Close the when.
389
- res << " " * (level*3) << "end\n"
390
- # Returns the result.
391
- return res
272
+ # Add the conversion to high.
273
+ class When
274
+ # Creates a new high when.
275
+ def to_high
276
+ return HDLRuby::High::When.new(self.match.to_high,
277
+ self.statement.to_high)
392
278
  end
393
279
  end
394
280
 
395
- ## Extends the Case class with generation of HDLRuby::High text.
396
- class Case
397
281
 
398
- # Generates the text of the equivalent HDLRuby::High code.
399
- # +level+ is the hierachical level of the object.
400
- def to_high(level = 0)
401
- # The result string.
402
- res = " " * (level*3)
403
- # Generate the test.
404
- res << "hcase " << self.value.to_high(level) << "\n"
405
- # Generate the whens.
406
- self.each_when do |w|
407
- res << w.to_high(level)
408
- end
409
- # Generatethe default.
282
+ # Add the conversion to high.
283
+ class Case
284
+ # Creates a new high case statement.
285
+ def to_high
286
+ # Is there a default?
410
287
  if self.default then
411
- res << " " * (level*3)
412
- res << "helse do\n"
413
- res << self.default.to_high(level+1)
414
- res << " " * (level*3)
415
- res << "end\n"
288
+ # Yes, create the new case statement with it.
289
+ return HDLRuby::High::Case.new(self.value.to_high,
290
+ self.default.to_high,
291
+ self.each_when.map { |w| w.to_high })
416
292
  end
417
- # Return the resulting string.
418
- return res
419
293
  end
420
294
  end
421
295
 
422
296
 
423
- ## Extends the Delay class with generation of HDLRuby::High text.
297
+ # Add the conversion to high.
424
298
  class Delay
425
-
426
- # Generates the text of the equivalent HDLRuby::High code.
427
- # +level+ is the hierachical level of the object.
428
- def to_high(level = 0)
429
- return self.value.to_high(level) + ".#{self.unit}"
299
+ # Creates a new high delay.
300
+ def to_high
301
+ return HDLRuby::High::Delay.new(self.value,self.unit)
430
302
  end
431
303
  end
432
304
 
433
305
 
434
- ## Extends the TimeWait class with generation of HDLRuby::High text.
435
- class TimeWait
436
-
437
- # Generates the text of the equivalent HDLRuby::High code.
438
- # +level+ is the hierachical level of the object.
439
- def to_high(level = 0)
440
- # The resulting string.
441
- res = " " * (level*3)
442
- # Generate the wait.
443
- res << "wait " << self.delay.to_high(level) << "\n"
444
- # Return the resulting string.
445
- return res
306
+ # Add the conversion to high.
307
+ class Print
308
+ # Creates a new high print statement.
309
+ def to_high
310
+ return HDLRuby::High::Print.new(
311
+ *self.each_arg.map {|arg| arg.to_high })
446
312
  end
447
313
  end
448
314
 
449
- ## Extends the TimeRepeat class with generation of HDLRuby::High text.
450
- class TimeRepeat
451
315
 
452
- # Generates the text of the equivalent HDLRuby::High code.
453
- # +level+ is the hierachical level of the object.
454
- def to_high(level = 0)
455
- # The resulting string.
456
- res = " " * (level*3)
457
- # Generate the header.
458
- res << "repeat " << self.delay.to_high(level) << " do\n"
459
- # Generate the statement to repeat.
460
- res << self.statement.to_high(level+1)
461
- # Close the repeat.
462
- res << " " * (level*3) << "end\n"
463
- # Return the resulting string.
464
- return res
316
+ # Add the conversion to high.
317
+ class TimeWait
318
+ # Creates a new high wait statement.
319
+ def to_high
320
+ return HDLRuby::High::TimeWait.new(self.delay.to_high)
465
321
  end
466
322
  end
467
323
 
468
- ## Extends the Block class with generation of HDLRuby::High text.
469
- class Block
470
324
 
471
- # Generates the text of the equivalent HDLRuby::High code.
472
- # +level+ is the hierachical level of the object.
473
- # +header+ tells if the header is to generate or not.
474
- # +timed+ tells if its a timed block.
475
- def to_high(level = 0, header = true, timed = false)
476
- # The resulting string.
477
- res = ""
478
- # Generate the header if required.
479
- if header then
480
- if timed then
481
- res << " " * (level*3) << "timed "
482
- else
483
- res << " " * (level*3) << "#{self.mode} "
484
- end
485
- unless self.name.empty? then
486
- res << ":" << Low2High.high_decl_name(self.name) << " "
487
- end
488
- res << "do\n"
489
- end
490
- level = level + 1 if header
491
- # Generate the inners declaration.
492
- self.each_inner do |inner|
493
- res << " " * (level*3)
494
- res << inner.type.to_high(level)
495
- res << ".inner :" << Low2High.high_decl_name(inner.name) << "\n"
496
- end
497
- # Generate the statements.
498
- self.each_statement do |stmnt|
499
- res << stmnt.to_high(level)
500
- end
501
- # Close the block.
502
- if header then
503
- res << " " * ((level-1)*3) << "end\n"
504
- end
505
- # Return the result.
506
- return res
325
+ # Add the conversion to high.
326
+ class TimeRepeat
327
+ # Creates a new high repreat statement.
328
+ def to_high
329
+ return HDLRuby::High::TimeReapeat.new(self.delay.to_high,
330
+ self.statement.to_high)
507
331
  end
508
332
  end
509
333
 
510
- ## Extends the TimeBlock class with generation of HDLRuby::High text.
511
- class TimeBlock
512
334
 
513
- # Generates the text of the equivalent HDLRuby::High code.
514
- # +level+ is the hierachical level of the object.
515
- def to_high(level = 0, header = true)
516
- super(level,header,true)
335
+ # Add the conversion to high.
336
+ class Block
337
+ # Creates a new high block statement.
338
+ def to_high
339
+ # Create the new block statement.
340
+ res = HDLRuby::High::Block.new(self.mode,self.name)
341
+ # Add the statements.
342
+ self.each_statement { |stmnt| res.add_statement(stmnt.to_high) }
343
+ return res
517
344
  end
518
345
  end
519
346
 
520
347
 
521
- ## Extends the Code class with generation of HDLRuby::High text.
522
- class Code
523
-
524
- # Generates the text of the equivalent HDLRuby::High code.
525
- # +level+ is the hierachical level of the object.
526
- def to_high(level = 0)
527
- return self.content.to_s
348
+ # Add the conversion to high.
349
+ class TimeBlock
350
+ # Creates a new high time block statement.
351
+ def to_high
352
+ # Create the new block statement.
353
+ res = HDLRuby::High::TimeBlock.new(self.mode,self.name)
354
+ # Add the statements.
355
+ self.each_statement { |stmnt| res.add_statement(stmnt.to_high) }
356
+ return res
528
357
  end
529
358
  end
530
359
 
531
- ## Extends the Connection class with generation of HDLRuby::High text.
360
+
361
+ # Add the conversion to high.
532
362
  class Connection
533
- # Nothing required, Transmit is generated identically.
363
+ # Creates a new high connection.
364
+ def to_high
365
+ return HDLRuby::High::Connection.new(self.left.to_high,
366
+ self.right.to_high)
367
+ end
534
368
  end
535
369
 
536
370
 
537
- ## Extends the Expression class with generation of HDLRuby::High text.
371
+ # Add the conversion to high.
538
372
  class Expression
539
-
540
- # Generates the text of the equivalent HDLRuby::High code.
541
- # +level+ is the hierachical level of the object.
542
- def to_high(level = 0)
543
- # Should never be here.
544
- raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
373
+ # Creates a new high expression.
374
+ def to_high
375
+ raise AnyError,
376
+ "Internal error: to_high is not defined for class: #{self.class}"
545
377
  end
546
378
  end
547
379
 
548
- ## Extends the Value class with generation of HDLRuby::High text.
380
+
381
+ # Add the conversion to high.
549
382
  class Value
550
-
551
- # Generates the text of the equivalent HDLRuby::High code.
552
- # +level+ is the hierachical level of the object.
553
- def to_high(level = 0)
554
- if self.content.is_a?(HDLRuby::BitString) then
555
- return "_#{self.content}"
383
+ # Creates a new high value expression.
384
+ def to_high
385
+ # Is there a content?
386
+ if (self.content) then
387
+ # Yes, use it for creating the new value.
388
+ return HDLRuby::High::Value.new(self.type.to_high,
389
+ self.content.to_high)
556
390
  else
557
- return self.content.to_s
391
+ # puts "Self.type.name=#{self.type.name}"
392
+ # No (this should be a void value).
393
+ return HDLRuby::High::Value.new(self.type.to_high,nil)
558
394
  end
559
395
  end
560
396
  end
561
397
 
562
- ## Extends the Cast class with generation of HDLRuby::High text.
563
- class Cast
564
398
 
565
- # Generates the text of the equivalent HDLRuby::High code.
566
- # +level+ is the hierachical level of the object.
567
- def to_high(level = 0)
568
- return self.child.to_high(level) +
569
- ".as(" + self.type.to_high(level) + ")"
399
+ # Add the conversion to high.
400
+ class Cast
401
+ # Creates a new high cast expression.
402
+ def to_high
403
+ return HDLRuby::High::Cast(self.type.to_high, self.child.to_high)
570
404
  end
571
405
  end
572
406
 
573
- ## Extends the Operation class with generation of HDLRuby::High text.
574
- class Operation
575
407
 
576
- # Generates the text of the equivalent HDLRuby::High code.
577
- # +level+ is the hierachical level of the object.
578
- def to_high(level = 0)
579
- # Should never be here.
580
- raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
581
- end
408
+ # Add the conversion to high.
409
+ class Operation
582
410
  end
583
411
 
584
- ## Extends the Unary class with generation of HDLRuby::High text.
585
- class Unary
586
412
 
587
- # Generates the text of the equivalent HDLRuby::High code.
588
- # +level+ is the hierachical level of the object.
589
- def to_high(level = 0)
590
- return "(#{self.operator.to_s[0]}" + self.child.to_high(level) + ")"
413
+ # Add the conversion to high.
414
+ class Unary
415
+ # Creates a new high unary expression.
416
+ def to_high
417
+ return HDLRuby::High::Unary.new(self.type.to_high,self.operator,
418
+ self.child.to_high)
591
419
  end
592
420
  end
593
421
 
594
- ## Extends the Binary class with generation of HDLRuby::High text.
595
- class Binary
596
422
 
597
- # Generates the text of the equivalent HDLRuby::High code.
598
- # +level+ is the hierachical level of the object.
599
- def to_high(level = 0)
600
- return "(" + self.left.to_high(level) + self.operator.to_s +
601
- self.right.to_high(level) + ")"
423
+ # Add the conversion to high.
424
+ class Binary
425
+ # Creates a new high binary expression.
426
+ def to_high
427
+ return HDLRuby::High::Binary.new(self.type.to_high,self.operator,
428
+ self.left.to_high,
429
+ self.right.to_high)
602
430
  end
603
431
  end
604
432
 
605
- ## Extends the Select class with generation of HDLRuby::High text.
606
- class Select
607
433
 
608
- # Generates the text of the equivalent HDLRuby::High code.
609
- # +level+ is the hierachical level of the object.
610
- def to_high(level = 0)
611
- # The resulting string.
612
- res = ""
613
- # Generate the header.
614
- res << "mux(" + self.select.to_high(level) << ", "
615
- # Generate the choices
616
- res << self.each_choice.map do |choice|
617
- choice.to_high(level+1)
618
- end.join(", ")
619
- # Close the select.
620
- res << ")"
621
- # Return the resulting string.
622
- return res
434
+ # Add the conversion to high.
435
+ class Select
436
+ # Creates a new high select expression.
437
+ def to_high
438
+ return HDLRuby::High::Select(self.type.to_high,self.operator,
439
+ self.select.to_high,
440
+ self.each_choice.map { |ch| ch.to_high })
623
441
  end
624
442
  end
625
443
 
626
- ## Extends the Concat class with generation of HDLRuby::High text.
627
- class Concat
628
444
 
629
- # Generates the text of the equivalent HDLRuby::High code.
630
- # +level+ is the hierachical level of the object.
631
- def to_high(level = 0)
632
- # The resulting string.
633
- res = ""
634
- # Generate the header.
635
- res << "[ "
636
- # Generate the expressions.
637
- res << self.each_expression.map do |expression|
638
- expression.to_high(level+1)
639
- end.join(", ")
640
- # Close the select.
641
- res << " ]"
642
- # Return the resulting string.
643
- return res
445
+ # Add the conversion to high.
446
+ class Concat
447
+ # Creates a new high concat expression.
448
+ def to_high
449
+ return HDLRuby::High::Concat.new(self.type.to_high,
450
+ self.each_expression.map { |ex| ex.to_high })
644
451
  end
645
452
  end
646
453
 
647
454
 
648
- ## Extends the Ref class with generation of HDLRuby::High text.
455
+ # Add the conversion to high.
649
456
  class Ref
650
-
651
- # Generates the text of the equivalent HDLRuby::High code.
652
- # +level+ is the hierachical level of the object.
653
- def to_high(level = 0)
654
- # Should never be here.
655
- raise AnyError, "Internal error: to_high should be implemented in class :#{self.class}"
656
- end
657
457
  end
658
458
 
659
- ## Extends the RefConcat class with generation of HDLRuby::High text.
660
- class RefConcat
661
459
 
662
- # Generates the text of the equivalent HDLRuby::High code.
663
- # +level+ is the hierachical level of the object.
664
- def to_high(level = 0)
665
- # The resulting string.
666
- res = ""
667
- # Generate the header.
668
- res << "[ "
669
- # Generate the references.
670
- res << self.each_ref.map do |ref|
671
- ref.to_high(level+1)
672
- end.join(", ")
673
- # Close the select.
674
- res << " ]"
675
- # Return the resulting string.
676
- return res
460
+ # Add the conversion to high.
461
+ class RefConcat
462
+ # Creates a new high concat reference.
463
+ def to_high
464
+ return HDLRuby::High::Ref.new(self.type.to_high,
465
+ self.each_ref.map { |ref| ref.to_high })
677
466
  end
678
467
  end
679
468
 
680
- ## Extends the RefIndex class with generation of HDLRuby::High text.
681
- class RefIndex
682
469
 
683
- # Generates the text of the equivalent HDLRuby::High code.
684
- # +level+ is the hierachical level of the object.
685
- def to_high(level = 0)
686
- return self.ref.to_high(level) + "[#{self.index.to_high(level)}]"
470
+ # Add the conversion to high.
471
+ class RefIndex
472
+ # Creates a new high index reference.
473
+ def to_high
474
+ return HDLRuby::High::RefIndex.new(self.type.to_high,
475
+ self.ref.to_high,
476
+ self.index.to_high)
687
477
  end
688
478
  end
689
479
 
690
- ## Extends the RefRange class with generation of HDLRuby::High text.
691
- class RefRange
692
480
 
693
- # Generates the text of the equivalent HDLRuby::High code.
694
- # +level+ is the hierachical level of the object.
695
- def to_high(level = 0)
696
- return self.ref.to_high(level) +
697
- "[(#{self.range.first.to_high(level)})..(#{self.range.last.to_high(level)})]"
481
+ # Add the conversion to high.
482
+ class RefRange
483
+ # Creates a new high range reference.
484
+ def to_high
485
+ return HDLRuby::High::RefRange.new(self.type.to_high,
486
+ self.ref.to_high,
487
+ self.range.first.to_high..self.range.last.to_high)
698
488
  end
699
489
  end
700
490
 
701
- ## Extends the RefName class with generation of HDLRuby::High text.
702
- class RefName
703
491
 
704
- # Generates the text of the equivalent HDLRuby::High code.
705
- # +level+ is the hierachical level of the object.
706
- def to_high(level = 0)
707
- # The resulting string.
708
- res = ""
709
- # Generates the sub reference if any.
710
- res << self.ref.to_high(level) << "." unless self.ref.is_a?(RefThis)
711
- # Generates the current reference.
712
- res << Low2High.high_use_name(self.name)
713
- # Returns the resulting string.
714
- return res
492
+ # Add the conversion to high.
493
+ class RefName
494
+ # Creates a new high range reference.
495
+ def to_high
496
+ return HDLRuby::High::RefName.new(self.type.to_high,
497
+ self.ref.to_high,
498
+ self.name)
715
499
  end
716
500
  end
717
501
 
718
- ## Extends the RefThis class with generation of HDLRuby::High text.
719
- class RefThis
720
502
 
721
- # Generates the text of the equivalent HDLRuby::High code.
722
- # +level+ is the hierachical level of the object.
723
- def to_high(level = 0)
724
- return ""
503
+ # Add the conversion to high.
504
+ class RefThis
505
+ # Creates a new high ref this.
506
+ def to_high
507
+ return HDLRuby::High::RefThis.new
725
508
  end
726
509
  end
727
510
 
728
- ## Extends the Numeric class with generation of HDLRuby::High text.
729
- class ::Numeric
730
511
 
731
- # Generates the text of the equivalent HDLRuby::High code.
732
- # +level+ is the hierachical level of the object.
733
- def to_high(level = 0)
734
- return self.to_s
512
+ # Add the conversion to high.
513
+ class StringE
514
+ # Creates a new high string expression.
515
+ def to_high
516
+ return HDLRuby::High::StringE.new(self.content,
517
+ *self.each_arg.map {|arg| arg.to_high })
735
518
  end
736
519
  end
737
-
738
520
  end