HDLRuby 2.6.23 → 2.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/HDLRuby/hdr_samples/case_bench.rb +35 -0
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +1 -1
- data/lib/HDLRuby/hdr_samples/if_bench.rb +24 -0
- data/lib/HDLRuby/hdr_samples/index_bench.rb +37 -0
- data/lib/HDLRuby/hdr_samples/range_bench.rb +47 -0
- data/lib/HDLRuby/hdr_samples/with_casts.rb +30 -0
- data/lib/HDLRuby/hdr_samples/with_concat.rb +26 -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/hdrcc.rb +38 -25
- data/lib/HDLRuby/hruby_high.rb +37 -5
- data/lib/HDLRuby/hruby_low.rb +13 -1
- data/lib/HDLRuby/hruby_low2c.rb +1339 -556
- data/lib/HDLRuby/hruby_low_casts_without_expression.rb +1 -1
- data/lib/HDLRuby/hruby_low_mutable.rb +12 -0
- data/lib/HDLRuby/hruby_low_with_port.rb +21 -6
- data/lib/HDLRuby/hruby_low_without_namespace.rb +4 -2
- data/lib/HDLRuby/hruby_tools.rb +8 -1
- data/lib/HDLRuby/hruby_verilog.rb +218 -149
- data/lib/HDLRuby/sim/hruby_sim.h +117 -0
- data/lib/HDLRuby/sim/hruby_sim_calc.c +38 -9
- data/lib/HDLRuby/sim/hruby_sim_stack_calc.c +250 -0
- data/lib/HDLRuby/sim/hruby_sim_stack_calc.c.sav +100 -0
- data/lib/HDLRuby/sim/hruby_value_pool.c +36 -0
- data/lib/HDLRuby/version.rb +1 -1
- metadata +15 -2
data/lib/HDLRuby/hruby_low2c.rb
CHANGED
@@ -39,15 +39,15 @@ module HDLRuby::Low
|
|
39
39
|
return str
|
40
40
|
end
|
41
41
|
|
42
|
-
## Tells if a +name+ is C-compatible.
|
43
|
-
# To ensure compatibile, assume all the character must have the
|
44
|
-
# same case.
|
45
|
-
def self.c_name?(name)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
42
|
+
# ## Tells if a +name+ is C-compatible.
|
43
|
+
# # To ensure compatibile, assume all the character must have the
|
44
|
+
# # same case.
|
45
|
+
# def self.c_name?(name)
|
46
|
+
# name = name.to_s
|
47
|
+
# # First: character check.
|
48
|
+
# return false unless name =~ /^[a-zA-Z]|([a-zA-Z][a-zA-Z_0-9]*[a-zA-Z0-9])$/
|
49
|
+
# return true
|
50
|
+
# end
|
51
51
|
|
52
52
|
## Converts a +name+ to a C-compatible name.
|
53
53
|
def self.c_name(name)
|
@@ -69,14 +69,29 @@ module HDLRuby::Low
|
|
69
69
|
return name
|
70
70
|
end
|
71
71
|
|
72
|
+
# ## Generates a uniq name for an object.
|
73
|
+
# def self.obj_name(obj)
|
74
|
+
# if obj.respond_to?(:name) then
|
75
|
+
# return Low2C.c_name(obj.name.to_s) +
|
76
|
+
# Low2C.c_name(obj.object_id.to_s)
|
77
|
+
# else
|
78
|
+
# return "_" + Low2C.c_name(obj.object_id.to_s)
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
|
82
|
+
@@hdrobj2c = {}
|
83
|
+
|
72
84
|
## Generates a uniq name for an object.
|
73
85
|
def self.obj_name(obj)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
86
|
+
id = obj.hierarchy.map! {|obj| obj.object_id}
|
87
|
+
oname = @@hdrobj2c[id]
|
88
|
+
unless oname then
|
89
|
+
# name = obj.respond_to?(:name) ? "_#{self.c_name(obj.name)}" : ""
|
90
|
+
# oname = "_c#{@@hdrobj2c.size}#{name}"
|
91
|
+
oname = "_" << @@hdrobj2c.size.to_s(36)
|
92
|
+
@@hdrobj2c[id] = oname
|
79
93
|
end
|
94
|
+
return oname
|
80
95
|
end
|
81
96
|
|
82
97
|
## Generates the name of a makeer for an object.
|
@@ -117,9 +132,9 @@ module HDLRuby::Low
|
|
117
132
|
res = Low2C.includes(*hnames)
|
118
133
|
res << "int main(int argc, char* argv[]) {\n"
|
119
134
|
# Build the objects.
|
120
|
-
objs.each { |obj| res << "
|
135
|
+
objs.each { |obj| res << " " << Low2C.make_name(obj) << "();\n" }
|
121
136
|
# Sets the top systemT.
|
122
|
-
res << " top_system =
|
137
|
+
res << " top_system = " << Low2C.obj_name(top) << ";\n"
|
123
138
|
# Starts the simulation.
|
124
139
|
res<< " hruby_sim_core(\"#{name}\",#{init_visualizer},-1);\n"
|
125
140
|
# Close the main.
|
@@ -140,8 +155,9 @@ module HDLRuby::Low
|
|
140
155
|
## Generates the code for a wait for time object +obj+ with +level+
|
141
156
|
# identation.
|
142
157
|
def self.wait(obj,level)
|
143
|
-
|
144
|
-
|
158
|
+
res = "hw_wait(#{obj.delay.to_c(level+1)},"
|
159
|
+
res << Low2C.behavior_access(obj) << ");\n"
|
160
|
+
return res
|
145
161
|
end
|
146
162
|
end
|
147
163
|
|
@@ -152,20 +168,24 @@ module HDLRuby::Low
|
|
152
168
|
# Generates the text of the equivalent HDLRuby code.
|
153
169
|
# +level+ is the hierachical level of the object and +hnames+
|
154
170
|
# is the list of extra h files to include.
|
155
|
-
def to_c(level = 0, *hnames)
|
171
|
+
# def to_c(level = 0, *hnames)
|
172
|
+
def to_c(res, level = 0, *hnames)
|
156
173
|
# The header
|
157
|
-
res = Low2C.includes(*hnames)
|
174
|
+
# res = Low2C.includes(*hnames)
|
175
|
+
res << Low2C.includes(*hnames)
|
158
176
|
|
159
177
|
# Declare the global variable holding the system.
|
160
|
-
res << "SystemT
|
178
|
+
res << "SystemT " << Low2C.obj_name(self) << ";\n\n"
|
161
179
|
|
162
180
|
# Generate the signals of the system.
|
163
|
-
self.each_signal { |signal|
|
181
|
+
# self.each_signal { |signal| signal.to_c(level) }
|
182
|
+
self.each_signal { |signal| signal.to_c(res,level) }
|
164
183
|
|
165
184
|
# Generate the code for all the blocks included in the system.
|
166
185
|
self.scope.each_scope_deep do |scope|
|
167
186
|
scope.each_behavior do |behavior|
|
168
|
-
res << behavior.block.to_c_code(level)
|
187
|
+
# res << behavior.block.to_c_code(level)
|
188
|
+
behavior.block.to_c_code(res,level)
|
169
189
|
end
|
170
190
|
end
|
171
191
|
|
@@ -173,35 +193,38 @@ module HDLRuby::Low
|
|
173
193
|
self.each_signal do |signal|
|
174
194
|
# res << signal.value.to_c_make(level) if signal.value
|
175
195
|
signal.value.each_node_deep do |node|
|
176
|
-
res << node.to_c_make(level) if node.respond_to?(:to_c_make)
|
196
|
+
# res << node.to_c_make(level) if node.respond_to?(:to_c_make)
|
197
|
+
node.to_c_make(res,level) if node.respond_to?(:to_c_make)
|
177
198
|
end if signal.value
|
178
199
|
end
|
179
200
|
self.scope.each_scope_deep do |scope|
|
180
201
|
scope.each_inner do |signal|
|
181
|
-
# res << signal.value.to_c_make(level) if signal.value
|
182
202
|
signal.value.each_node_deep do |node|
|
183
|
-
res << node.to_c_make(level) if node.respond_to?(:to_c_make)
|
203
|
+
# res << node.to_c_make(level) if node.respond_to?(:to_c_make)
|
204
|
+
node.to_c_make(res,level) if node.respond_to?(:to_c_make)
|
184
205
|
end if signal.value
|
185
206
|
end
|
186
207
|
end
|
187
208
|
self.scope.each_block_deep do |block|
|
188
209
|
# puts "treating for block=#{Low2C.obj_name(block)} with=#{block.each_inner.count} inners"
|
189
210
|
block.each_inner do |signal|
|
190
|
-
# res << signal.value.to_c_make(level) if signal.value
|
191
211
|
signal.value.each_node_deep do |node|
|
192
|
-
res << node.to_c_make(level) if node.respond_to?(:to_c_make)
|
212
|
+
# res << node.to_c_make(level) if node.respond_to?(:to_c_make)
|
213
|
+
node.to_c_make(res,level) if node.respond_to?(:to_c_make)
|
193
214
|
end if signal.value
|
194
215
|
end
|
195
216
|
end
|
196
217
|
self.scope.each_node_deep do |node|
|
197
|
-
res << node.to_c_make(level) if node.is_a?(Value)
|
218
|
+
# res << node.to_c_make(level) if node.is_a?(Value)
|
219
|
+
node.to_c_make(res,level) if node.is_a?(Value)
|
198
220
|
end
|
199
221
|
|
200
222
|
# Generate the scope.
|
201
|
-
res << self.scope.to_c(level)
|
223
|
+
# res << self.scope.to_c(level)
|
224
|
+
self.scope.to_c(res,level)
|
202
225
|
|
203
226
|
# Generate the entity
|
204
|
-
res << "SystemT
|
227
|
+
res << "SystemT " << Low2C.make_name(self) << "() {\n"
|
205
228
|
# Creates the structure.
|
206
229
|
res << " " * (level+1)*3
|
207
230
|
res << "SystemT systemT = malloc(sizeof(SystemTS));\n"
|
@@ -211,13 +234,13 @@ module HDLRuby::Low
|
|
211
234
|
# Sets the global variable of the system.
|
212
235
|
res << "\n"
|
213
236
|
res << " " * (level+1)*3
|
214
|
-
res <<
|
237
|
+
res << Low2C.obj_name(self) << " = systemT;\n"
|
215
238
|
|
216
239
|
# Set the owner if any.
|
217
240
|
if @owner then
|
218
241
|
res << " " * (level+1)*3
|
219
|
-
res << "systemT->owner = (Object)"
|
220
|
-
|
242
|
+
res << "systemT->owner = (Object)"
|
243
|
+
res << Low2C.obj_name(@owner) << ";\n"
|
221
244
|
else
|
222
245
|
res << "systemT->owner = NULL;\n"
|
223
246
|
end
|
@@ -231,23 +254,23 @@ module HDLRuby::Low
|
|
231
254
|
res << " " * (level+1)*3
|
232
255
|
res << "systemT->num_inputs = #{self.each_input.to_a.size};\n"
|
233
256
|
res << " " * (level+1)*3
|
234
|
-
res << "systemT->inputs = calloc(sizeof(SignalI),"
|
235
|
-
|
257
|
+
res << "systemT->inputs = calloc(sizeof(SignalI),"
|
258
|
+
res << "systemT->num_inputs);\n"
|
236
259
|
self.each_input.with_index do |input,i|
|
237
260
|
res << " " * (level+1)*3
|
238
|
-
res << "systemT->inputs[#{i}] = "
|
239
|
-
|
261
|
+
res << "systemT->inputs[#{i}] = "
|
262
|
+
res << Low2C.make_name(input) << "();\n"
|
240
263
|
end
|
241
264
|
# Outputs
|
242
265
|
res << " " * (level+1)*3
|
243
266
|
res << "systemT->num_outputs = #{self.each_output.to_a.size};\n"
|
244
267
|
res << " " * (level+1)*3
|
245
|
-
res << "systemT->outputs = calloc(sizeof(SignalI),"
|
246
|
-
|
268
|
+
res << "systemT->outputs = calloc(sizeof(SignalI),"
|
269
|
+
res << "systemT->num_outputs);\n"
|
247
270
|
self.each_output.with_index do |output,i|
|
248
271
|
res << " " * (level+1)*3
|
249
|
-
res << "systemT->outputs[#{i}] = "
|
250
|
-
|
272
|
+
res << "systemT->outputs[#{i}] = "
|
273
|
+
res << Low2C.make_name(output) << "();\n"
|
251
274
|
end
|
252
275
|
# Inouts
|
253
276
|
res << " " * (level+1)*3
|
@@ -257,14 +280,14 @@ module HDLRuby::Low
|
|
257
280
|
"systemT->num_inouts);\n"
|
258
281
|
self.each_inout.with_index do |inout,i|
|
259
282
|
res << " " * (level+1)*3
|
260
|
-
res << "systemT->inouts[#{i}] = "
|
261
|
-
|
283
|
+
res << "systemT->inouts[#{i}] = "
|
284
|
+
res << Low2C.make_name(inout) << "();\n"
|
262
285
|
end
|
263
286
|
|
264
287
|
# Adds the scope.
|
265
288
|
res << "\n"
|
266
289
|
res << " " * (level+1)*3
|
267
|
-
res << "systemT->scope =
|
290
|
+
res << "systemT->scope = " << Low2C.make_name(self.scope) << "();\n"
|
268
291
|
|
269
292
|
# Generate the Returns of the result.
|
270
293
|
res << "\n"
|
@@ -280,16 +303,17 @@ module HDLRuby::Low
|
|
280
303
|
|
281
304
|
## Generates the code for an execution starting from the system.
|
282
305
|
# +level+ is the hierachical level of the object.
|
283
|
-
def to_c_code(level)
|
306
|
+
# def to_c_code(level)
|
307
|
+
def to_c_code(res,level)
|
284
308
|
res << " " * (level*3)
|
285
|
-
res <<
|
309
|
+
res << Low2C.code_name(self) << "() {\n"
|
286
310
|
# res << "printf(\"Executing #{Low2C.code_name(self)}...\\n\");"
|
287
311
|
# Launch the execution of all the time behaviors of the
|
288
312
|
# system.
|
289
313
|
self.each_behavior_deep do |behavior|
|
290
314
|
if behavior.is_a?(HDLRuby::Low::TimeBehavior) then
|
291
315
|
res << " " * (level+1)*3
|
292
|
-
res <<
|
316
|
+
res << Low2C.code_name(behavior.block) << "();\n"
|
293
317
|
end
|
294
318
|
end
|
295
319
|
# Close the execution procedure.
|
@@ -301,50 +325,58 @@ module HDLRuby::Low
|
|
301
325
|
|
302
326
|
|
303
327
|
## Generates the content of the h file.
|
304
|
-
def to_ch
|
305
|
-
|
328
|
+
# def to_ch
|
329
|
+
def to_ch(res)
|
330
|
+
# res = ""
|
306
331
|
# Declare the global variable holding the signal.
|
307
|
-
res << "extern SystemT
|
332
|
+
res << "extern SystemT " << Low2C.obj_name(self) << ";\n\n"
|
308
333
|
|
309
334
|
# Generate the access to the function making the systemT. */
|
310
|
-
res << "extern SystemT
|
335
|
+
res << "extern SystemT " << Low2C.make_name(self) << "();\n\n"
|
311
336
|
|
312
337
|
# Generate the accesses to the values.
|
313
338
|
self.each_signal do |signal|
|
314
339
|
# res << signal.value.to_ch if signal.value
|
315
340
|
if signal.value then
|
316
341
|
signal.value.each_node_deep do |node|
|
317
|
-
res << node.to_ch if node.is_a?(Value)
|
342
|
+
# res << node.to_ch if node.is_a?(Value)
|
343
|
+
node.to_ch(res) if node.is_a?(Value)
|
318
344
|
end
|
319
345
|
end
|
320
346
|
end
|
321
347
|
self.scope.each_scope_deep do |scope|
|
322
348
|
scope.each_inner do |signal|
|
323
|
-
# res << signal.value.to_ch if signal.value
|
324
349
|
if signal.value then
|
325
350
|
signal.value.each_node_deep do |node|
|
326
|
-
res << node.to_ch if node.is_a?(Value)
|
351
|
+
# res << node.to_ch if node.is_a?(Value)
|
352
|
+
node.to_ch(res) if node.is_a?(Value)
|
327
353
|
end
|
328
354
|
end
|
329
355
|
end
|
330
356
|
end
|
331
357
|
self.scope.each_block_deep do |block|
|
332
358
|
block.each_inner do |signal|
|
333
|
-
res << signal.value.to_ch if signal.value
|
359
|
+
# res << signal.value.to_ch if signal.value
|
360
|
+
signal.value.to_ch(res) if signal.value
|
334
361
|
end
|
335
362
|
block.each_node_deep do |node|
|
336
|
-
res << node.to_ch if node.is_a?(Value)
|
363
|
+
# res << node.to_ch if node.is_a?(Value)
|
364
|
+
node.to_ch(res) if node.is_a?(Value)
|
337
365
|
end
|
338
366
|
end
|
339
367
|
|
340
368
|
# Generate the accesses to the ports.
|
341
|
-
self.each_input { |input| res << input.to_ch }
|
342
|
-
self.
|
343
|
-
self.
|
369
|
+
# self.each_input { |input| res << input.to_ch }
|
370
|
+
self.each_input { |input| input.to_ch(res) }
|
371
|
+
# self.each_output { |output| res << output.to_ch }
|
372
|
+
self.each_output { |output| output.to_ch(res) }
|
373
|
+
# self.each_inout { |inout| res << inout.to_ch }
|
374
|
+
self.each_inout { |inout| inout.to_ch(res) }
|
344
375
|
|
345
376
|
# Generate the accesses to the scope.
|
346
|
-
res << self.scope.to_ch << "\n"
|
347
|
-
|
377
|
+
# res << self.scope.to_ch << "\n"
|
378
|
+
self.scope.to_ch(res)
|
379
|
+
res << "\n"
|
348
380
|
|
349
381
|
return res;
|
350
382
|
end
|
@@ -357,31 +389,37 @@ module HDLRuby::Low
|
|
357
389
|
|
358
390
|
# Generates the C text of the equivalent HDLRuby code.
|
359
391
|
# +level+ is the hierachical level of the object.
|
360
|
-
def to_c(level = 0)
|
392
|
+
# def to_c(level = 0)
|
393
|
+
def to_c(res,level = 0)
|
361
394
|
# The resulting string.
|
362
|
-
res = ""
|
395
|
+
# res = ""
|
363
396
|
|
364
397
|
# Declare the global variable holding the scope.
|
365
|
-
res << "Scope
|
398
|
+
res << "Scope " << Low2C.obj_name(self) << ";\n\n"
|
366
399
|
|
367
400
|
# Generate the code makeing the complex sub components.
|
368
401
|
|
369
402
|
# Generates the code for making signals if any.
|
370
|
-
self.each_signal { |signal| res << signal.to_c(level) }
|
403
|
+
# self.each_signal { |signal| res << signal.to_c(level) }
|
404
|
+
self.each_signal { |signal| signal.to_c(res,level) }
|
371
405
|
# Generates the code for making signals if any.
|
372
|
-
self.each_systemI { |systemI| res << systemI.to_c(level) }
|
406
|
+
# self.each_systemI { |systemI| res << systemI.to_c(level) }
|
407
|
+
self.each_systemI { |systemI| systemI.to_c(res,level) }
|
373
408
|
# Generates the code for making sub scopes if any.
|
374
|
-
self.each_scope { |scope| res << scope.to_c(level) }
|
409
|
+
# self.each_scope { |scope| res << scope.to_c(level) }
|
410
|
+
self.each_scope { |scope| scope.to_c(res,level) }
|
375
411
|
# Generate the code for making the behaviors.
|
376
|
-
self.each_behavior { |behavior| res << behavior.to_c(level) }
|
412
|
+
# self.each_behavior { |behavior| res << behavior.to_c(level) }
|
413
|
+
self.each_behavior { |behavior| behavior.to_c(res,level) }
|
377
414
|
# Generate the code for making the non-HDLRuby codes.
|
378
|
-
self.each_code { |code| res << code.to_c(level) }
|
415
|
+
# self.each_code { |code| res << code.to_c(level) }
|
416
|
+
self.each_code { |code| code.to_c(res,level) }
|
379
417
|
|
380
418
|
# Generate the code of the scope.
|
381
419
|
|
382
420
|
# The header of the scope.
|
383
421
|
res << " " * level*3
|
384
|
-
res << "Scope
|
422
|
+
res << "Scope " << Low2C.make_name(self) << "() {\n"
|
385
423
|
res << " " * (level+1)*3
|
386
424
|
res << "Scope scope = malloc(sizeof(ScopeS));\n"
|
387
425
|
res << " " * (level+1)*3
|
@@ -390,13 +428,13 @@ module HDLRuby::Low
|
|
390
428
|
# Sets the global variable of the scope.
|
391
429
|
res << "\n"
|
392
430
|
res << " " * (level+1)*3
|
393
|
-
res <<
|
431
|
+
res << Low2C.obj_name(self) << " = scope;\n"
|
394
432
|
|
395
433
|
# Set the owner if any.
|
396
434
|
if self.parent then
|
397
435
|
res << " " * (level+1)*3
|
398
|
-
res << "scope->owner = (Object)"
|
399
|
-
|
436
|
+
res << "scope->owner = (Object)"
|
437
|
+
res << Low2C.obj_name(self.parent) << ";\n"
|
400
438
|
else
|
401
439
|
res << "scope->owner = NULL;\n"
|
402
440
|
end
|
@@ -413,44 +451,44 @@ module HDLRuby::Low
|
|
413
451
|
"scope->num_systemIs);\n"
|
414
452
|
self.each_systemI.with_index do |systemI,i|
|
415
453
|
res << " " * (level+1)*3
|
416
|
-
res << "scope->systemIs[#{i}] = "
|
417
|
-
|
454
|
+
res << "scope->systemIs[#{i}] = "
|
455
|
+
res << Low2C.make_name(systemI) << "();\n"
|
418
456
|
end
|
419
457
|
|
420
458
|
# Add the inner signals declaration.
|
421
459
|
res << " " * (level+1)*3
|
422
460
|
res << "scope->num_inners = #{self.each_inner.to_a.size};\n"
|
423
461
|
res << " " * (level+1)*3
|
424
|
-
res << "scope->inners = calloc(sizeof(SignalI),"
|
425
|
-
|
462
|
+
res << "scope->inners = calloc(sizeof(SignalI),"
|
463
|
+
res << "scope->num_inners);\n"
|
426
464
|
self.each_inner.with_index do |inner,i|
|
427
465
|
res << " " * (level+1)*3
|
428
|
-
res << "scope->inners[#{i}] = "
|
429
|
-
|
466
|
+
res << "scope->inners[#{i}] = "
|
467
|
+
res << Low2C.make_name(inner) << "();\n"
|
430
468
|
end
|
431
469
|
|
432
470
|
# Add the sub scopes.
|
433
471
|
res << " " * (level+1)*3
|
434
472
|
res << "scope->num_scopes = #{self.each_scope.to_a.size};\n"
|
435
473
|
res << " " * (level+1)*3
|
436
|
-
res << "scope->scopes = calloc(sizeof(Scope),"
|
437
|
-
|
474
|
+
res << "scope->scopes = calloc(sizeof(Scope),"
|
475
|
+
res << "scope->num_scopes);\n"
|
438
476
|
self.each_scope.with_index do |scope,i|
|
439
477
|
res << " " * (level+1)*3
|
440
|
-
res << "scope->scopes[#{i}] = "
|
441
|
-
|
478
|
+
res << "scope->scopes[#{i}] = "
|
479
|
+
res << Low2C.make_name(scope) << "();\n"
|
442
480
|
end
|
443
481
|
|
444
482
|
# Add the behaviors.
|
445
483
|
res << " " * (level+1)*3
|
446
484
|
res << "scope->num_behaviors = #{self.each_behavior.to_a.size};\n"
|
447
485
|
res << " " * (level+1)*3
|
448
|
-
res << "scope->behaviors = calloc(sizeof(Behavior),"
|
449
|
-
|
486
|
+
res << "scope->behaviors = calloc(sizeof(Behavior),"
|
487
|
+
res << "scope->num_behaviors);\n"
|
450
488
|
self.each_behavior.with_index do |behavior,i|
|
451
489
|
res << " " * (level+1)*3
|
452
|
-
res << "scope->behaviors[#{i}] = "
|
453
|
-
|
490
|
+
res << "scope->behaviors[#{i}] = "
|
491
|
+
res << Low2C.make_name(behavior) << "();\n"
|
454
492
|
end
|
455
493
|
|
456
494
|
# Add the non-HDLRuby codes.
|
@@ -461,8 +499,8 @@ module HDLRuby::Low
|
|
461
499
|
"scope->num_codes);\n"
|
462
500
|
self.each_code.with_index do |code,i|
|
463
501
|
res << " " * (level+1)*3
|
464
|
-
res << "scope->codes[#{i}] = "
|
465
|
-
|
502
|
+
res << "scope->codes[#{i}] = "
|
503
|
+
res << Low2C.make_name(code) << "();\n"
|
466
504
|
end
|
467
505
|
|
468
506
|
# Generate the Returns of the result.
|
@@ -477,28 +515,34 @@ module HDLRuby::Low
|
|
477
515
|
end
|
478
516
|
|
479
517
|
## Generates the content of the h file.
|
480
|
-
def to_ch
|
481
|
-
|
518
|
+
# def to_ch
|
519
|
+
def to_ch(res)
|
520
|
+
# res = ""
|
482
521
|
# Declare the global variable holding the signal.
|
483
|
-
res << "extern Scope
|
522
|
+
res << "extern Scope " << Low2C.obj_name(self) << ";\n\n"
|
484
523
|
|
485
524
|
# Generate the access to the function making the scope.
|
486
|
-
res << "extern Scope
|
525
|
+
res << "extern Scope " << Low2C.make_name(self) << "();\n\n"
|
487
526
|
|
488
527
|
# Generate the accesses to the system instances.
|
489
|
-
self.each_systemI { |systemI| res << systemI.to_ch }
|
528
|
+
# self.each_systemI { |systemI| res << systemI.to_ch }
|
529
|
+
self.each_systemI { |systemI| systemI.to_ch(res) }
|
490
530
|
|
491
531
|
# Generate the accesses to the signals.
|
492
|
-
self.each_inner { |inner| res << inner.to_ch }
|
532
|
+
# self.each_inner { |inner| res << inner.to_ch }
|
533
|
+
self.each_inner { |inner| inner.to_ch(res) }
|
493
534
|
|
494
535
|
# Generate the access to the sub scopes.
|
495
|
-
self.each_scope { |scope| res << scope.to_ch }
|
536
|
+
# self.each_scope { |scope| res << scope.to_ch }
|
537
|
+
self.each_scope { |scope| scope.to_ch(res) }
|
496
538
|
|
497
539
|
# Generate the access to the behaviors.
|
498
|
-
self.each_behavior { |behavior| res << behavior.to_ch }
|
540
|
+
# self.each_behavior { |behavior| res << behavior.to_ch }
|
541
|
+
self.each_behavior { |behavior| behavior.to_ch(res) }
|
499
542
|
|
500
543
|
# Generate the access to the non-HDLRuby code.
|
501
|
-
self.each_behavior { |code| res << code.to_ch }
|
544
|
+
# self.each_behavior { |code| res << code.to_ch }
|
545
|
+
self.each_behavior { |code| code.to_ch(res) }
|
502
546
|
|
503
547
|
return res;
|
504
548
|
end
|
@@ -510,16 +554,18 @@ module HDLRuby::Low
|
|
510
554
|
|
511
555
|
# Generates the C text of the equivalent HDLRuby code.
|
512
556
|
# +level+ is the hierachical level of the object.
|
513
|
-
def to_c(level = 0)
|
514
|
-
|
515
|
-
# return Low2C.type_name(Bit) + "()"
|
557
|
+
# def to_c(level = 0)
|
558
|
+
def to_c(res,level = 0)
|
516
559
|
if self.name == :bit || self.name == :unsigned then
|
517
|
-
return "get_type_bit()"
|
560
|
+
# return "get_type_bit()"
|
561
|
+
res << "get_type_bit()"
|
518
562
|
elsif self.name == :signed then
|
519
|
-
return "get_type_signed()"
|
563
|
+
# return "get_type_signed()"
|
564
|
+
res << "get_type_signed()"
|
520
565
|
else
|
521
566
|
raise "Unknown type: #{self.name}"
|
522
567
|
end
|
568
|
+
return res
|
523
569
|
end
|
524
570
|
end
|
525
571
|
|
@@ -528,11 +574,12 @@ module HDLRuby::Low
|
|
528
574
|
|
529
575
|
# Generates the C text of the equivalent HDLRuby code.
|
530
576
|
# +level+ is the hierachical level of the object.
|
531
|
-
def to_c(level = 0)
|
532
|
-
|
533
|
-
# return Low2C.type_name(self.name) + "()"
|
577
|
+
# def to_c(level = 0)
|
578
|
+
def to_c(res,level = 0)
|
534
579
|
# Simply return the defined type.
|
535
|
-
return self.def.to_c(level)
|
580
|
+
# return self.def.to_c(level)
|
581
|
+
self.def.to_c(res,level)
|
582
|
+
return res
|
536
583
|
end
|
537
584
|
end
|
538
585
|
|
@@ -541,10 +588,15 @@ module HDLRuby::Low
|
|
541
588
|
|
542
589
|
# Generates the C text of the equivalent HDLRuby code.
|
543
590
|
# +level+ is the hierachical level of the object.
|
544
|
-
def to_c(level = 0)
|
591
|
+
# def to_c(level = 0)
|
592
|
+
def to_c(res,level = 0)
|
545
593
|
# The resulting string.
|
546
|
-
return "get_type_vector(#{self.base.to_c(level+1)}," +
|
547
|
-
|
594
|
+
# return "get_type_vector(#{self.base.to_c(level+1)}," +
|
595
|
+
# "#{self.size})"
|
596
|
+
res << "get_type_vector("
|
597
|
+
self.base.to_c(res,level+1)
|
598
|
+
res << ",#{self.size})"
|
599
|
+
return res
|
548
600
|
end
|
549
601
|
end
|
550
602
|
|
@@ -555,11 +607,11 @@ module HDLRuby::Low
|
|
555
607
|
# +level+ is the hierachical level of the object.
|
556
608
|
#
|
557
609
|
# NOTE: type tuples are converted to bit vector of their contents.
|
558
|
-
def to_c(level = 0)
|
559
|
-
|
560
|
-
#
|
561
|
-
|
562
|
-
return
|
610
|
+
# def to_c(level = 0)
|
611
|
+
def to_c(res,level = 0)
|
612
|
+
# return self.to_vector.to_c(level)
|
613
|
+
self.to_vector.to_c(res,level)
|
614
|
+
return res
|
563
615
|
end
|
564
616
|
end
|
565
617
|
|
@@ -569,10 +621,15 @@ module HDLRuby::Low
|
|
569
621
|
|
570
622
|
# Generates the text of the equivalent HDLRuby code.
|
571
623
|
# +level+ is the hierachical level of the object.
|
572
|
-
def to_c(level = 0)
|
573
|
-
|
574
|
-
|
624
|
+
# def to_c(level = 0)
|
625
|
+
def to_c(res,level = 0)
|
626
|
+
# return "get_type_struct(#{self.each.join(",") do |key,type|
|
627
|
+
# "\"#{key.to_s}\",#{type.to_c(level+1)}"
|
628
|
+
# end})"
|
629
|
+
res << "get_type_struct(#{self.each.join(",") do |key,type|
|
630
|
+
"\"#{key.to_s}\",#{type.to_c("",level+1)}"
|
575
631
|
end})"
|
632
|
+
return res
|
576
633
|
end
|
577
634
|
end
|
578
635
|
|
@@ -583,19 +640,20 @@ module HDLRuby::Low
|
|
583
640
|
# Generates the text of the equivalent HDLRuby code.
|
584
641
|
# +level+ is the hierachical level of the object and
|
585
642
|
# +time+ is a flag telling if the behavior is timed or not.
|
586
|
-
def to_c(level = 0, time = false)
|
643
|
+
# def to_c(level = 0, time = false)
|
644
|
+
def to_c(res, level = 0, time = false)
|
587
645
|
# puts "For behavior: #{self}"
|
588
|
-
# The resulting string.
|
589
|
-
res = ""
|
646
|
+
# # The resulting string.
|
647
|
+
# res = ""
|
590
648
|
|
591
649
|
# Declare the global variable holding the behavior.
|
592
|
-
res << "Behavior
|
650
|
+
res << "Behavior " << Low2C.obj_name(self) << ";\n\n"
|
593
651
|
|
594
652
|
# Generate the code of the behavior.
|
595
653
|
|
596
654
|
# The header of the behavior.
|
597
655
|
res << " " * level*3
|
598
|
-
res << "Behavior
|
656
|
+
res << "Behavior " << Low2C.make_name(self) << "() {\n"
|
599
657
|
res << " " * (level+1)*3
|
600
658
|
|
601
659
|
# Allocate the behavior.
|
@@ -606,7 +664,7 @@ module HDLRuby::Low
|
|
606
664
|
# Sets the global variable of the behavior.
|
607
665
|
res << "\n"
|
608
666
|
res << " " * (level+1)*3
|
609
|
-
res <<
|
667
|
+
res << Low2C.obj_name(self) << " = behavior;\n"
|
610
668
|
|
611
669
|
# Register it as a time behavior if it is one of them. */
|
612
670
|
if time then
|
@@ -617,8 +675,8 @@ module HDLRuby::Low
|
|
617
675
|
# Set the owner if any.
|
618
676
|
if self.parent then
|
619
677
|
res << " " * (level+1)*3
|
620
|
-
res << "behavior->owner = (Object)"
|
621
|
-
|
678
|
+
res << "behavior->owner = (Object)"
|
679
|
+
res << Low2C.obj_name(self.parent) << ";\n"
|
622
680
|
else
|
623
681
|
res << "behavior->owner = NULL;\n"
|
624
682
|
end
|
@@ -655,14 +713,17 @@ module HDLRuby::Low
|
|
655
713
|
res << " " * (level+1)*3
|
656
714
|
res << "behavior->num_events = #{events.size};\n"
|
657
715
|
res << " " * (level+1)*3
|
658
|
-
res << "behavior->events = calloc(sizeof(Event),"
|
659
|
-
|
716
|
+
res << "behavior->events = calloc(sizeof(Event),"
|
717
|
+
res << "behavior->num_events);\n"
|
660
718
|
# Then, create and add them.
|
661
719
|
events.each_with_index do |event,i|
|
662
720
|
# puts "for event=#{event}"
|
663
721
|
# Add the event.
|
664
722
|
res << " " * (level+1)*3
|
665
|
-
res << "behavior->events[#{i}] = #{event.to_c};\n"
|
723
|
+
# res << "behavior->events[#{i}] = #{event.to_c};\n"
|
724
|
+
res << "behavior->events[#{i}] = "
|
725
|
+
event.to_c(res)
|
726
|
+
res << ";\n"
|
666
727
|
|
667
728
|
# Register the behavior as activable on this event.
|
668
729
|
# Select the active field.
|
@@ -671,20 +732,22 @@ module HDLRuby::Low
|
|
671
732
|
field = "neg" if event.type == :negedge
|
672
733
|
# puts "Adding #{field} event: #{event}\n"
|
673
734
|
# Get the target signal access
|
674
|
-
sigad = event.ref.resolve.to_c_signal
|
735
|
+
# sigad = event.ref.resolve.to_c_signal
|
736
|
+
sigad = ""
|
737
|
+
event.ref.resolve.to_c_signal(sigad)
|
675
738
|
# Add the behavior to the relevant field.
|
676
739
|
res << " " * (level+1)*3
|
677
740
|
res << "#{sigad}->num_#{field} += 1;\n"
|
678
741
|
res << " " * (level+1)*3
|
679
|
-
res << "#{sigad}->#{field} = realloc(#{sigad}->#{field},"
|
680
|
-
|
681
|
-
res << "#{sigad}->#{field}[#{sigad}->num_#{field}-1] = "
|
682
|
-
|
742
|
+
res << "#{sigad}->#{field} = realloc(#{sigad}->#{field},"
|
743
|
+
res << "#{sigad}->num_#{field}*sizeof(Object));\n"
|
744
|
+
res << "#{sigad}->#{field}[#{sigad}->num_#{field}-1] = "
|
745
|
+
res << "(Object)behavior;\n"
|
683
746
|
end
|
684
747
|
|
685
748
|
# Adds the block.
|
686
749
|
res << " " * (level+1)*3
|
687
|
-
res << "behavior->block =
|
750
|
+
res << "behavior->block = " << Low2C.make_name(self.block) << "();\n"
|
688
751
|
|
689
752
|
# Generate the Returns of the result.
|
690
753
|
res << "\n"
|
@@ -698,16 +761,18 @@ module HDLRuby::Low
|
|
698
761
|
end
|
699
762
|
|
700
763
|
## Generates the content of the h file.
|
701
|
-
def to_ch
|
702
|
-
|
764
|
+
# def to_ch
|
765
|
+
def to_ch(res)
|
766
|
+
# res = ""
|
703
767
|
# Declare the global variable holding the signal.
|
704
|
-
res << "extern Behavior
|
768
|
+
res << "extern Behavior " << Low2C.obj_name(self) << ";\n\n"
|
705
769
|
|
706
770
|
# Generate the access to the function making the behavior.
|
707
|
-
res << "extern Behavior
|
771
|
+
res << "extern Behavior " << Low2C.make_name(self) << "();\n\n"
|
708
772
|
|
709
773
|
# Generate the accesses to the block of the behavior.
|
710
|
-
res << self.block.to_ch
|
774
|
+
# res << self.block.to_ch
|
775
|
+
self.block.to_ch(res)
|
711
776
|
|
712
777
|
return res;
|
713
778
|
end
|
@@ -718,8 +783,10 @@ module HDLRuby::Low
|
|
718
783
|
|
719
784
|
# Generates the C text of the equivalent HDLRuby code.
|
720
785
|
# +level+ is the hierachical level of the object.
|
721
|
-
def to_c(level = 0)
|
722
|
-
|
786
|
+
# def to_c(level = 0)
|
787
|
+
def to_c(res,level = 0)
|
788
|
+
# super(level,true)
|
789
|
+
super(res,level,true)
|
723
790
|
end
|
724
791
|
end
|
725
792
|
|
@@ -729,12 +796,17 @@ module HDLRuby::Low
|
|
729
796
|
|
730
797
|
# Generates the C text of the equivalent HDLRuby code.
|
731
798
|
# +level+ is the hierachical level of the object.
|
732
|
-
def to_c(level = 0)
|
799
|
+
# def to_c(level = 0)
|
800
|
+
def to_c(res,level = 0)
|
733
801
|
edge = "ANYEDGE"
|
734
802
|
edge = "POSEDGE" if self.type == :posedge
|
735
803
|
edge = "NEGEDGE" if self.type == :negedge
|
736
|
-
return "make_event(#{edge}," +
|
737
|
-
|
804
|
+
# return "make_event(#{edge}," +
|
805
|
+
# "#{self.ref.resolve.to_c_signal(level+1)})"
|
806
|
+
res << "make_event(#{edge},"
|
807
|
+
self.ref.resolve.to_c_signal(res,level+1)
|
808
|
+
res << ")"
|
809
|
+
return res
|
738
810
|
end
|
739
811
|
end
|
740
812
|
|
@@ -744,29 +816,39 @@ module HDLRuby::Low
|
|
744
816
|
|
745
817
|
## Generates the C text for an access to the signal.
|
746
818
|
# +level+ is the hierachical level of the object.
|
747
|
-
def to_c_signal(level = 0)
|
748
|
-
|
749
|
-
#
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
819
|
+
# def to_c_signal(level = 0)
|
820
|
+
def to_c_signal(res,level = 0)
|
821
|
+
# res = Low2C.obj_name(self)
|
822
|
+
res << Low2C.obj_name(self)
|
823
|
+
# # Accumulate the names of each parent until there is no one left.
|
824
|
+
# obj = self.parent
|
825
|
+
# while(obj) do
|
826
|
+
# res << "_" << Low2C.obj_name(obj)
|
827
|
+
# obj = obj.parent
|
828
|
+
# end
|
755
829
|
return res
|
756
830
|
end
|
757
831
|
|
758
832
|
## Generates the C text of the equivalent HDLRuby code.
|
759
833
|
# +level+ is the hierachical level of the object.
|
760
|
-
def to_c(level = 0)
|
834
|
+
# def to_c(level = 0)
|
835
|
+
def to_c(res,level = 0)
|
761
836
|
# The resulting string.
|
762
|
-
res = ""
|
837
|
+
# res = ""
|
763
838
|
|
764
839
|
# Declare the global variable holding the signal.
|
765
|
-
res << "SignalI #{self.to_c_signal(level+1)};\n\n"
|
840
|
+
# res << "SignalI #{self.to_c_signal(level+1)};\n\n"
|
841
|
+
res << "SignalI "
|
842
|
+
self.to_c_signal(res,level+1)
|
843
|
+
res << ";\n\n"
|
766
844
|
|
767
845
|
# The header of the signal generation.
|
768
846
|
res << " " * level*3
|
769
|
-
res << "SignalI
|
847
|
+
res << "SignalI " << Low2C.make_name(self) << "() {\n"
|
848
|
+
# res << " " * level*3
|
849
|
+
# res << "Value l,r,d;\n"
|
850
|
+
# res << " " * (level+1)*3
|
851
|
+
# res << "unsigned long long i;\n"
|
770
852
|
res << " " * (level+1)*3
|
771
853
|
res << "SignalI signalI = malloc(sizeof(SignalIS));\n"
|
772
854
|
res << " " * (level+1)*3
|
@@ -775,13 +857,15 @@ module HDLRuby::Low
|
|
775
857
|
# Sets the global variable of the signal.
|
776
858
|
res << "\n"
|
777
859
|
res << " " * (level+1)*3
|
778
|
-
res << "#{self.to_c_signal(level+1)} = signalI;\n"
|
860
|
+
# res << "#{self.to_c_signal(level+1)} = signalI;\n"
|
861
|
+
self.to_c_signal(res,level+1)
|
862
|
+
res << " = signalI;\n"
|
779
863
|
|
780
864
|
# Set the owner if any.
|
781
865
|
if self.parent then
|
782
866
|
res << " " * (level+1)*3
|
783
|
-
res << "signalI->owner = (Object)"
|
784
|
-
|
867
|
+
res << "signalI->owner = (Object)"
|
868
|
+
res << Low2C.obj_name(self.parent) << ";\n"
|
785
869
|
else
|
786
870
|
res << "signalI->owner = NULL;\n"
|
787
871
|
end
|
@@ -791,7 +875,10 @@ module HDLRuby::Low
|
|
791
875
|
res << "signalI->name = \"#{self.name}\";\n"
|
792
876
|
# Set the type.
|
793
877
|
res << " " * (level+1)*3
|
794
|
-
res << "signalI->type = #{self.type.to_c(level+2)};\n"
|
878
|
+
# res << "signalI->type = #{self.type.to_c(level+2)};\n"
|
879
|
+
res << "signalI->type = "
|
880
|
+
self.type.to_c(res,level+2)
|
881
|
+
res << ";\n"
|
795
882
|
# Set the current and the next value.
|
796
883
|
res << " " * (level+1)*3
|
797
884
|
res << "signalI->c_value = make_value(signalI->type,0);\n"
|
@@ -804,8 +891,11 @@ module HDLRuby::Low
|
|
804
891
|
if self.value then
|
805
892
|
# There is an initial value.
|
806
893
|
res << " " * (level+1)*3
|
807
|
-
res << "copy_value(#{self.value.to_c(level+2)}," +
|
808
|
-
|
894
|
+
# res << "copy_value(#{self.value.to_c(level+2)}," +
|
895
|
+
# "signalI->c_value);\n"
|
896
|
+
res << "copy_value("
|
897
|
+
self.value.to_c_expr(res,level+2)
|
898
|
+
res << ",signalI->c_value);\n"
|
809
899
|
end
|
810
900
|
|
811
901
|
# Initially the signal can be overwritten by anything.
|
@@ -843,14 +933,18 @@ module HDLRuby::Low
|
|
843
933
|
end
|
844
934
|
|
845
935
|
## Generates the content of the h file.
|
846
|
-
def to_ch
|
847
|
-
|
936
|
+
# def to_ch
|
937
|
+
def to_ch(res)
|
938
|
+
# res = ""
|
848
939
|
# puts "to_ch for SignalI: #{self.to_c_signal()}"
|
849
940
|
# Declare the global variable holding the signal.
|
850
|
-
res << "extern SignalI #{self.to_c_signal()};\n\n"
|
941
|
+
# res << "extern SignalI #{self.to_c_signal()};\n\n"
|
942
|
+
res << "extern SignalI "
|
943
|
+
self.to_c_signal(res)
|
944
|
+
res << ";\n\n"
|
851
945
|
|
852
946
|
# Generate the access to the function making the behavior.
|
853
|
-
res << "extern SignalI
|
947
|
+
res << "extern SignalI " << Low2C.make_name(self) << "();\n\n"
|
854
948
|
|
855
949
|
return res;
|
856
950
|
end
|
@@ -862,16 +956,17 @@ module HDLRuby::Low
|
|
862
956
|
|
863
957
|
## Generates the C text of the equivalent HDLRuby code.
|
864
958
|
# +level+ is the hierachical level of the object.
|
865
|
-
def to_c(level = 0)
|
959
|
+
# def to_c(level = 0)
|
960
|
+
def to_c(res,level = 0)
|
866
961
|
# The resulting string.
|
867
|
-
res = ""
|
962
|
+
# res = ""
|
868
963
|
|
869
964
|
# Declare the global variable holding the signal.
|
870
|
-
res << "SystemI
|
965
|
+
res << "SystemI " << Low2C.obj_name(self) << ";\n\n"
|
871
966
|
|
872
967
|
# The header of the signal generation.
|
873
968
|
res << " " * level*3
|
874
|
-
res << "SystemI
|
969
|
+
res << "SystemI " << Low2C.make_name(self) << "() {\n"
|
875
970
|
res << " " * (level+1)*3
|
876
971
|
res << "SystemI systemI = malloc(sizeof(SystemIS));\n"
|
877
972
|
res << " " * (level+1)*3
|
@@ -880,13 +975,13 @@ module HDLRuby::Low
|
|
880
975
|
# Sets the global variable of the system instance.
|
881
976
|
res << "\n"
|
882
977
|
res << " " * (level+1)*3
|
883
|
-
res <<
|
978
|
+
res << Low2C.obj_name(self) << " = systemI;\n"
|
884
979
|
|
885
980
|
# Set the owner if any.
|
886
981
|
if self.parent then
|
887
982
|
res << " " * (level+1)*3
|
888
|
-
res << "systemI->owner = (Object)"
|
889
|
-
|
983
|
+
res << "systemI->owner = (Object)"
|
984
|
+
res << Low2C.obj_name(self.parent) << ";\n"
|
890
985
|
else
|
891
986
|
res << "systemI->owner = NULL;\n"
|
892
987
|
end
|
@@ -896,7 +991,7 @@ module HDLRuby::Low
|
|
896
991
|
res << "systemI->name = \"#{self.name}\";\n"
|
897
992
|
# Set the type.
|
898
993
|
res << " " * (level+1)*3
|
899
|
-
res << "systemI->system =
|
994
|
+
res << "systemI->system = " << Low2C.obj_name(self.systemT) << ";\n"
|
900
995
|
|
901
996
|
# Generate the return of the signal.
|
902
997
|
res << "\n"
|
@@ -910,13 +1005,14 @@ module HDLRuby::Low
|
|
910
1005
|
end
|
911
1006
|
|
912
1007
|
## Generates the content of the h file.
|
913
|
-
def to_ch
|
914
|
-
|
1008
|
+
# def to_ch
|
1009
|
+
def to_ch(res)
|
1010
|
+
# res = ""
|
915
1011
|
# Declare the global variable holding the signal.
|
916
|
-
res << "extern SystemI
|
1012
|
+
res << "extern SystemI " << Low2C.obj_name(self) << ";\n\n"
|
917
1013
|
|
918
1014
|
# Generate the access to the function making the systemT. */
|
919
|
-
res << "extern SystemI
|
1015
|
+
res << "extern SystemI " << Low2C.make_name(self) << "();\n\n"
|
920
1016
|
|
921
1017
|
return res
|
922
1018
|
end
|
@@ -928,15 +1024,28 @@ module HDLRuby::Low
|
|
928
1024
|
|
929
1025
|
# Generates the C text of the equivalent HDLRuby code.
|
930
1026
|
# +level+ is the hierachical level of the object.
|
931
|
-
def to_c(level = 0)
|
932
|
-
|
933
|
-
res
|
1027
|
+
# def to_c(level = 0)
|
1028
|
+
def to_c(res,level = 0)
|
1029
|
+
# res = " " * level
|
1030
|
+
res << " " * level
|
1031
|
+
# res << self.each_lump.map do |lump|
|
1032
|
+
# if !lump.is_a?(String) then
|
1033
|
+
# lump.respond_to?(:to_c) ? lump.to_c(level+1) : lump.to_s
|
1034
|
+
# else
|
1035
|
+
# lump
|
1036
|
+
# end
|
1037
|
+
# end.join
|
1038
|
+
self.each_lump do |lump|
|
934
1039
|
if !lump.is_a?(String) then
|
935
|
-
lump.respond_to?(:to_c)
|
1040
|
+
if lump.respond_to?(:to_c) then
|
1041
|
+
lump.to_c(res,level+1)
|
1042
|
+
else
|
1043
|
+
res << lump.to_s
|
1044
|
+
end
|
936
1045
|
else
|
937
|
-
lump
|
1046
|
+
res << lump
|
938
1047
|
end
|
939
|
-
end
|
1048
|
+
end
|
940
1049
|
return res
|
941
1050
|
end
|
942
1051
|
end
|
@@ -946,19 +1055,20 @@ module HDLRuby::Low
|
|
946
1055
|
class Code
|
947
1056
|
# Generates the C text of the equivalent HDLRuby code.
|
948
1057
|
# +level+ is the hierachical level of the object.
|
949
|
-
def to_c(level = 0)
|
1058
|
+
# def to_c(level = 0)
|
1059
|
+
def to_c(res,level = 0)
|
950
1060
|
# puts "For behavior: #{self}"
|
951
1061
|
# The resulting string.
|
952
|
-
res = ""
|
1062
|
+
# res = ""
|
953
1063
|
|
954
1064
|
# Declare the global variable holding the behavior.
|
955
|
-
res << "Code
|
1065
|
+
res << "Code " << Low2C.obj_name(self) << ";\n\n"
|
956
1066
|
|
957
1067
|
# Generate the code of the behavior.
|
958
1068
|
|
959
1069
|
# The header of the behavior.
|
960
1070
|
res << " " * level*3
|
961
|
-
res << "Code
|
1071
|
+
res << "Code " << Low2C.make_name(self) << "() {\n"
|
962
1072
|
res << " " * (level+1)*3
|
963
1073
|
|
964
1074
|
# Allocate the code.
|
@@ -969,13 +1079,13 @@ module HDLRuby::Low
|
|
969
1079
|
# Sets the global variable of the code.
|
970
1080
|
res << "\n"
|
971
1081
|
res << " " * (level+1)*3
|
972
|
-
res <<
|
1082
|
+
res << Low2C.obj_name(self) << " = code;\n"
|
973
1083
|
|
974
1084
|
# Set the owner if any.
|
975
1085
|
if self.parent then
|
976
1086
|
res << " " * (level+1)*3
|
977
|
-
res << "code->owner = (Object)"
|
978
|
-
|
1087
|
+
res << "code->owner = (Object)"
|
1088
|
+
res << Low2C.obj_name(self.parent) << ";\n"
|
979
1089
|
else
|
980
1090
|
res << "code->owner = NULL;\n"
|
981
1091
|
end
|
@@ -997,7 +1107,10 @@ module HDLRuby::Low
|
|
997
1107
|
# puts "for event=#{event}"
|
998
1108
|
# Add the event.
|
999
1109
|
res << " " * (level+1)*3
|
1000
|
-
res << "code->events[#{i}] = #{event.to_c};\n"
|
1110
|
+
# res << "code->events[#{i}] = #{event.to_c};\n"
|
1111
|
+
res << "code->events[#{i}] = "
|
1112
|
+
event.to_c(res)
|
1113
|
+
res << ";\n"
|
1001
1114
|
|
1002
1115
|
# Register the behavior as activable on this event.
|
1003
1116
|
# Select the active field.
|
@@ -1005,7 +1118,9 @@ module HDLRuby::Low
|
|
1005
1118
|
field = "pos" if event.type == :posedge
|
1006
1119
|
field = "neg" if event.type == :negedge
|
1007
1120
|
# Get the target signal access
|
1008
|
-
sigad = event.ref.resolve.to_c_signal
|
1121
|
+
# sigad = event.ref.resolve.to_c_signal
|
1122
|
+
sigad = ""
|
1123
|
+
event.ref.resolve.to_c_signal(sigad)
|
1009
1124
|
# Add the code to the relevant field.
|
1010
1125
|
res << " " * (level+1)*3
|
1011
1126
|
res << "#{sigad}->num_#{field} += 1;\n"
|
@@ -1019,7 +1134,10 @@ module HDLRuby::Low
|
|
1019
1134
|
# Adds the function to execute.
|
1020
1135
|
function = self.each_chunk.find { |chunk| chunk.name == :sim }
|
1021
1136
|
res << " " * (level+1)*3
|
1022
|
-
res << "code->function = &#{function.to_c};\n"
|
1137
|
+
# res << "code->function = &#{function.to_c};\n"
|
1138
|
+
res << "code->function = &"
|
1139
|
+
function.to_c(res)
|
1140
|
+
res << ";\n"
|
1023
1141
|
|
1024
1142
|
# Generate the Returns of the result.
|
1025
1143
|
res << "\n"
|
@@ -1033,16 +1151,18 @@ module HDLRuby::Low
|
|
1033
1151
|
end
|
1034
1152
|
|
1035
1153
|
## Generates the content of the h file.
|
1036
|
-
def to_ch
|
1037
|
-
|
1154
|
+
# def to_ch
|
1155
|
+
def to_ch(res)
|
1156
|
+
# res = ""
|
1038
1157
|
# Declare the global variable holding the signal.
|
1039
|
-
res << "extern Behavior
|
1158
|
+
res << "extern Behavior " << Low2C.obj_name(self) << ";\n\n"
|
1040
1159
|
|
1041
1160
|
# Generate the access to the function making the behavior.
|
1042
|
-
res << "extern Behavior
|
1161
|
+
res << "extern Behavior " << Low2C.make_name(self) << "();\n\n"
|
1043
1162
|
|
1044
1163
|
# Generate the accesses to the block of the behavior.
|
1045
|
-
res << self.block.to_ch
|
1164
|
+
# res << self.block.to_ch
|
1165
|
+
self.block.to_ch(res)
|
1046
1166
|
|
1047
1167
|
return res;
|
1048
1168
|
end
|
@@ -1054,15 +1174,18 @@ module HDLRuby::Low
|
|
1054
1174
|
|
1055
1175
|
# Generates the C text of the equivalent HDLRuby code.
|
1056
1176
|
# +level+ is the hierachical level of the object.
|
1057
|
-
def to_c(level = 0)
|
1177
|
+
# def to_c(level = 0)
|
1178
|
+
def to_c(res,level = 0)
|
1058
1179
|
# Should never be here.
|
1059
1180
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1060
1181
|
end
|
1061
1182
|
|
1062
1183
|
## Generates the content of the h file.
|
1063
|
-
def to_ch
|
1184
|
+
# def to_ch
|
1185
|
+
def to_ch(res)
|
1064
1186
|
# By default nothing to generate.
|
1065
|
-
return ""
|
1187
|
+
# return ""
|
1188
|
+
return res
|
1066
1189
|
end
|
1067
1190
|
|
1068
1191
|
# Adds the c code of the blocks to +res+ at +level+
|
@@ -1091,34 +1214,100 @@ module HDLRuby::Low
|
|
1091
1214
|
## Extends the Transmit class with generation of C text.
|
1092
1215
|
class Transmit
|
1093
1216
|
|
1217
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
1218
|
+
# # +level+ is the hierachical level of the object.
|
1219
|
+
# # def to_c(level = 0)
|
1220
|
+
# def to_c(res,level = 0)
|
1221
|
+
# # Save the state of the value pool.
|
1222
|
+
# # res = (" " * ((level)*3))
|
1223
|
+
# res << (" " * ((level)*3))
|
1224
|
+
# res << "{\n"
|
1225
|
+
# res << (" " * ((level+1)*3))
|
1226
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
1227
|
+
# # Perform the copy and the touching only if the new content
|
1228
|
+
# # is different.
|
1229
|
+
# # res << (" " * ((level+1)*3))
|
1230
|
+
# # Is it a sequential execution model?
|
1231
|
+
# seq = self.block.mode == :seq ? "_seq" : ""
|
1232
|
+
# # # Generate the assignment.
|
1233
|
+
# # if (self.left.is_a?(RefName)) then
|
1234
|
+
# # # Direct assignment to a signal, simple transmission.
|
1235
|
+
# # res << "transmit_to_signal#{seq}("
|
1236
|
+
# # self.right.to_c(res,level)
|
1237
|
+
# # res << ","
|
1238
|
+
# # self.left.to_c_signal(res,level)
|
1239
|
+
# # res << ");\n"
|
1240
|
+
# # else
|
1241
|
+
# # # Assignment inside a signal (RefIndex or RefRange).
|
1242
|
+
# # res << "transmit_to_signal_range#{seq}("
|
1243
|
+
# # self.right.to_c(res,level)
|
1244
|
+
# # res << ","
|
1245
|
+
# # self.left.to_c_signal(res,level)
|
1246
|
+
# # res << ");\n"
|
1247
|
+
# # ### Why twice ???
|
1248
|
+
# # res << "transmit_to_signal_range#{seq}("
|
1249
|
+
# # self.right.to_c(res,level)
|
1250
|
+
# # res << ","
|
1251
|
+
# # self.left.to_c_signal(res,level)
|
1252
|
+
# # res << ");\n"
|
1253
|
+
# # end
|
1254
|
+
# # Generate the assignment.
|
1255
|
+
# if (self.left.is_a?(RefName)) then
|
1256
|
+
# # Generate the right value.
|
1257
|
+
# self.right.to_c(res,level+1)
|
1258
|
+
# # Direct assignment to a signal, simple transmission.
|
1259
|
+
# res << (" " * ((level+1)*3))
|
1260
|
+
# res << "transmit_to_signal#{seq}(d,"
|
1261
|
+
# # Generate the left value (target signal).
|
1262
|
+
# self.left.to_c_signal(res,level+1)
|
1263
|
+
# res << ");\n"
|
1264
|
+
# else
|
1265
|
+
# # Generate the right value.
|
1266
|
+
# self.right.to_c(res,level+1)
|
1267
|
+
# # Assignment inside a signal (RefIndex or RefRange).
|
1268
|
+
# res << "transmit_to_signal_range#{seq}(d,"
|
1269
|
+
# # Generate the left value (target signal).
|
1270
|
+
# self.left.to_c_signal(res,level+1)
|
1271
|
+
# res << ");\n"
|
1272
|
+
# end
|
1273
|
+
# # Restore the value pool state.
|
1274
|
+
# res << (" " * ((level+1)*3))
|
1275
|
+
# res << "set_value_pos(pool_state);\n"
|
1276
|
+
# res << (" " * ((level)*3))
|
1277
|
+
# res << "}\n"
|
1278
|
+
# return res
|
1279
|
+
# end
|
1094
1280
|
# Generates the C text of the equivalent HDLRuby code.
|
1095
1281
|
# +level+ is the hierachical level of the object.
|
1096
|
-
def to_c(level = 0)
|
1097
|
-
|
1098
|
-
|
1099
|
-
res << "
|
1100
|
-
res << (" " * ((level+1)*3))
|
1101
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
1282
|
+
# def to_c(level = 0)
|
1283
|
+
def to_c(res,level = 0)
|
1284
|
+
# Save the value pool state.
|
1285
|
+
res << (" " * (level*3)) << "SV;\n"
|
1102
1286
|
# Perform the copy and the touching only if the new content
|
1103
1287
|
# is different.
|
1104
|
-
res << (" " * ((level+1)*3))
|
1105
1288
|
# Is it a sequential execution model?
|
1106
1289
|
seq = self.block.mode == :seq ? "_seq" : ""
|
1107
1290
|
# Generate the assignment.
|
1108
1291
|
if (self.left.is_a?(RefName)) then
|
1292
|
+
# Generate the right value.
|
1293
|
+
self.right.to_c(res,level)
|
1109
1294
|
# Direct assignment to a signal, simple transmission.
|
1110
|
-
res << "
|
1111
|
-
|
1295
|
+
res << (" " * (level*3))
|
1296
|
+
res << "transmit#{seq}("
|
1297
|
+
# Generate the left value (target signal).
|
1298
|
+
self.left.to_c_signal(res,level+1)
|
1299
|
+
res << ");\n"
|
1112
1300
|
else
|
1301
|
+
# Generate the right value.
|
1302
|
+
self.right.to_c(res,level)
|
1113
1303
|
# Assignment inside a signal (RefIndex or RefRange).
|
1114
|
-
res << "
|
1115
|
-
|
1304
|
+
res << "transmitR#{seq}("
|
1305
|
+
# Generate the left value (target signal).
|
1306
|
+
self.left.to_c_signal(res,level+1)
|
1307
|
+
res << ");\n"
|
1116
1308
|
end
|
1117
1309
|
# Restore the value pool state.
|
1118
|
-
res << (" " * (
|
1119
|
-
res << "set_value_pos(pool_state);\n"
|
1120
|
-
res << (" " * ((level)*3))
|
1121
|
-
res << "}\n"
|
1310
|
+
res << (" " * (level*3)) << "RV;\n"
|
1122
1311
|
return res
|
1123
1312
|
end
|
1124
1313
|
end
|
@@ -1127,35 +1316,68 @@ module HDLRuby::Low
|
|
1127
1316
|
## Extends the Print class with generation of C text.
|
1128
1317
|
class Print
|
1129
1318
|
|
1319
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
1320
|
+
# # +level+ is the hierachical level of the object.
|
1321
|
+
# # def to_c(level = 0)
|
1322
|
+
# def to_c(res,level = 0)
|
1323
|
+
# # Save the state of the value pool.
|
1324
|
+
# # res = (" " * ((level)*3))
|
1325
|
+
# res << (" " * ((level)*3))
|
1326
|
+
# res << "{\n"
|
1327
|
+
# res << (" " * ((level+1)*3))
|
1328
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
1329
|
+
# # Perform the copy and the touching only if the new content
|
1330
|
+
# # is different.
|
1331
|
+
# res << (" " * ((level+1)*3))
|
1332
|
+
# # Is it a sequential execution model?
|
1333
|
+
# seq = self.block.mode == :seq ? "_seq" : ""
|
1334
|
+
# # Generate the print.
|
1335
|
+
# self.each_arg do |arg|
|
1336
|
+
# if (arg.is_a?(StringE)) then
|
1337
|
+
# res << "printer.print_string(\"" +
|
1338
|
+
# Low2C.c_string(arg.content) + "\");\n"
|
1339
|
+
# elsif (arg.is_a?(Expression)) then
|
1340
|
+
# # res << "printer.print_string_value(" + arg.to_c + ");\n"
|
1341
|
+
# res << "printer.print_string_value("
|
1342
|
+
# arg.to_c(res)
|
1343
|
+
# res << ");\n"
|
1344
|
+
# else
|
1345
|
+
# # res << "printer.print_string_name(" + arg.to_c + ");\n"
|
1346
|
+
# res << "printer.print_string_name("
|
1347
|
+
# arg.to_c(res)
|
1348
|
+
# res << ");\n"
|
1349
|
+
# end
|
1350
|
+
# end
|
1351
|
+
# # Restore the value pool state.
|
1352
|
+
# res << (" " * ((level+1)*3))
|
1353
|
+
# res << "set_value_pos(pool_state);\n"
|
1354
|
+
# res << (" " * ((level)*3))
|
1355
|
+
# res << "}\n"
|
1356
|
+
# return res
|
1357
|
+
# end
|
1130
1358
|
# Generates the C text of the equivalent HDLRuby code.
|
1131
1359
|
# +level+ is the hierachical level of the object.
|
1132
|
-
def to_c(level = 0)
|
1133
|
-
|
1134
|
-
|
1135
|
-
res << "
|
1136
|
-
|
1137
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
1138
|
-
# Perform the copy and the touching only if the new content
|
1139
|
-
# is different.
|
1140
|
-
res << (" " * ((level+1)*3))
|
1141
|
-
# Is it a sequential execution model?
|
1142
|
-
seq = self.block.mode == :seq ? "_seq" : ""
|
1143
|
-
# Generate the print.
|
1360
|
+
# def to_c(level = 0)
|
1361
|
+
def to_c(res,level = 0)
|
1362
|
+
# Save the value pool state.
|
1363
|
+
res << (" " * (level*3)) << "PV;\n"
|
1364
|
+
# Generate the print for each argument.
|
1144
1365
|
self.each_arg do |arg|
|
1145
1366
|
if (arg.is_a?(StringE)) then
|
1367
|
+
res << (" " * (level*3))
|
1146
1368
|
res << "printer.print_string(\"" +
|
1147
1369
|
Low2C.c_string(arg.content) + "\");\n"
|
1148
1370
|
elsif (arg.is_a?(Expression)) then
|
1149
|
-
|
1371
|
+
arg.to_c(res)
|
1372
|
+
res << (" " * (level*3))
|
1373
|
+
res << "printer.print_string_value(pop());\n"
|
1150
1374
|
else
|
1151
|
-
|
1375
|
+
arg.to_c(res)
|
1376
|
+
res << "printer.print_string_name(pop());\n"
|
1152
1377
|
end
|
1153
1378
|
end
|
1154
1379
|
# Restore the value pool state.
|
1155
|
-
res << (" " * (
|
1156
|
-
res << "set_value_pos(pool_state);\n"
|
1157
|
-
res << (" " * ((level)*3))
|
1158
|
-
res << "}\n"
|
1380
|
+
res << (" " * (level*3)) << "RV;\n"
|
1159
1381
|
return res
|
1160
1382
|
end
|
1161
1383
|
end
|
@@ -1164,58 +1386,120 @@ module HDLRuby::Low
|
|
1164
1386
|
## Extends the If class with generation of C text.
|
1165
1387
|
class If
|
1166
1388
|
|
1389
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
1390
|
+
# # +level+ is the hierachical level of the object.
|
1391
|
+
# # def to_c(level = 0)
|
1392
|
+
# def to_c(res,level = 0)
|
1393
|
+
# # The result string.
|
1394
|
+
# # res = " " * level*3
|
1395
|
+
# res << " " * level*3
|
1396
|
+
# # Compute the condition.
|
1397
|
+
# res << "{\n"
|
1398
|
+
# res << " " * (level+1)*3
|
1399
|
+
# # res << "Value cond = " << self.condition.to_c(level+1) << ";\n"
|
1400
|
+
# res << "Value cond = "
|
1401
|
+
# self.condition.to_c(res,level+1)
|
1402
|
+
# res << ";\n"
|
1403
|
+
# # Ensure the condition is testable.
|
1404
|
+
# res << " " * (level+1)*3
|
1405
|
+
# res << "if (is_defined_value(cond)) {\n"
|
1406
|
+
# # The condition is testable.
|
1407
|
+
# res << " " * (level+2)*3
|
1408
|
+
# res << "if (value2integer(cond)) {\n"
|
1409
|
+
# # Generate the yes part.
|
1410
|
+
# # res << self.yes.to_c(level+3)
|
1411
|
+
# self.yes.to_c(res,level+3)
|
1412
|
+
# res << " " * level*3
|
1413
|
+
# res << "}\n"
|
1414
|
+
# # Generate the alternate if parts.
|
1415
|
+
# self.each_noif do |cond,stmnt|
|
1416
|
+
# res << " " * level*3
|
1417
|
+
# # res << "else if (value2integer(" << cond.to_c(level+1) << ")) {\n"
|
1418
|
+
# res << "else if (value2integer("
|
1419
|
+
# cond.to_c(res,level+1)
|
1420
|
+
# res << ")) {\n"
|
1421
|
+
# # res << stmnt.to_c(level+1)
|
1422
|
+
# stmnt.to_c(res,level+1)
|
1423
|
+
# res << " " * level*3
|
1424
|
+
# res << "}\n"
|
1425
|
+
# end
|
1426
|
+
# # Generate the no part if any.
|
1427
|
+
# if self.no then
|
1428
|
+
# res << " " * level*3
|
1429
|
+
# # res << "else {\n" << self.no.to_c(level+1)
|
1430
|
+
# res << "else {\n"
|
1431
|
+
# self.no.to_c(res,level+1)
|
1432
|
+
# res << " " * level*3
|
1433
|
+
# res << "}\n"
|
1434
|
+
# end
|
1435
|
+
# # Close the if.
|
1436
|
+
# res << " " * (level+1)*3
|
1437
|
+
# res << "}\n"
|
1438
|
+
# res << " " * (level)*3
|
1439
|
+
# res << "}\n"
|
1440
|
+
# # Return the result.
|
1441
|
+
# return res
|
1442
|
+
# end
|
1167
1443
|
# Generates the C text of the equivalent HDLRuby code.
|
1168
1444
|
# +level+ is the hierachical level of the object.
|
1169
|
-
def to_c(level = 0)
|
1170
|
-
|
1171
|
-
res = " " * level*3
|
1445
|
+
def to_c(res,level = 0)
|
1446
|
+
res << " " * level*3
|
1172
1447
|
# Compute the condition.
|
1173
|
-
res
|
1174
|
-
|
1175
|
-
res << "
|
1176
|
-
|
1177
|
-
res << " " * (level+1)*3
|
1178
|
-
res << "if (is_defined_value(cond)) {\n"
|
1179
|
-
# The condition is testable.
|
1180
|
-
res << " " * (level+2)*3
|
1181
|
-
res << "if (value2integer(cond)) {\n"
|
1448
|
+
self.condition.to_c(res,level)
|
1449
|
+
# Check is the value is true.
|
1450
|
+
res << " " * level*3
|
1451
|
+
res << "if (is_true()) {\n"
|
1182
1452
|
# Generate the yes part.
|
1183
|
-
|
1453
|
+
self.yes.to_c(res,level+1)
|
1184
1454
|
res << " " * level*3
|
1185
1455
|
res << "}\n"
|
1186
1456
|
# Generate the alternate if parts.
|
1187
1457
|
self.each_noif do |cond,stmnt|
|
1188
|
-
res << " " * level*3
|
1189
|
-
res << "else
|
1190
|
-
|
1191
|
-
|
1458
|
+
res << " " * (level*3)
|
1459
|
+
res << "else {\n"
|
1460
|
+
cond.to_c(res,level+1)
|
1461
|
+
# Check is the value is true.
|
1462
|
+
res << " " * (level+1)*3
|
1463
|
+
res << "if (is_true()) {\n"
|
1464
|
+
stmnt.to_c(res,level+2)
|
1465
|
+
res << " " * ((level+1)*3)
|
1192
1466
|
res << "}\n"
|
1193
1467
|
end
|
1194
1468
|
# Generate the no part if any.
|
1195
1469
|
if self.no then
|
1196
|
-
res << " " * level*3
|
1197
|
-
res << "else {\n"
|
1470
|
+
res << " " * (level*3)
|
1471
|
+
res << "else {\n"
|
1472
|
+
self.no.to_c(res,level+1)
|
1198
1473
|
res << " " * level*3
|
1199
1474
|
res << "}\n"
|
1200
1475
|
end
|
1201
|
-
# Close the
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1476
|
+
# Close the noifs.
|
1477
|
+
self.each_noif do |cond,stmnt|
|
1478
|
+
res << " " * (level*3)
|
1479
|
+
res << "}\n"
|
1480
|
+
end
|
1481
|
+
# # Close the if.
|
1482
|
+
# res << " " * ((level+1)*3)
|
1483
|
+
# res << "}\n"
|
1484
|
+
# res << " " * (level*3)
|
1485
|
+
# res << "}\n"
|
1206
1486
|
# Return the result.
|
1207
1487
|
return res
|
1208
1488
|
end
|
1209
1489
|
|
1210
1490
|
## Generates the content of the h file.
|
1211
|
-
def to_ch
|
1212
|
-
|
1491
|
+
# def to_ch
|
1492
|
+
def to_ch(res)
|
1493
|
+
# res = ""
|
1213
1494
|
# Recurse on the sub statements.
|
1214
|
-
res << self.yes.to_ch
|
1495
|
+
# res << self.yes.to_ch
|
1496
|
+
self.yes.to_ch(res)
|
1215
1497
|
self.each_noif do |cond,stmnt|
|
1216
|
-
res << stmnt.to_ch
|
1498
|
+
# res << stmnt.to_ch
|
1499
|
+
stmnt.to_ch(res)
|
1217
1500
|
end
|
1218
|
-
res << self.no.to_ch if self.no
|
1501
|
+
# res << self.no.to_ch if self.no
|
1502
|
+
self.no.to_ch(res) if self.no
|
1219
1503
|
return res
|
1220
1504
|
end
|
1221
1505
|
end
|
@@ -1225,13 +1509,19 @@ module HDLRuby::Low
|
|
1225
1509
|
|
1226
1510
|
# Generates the C text of the equivalent HDLRuby code.
|
1227
1511
|
# +level+ is the hierachical level of the object.
|
1228
|
-
def to_c(level = 0)
|
1512
|
+
# def to_c(level = 0)
|
1513
|
+
def to_c(res,level = 0)
|
1229
1514
|
# The result string.
|
1230
|
-
res = " " * level*3
|
1515
|
+
# res = " " * level*3
|
1516
|
+
res << " " * level*3
|
1231
1517
|
# Generate the match.
|
1232
|
-
res << "case " << self.match.to_c(level+1) << ": {\n"
|
1518
|
+
# res << "case " << self.match.to_c(level+1) << ": {\n"
|
1519
|
+
res << "case "
|
1520
|
+
self.match.to_c(res,level+1)
|
1521
|
+
res << ": {\n"
|
1233
1522
|
# Generate the statement.
|
1234
|
-
res << self.statement.to_c(level+1)
|
1523
|
+
# res << self.statement.to_c(level+1)
|
1524
|
+
self.statement.to_c(res,level+1)
|
1235
1525
|
# Adds a break
|
1236
1526
|
res << " " * (level+1)*3 << "break;\n"
|
1237
1527
|
res << " " * level*3 << "}\n"
|
@@ -1240,8 +1530,11 @@ module HDLRuby::Low
|
|
1240
1530
|
end
|
1241
1531
|
|
1242
1532
|
## Generates the content of the h file.
|
1243
|
-
def to_ch
|
1244
|
-
|
1533
|
+
# def to_ch
|
1534
|
+
def to_ch(res)
|
1535
|
+
# return self.statement.to_ch
|
1536
|
+
self.statement.to_ch(res)
|
1537
|
+
return res
|
1245
1538
|
end
|
1246
1539
|
|
1247
1540
|
# Adds the c code of the blocks to +res+ at +level+
|
@@ -1258,42 +1551,92 @@ module HDLRuby::Low
|
|
1258
1551
|
## Extends the Case class with generation of C text.
|
1259
1552
|
class Case
|
1260
1553
|
|
1554
|
+
# # Generates the text of the equivalent HDLRuby code.
|
1555
|
+
# # +level+ is the hierachical level of the object.
|
1556
|
+
# # def to_c(level = 0)
|
1557
|
+
# def to_c(res,level = 0)
|
1558
|
+
# # res = ""
|
1559
|
+
# # Compute the selection value.
|
1560
|
+
# res << "{\n"
|
1561
|
+
# res << " " * (level+1)*3
|
1562
|
+
# # res << "Value value = " << self.value.to_c(level+1) << ";\n"
|
1563
|
+
# res << "Value value = "
|
1564
|
+
# self.value.to_c(res,level+1)
|
1565
|
+
# res << ";\n"
|
1566
|
+
# # Ensure the selection value is testable.
|
1567
|
+
# res << " " * (level+1)*3
|
1568
|
+
# res << "if (is_defined_value(value)) {\n"
|
1569
|
+
# # The condition is testable.
|
1570
|
+
# # Generate the case as a succession of if statements.
|
1571
|
+
# first = true
|
1572
|
+
# self.each_when do |w|
|
1573
|
+
# res << " " * (level+2)*3
|
1574
|
+
# if first then
|
1575
|
+
# first = false
|
1576
|
+
# else
|
1577
|
+
# res << "else "
|
1578
|
+
# end
|
1579
|
+
# res << "if (value2integer(value) == "
|
1580
|
+
# # res << "value2integer(" << w.match.to_c(level+2) << ")) {\n"
|
1581
|
+
# res << "value2integer("
|
1582
|
+
# w.match.to_c(res,level+2)
|
1583
|
+
# res << ")) {\n"
|
1584
|
+
# # res << w.statement.to_c(level+3)
|
1585
|
+
# w.statement.to_c(res,level+3)
|
1586
|
+
# res << " " * (level+2)*3
|
1587
|
+
# res << "}\n"
|
1588
|
+
# end
|
1589
|
+
# if self.default then
|
1590
|
+
# res << " " * (level+2)*3
|
1591
|
+
# res << "else {\n"
|
1592
|
+
# # res << self.default.to_c(level+3)
|
1593
|
+
# self.default.to_c(res,level+3)
|
1594
|
+
# res << " " * (level+2)*3
|
1595
|
+
# res << "}\n"
|
1596
|
+
# end
|
1597
|
+
# # Close the case.
|
1598
|
+
# res << " " * (level+1)*3
|
1599
|
+
# res << "}\n"
|
1600
|
+
# res << " " * (level)*3
|
1601
|
+
# res << "}\n"
|
1602
|
+
# # Return the resulting string.
|
1603
|
+
# return res
|
1604
|
+
# end
|
1261
1605
|
# Generates the text of the equivalent HDLRuby code.
|
1262
1606
|
# +level+ is the hierachical level of the object.
|
1263
|
-
def to_c(level = 0)
|
1264
|
-
|
1607
|
+
# def to_c(level = 0)
|
1608
|
+
def to_c(res,level = 0)
|
1265
1609
|
# Compute the selection value.
|
1266
1610
|
res << "{\n"
|
1267
|
-
res
|
1268
|
-
res << "
|
1611
|
+
self.value.to_c(res,level+1)
|
1612
|
+
res << " " * ((level+1)*3)
|
1613
|
+
res << "dup();\n"
|
1269
1614
|
# Ensure the selection value is testable.
|
1270
|
-
res << " " * (level+1)*3
|
1271
|
-
res << "if (
|
1615
|
+
res << " " * ((level+1)*3)
|
1616
|
+
res << "if (is_defined()) {\n"
|
1272
1617
|
# The condition is testable.
|
1273
1618
|
# Generate the case as a succession of if statements.
|
1274
|
-
first = true
|
1275
1619
|
self.each_when do |w|
|
1276
|
-
res << " " * (level+2)*3
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
res << "if (value2integer(value) == "
|
1283
|
-
res << "value2integer(" << w.match.to_c(level+2) << ")) {\n"
|
1284
|
-
res << w.statement.to_c(level+3)
|
1620
|
+
res << " " * ((level+2)*3)
|
1621
|
+
res << "dup();\n"
|
1622
|
+
res << " " * ((level+2)*3)
|
1623
|
+
w.match.to_c(res,level+2)
|
1624
|
+
res << "if (to_integer() == to_integer()) {\n"
|
1625
|
+
w.statement.to_c(res,level+3)
|
1285
1626
|
res << " " * (level+2)*3
|
1286
1627
|
res << "}\n"
|
1287
1628
|
end
|
1288
1629
|
if self.default then
|
1289
1630
|
res << " " * (level+2)*3
|
1290
1631
|
res << "else {\n"
|
1291
|
-
|
1632
|
+
self.default.to_c(res,level+3)
|
1292
1633
|
res << " " * (level+2)*3
|
1293
1634
|
res << "}\n"
|
1294
1635
|
end
|
1295
1636
|
# Close the case.
|
1296
1637
|
res << " " * (level+1)*3
|
1638
|
+
res << "pop();\n" # Remove the testing value.
|
1639
|
+
res << " " * (level+1)*3
|
1297
1640
|
res << "}\n"
|
1298
1641
|
res << " " * (level)*3
|
1299
1642
|
res << "}\n"
|
@@ -1302,12 +1645,15 @@ module HDLRuby::Low
|
|
1302
1645
|
end
|
1303
1646
|
|
1304
1647
|
## Generates the content of the h file.
|
1305
|
-
def to_ch
|
1306
|
-
|
1648
|
+
# def to_ch
|
1649
|
+
def to_ch(res)
|
1650
|
+
# res = ""
|
1307
1651
|
# Recurse on the whens.
|
1308
|
-
self.each_when {|w| res << w.to_ch }
|
1652
|
+
# self.each_when {|w| res << w.to_ch }
|
1653
|
+
self.each_when {|w| w.to_ch(res) }
|
1309
1654
|
# Recurse on the default statement.
|
1310
|
-
res << self.default.to_ch if self.default
|
1655
|
+
# res << self.default.to_ch if self.default
|
1656
|
+
self.default.to_ch(res) if self.default
|
1311
1657
|
return res
|
1312
1658
|
end
|
1313
1659
|
end
|
@@ -1318,9 +1664,13 @@ module HDLRuby::Low
|
|
1318
1664
|
|
1319
1665
|
# Generates the C text of the equivalent HDLRuby code.
|
1320
1666
|
# +level+ is the hierachical level of the object.
|
1321
|
-
def to_c(level = 0)
|
1322
|
-
|
1323
|
-
|
1667
|
+
# def to_c(level = 0)
|
1668
|
+
def to_c(res,level = 0)
|
1669
|
+
# return "make_delay(#{self.value.to_s}," +
|
1670
|
+
# "#{Low2C.unit_name(self.unit)})"
|
1671
|
+
res << "make_delay(#{self.value.to_s},"
|
1672
|
+
res << Low2C.unit_name(self.unit) << ")"
|
1673
|
+
return res
|
1324
1674
|
end
|
1325
1675
|
end
|
1326
1676
|
|
@@ -1330,12 +1680,17 @@ module HDLRuby::Low
|
|
1330
1680
|
|
1331
1681
|
# Generates the C text of the equivalent HDLRuby code.
|
1332
1682
|
# +level+ is the hierachical level of the object.
|
1333
|
-
def to_c(level = 0)
|
1683
|
+
# def to_c(level = 0)
|
1684
|
+
def to_c(res,level = 0)
|
1334
1685
|
# The resulting string.
|
1335
|
-
res = " " * level*3
|
1686
|
+
# res = " " * level*3
|
1687
|
+
res << " " * level*3
|
1336
1688
|
# Generate the wait.
|
1337
|
-
res << "hw_wait(#{self.delay.to_c(level+1)}," +
|
1338
|
-
|
1689
|
+
# res << "hw_wait(#{self.delay.to_c(level+1)}," +
|
1690
|
+
# "#{Low2C.behavior_access(self)});\n"
|
1691
|
+
res << "hw_wait("
|
1692
|
+
self.delay.to_c(res,level+1)
|
1693
|
+
res << "," << Low2C.behavior_access(self) << ");\n"
|
1339
1694
|
# Return the resulting string.
|
1340
1695
|
return res
|
1341
1696
|
end
|
@@ -1346,13 +1701,17 @@ module HDLRuby::Low
|
|
1346
1701
|
|
1347
1702
|
# Generates the C text of the equivalent HDLRuby code.
|
1348
1703
|
# +level+ is the hierachical level of the object.
|
1349
|
-
def to_c(level = 0)
|
1704
|
+
# def to_c(level = 0)
|
1705
|
+
def to_c(res,level = 0)
|
1350
1706
|
# The resulting string.
|
1351
|
-
res = " " * level*3
|
1707
|
+
# res = " " * level*3
|
1708
|
+
res << " " * level*3
|
1352
1709
|
# Generate an infinite loop executing the block and waiting.
|
1353
1710
|
res << "for(;;) {\n"
|
1354
|
-
res << "#{self.to_c(level+1)}\n"
|
1355
|
-
res
|
1711
|
+
# res << "#{self.statement.to_c(level+1)}\n"
|
1712
|
+
self.statement.to_c(res,level+1)
|
1713
|
+
res << "\n"
|
1714
|
+
res << " " * (level+1)*3
|
1356
1715
|
res << Low2C.wait_code(self,level)
|
1357
1716
|
# Return the resulting string.
|
1358
1717
|
return res
|
@@ -1364,24 +1723,27 @@ module HDLRuby::Low
|
|
1364
1723
|
|
1365
1724
|
# Adds the c code of the blocks to +res+ at +level+
|
1366
1725
|
def add_blocks_code(res,level)
|
1367
|
-
res << self.to_c_code(level)
|
1726
|
+
# res << self.to_c_code(level)
|
1727
|
+
self.to_c_code(res,level)
|
1728
|
+
return res
|
1368
1729
|
end
|
1369
1730
|
|
1370
1731
|
# Adds the creation of the blocks to +res+ at +level+.
|
1371
1732
|
def add_make_block(res,level)
|
1372
1733
|
res << " " * level*3
|
1373
|
-
res <<
|
1734
|
+
res << Low2C.make_name(self) << "();\n"
|
1374
1735
|
end
|
1375
1736
|
|
1376
1737
|
# Generates the C text of the equivalent HDLRuby code.
|
1377
1738
|
# +level+ is the hierachical level of the object.
|
1378
|
-
def to_c_code(level = 0)
|
1739
|
+
# def to_c_code(level = 0)
|
1740
|
+
def to_c_code(res,level = 0)
|
1379
1741
|
# The resulting string.
|
1380
|
-
res = ""
|
1742
|
+
# res = ""
|
1381
1743
|
# puts "generating self=#{self.object_id}"
|
1382
1744
|
|
1383
1745
|
# Declare the global variable holding the block.
|
1384
|
-
res << "Block
|
1746
|
+
res << "Block " << Low2C.obj_name(self) << ";\n\n"
|
1385
1747
|
|
1386
1748
|
# Generate the c code of the sub blocks if any.
|
1387
1749
|
self.each_statement do |stmnt|
|
@@ -1390,11 +1752,16 @@ module HDLRuby::Low
|
|
1390
1752
|
|
1391
1753
|
# Generate the execution function.
|
1392
1754
|
res << " " * level*3
|
1393
|
-
res << "void
|
1755
|
+
res << "void " << Low2C.code_name(self) << "() {\n"
|
1756
|
+
res << " " * (level+1)*3
|
1757
|
+
# res << "Value l,r,d;\n"
|
1758
|
+
# res << " " * (level+1)*3
|
1759
|
+
# res << "unsigned long long i;\n"
|
1394
1760
|
# res << "printf(\"Executing #{Low2C.code_name(self)}...\\n\");"
|
1395
1761
|
# Generate the statements.
|
1396
1762
|
self.each_statement do |stmnt|
|
1397
|
-
res << stmnt.to_c(level+1)
|
1763
|
+
# res << stmnt.to_c(level+1)
|
1764
|
+
stmnt.to_c(res,level+1)
|
1398
1765
|
end
|
1399
1766
|
# Close the execution function.
|
1400
1767
|
res << " " * level*3
|
@@ -1402,11 +1769,12 @@ module HDLRuby::Low
|
|
1402
1769
|
|
1403
1770
|
|
1404
1771
|
# Generate the signals.
|
1405
|
-
self.each_signal { |signal| res << signal.to_c(level) }
|
1772
|
+
# self.each_signal { |signal| res << signal.to_c(level) }
|
1773
|
+
self.each_signal { |signal| signal.to_c(res,level) }
|
1406
1774
|
|
1407
1775
|
# The header of the block.
|
1408
1776
|
res << " " * level*3
|
1409
|
-
res << "Block
|
1777
|
+
res << "Block " << Low2C.make_name(self) << "() {\n"
|
1410
1778
|
res << " " * (level+1)*3
|
1411
1779
|
res << "Block block = malloc(sizeof(BlockS));\n"
|
1412
1780
|
res << " " * (level+1)*3
|
@@ -1415,7 +1783,7 @@ module HDLRuby::Low
|
|
1415
1783
|
# Sets the global variable of the block.
|
1416
1784
|
res << "\n"
|
1417
1785
|
res << " " * (level+1)*3
|
1418
|
-
res <<
|
1786
|
+
res << Low2C.obj_name(self) << " = block;\n"
|
1419
1787
|
|
1420
1788
|
# Set the owner if any.
|
1421
1789
|
if self.parent then
|
@@ -1426,8 +1794,8 @@ module HDLRuby::Low
|
|
1426
1794
|
end
|
1427
1795
|
# Set it as the real parent.
|
1428
1796
|
res << " " * (level+1)*3
|
1429
|
-
res << "block->owner = (Object)"
|
1430
|
-
|
1797
|
+
res << "block->owner = (Object)"
|
1798
|
+
res << Low2C.obj_name(true_parent) << ";\n"
|
1431
1799
|
else
|
1432
1800
|
res << "block->owner = NULL;\n"
|
1433
1801
|
end
|
@@ -1444,13 +1812,13 @@ module HDLRuby::Low
|
|
1444
1812
|
"block->num_inners);\n"
|
1445
1813
|
self.each_inner.with_index do |inner,i|
|
1446
1814
|
res << " " * (level+1)*3
|
1447
|
-
res << "block->inners[#{i}] = "
|
1448
|
-
|
1815
|
+
res << "block->inners[#{i}] = "
|
1816
|
+
res << Low2C.make_name(inner) << "();\n"
|
1449
1817
|
end
|
1450
1818
|
|
1451
1819
|
# Sets the execution function.
|
1452
1820
|
res << " " * (level+1)*3
|
1453
|
-
res << "block->function =
|
1821
|
+
res << "block->function = &" << Low2C.code_name(self) << ";\n"
|
1454
1822
|
|
1455
1823
|
# Generate creation of the sub blocks.
|
1456
1824
|
self.each_statement do |stmnt|
|
@@ -1471,28 +1839,32 @@ module HDLRuby::Low
|
|
1471
1839
|
# Generates the execution of the block C text of the equivalent
|
1472
1840
|
# HDLRuby code.
|
1473
1841
|
# +level+ is the hierachical level of the object.
|
1474
|
-
def to_c(level = 0)
|
1475
|
-
|
1476
|
-
res
|
1842
|
+
# def to_c(level = 0)
|
1843
|
+
def to_c(res,level = 0)
|
1844
|
+
# res = " " * (level*3)
|
1845
|
+
res << " " * (level*3)
|
1846
|
+
res << Low2C.code_name(self) << "();\n"
|
1477
1847
|
return res
|
1478
1848
|
end
|
1479
1849
|
|
1480
1850
|
## Generates the content of the h file.
|
1481
|
-
def to_ch
|
1851
|
+
# def to_ch
|
1852
|
+
def to_ch(res)
|
1482
1853
|
# puts "to_ch for block=#{Low2C.obj_name(self)} with=#{self.each_inner.count} inners"
|
1483
|
-
res = ""
|
1854
|
+
# res = ""
|
1484
1855
|
# Declare the global variable holding the block.
|
1485
|
-
res << "extern Block
|
1856
|
+
res << "extern Block " << Low2C.obj_name(self) << ";\n\n"
|
1486
1857
|
|
1487
1858
|
# Generate the access to the function making the block. */
|
1488
|
-
res << "extern Block
|
1859
|
+
res << "extern Block " << Low2C.make_name(self) << "();\n\n"
|
1489
1860
|
|
1490
1861
|
# Generate the accesses to the ports.
|
1491
|
-
self.each_inner { |inner| res << inner.to_ch }
|
1862
|
+
# self.each_inner { |inner| res << inner.to_ch }
|
1863
|
+
self.each_inner { |inner| inner.to_ch(res) }
|
1492
1864
|
|
1493
1865
|
# Recurse on the statements.
|
1494
|
-
self.each_statement { |stmnt| res << stmnt.to_ch }
|
1495
|
-
|
1866
|
+
# self.each_statement { |stmnt| res << stmnt.to_ch }
|
1867
|
+
self.each_statement { |stmnt| stmnt.to_ch(res) }
|
1496
1868
|
|
1497
1869
|
return res
|
1498
1870
|
end
|
@@ -1516,7 +1888,8 @@ module HDLRuby::Low
|
|
1516
1888
|
|
1517
1889
|
# Generates the C text of the equivalent HDLRuby code.
|
1518
1890
|
# +level+ is the hierachical level of the object.
|
1519
|
-
def to_c(level = 0)
|
1891
|
+
# def to_c(level = 0)
|
1892
|
+
def to_c(res,level = 0)
|
1520
1893
|
# Should never be here.
|
1521
1894
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1522
1895
|
end
|
@@ -1528,25 +1901,50 @@ module HDLRuby::Low
|
|
1528
1901
|
|
1529
1902
|
## Generates the C text for an access to the value.
|
1530
1903
|
# +level+ is the hierachical level of the object.
|
1531
|
-
def to_c(level = 0)
|
1532
|
-
|
1904
|
+
def to_c(res,level = 0)
|
1905
|
+
# res << Low2C.make_name(self) << "()"
|
1906
|
+
# return res
|
1907
|
+
res << (" " * (level*3))
|
1908
|
+
# res << "d=" << Low2C.make_name(self) << "();\n"
|
1909
|
+
res << "push(" << Low2C.make_name(self) << "());\n"
|
1910
|
+
return res
|
1911
|
+
end
|
1912
|
+
|
1913
|
+
## Generates the C text for an expression access to the value.
|
1914
|
+
# +level+ is the hierachical level of the object.
|
1915
|
+
def to_c_expr(res,level = 0)
|
1916
|
+
res << Low2C.make_name(self) << "()"
|
1917
|
+
return res
|
1533
1918
|
end
|
1534
1919
|
|
1535
1920
|
## Generates the content of the h file.
|
1536
|
-
def to_ch
|
1537
|
-
|
1538
|
-
|
1921
|
+
# def to_ch
|
1922
|
+
def to_ch(res)
|
1923
|
+
# res = ""
|
1924
|
+
# return "extern Value #{Low2C.make_name(self)}();"
|
1925
|
+
res << "extern Value " << Low2C.make_name(self) << "();"
|
1926
|
+
return res
|
1539
1927
|
end
|
1540
1928
|
|
1929
|
+
@@made_values = Set.new
|
1930
|
+
|
1541
1931
|
# Generates the text of the equivalent c.
|
1542
1932
|
# +level+ is the hierachical level of the object.
|
1543
|
-
def to_c_make(level = 0)
|
1933
|
+
# def to_c_make(level = 0)
|
1934
|
+
def to_c_make(res,level = 0)
|
1935
|
+
# Check is the value maker is already present.
|
1936
|
+
maker = Low2C.make_name(self);
|
1937
|
+
# return "" if @@made_values.include?(maker)
|
1938
|
+
return res if @@made_values.include?(maker)
|
1939
|
+
@@made_values.add(maker)
|
1940
|
+
|
1544
1941
|
# The resulting string.
|
1545
|
-
res = ""
|
1942
|
+
# res = ""
|
1546
1943
|
|
1547
1944
|
# The header of the value generation.
|
1548
1945
|
res << " " * level*3
|
1549
|
-
res << "Value
|
1946
|
+
# res << "Value " << Low2C.make_name(self) << "() {\n"
|
1947
|
+
res << "Value " << maker << "() {\n"
|
1550
1948
|
|
1551
1949
|
# Declares the data.
|
1552
1950
|
# Create the bit string.
|
@@ -1577,15 +1975,18 @@ module HDLRuby::Low
|
|
1577
1975
|
res << " " * (level+1)*3
|
1578
1976
|
# res << "static unsigned long long data[] = { "
|
1579
1977
|
res << "static unsigned int data[] = { "
|
1580
|
-
res << str.scan(/.{1,#{Low2C.int_width}}/m).map do |sub|
|
1978
|
+
res << str.scan(/.{1,#{Low2C.int_width}}/m).reverse.map do |sub|
|
1581
1979
|
sub.to_i(2).to_s # + "ULL"
|
1582
1980
|
end.join(",")
|
1583
1981
|
res << " };\n"
|
1584
1982
|
# Create the value.
|
1585
1983
|
res << " " * (level+1)*3
|
1586
1984
|
# puts "str=#{str} type width=#{self.type.width} signed? #{type.signed?}"
|
1587
|
-
res << "return make_set_value(#{self.type.to_c(level+1)},1," +
|
1588
|
-
|
1985
|
+
# res << "return make_set_value(#{self.type.to_c(level+1)},1," +
|
1986
|
+
# "data);\n"
|
1987
|
+
res << "return make_set_value("
|
1988
|
+
self.type.to_c(res,level+1)
|
1989
|
+
res << ",1,data);\n"
|
1589
1990
|
else
|
1590
1991
|
# No, generate a bit string value.
|
1591
1992
|
res << " " * (level+1)*3
|
@@ -1593,8 +1994,11 @@ module HDLRuby::Low
|
|
1593
1994
|
res << "static unsigned char data[] = \"#{str.reverse}\";\n"
|
1594
1995
|
# Create the value.
|
1595
1996
|
res << " " * (level+1)*3
|
1596
|
-
res << "return make_set_value(#{self.type.to_c(level+1)},0," +
|
1597
|
-
|
1997
|
+
# res << "return make_set_value(#{self.type.to_c(level+1)},0," +
|
1998
|
+
# "data);\n"
|
1999
|
+
res << "return make_set_value("
|
2000
|
+
self.type.to_c(res,level+1)
|
2001
|
+
res << ",0,data);\n"
|
1598
2002
|
end
|
1599
2003
|
|
1600
2004
|
# Close the value.
|
@@ -1608,29 +2012,54 @@ module HDLRuby::Low
|
|
1608
2012
|
## Extends the Cast class with generation of C text.
|
1609
2013
|
class Cast
|
1610
2014
|
|
2015
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2016
|
+
# # +level+ is the hierachical level of the object.
|
2017
|
+
# # def to_c(level = 0)
|
2018
|
+
# def to_c(res,level = 0)
|
2019
|
+
# # res = "({\n"
|
2020
|
+
# res << "({\n"
|
2021
|
+
# # Overrides the upper src0 and dst...
|
2022
|
+
# res << (" " * ((level+1)*3))
|
2023
|
+
# res << "Value src0, dst = get_value();\n"
|
2024
|
+
# # Save the state of the value pool.
|
2025
|
+
# res << (" " * ((level+1)*3))
|
2026
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2027
|
+
# # Compute the child.
|
2028
|
+
# res << (" " * ((level+1)*3))
|
2029
|
+
# # res << "src0 = #{self.child.to_c(level+2)};\n"
|
2030
|
+
# res << "src0 = "
|
2031
|
+
# self.child.to_c(res,level+2)
|
2032
|
+
# res << ";\n"
|
2033
|
+
# res << (" " * ((level+1)*3))
|
2034
|
+
# # res += "dst = cast_value(src0," +
|
2035
|
+
# # "#{self.type.to_c(level+1)},dst);\n"
|
2036
|
+
# res << "dst = cast_value(src0,"
|
2037
|
+
# self.type.to_c(res,level+1)
|
2038
|
+
# res << ",dst);\n"
|
2039
|
+
# # Restore the value pool state.
|
2040
|
+
# res << (" " * ((level+1)*3))
|
2041
|
+
# res << "set_value_pos(pool_state);\n"
|
2042
|
+
# # Close the computation
|
2043
|
+
# res << (" " * (level*3))
|
2044
|
+
# res << "dst; })"
|
2045
|
+
|
2046
|
+
# return res
|
2047
|
+
# end
|
1611
2048
|
# Generates the C text of the equivalent HDLRuby code.
|
1612
2049
|
# +level+ is the hierachical level of the object.
|
1613
|
-
def to_c(level = 0)
|
1614
|
-
|
1615
|
-
#
|
1616
|
-
res << (" " * (
|
1617
|
-
|
1618
|
-
|
1619
|
-
res << (" " * ((level+1)*3))
|
1620
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
1621
|
-
# Compute the child.
|
1622
|
-
res << (" " * ((level+1)*3))
|
1623
|
-
res << "src0 = #{self.child.to_c(level+2)};\n"
|
1624
|
-
res << (" " * ((level+1)*3))
|
1625
|
-
res += "dst = cast_value(src0," +
|
1626
|
-
"#{self.type.to_c(level+1)},dst);\n"
|
1627
|
-
# Restore the value pool state.
|
1628
|
-
res << (" " * ((level+1)*3))
|
1629
|
-
res << "set_value_pos(pool_state);\n"
|
1630
|
-
# Close the computation
|
2050
|
+
# def to_c(level = 0)
|
2051
|
+
def to_c(res,level = 0)
|
2052
|
+
# Save the value pool state.
|
2053
|
+
res << (" " * (level*3)) << "PV;\n"
|
2054
|
+
# Generate the child.
|
2055
|
+
self.child.to_c(res,level)
|
1631
2056
|
res << (" " * (level*3))
|
1632
|
-
res << "
|
1633
|
-
|
2057
|
+
# res << "d=cast(d,"
|
2058
|
+
res << "cast("
|
2059
|
+
self.type.to_c(res,level+1)
|
2060
|
+
res << ");\n"
|
2061
|
+
# Restore the value pool state.
|
2062
|
+
res << (" " * (level*3)) << "RV;\n"
|
1634
2063
|
return res
|
1635
2064
|
end
|
1636
2065
|
end
|
@@ -1641,7 +2070,8 @@ module HDLRuby::Low
|
|
1641
2070
|
|
1642
2071
|
# Generates the C text of the equivalent HDLRuby code.
|
1643
2072
|
# +level+ is the hierachical level of the object.
|
1644
|
-
def to_c(level = 0)
|
2073
|
+
# def to_c(level = 0)
|
2074
|
+
def to_c(res,level = 0)
|
1645
2075
|
# Should never be here.
|
1646
2076
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1647
2077
|
end
|
@@ -1650,42 +2080,81 @@ module HDLRuby::Low
|
|
1650
2080
|
## Extends the Unary class with generation of C text.
|
1651
2081
|
class Unary
|
1652
2082
|
|
2083
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2084
|
+
# # +level+ is the hierachical level of the object.
|
2085
|
+
# # def to_c(level = 0)
|
2086
|
+
# def to_c(res,level = 0)
|
2087
|
+
# # res = "({\n"
|
2088
|
+
# res << "({\n"
|
2089
|
+
# # Overrides the upper src0 and dst...
|
2090
|
+
# res << (" " * ((level+1)*3))
|
2091
|
+
# res << "Value src0, dst;\n"
|
2092
|
+
# if (self.operator != :+@) then
|
2093
|
+
# # And allocates a new value for dst unless the operator
|
2094
|
+
# # is +@ that does not compute anything.
|
2095
|
+
# res << (" " * ((level+1)*3))
|
2096
|
+
# res << "dst = get_value();\n"
|
2097
|
+
# end
|
2098
|
+
# # Save the state of the value pool.
|
2099
|
+
# res << (" " * ((level+1)*3))
|
2100
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2101
|
+
# # Compute the child.
|
2102
|
+
# res << (" " * ((level+1)*3))
|
2103
|
+
# # res << "src0 = #{self.child.to_c(level+2)};\n"
|
2104
|
+
# res << "src0 = "
|
2105
|
+
# self.child.to_c(res,level+2)
|
2106
|
+
# res << ";\n"
|
2107
|
+
# res << (" " * ((level+1)*3))
|
2108
|
+
# case self.operator
|
2109
|
+
# when :~ then
|
2110
|
+
# res << "dst = not_value(src0,dst);\n"
|
2111
|
+
# when :-@ then
|
2112
|
+
# res << "dst = neg_value(src0,dst);\n"
|
2113
|
+
# when :+@ then
|
2114
|
+
# # res << "dst = #{self.child.to_c(level)};\n"
|
2115
|
+
# res << "dst = "
|
2116
|
+
# self.child.to_c(res,level)
|
2117
|
+
# res << ";\n"
|
2118
|
+
# else
|
2119
|
+
# raise "Invalid unary operator: #{self.operator}."
|
2120
|
+
# end
|
2121
|
+
# # Restore the value pool state.
|
2122
|
+
# res << (" " * ((level+1)*3))
|
2123
|
+
# res << "set_value_pos(pool_state);\n"
|
2124
|
+
# # Close the computation
|
2125
|
+
# res << (" " * (level*3))
|
2126
|
+
# res << "dst; })"
|
2127
|
+
|
2128
|
+
# return res
|
2129
|
+
# end
|
1653
2130
|
# Generates the C text of the equivalent HDLRuby code.
|
1654
2131
|
# +level+ is the hierachical level of the object.
|
1655
|
-
def to_c(level = 0)
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
# And allocates a new value for dst unless the operator
|
1662
|
-
# is +@ that does not compute anything.
|
1663
|
-
res << (" " * ((level+1)*3))
|
1664
|
-
res << "dst = get_value();\n"
|
2132
|
+
# def to_c(level = 0)
|
2133
|
+
def to_c(res,level = 0)
|
2134
|
+
if (self.operator == :+@) then
|
2135
|
+
# No computation required.
|
2136
|
+
self.child.to_c(res,level)
|
2137
|
+
return res
|
1665
2138
|
end
|
1666
|
-
#
|
1667
|
-
|
1668
|
-
res << "
|
1669
|
-
#
|
1670
|
-
res
|
1671
|
-
res << "
|
1672
|
-
res << ("
|
2139
|
+
# Some computation required.
|
2140
|
+
# Save the value pool state.
|
2141
|
+
res << (" " * (level*3)) << "PV;\n"
|
2142
|
+
# Generate the child.
|
2143
|
+
self.child.to_c(res,level)
|
2144
|
+
res << (" " * (level*3))
|
2145
|
+
res << "unary("
|
2146
|
+
# Adds the operation
|
1673
2147
|
case self.operator
|
1674
2148
|
when :~ then
|
1675
|
-
res
|
2149
|
+
res << "¬_value"
|
1676
2150
|
when :-@ then
|
1677
|
-
res
|
1678
|
-
when :+@ then
|
1679
|
-
res += "dst = #{self.child.to_c(level)};\n"
|
2151
|
+
res << "&neg_value"
|
1680
2152
|
else
|
1681
2153
|
raise "Invalid unary operator: #{self.operator}."
|
1682
2154
|
end
|
2155
|
+
res << ");\n"
|
1683
2156
|
# Restore the value pool state.
|
1684
|
-
res << (" " * (
|
1685
|
-
res << "set_value_pos(pool_state);\n"
|
1686
|
-
# Close the computation
|
1687
|
-
res << (" " * (level*3))
|
1688
|
-
res << "dst; })"
|
2157
|
+
res << (" " * (level*3)) << "RV;\n"
|
1689
2158
|
|
1690
2159
|
return res
|
1691
2160
|
end
|
@@ -1695,78 +2164,147 @@ module HDLRuby::Low
|
|
1695
2164
|
## Extends the Binary class with generation of C text.
|
1696
2165
|
class Binary
|
1697
2166
|
|
2167
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2168
|
+
# # +level+ is the hierachical level of the object.
|
2169
|
+
# # def to_c(level = 0)
|
2170
|
+
# def to_c(res, level = 0)
|
2171
|
+
# # res = "({\n"
|
2172
|
+
# res << "({\n"
|
2173
|
+
# # Overrides the upper src0, src1 and dst...
|
2174
|
+
# # And allocates a new value for dst.
|
2175
|
+
# res << (" " * ((level+1)*3))
|
2176
|
+
# res << "Value src0,src1,dst = get_value();\n"
|
2177
|
+
# # Save the state of the value pool.
|
2178
|
+
# res << (" " * ((level+1)*3))
|
2179
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2180
|
+
# # Compute the left.
|
2181
|
+
# res << (" " * ((level+1)*3))
|
2182
|
+
# # res << "src0 = " << self.left.to_c(level+2) << ";\n"
|
2183
|
+
# res << "src0 = "
|
2184
|
+
# self.left.to_c(res,level+2)
|
2185
|
+
# res << ";\n"
|
2186
|
+
# # Compute the right.
|
2187
|
+
# res << (" " * ((level+1)*3))
|
2188
|
+
# # res << "src1 = " << self.right.to_c(level+2) << ";\n"
|
2189
|
+
# res << "src1 = "
|
2190
|
+
# self.right.to_c(res,level+2)
|
2191
|
+
# res << ";\n"
|
2192
|
+
# res << (" " * ((level+1)*3))
|
2193
|
+
|
2194
|
+
# # Compute the current binary operation.
|
2195
|
+
# case self.operator
|
2196
|
+
# when :+ then
|
2197
|
+
# res << "dst = add_value(src0,src1,dst);\n"
|
2198
|
+
# when :- then
|
2199
|
+
# res << "dst = sub_value(src0,src1,dst);\n"
|
2200
|
+
# when :* then
|
2201
|
+
# res << "dst = mul_value(src0,src1,dst);\n"
|
2202
|
+
# when :/ then
|
2203
|
+
# res << "dst = div_value(src0,src1,dst);\n"
|
2204
|
+
# when :% then
|
2205
|
+
# res << "dst = mod_value(src0,src1,dst);\n"
|
2206
|
+
# when :** then
|
2207
|
+
# res << "dst = pow_value(src0,src1,dst);\n"
|
2208
|
+
# when :& then
|
2209
|
+
# res << "dst = and_value(src0,src1,dst);\n"
|
2210
|
+
# when :| then
|
2211
|
+
# res << "dst = or_value(src0,src1,dst);\n"
|
2212
|
+
# when :^ then
|
2213
|
+
# res << "dst = xor_value(src0,src1,dst);\n"
|
2214
|
+
# when :<<,:ls then
|
2215
|
+
# res << "dst = shift_left_value(src0,src1,dst);\n"
|
2216
|
+
# when :>>,:rs then
|
2217
|
+
# res << "dst = shift_right_value(src0,src1,dst);\n"
|
2218
|
+
# when :lr then
|
2219
|
+
# res << "dst = rotate_left_value(src0,src1,dst);\n"
|
2220
|
+
# when :rr then
|
2221
|
+
# res << "dst = rotate_right_value(src0,src1,dst);\n"
|
2222
|
+
# when :== then
|
2223
|
+
# res << "dst = equal_value(src0,src1,dst);\n"
|
2224
|
+
# res << "dst = reduce_or_value(dst,dst);"
|
2225
|
+
# when :!= then
|
2226
|
+
# res << "dst = xor_value(src0,src1,dst);\n"
|
2227
|
+
# res << "dst = reduce_or_value(dst,dst);"
|
2228
|
+
# when :> then
|
2229
|
+
# res << "dst = greater_value(src0,src1,dst);\n"
|
2230
|
+
# when :< then
|
2231
|
+
# res << "dst = lesser_value(src0,src1,dst);\n"
|
2232
|
+
# when :>= then
|
2233
|
+
# res << "dst = greater_equal_value(src0,src1,dst);\n"
|
2234
|
+
# when :<= then
|
2235
|
+
# res << "dst = lesser_equal_value(src0,src1,dst);\n"
|
2236
|
+
# else
|
2237
|
+
# raise "Invalid binary operator: #{self.operator}."
|
2238
|
+
# end
|
2239
|
+
# # Restore the state of the value pool.
|
2240
|
+
# res << (" " * ((level+1)*3))
|
2241
|
+
# res << "set_value_pos(pool_state);\n"
|
2242
|
+
# # Close the computation.
|
2243
|
+
# res << (" " * (level*3))
|
2244
|
+
# res << "dst;})"
|
2245
|
+
|
2246
|
+
# return res
|
2247
|
+
# end
|
1698
2248
|
# Generates the C text of the equivalent HDLRuby code.
|
1699
2249
|
# +level+ is the hierachical level of the object.
|
1700
|
-
def to_c(level = 0)
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
#
|
1705
|
-
res
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
res << "
|
1710
|
-
|
1711
|
-
|
1712
|
-
res << "src0 = #{self.left.to_c(level+2)};\n"
|
1713
|
-
# Compute the right.
|
1714
|
-
res << (" " * ((level+1)*3))
|
1715
|
-
res << "src1 = #{self.right.to_c(level+2)};\n"
|
1716
|
-
res << (" " * ((level+1)*3))
|
1717
|
-
|
1718
|
-
# Compute the current binary operation.
|
2250
|
+
# def to_c(level = 0)
|
2251
|
+
def to_c(res, level = 0)
|
2252
|
+
# Save the value pool state.
|
2253
|
+
res << (" " * (level*3)) << "PV;\n"
|
2254
|
+
# Generate the left computation.
|
2255
|
+
self.left.to_c(res,level)
|
2256
|
+
# Generate the right computation.
|
2257
|
+
self.right.to_c(res,level)
|
2258
|
+
# Generate the binary.
|
2259
|
+
res << (" " * (level*3))
|
2260
|
+
res << "binary("
|
2261
|
+
# Set the operation.
|
1719
2262
|
case self.operator
|
1720
2263
|
when :+ then
|
1721
|
-
res
|
2264
|
+
res << "&add_value"
|
1722
2265
|
when :- then
|
1723
|
-
res
|
2266
|
+
res << "&sub_value"
|
1724
2267
|
when :* then
|
1725
|
-
res
|
2268
|
+
res << "&mul_value"
|
1726
2269
|
when :/ then
|
1727
|
-
res
|
2270
|
+
res << "&div_value"
|
1728
2271
|
when :% then
|
1729
|
-
res
|
2272
|
+
res << "&mod_value"
|
1730
2273
|
when :** then
|
1731
|
-
res
|
2274
|
+
res << "&pow_value"
|
1732
2275
|
when :& then
|
1733
|
-
res
|
2276
|
+
res << "&and_value"
|
1734
2277
|
when :| then
|
1735
|
-
res
|
2278
|
+
res << "&or_value"
|
1736
2279
|
when :^ then
|
1737
|
-
res
|
2280
|
+
res << "&xor_value"
|
1738
2281
|
when :<<,:ls then
|
1739
|
-
res
|
2282
|
+
res << "&shift_left_value"
|
1740
2283
|
when :>>,:rs then
|
1741
|
-
res
|
2284
|
+
res << "&shift_right_value"
|
1742
2285
|
when :lr then
|
1743
|
-
res
|
2286
|
+
res << "&rotate_left_value"
|
1744
2287
|
when :rr then
|
1745
|
-
res
|
2288
|
+
res << "&rotate_right_value"
|
1746
2289
|
when :== then
|
1747
|
-
res
|
1748
|
-
"dst = reduce_or_value(dst,dst);"
|
2290
|
+
res << "&equal_value_c"
|
1749
2291
|
when :!= then
|
1750
|
-
|
1751
|
-
res += "dst = xor_value(src0,src1,dst);\n" +
|
1752
|
-
"dst = reduce_or_value(dst,dst);"
|
2292
|
+
res << "¬_equal_value_c"
|
1753
2293
|
when :> then
|
1754
|
-
res
|
2294
|
+
res << "&greater_value"
|
1755
2295
|
when :< then
|
1756
|
-
res
|
2296
|
+
res << "&lesser_value"
|
1757
2297
|
when :>= then
|
1758
|
-
res
|
2298
|
+
res << "&greater_equal_value"
|
1759
2299
|
when :<= then
|
1760
|
-
res
|
2300
|
+
res << "&lesser_equal_value"
|
1761
2301
|
else
|
1762
2302
|
raise "Invalid binary operator: #{self.operator}."
|
1763
2303
|
end
|
1764
|
-
# Restore the state of the value pool.
|
1765
|
-
res << (" " * ((level+1)*3))
|
1766
|
-
res << "set_value_pos(pool_state);\n"
|
1767
2304
|
# Close the computation.
|
1768
|
-
res <<
|
1769
|
-
|
2305
|
+
res << ");\n"
|
2306
|
+
# Restore the value pool state.
|
2307
|
+
res << (" " * (level*3)) << "RV;\n"
|
1770
2308
|
|
1771
2309
|
return res
|
1772
2310
|
end
|
@@ -1775,103 +2313,200 @@ module HDLRuby::Low
|
|
1775
2313
|
## Extends the Select class with generation of C text.
|
1776
2314
|
class Select
|
1777
2315
|
|
2316
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2317
|
+
# # +level+ is the hierachical level of the object.
|
2318
|
+
# # def to_c(level = 0)
|
2319
|
+
# def to_c(res,level = 0)
|
2320
|
+
# # Gather the possible selection choices.
|
2321
|
+
# expressions = self.each_choice.to_a
|
2322
|
+
# # Create the resulting string.
|
2323
|
+
# # res = "({\n"
|
2324
|
+
# res << "({\n"
|
2325
|
+
# # Overrides the upper sel, src0, src1, ..., and dst...
|
2326
|
+
# # And allocates a new value for dst.
|
2327
|
+
# res << (" " * ((level+1)*3))
|
2328
|
+
# res << "Value sel;\n"
|
2329
|
+
# res << (" " * ((level+1)*3))
|
2330
|
+
# res << "Value "
|
2331
|
+
# res << expressions.size.times.map do |i|
|
2332
|
+
# "src#{i}"
|
2333
|
+
# end.join(",")
|
2334
|
+
# res << ";\n"
|
2335
|
+
# res << (" " * ((level+1)*3))
|
2336
|
+
# res << "Value dst = get_value();\n"
|
2337
|
+
# # Save the state of the value pool.
|
2338
|
+
# res << (" " * ((level+1)*3))
|
2339
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2340
|
+
# # Compute the selection.
|
2341
|
+
# res << (" " * ((level+1)*3))
|
2342
|
+
# # res << "sel = #{self.select.to_c(level+2)};\n"
|
2343
|
+
# res << "sel = "
|
2344
|
+
# self.select.to_c(res,level+2)
|
2345
|
+
# res << ";\n"
|
2346
|
+
# # Compute each choice expression.
|
2347
|
+
# expressions.each_with_index do |expr,i|
|
2348
|
+
# res << (" " * ((level+1)*3))
|
2349
|
+
# # res << "src#{i} = #{expr.to_c(level+2)};\n"
|
2350
|
+
# res << "src#{i} = "
|
2351
|
+
# expr.to_c(res,level+2)
|
2352
|
+
# res << ";\n"
|
2353
|
+
# end
|
2354
|
+
# # Compute the resulting selection.
|
2355
|
+
# res << (" " * ((level+1)*3))
|
2356
|
+
# res << "select_value(sel,dst,#{expressions.size},"
|
2357
|
+
# # res << "#{expressions.size.times.map { |i| "src#{i}" }.join(",")}"
|
2358
|
+
# res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
2359
|
+
# res << ");\n"
|
2360
|
+
# # Restore the state of the value pool.
|
2361
|
+
# res << (" " * ((level+1)*3))
|
2362
|
+
# res << "set_value_pos(pool_state);\n"
|
2363
|
+
# # Close the computation.
|
2364
|
+
# res << (" " * (level*3))
|
2365
|
+
# res << "dst; })"
|
2366
|
+
# return res
|
2367
|
+
# end
|
1778
2368
|
# Generates the C text of the equivalent HDLRuby code.
|
1779
2369
|
# +level+ is the hierachical level of the object.
|
1780
|
-
def to_c(level = 0)
|
2370
|
+
def to_c(res,level = 0)
|
2371
|
+
# Save the value pool state.
|
2372
|
+
res << (" " * (level*3)) << "PV;\n"
|
1781
2373
|
# Gather the possible selection choices.
|
1782
2374
|
expressions = self.each_choice.to_a
|
1783
2375
|
# Create the resulting string.
|
1784
|
-
# res = " " * (level*3)
|
1785
|
-
res = "({\n"
|
1786
|
-
# Overrides the upper sel, src0, src1, ..., and dst...
|
1787
|
-
# And allocates a new value for dst.
|
1788
|
-
res << (" " * ((level+1)*3))
|
1789
|
-
res << "Value sel;\n"
|
1790
|
-
res << (" " * ((level+1)*3))
|
1791
|
-
res << "Value #{expressions.size.times.map do |i|
|
1792
|
-
"src#{i}"
|
1793
|
-
end.join(",")};\n"
|
1794
|
-
res << (" " * ((level+1)*3))
|
1795
|
-
res << "Value dst = get_value();\n"
|
1796
|
-
# Save the state of the value pool.
|
1797
|
-
res << (" " * ((level+1)*3))
|
1798
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
1799
2376
|
# Compute the selection.
|
1800
|
-
res
|
1801
|
-
res << "sel = #{self.select.to_c(level+2)};\n"
|
2377
|
+
self.select.to_c(res,level)
|
1802
2378
|
# Compute each choice expression.
|
1803
2379
|
expressions.each_with_index do |expr,i|
|
1804
|
-
res
|
1805
|
-
res << "src#{i} = #{expr.to_c(level+2)};\n"
|
2380
|
+
expr.to_c(res,level)
|
1806
2381
|
end
|
1807
2382
|
# Compute the resulting selection.
|
1808
|
-
res << (" " * ((level+1)*3))
|
1809
|
-
res << "select_value(sel,dst,#{expressions.size},"
|
1810
|
-
res << "#{expressions.size.times.map { |i| "src#{i}" }.join(",")}"
|
1811
|
-
res << ");\n"
|
1812
|
-
# Restore the state of the value pool.
|
1813
|
-
res << (" " * ((level+1)*3))
|
1814
|
-
res << "set_value_pos(pool_state);\n"
|
1815
|
-
# Close the computation.
|
1816
2383
|
res << (" " * (level*3))
|
1817
|
-
res << "
|
2384
|
+
res << "select(#{expressions.size});\n"
|
2385
|
+
# Restore the value pool state.
|
2386
|
+
res << (" " * (level*3)) << "RV;\n"
|
2387
|
+
return res
|
1818
2388
|
end
|
1819
2389
|
end
|
1820
2390
|
|
1821
2391
|
## Extends the Concat class with generation of C text.
|
1822
2392
|
class Concat
|
1823
2393
|
|
1824
|
-
|
2394
|
+
|
2395
|
+
# # Generates the C text for the equivalent HDLRuby code.
|
2396
|
+
# # +level+ is the hierachical level of the object.
|
2397
|
+
# def to_c(res,level = 0)
|
2398
|
+
# # Gather the content to concat.
|
2399
|
+
# expressions = self.each_expression.to_a
|
2400
|
+
# # Create the resulting string.
|
2401
|
+
# res << "({\n"
|
2402
|
+
# # Overrides the upper src0, src1, ..., and dst...
|
2403
|
+
# # And allocates a new value for dst.
|
2404
|
+
# res << (" " * ((level+1)*3))
|
2405
|
+
# res << "Value "
|
2406
|
+
# res << expressions.size.times.map do |i|
|
2407
|
+
# "src#{i}"
|
2408
|
+
# end.join(",")
|
2409
|
+
# res << ";\n"
|
2410
|
+
# res << (" " * ((level+1)*3))
|
2411
|
+
# res << "Value dst = get_value();\n"
|
2412
|
+
# # Save the state of the value pool.
|
2413
|
+
# res << (" " * ((level+1)*3))
|
2414
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2415
|
+
# # Compute each sub expression.
|
2416
|
+
# expressions.each_with_index do |expr,i|
|
2417
|
+
# res << (" " * ((level+1)*3))
|
2418
|
+
# res << "src#{i} = "
|
2419
|
+
# expr.to_c_expr(res,level+2)
|
2420
|
+
# res << ";\n"
|
2421
|
+
# end
|
2422
|
+
# # Compute the direction.
|
2423
|
+
# # Compute the resulting concatenation.
|
2424
|
+
# res << (" " * ((level+1)*3))
|
2425
|
+
# res << "concat_value(#{expressions.size},"
|
2426
|
+
# res << "#{self.type.direction == :little ? 1 : 0},dst,"
|
2427
|
+
# res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
2428
|
+
# res << ");\n"
|
2429
|
+
# # Restore the state of the value pool.
|
2430
|
+
# res << (" " * ((level+1)*3))
|
2431
|
+
# res << "set_value_pos(pool_state);\n"
|
2432
|
+
# # Close the computation.
|
2433
|
+
# res << (" " * (level*3))
|
2434
|
+
# res << "dst; })"
|
2435
|
+
# return res
|
2436
|
+
# end
|
2437
|
+
# Generates the C text for the equivalent HDLRuby code.
|
2438
|
+
# +level+ is the hierachical level of the object.
|
2439
|
+
def to_c(res,level = 0)
|
2440
|
+
# Save the value pool state.
|
2441
|
+
res << (" " * (level*3)) << "PV;\n"
|
2442
|
+
# Gather the content to concat.
|
2443
|
+
expressions = self.each_expression.to_a
|
2444
|
+
# Compute each sub expression.
|
2445
|
+
expressions.each_with_index do |expr,i|
|
2446
|
+
expr.to_c(res,level+2)
|
2447
|
+
end
|
2448
|
+
# Compute the resulting concatenation.
|
2449
|
+
res << (" " * ((level+1)*3))
|
2450
|
+
res << "sconcat(#{expressions.size},"
|
2451
|
+
res << (self.type.direction == :little ? "1" : "0")
|
2452
|
+
res << ");\n"
|
2453
|
+
# Restore the value pool state.
|
2454
|
+
res << (" " * (level*3)) << "RV;\n"
|
2455
|
+
return res
|
2456
|
+
end
|
2457
|
+
|
2458
|
+
# Generates the C text of expression for the equivalent HDLRuby code.
|
1825
2459
|
# +level+ is the hierachical level of the object.
|
1826
|
-
def
|
2460
|
+
def to_c_expr(res,level = 0)
|
1827
2461
|
# Gather the content to concat.
|
1828
2462
|
expressions = self.each_expression.to_a
|
1829
2463
|
# Create the resulting string.
|
1830
|
-
|
1831
|
-
res = "({\n"
|
2464
|
+
res << "({\n"
|
1832
2465
|
# Overrides the upper src0, src1, ..., and dst...
|
1833
2466
|
# And allocates a new value for dst.
|
1834
2467
|
res << (" " * ((level+1)*3))
|
1835
|
-
res << "Value
|
2468
|
+
res << "Value "
|
2469
|
+
res << expressions.size.times.map do |i|
|
1836
2470
|
"src#{i}"
|
1837
|
-
end.join(",")
|
2471
|
+
end.join(",")
|
2472
|
+
res << ";\n"
|
1838
2473
|
res << (" " * ((level+1)*3))
|
1839
2474
|
res << "Value dst = get_value();\n"
|
1840
|
-
# Save the
|
1841
|
-
res << (" " * (
|
1842
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
2475
|
+
# Save the value pool state.
|
2476
|
+
res << (" " * (level*3)) << "SV;\n"
|
1843
2477
|
# Compute each sub expression.
|
1844
2478
|
expressions.each_with_index do |expr,i|
|
1845
2479
|
res << (" " * ((level+1)*3))
|
1846
|
-
res << "src#{i} =
|
2480
|
+
res << "src#{i} = "
|
2481
|
+
expr.to_c_expr(res,level+2)
|
2482
|
+
res << ";\n"
|
1847
2483
|
end
|
1848
2484
|
# Compute the direction.
|
1849
2485
|
# Compute the resulting concatenation.
|
1850
2486
|
res << (" " * ((level+1)*3))
|
1851
2487
|
res << "concat_value(#{expressions.size},"
|
1852
2488
|
res << "#{self.type.direction == :little ? 1 : 0},dst,"
|
1853
|
-
res <<
|
2489
|
+
res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
1854
2490
|
res << ");\n"
|
1855
|
-
#
|
1856
|
-
res << (" " * (
|
1857
|
-
res << "set_value_pos(pool_state);\n"
|
2491
|
+
# Save the value pool state.
|
2492
|
+
res << (" " * (level*3)) << "SV;\n"
|
1858
2493
|
# Close the computation.
|
1859
2494
|
res << (" " * (level*3))
|
1860
2495
|
res << "dst; })"
|
1861
|
-
|
1862
2496
|
return res
|
1863
|
-
|
1864
2497
|
end
|
1865
2498
|
end
|
1866
2499
|
|
1867
2500
|
|
2501
|
+
|
1868
2502
|
## Extends the Ref class with generation of C text.
|
1869
2503
|
class Ref
|
1870
2504
|
|
1871
2505
|
# Generates the C text of the equivalent HDLRuby code.
|
1872
2506
|
# +level+ is the hierachical level of the object and
|
1873
2507
|
# +left+ tells if it is a left value or not.
|
1874
|
-
def to_c(level = 0, left = false)
|
2508
|
+
# def to_c(level = 0, left = false)
|
2509
|
+
def to_c(res,level = 0, left = false)
|
1875
2510
|
# Should never be here.
|
1876
2511
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1877
2512
|
end
|
@@ -1884,7 +2519,8 @@ module HDLRuby::Low
|
|
1884
2519
|
# Generates the C text of the equivalent HDLRuby code.
|
1885
2520
|
# +level+ is the hierachical level of the object and
|
1886
2521
|
# +left+ tells if it is a left value or not.
|
1887
|
-
def to_c(level = 0, left = false)
|
2522
|
+
# def to_c(level = 0, left = false)
|
2523
|
+
def to_c(res,level = 0, left = false)
|
1888
2524
|
raise "RefConcat cannot be converted to C directly, please use break_concat_assign!."
|
1889
2525
|
# # The resulting string.
|
1890
2526
|
# res = "ref_concat(#{self.each_ref.to_a.size}"
|
@@ -1897,7 +2533,8 @@ module HDLRuby::Low
|
|
1897
2533
|
|
1898
2534
|
# Generates the C text for reference as left value to a signal.
|
1899
2535
|
# +level+ is the hierarchical level of the object.
|
1900
|
-
def to_c_signal(level = 0)
|
2536
|
+
# def to_c_signal(level = 0)
|
2537
|
+
def to_c_signal(res,level = 0)
|
1901
2538
|
raise "RefConcat cannot be converted to C directly, please use break_concat_assign!."
|
1902
2539
|
# # The resulting string.
|
1903
2540
|
# res = "sig_concat(#{self.each_ref.to_a.size}"
|
@@ -1913,44 +2550,109 @@ module HDLRuby::Low
|
|
1913
2550
|
## Extends the RefIndex class with generation of C text.
|
1914
2551
|
class RefIndex
|
1915
2552
|
|
2553
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2554
|
+
# # +level+ is thehierachical level of the object and
|
2555
|
+
# # +left+ tells if it is a left value or not.
|
2556
|
+
# # def to_c(level = 0, left = false)
|
2557
|
+
# def to_c(res,level = 0, left = false)
|
2558
|
+
# # res = "({\n"
|
2559
|
+
# res << "({\n"
|
2560
|
+
# # And allocates a new value for dst.
|
2561
|
+
# res << (" " * ((level+1)*3))
|
2562
|
+
# res << "Value ref,dst = get_value();\n"
|
2563
|
+
# res << (" " * ((level+1)*3))
|
2564
|
+
# res << "unsigned long long idx;\n"
|
2565
|
+
# # Save the state of the value pool.
|
2566
|
+
# res << (" " * ((level+1)*3))
|
2567
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2568
|
+
# # Compute the reference.
|
2569
|
+
# res << (" " * ((level+1)*3))
|
2570
|
+
# # res << "ref = #{self.ref.to_c(level+2)};\n"
|
2571
|
+
# res << "ref = "
|
2572
|
+
# self.ref.to_c(res,level+2)
|
2573
|
+
# res << ";\n"
|
2574
|
+
# # Compute the index.
|
2575
|
+
# res << (" " * ((level+1)*3))
|
2576
|
+
# # res << "idx = value2integer(#{self.index.to_c(level+2)});\n"
|
2577
|
+
# res << "idx = value2integer("
|
2578
|
+
# self.index.to_c(res,level+2)
|
2579
|
+
# res << ");\n"
|
2580
|
+
# # Make the access.
|
2581
|
+
# res << (" " * ((level+1)*3))
|
2582
|
+
# # puts "self.type.width=#{self.type.width}"
|
2583
|
+
# # res << "dst = read_range(ref,idx,idx,#{self.type.to_c(level)},dst);\n"
|
2584
|
+
# res << "dst = read_range(ref,idx,idx,"
|
2585
|
+
# # res << self.type.to_c(level)
|
2586
|
+
# self.type.to_c(res,level)
|
2587
|
+
# res << ",dst);\n"
|
2588
|
+
# # Restore the state of the value pool.
|
2589
|
+
# res << (" " * ((level+1)*3))
|
2590
|
+
# res << "set_value_pos(pool_state);\n"
|
2591
|
+
# # Close the computation.
|
2592
|
+
# res << (" " * (level*3))
|
2593
|
+
# res << "dst; })"
|
2594
|
+
# return res
|
2595
|
+
# end
|
1916
2596
|
# Generates the C text of the equivalent HDLRuby code.
|
1917
2597
|
# +level+ is thehierachical level of the object and
|
1918
2598
|
# +left+ tells if it is a left value or not.
|
1919
|
-
def to_c(level = 0, left = false)
|
1920
|
-
|
1921
|
-
|
1922
|
-
res << (" " * ((level+1)*3))
|
1923
|
-
res << "Value ref,dst = get_value();\n"
|
1924
|
-
res << (" " * ((level+1)*3))
|
1925
|
-
res << "unsigned long long idx;\n"
|
1926
|
-
# Save the state of the value pool.
|
1927
|
-
res << (" " * ((level+1)*3))
|
1928
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
2599
|
+
def to_c(res,level = 0, left = false)
|
2600
|
+
# Save the value pool state.
|
2601
|
+
res << (" " * (level*3)) << "PV;\n"
|
1929
2602
|
# Compute the reference.
|
1930
|
-
res
|
1931
|
-
res << "ref = #{self.ref.to_c(level+2)};\n"
|
2603
|
+
self.ref.to_c(res,level)
|
1932
2604
|
# Compute the index.
|
1933
|
-
res
|
1934
|
-
res << "
|
2605
|
+
self.index.to_c(res,level)
|
2606
|
+
res << (" " * (level*3))
|
1935
2607
|
# Make the access.
|
1936
|
-
res << (" " * ((level+1)*3))
|
1937
|
-
# puts "self.type.width=#{self.type.width}"
|
1938
|
-
res << "dst = read_range(ref,idx,idx,#{self.type.to_c(level)},dst);\n"
|
1939
|
-
# Restore the state of the value pool.
|
1940
|
-
res << (" " * ((level+1)*3))
|
1941
|
-
res << "set_value_pos(pool_state);\n"
|
1942
|
-
# Close the computation.
|
1943
2608
|
res << (" " * (level*3))
|
1944
|
-
|
2609
|
+
if (left) then
|
2610
|
+
res << "swriteI("
|
2611
|
+
else
|
2612
|
+
res << "sreadI("
|
2613
|
+
end
|
2614
|
+
self.type.to_c(res,level)
|
2615
|
+
res << ");\n"
|
2616
|
+
# Restore the value pool state.
|
2617
|
+
res << (" " * (level*3)) << "RV;\n"
|
2618
|
+
return res
|
1945
2619
|
end
|
1946
2620
|
|
2621
|
+
# # Generates the C text for reference as left value to a signal.
|
2622
|
+
# # +level+ is the hierarchical level of the object.
|
2623
|
+
# # def to_c_signal(level = 0)
|
2624
|
+
# def to_c_signal(res,level = 0)
|
2625
|
+
# # puts "to_c_signal for RefIndex"
|
2626
|
+
# res << "make_ref_rangeS("
|
2627
|
+
# self.ref.to_c_signal(res,level)
|
2628
|
+
# res << ","
|
2629
|
+
# self.type.to_c(res,level)
|
2630
|
+
# res << ",value2integer("
|
2631
|
+
# self.index.to_c(res,level)
|
2632
|
+
# res << "),value2integer("
|
2633
|
+
# self.index.to_c(res,level)
|
2634
|
+
# res << "))"
|
2635
|
+
# return res
|
2636
|
+
# end
|
1947
2637
|
# Generates the C text for reference as left value to a signal.
|
1948
2638
|
# +level+ is the hierarchical level of the object.
|
1949
|
-
def to_c_signal(level = 0)
|
2639
|
+
# def to_c_signal(level = 0)
|
2640
|
+
def to_c_signal(res,level = 0)
|
1950
2641
|
# puts "to_c_signal for RefIndex"
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
2642
|
+
res << "make_ref_rangeS("
|
2643
|
+
self.ref.to_c_signal(res,level)
|
2644
|
+
res << ","
|
2645
|
+
self.type.to_c(res,level)
|
2646
|
+
res << ",value2integer(({\n"
|
2647
|
+
self.index.to_c(res,level)
|
2648
|
+
res << " " * ((level+1)*3)
|
2649
|
+
res << "pop();})"
|
2650
|
+
res << "),value2integer(({\n"
|
2651
|
+
self.index.to_c(res,level)
|
2652
|
+
res << " " * ((level+1)*3)
|
2653
|
+
res << "pop();})"
|
2654
|
+
res << "))"
|
2655
|
+
return res
|
1954
2656
|
end
|
1955
2657
|
end
|
1956
2658
|
|
@@ -1958,51 +2660,112 @@ module HDLRuby::Low
|
|
1958
2660
|
## Extends the RefRange class with generation of C text.
|
1959
2661
|
class RefRange
|
1960
2662
|
|
1961
|
-
# Generates the C text of the equivalent HDLRuby code.
|
1962
|
-
# +level+ is the hierachical level of the object and
|
1963
|
-
# +left+ tells if it is a left value or not.
|
1964
|
-
def to_c(level = 0, left = false)
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
2663
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2664
|
+
# # +level+ is the hierachical level of the object and
|
2665
|
+
# # +left+ tells if it is a left value or not.
|
2666
|
+
# # def to_c(level = 0, left = false)
|
2667
|
+
# def to_c(res,level = 0, left = false)
|
2668
|
+
# # Decide if it is a read or a write
|
2669
|
+
# command = left ? "write" : "read"
|
2670
|
+
# # res = "({\n"
|
2671
|
+
# res << "({\n"
|
2672
|
+
# # Overrides the upper ref and dst...
|
2673
|
+
# # And allocates a new value for dst.
|
2674
|
+
# res << (" " * ((level+1)*3))
|
2675
|
+
# res << "Value ref,dst = get_value();\n"
|
2676
|
+
# res << (" " * ((level+1)*3))
|
2677
|
+
# res << "unsigned long long first,last;\n"
|
2678
|
+
# # Save the state of the value pool.
|
2679
|
+
# res << (" " * ((level+1)*3))
|
2680
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2681
|
+
# # Compute the reference.
|
2682
|
+
# res << (" " * ((level+1)*3))
|
2683
|
+
# # res << "ref = #{self.ref.to_c(level+2)};\n"
|
2684
|
+
# res << "ref = "
|
2685
|
+
# self.ref.to_c(res,level+2)
|
2686
|
+
# res << ";\n"
|
2687
|
+
# # Compute the range.
|
2688
|
+
# res << (" " * ((level+1)*3))
|
2689
|
+
# # res << "first = value2integer(#{self.range.first.to_c(level+2)});\n"
|
2690
|
+
# res << "first = value2integer("
|
2691
|
+
# self.range.first.to_c(res,level+2)
|
2692
|
+
# res << ");\n"
|
2693
|
+
# res << (" " * ((level+1)*3))
|
2694
|
+
# # res << "last = value2integer(#{self.range.last.to_c(level+2)});\n"
|
2695
|
+
# res << "last = value2integer("
|
2696
|
+
# self.range.last.to_c(res,level+2)
|
2697
|
+
# res << ");\n"
|
2698
|
+
# # Make the access.
|
2699
|
+
# res << (" " * ((level+1)*3))
|
2700
|
+
# # puts "#{command}_range with first=#{self.range.first} and last=#{self.range.last}"
|
2701
|
+
# # res << "dst = #{command}_range(ref,first,last,#{self.type.base.to_c(level)},dst);\n"
|
2702
|
+
# res << "dst = #{command}_range(ref,first,last,"
|
2703
|
+
# self.type.base.to_c(res,level)
|
2704
|
+
# res << ",dst);\n"
|
2705
|
+
# # Restore the state of the value pool.
|
2706
|
+
# res << (" " * ((level+1)*3))
|
2707
|
+
# res << "set_value_pos(pool_state);\n"
|
2708
|
+
# # Close the computation.
|
2709
|
+
# res << (" " * (level*3))
|
2710
|
+
# res << "dst; })"
|
2711
|
+
# return res
|
2712
|
+
# end
|
2713
|
+
def to_c(res,level = 0, left = false)
|
2714
|
+
# Save the value pool state.
|
2715
|
+
res << (" " * (level*3)) << "PV;\n"
|
1977
2716
|
# Compute the reference.
|
1978
|
-
res
|
1979
|
-
res << "
|
2717
|
+
self.ref.to_c(res,level)
|
2718
|
+
# res << (" " * (level*3))
|
1980
2719
|
# Compute the range.
|
1981
|
-
res
|
1982
|
-
|
1983
|
-
res << "first = value2integer(#{self.range.first.to_c(level+2)});\n"
|
1984
|
-
res << (" " * ((level+1)*3))
|
1985
|
-
# res << "last = read64(#{self.range.last.to_c(level+2)});\n"
|
1986
|
-
res << "last = value2integer(#{self.range.last.to_c(level+2)});\n"
|
2720
|
+
self.range.first.to_c(res,level)
|
2721
|
+
self.range.last.to_c(res,level)
|
1987
2722
|
# Make the access.
|
1988
|
-
res << (" " * ((level+1)*3))
|
1989
|
-
# res << "dst = #{command}_range(ref,first,last,#{self.ref.type.base.to_c(level)},dst);\n"
|
1990
|
-
# puts "#{command}_range with first=#{self.range.first} and last=#{self.range.last}"
|
1991
|
-
res << "dst = #{command}_range(ref,first,last,#{self.type.base.to_c(level)},dst);\n"
|
1992
|
-
# Restore the state of the value pool.
|
1993
|
-
res << (" " * ((level+1)*3))
|
1994
|
-
res << "set_value_pos(pool_state);\n"
|
1995
|
-
# Close the computation.
|
1996
2723
|
res << (" " * (level*3))
|
1997
|
-
|
2724
|
+
if left then
|
2725
|
+
res << "swriteR("
|
2726
|
+
else
|
2727
|
+
res << "sreadR("
|
2728
|
+
end
|
2729
|
+
self.type.base.to_c(res,level)
|
2730
|
+
res << ");\n"
|
2731
|
+
# Restore the value pool state.
|
2732
|
+
res << (" " * (level*3)) << "RV;\n"
|
2733
|
+
return res
|
1998
2734
|
end
|
1999
2735
|
|
2736
|
+
# # Generates the C text for reference as left value to a signal.
|
2737
|
+
# # +level+ is the hierarchical level of the object.
|
2738
|
+
# # def to_c_signal(level = 0)
|
2739
|
+
# def to_c_signal(res,level = 0)
|
2740
|
+
# # return "make_ref_rangeS(#{self.ref.to_c_signal(level)}," +
|
2741
|
+
# # "value2integer(#{self.range.first.to_c(level)}),value2integer(#{self.range.last.to_c(level)}))"
|
2742
|
+
# res << "make_ref_rangeS("
|
2743
|
+
# self.ref.to_c_signal(res,level)
|
2744
|
+
# res << ",value2integer("
|
2745
|
+
# self.range.first.to_c(res,level)
|
2746
|
+
# res << "),value2integer("
|
2747
|
+
# self.range.last.to_c(res,level)
|
2748
|
+
# res << "))"
|
2749
|
+
# return res
|
2750
|
+
# end
|
2000
2751
|
# Generates the C text for reference as left value to a signal.
|
2001
2752
|
# +level+ is the hierarchical level of the object.
|
2002
|
-
def to_c_signal(level = 0)
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2753
|
+
# def to_c_signal(level = 0)
|
2754
|
+
def to_c_signal(res,level = 0)
|
2755
|
+
res << "make_ref_rangeS("
|
2756
|
+
self.ref.to_c_signal(res,level)
|
2757
|
+
res << ","
|
2758
|
+
self.type.base.to_c(res,level)
|
2759
|
+
res << ",value2integer(({\n"
|
2760
|
+
self.range.first.to_c(res,level)
|
2761
|
+
res << " " * ((level+1)*3)
|
2762
|
+
res << "pop();})"
|
2763
|
+
res << "),value2integer(({\n"
|
2764
|
+
self.range.last.to_c(res,level)
|
2765
|
+
res << " " * ((level+1)*3)
|
2766
|
+
res << "pop();})"
|
2767
|
+
res << "))"
|
2768
|
+
return res
|
2006
2769
|
end
|
2007
2770
|
end
|
2008
2771
|
|
@@ -2013,17 +2776,31 @@ module HDLRuby::Low
|
|
2013
2776
|
# Generates the C text of the equivalent HDLRuby code.
|
2014
2777
|
# +level+ is the hierachical level of the object and
|
2015
2778
|
# +left+ tells if it is a left value or not.
|
2016
|
-
def to_c(level = 0, left = false)
|
2779
|
+
# def to_c(level = 0, left = false)
|
2780
|
+
def to_c(res,level = 0, left = false)
|
2781
|
+
# # puts "RefName to_c for #{self.name}"
|
2782
|
+
# self.resolve.to_c_signal(res,level+1)
|
2783
|
+
# res << "->" << (left ? "f_value" : "c_value")
|
2784
|
+
# return res
|
2017
2785
|
# puts "RefName to_c for #{self.name}"
|
2018
|
-
|
2019
|
-
|
2786
|
+
res << (" " * (level*3))
|
2787
|
+
# res << "d="
|
2788
|
+
res << "push("
|
2789
|
+
self.resolve.to_c_signal(res,level+1)
|
2790
|
+
res << "->" << (left ? "f_value" : "c_value")
|
2791
|
+
# res << ";\n"
|
2792
|
+
res << ");\n"
|
2793
|
+
return res
|
2020
2794
|
end
|
2021
2795
|
|
2022
2796
|
# Generates the C text for reference as left value to a signal.
|
2023
2797
|
# +level+ is the hierarchical level of the object.
|
2024
|
-
def to_c_signal(level = 0)
|
2798
|
+
# def to_c_signal(level = 0)
|
2799
|
+
def to_c_signal(res,level = 0)
|
2025
2800
|
# puts "to_c_signal with self=#{self.name}, resolve=#{self.resolve}"
|
2026
|
-
return "#{self.resolve.to_c_signal(level+1)}"
|
2801
|
+
# return "#{self.resolve.to_c_signal(level+1)}"
|
2802
|
+
self.resolve.to_c_signal(res,level+1)
|
2803
|
+
return res
|
2027
2804
|
end
|
2028
2805
|
end
|
2029
2806
|
|
@@ -2033,14 +2810,20 @@ module HDLRuby::Low
|
|
2033
2810
|
# Generates the C text of the equivalent HDLRuby code.
|
2034
2811
|
# +level+ is the hierachical level of the object and
|
2035
2812
|
# +left+ tells if it is a left value or not.
|
2036
|
-
def to_c(level = 0, left = false)
|
2037
|
-
|
2813
|
+
# def to_c(level = 0, left = false)
|
2814
|
+
def to_c(res,level = 0, left = false)
|
2815
|
+
# return "this()"
|
2816
|
+
res << "this()"
|
2817
|
+
return res
|
2038
2818
|
end
|
2039
2819
|
|
2040
2820
|
# Generates the C text for reference as left value to a signal.
|
2041
2821
|
# +level+ is the hierarchical level of the object.
|
2042
|
-
def to_c_signal(level = 0)
|
2043
|
-
|
2822
|
+
# def to_c_signal(level = 0)
|
2823
|
+
def to_c_signal(res,level = 0)
|
2824
|
+
# return "this()"
|
2825
|
+
res << "this()"
|
2826
|
+
return res
|
2044
2827
|
end
|
2045
2828
|
end
|
2046
2829
|
|