HDLRuby 2.6.24 → 2.6.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/HDLRuby/hdr_samples/case_bench.rb +30 -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/hdrcc.rb +38 -25
- data/lib/HDLRuby/hruby_high.rb +6 -0
- data/lib/HDLRuby/hruby_low.rb +11 -0
- data/lib/HDLRuby/hruby_low2c.rb +1338 -549
- 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 +109 -0
- data/lib/HDLRuby/sim/hruby_sim_calc.c +38 -9
- data/lib/HDLRuby/sim/hruby_sim_stack_calc.c +203 -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 +10 -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)) << "SV;\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,37 +1551,93 @@ 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 << "Value v=d;\n"
|
1269
1614
|
# Ensure the selection value is testable.
|
1270
|
-
res << " " * (level+1)*3
|
1271
|
-
res << "if (is_defined_value(
|
1615
|
+
res << " " * ((level+1)*3)
|
1616
|
+
res << "if (is_defined_value(v)) {\n"
|
1272
1617
|
# The condition is testable.
|
1273
1618
|
# Generate the case as a succession of if statements.
|
1274
1619
|
first = true
|
1275
1620
|
self.each_when do |w|
|
1276
|
-
res << " " * (level+2)*3
|
1621
|
+
res << " " * ((level+2)*3)
|
1277
1622
|
if first then
|
1278
1623
|
first = false
|
1279
1624
|
else
|
1280
1625
|
res << "else "
|
1281
1626
|
end
|
1282
|
-
res << "if (value2integer(
|
1283
|
-
res << "value2integer(
|
1284
|
-
res <<
|
1627
|
+
res << "if (value2integer(v) == "
|
1628
|
+
res << "value2integer(({\n"
|
1629
|
+
res << " " * ((level+2)*3)
|
1630
|
+
w.match.to_c(res,level+2)
|
1631
|
+
res << "d;})"
|
1632
|
+
res << ")) {\n"
|
1633
|
+
w.statement.to_c(res,level+3)
|
1285
1634
|
res << " " * (level+2)*3
|
1286
1635
|
res << "}\n"
|
1287
1636
|
end
|
1288
1637
|
if self.default then
|
1289
1638
|
res << " " * (level+2)*3
|
1290
1639
|
res << "else {\n"
|
1291
|
-
|
1640
|
+
self.default.to_c(res,level+3)
|
1292
1641
|
res << " " * (level+2)*3
|
1293
1642
|
res << "}\n"
|
1294
1643
|
end
|
@@ -1302,12 +1651,15 @@ module HDLRuby::Low
|
|
1302
1651
|
end
|
1303
1652
|
|
1304
1653
|
## Generates the content of the h file.
|
1305
|
-
def to_ch
|
1306
|
-
|
1654
|
+
# def to_ch
|
1655
|
+
def to_ch(res)
|
1656
|
+
# res = ""
|
1307
1657
|
# Recurse on the whens.
|
1308
|
-
self.each_when {|w| res << w.to_ch }
|
1658
|
+
# self.each_when {|w| res << w.to_ch }
|
1659
|
+
self.each_when {|w| w.to_ch(res) }
|
1309
1660
|
# Recurse on the default statement.
|
1310
|
-
res << self.default.to_ch if self.default
|
1661
|
+
# res << self.default.to_ch if self.default
|
1662
|
+
self.default.to_ch(res) if self.default
|
1311
1663
|
return res
|
1312
1664
|
end
|
1313
1665
|
end
|
@@ -1318,9 +1670,13 @@ module HDLRuby::Low
|
|
1318
1670
|
|
1319
1671
|
# Generates the C text of the equivalent HDLRuby code.
|
1320
1672
|
# +level+ is the hierachical level of the object.
|
1321
|
-
def to_c(level = 0)
|
1322
|
-
|
1323
|
-
|
1673
|
+
# def to_c(level = 0)
|
1674
|
+
def to_c(res,level = 0)
|
1675
|
+
# return "make_delay(#{self.value.to_s}," +
|
1676
|
+
# "#{Low2C.unit_name(self.unit)})"
|
1677
|
+
res << "make_delay(#{self.value.to_s},"
|
1678
|
+
res << Low2C.unit_name(self.unit) << ")"
|
1679
|
+
return res
|
1324
1680
|
end
|
1325
1681
|
end
|
1326
1682
|
|
@@ -1330,12 +1686,17 @@ module HDLRuby::Low
|
|
1330
1686
|
|
1331
1687
|
# Generates the C text of the equivalent HDLRuby code.
|
1332
1688
|
# +level+ is the hierachical level of the object.
|
1333
|
-
def to_c(level = 0)
|
1689
|
+
# def to_c(level = 0)
|
1690
|
+
def to_c(res,level = 0)
|
1334
1691
|
# The resulting string.
|
1335
|
-
res = " " * level*3
|
1692
|
+
# res = " " * level*3
|
1693
|
+
res << " " * level*3
|
1336
1694
|
# Generate the wait.
|
1337
|
-
res << "hw_wait(#{self.delay.to_c(level+1)}," +
|
1338
|
-
|
1695
|
+
# res << "hw_wait(#{self.delay.to_c(level+1)}," +
|
1696
|
+
# "#{Low2C.behavior_access(self)});\n"
|
1697
|
+
res << "hw_wait("
|
1698
|
+
self.delay.to_c(res,level+1)
|
1699
|
+
res << "," << Low2C.behavior_access(self) << ");\n"
|
1339
1700
|
# Return the resulting string.
|
1340
1701
|
return res
|
1341
1702
|
end
|
@@ -1346,13 +1707,17 @@ module HDLRuby::Low
|
|
1346
1707
|
|
1347
1708
|
# Generates the C text of the equivalent HDLRuby code.
|
1348
1709
|
# +level+ is the hierachical level of the object.
|
1349
|
-
def to_c(level = 0)
|
1710
|
+
# def to_c(level = 0)
|
1711
|
+
def to_c(res,level = 0)
|
1350
1712
|
# The resulting string.
|
1351
|
-
res = " " * level*3
|
1713
|
+
# res = " " * level*3
|
1714
|
+
res << " " * level*3
|
1352
1715
|
# Generate an infinite loop executing the block and waiting.
|
1353
1716
|
res << "for(;;) {\n"
|
1354
|
-
res << "#{self.to_c(level+1)}\n"
|
1355
|
-
res
|
1717
|
+
# res << "#{self.statement.to_c(level+1)}\n"
|
1718
|
+
self.statement.to_c(res,level+1)
|
1719
|
+
res << "\n"
|
1720
|
+
res << " " * (level+1)*3
|
1356
1721
|
res << Low2C.wait_code(self,level)
|
1357
1722
|
# Return the resulting string.
|
1358
1723
|
return res
|
@@ -1364,24 +1729,27 @@ module HDLRuby::Low
|
|
1364
1729
|
|
1365
1730
|
# Adds the c code of the blocks to +res+ at +level+
|
1366
1731
|
def add_blocks_code(res,level)
|
1367
|
-
res << self.to_c_code(level)
|
1732
|
+
# res << self.to_c_code(level)
|
1733
|
+
self.to_c_code(res,level)
|
1734
|
+
return res
|
1368
1735
|
end
|
1369
1736
|
|
1370
1737
|
# Adds the creation of the blocks to +res+ at +level+.
|
1371
1738
|
def add_make_block(res,level)
|
1372
1739
|
res << " " * level*3
|
1373
|
-
res <<
|
1740
|
+
res << Low2C.make_name(self) << "();\n"
|
1374
1741
|
end
|
1375
1742
|
|
1376
1743
|
# Generates the C text of the equivalent HDLRuby code.
|
1377
1744
|
# +level+ is the hierachical level of the object.
|
1378
|
-
def to_c_code(level = 0)
|
1745
|
+
# def to_c_code(level = 0)
|
1746
|
+
def to_c_code(res,level = 0)
|
1379
1747
|
# The resulting string.
|
1380
|
-
res = ""
|
1748
|
+
# res = ""
|
1381
1749
|
# puts "generating self=#{self.object_id}"
|
1382
1750
|
|
1383
1751
|
# Declare the global variable holding the block.
|
1384
|
-
res << "Block
|
1752
|
+
res << "Block " << Low2C.obj_name(self) << ";\n\n"
|
1385
1753
|
|
1386
1754
|
# Generate the c code of the sub blocks if any.
|
1387
1755
|
self.each_statement do |stmnt|
|
@@ -1390,11 +1758,16 @@ module HDLRuby::Low
|
|
1390
1758
|
|
1391
1759
|
# Generate the execution function.
|
1392
1760
|
res << " " * level*3
|
1393
|
-
res << "void
|
1761
|
+
res << "void " << Low2C.code_name(self) << "() {\n"
|
1762
|
+
res << " " * (level+1)*3
|
1763
|
+
# res << "Value l,r,d;\n"
|
1764
|
+
# res << " " * (level+1)*3
|
1765
|
+
# res << "unsigned long long i;\n"
|
1394
1766
|
# res << "printf(\"Executing #{Low2C.code_name(self)}...\\n\");"
|
1395
1767
|
# Generate the statements.
|
1396
1768
|
self.each_statement do |stmnt|
|
1397
|
-
res << stmnt.to_c(level+1)
|
1769
|
+
# res << stmnt.to_c(level+1)
|
1770
|
+
stmnt.to_c(res,level+1)
|
1398
1771
|
end
|
1399
1772
|
# Close the execution function.
|
1400
1773
|
res << " " * level*3
|
@@ -1402,11 +1775,12 @@ module HDLRuby::Low
|
|
1402
1775
|
|
1403
1776
|
|
1404
1777
|
# Generate the signals.
|
1405
|
-
self.each_signal { |signal| res << signal.to_c(level) }
|
1778
|
+
# self.each_signal { |signal| res << signal.to_c(level) }
|
1779
|
+
self.each_signal { |signal| signal.to_c(res,level) }
|
1406
1780
|
|
1407
1781
|
# The header of the block.
|
1408
1782
|
res << " " * level*3
|
1409
|
-
res << "Block
|
1783
|
+
res << "Block " << Low2C.make_name(self) << "() {\n"
|
1410
1784
|
res << " " * (level+1)*3
|
1411
1785
|
res << "Block block = malloc(sizeof(BlockS));\n"
|
1412
1786
|
res << " " * (level+1)*3
|
@@ -1415,7 +1789,7 @@ module HDLRuby::Low
|
|
1415
1789
|
# Sets the global variable of the block.
|
1416
1790
|
res << "\n"
|
1417
1791
|
res << " " * (level+1)*3
|
1418
|
-
res <<
|
1792
|
+
res << Low2C.obj_name(self) << " = block;\n"
|
1419
1793
|
|
1420
1794
|
# Set the owner if any.
|
1421
1795
|
if self.parent then
|
@@ -1426,8 +1800,8 @@ module HDLRuby::Low
|
|
1426
1800
|
end
|
1427
1801
|
# Set it as the real parent.
|
1428
1802
|
res << " " * (level+1)*3
|
1429
|
-
res << "block->owner = (Object)"
|
1430
|
-
|
1803
|
+
res << "block->owner = (Object)"
|
1804
|
+
res << Low2C.obj_name(true_parent) << ";\n"
|
1431
1805
|
else
|
1432
1806
|
res << "block->owner = NULL;\n"
|
1433
1807
|
end
|
@@ -1444,13 +1818,13 @@ module HDLRuby::Low
|
|
1444
1818
|
"block->num_inners);\n"
|
1445
1819
|
self.each_inner.with_index do |inner,i|
|
1446
1820
|
res << " " * (level+1)*3
|
1447
|
-
res << "block->inners[#{i}] = "
|
1448
|
-
|
1821
|
+
res << "block->inners[#{i}] = "
|
1822
|
+
res << Low2C.make_name(inner) << "();\n"
|
1449
1823
|
end
|
1450
1824
|
|
1451
1825
|
# Sets the execution function.
|
1452
1826
|
res << " " * (level+1)*3
|
1453
|
-
res << "block->function =
|
1827
|
+
res << "block->function = &" << Low2C.code_name(self) << ";\n"
|
1454
1828
|
|
1455
1829
|
# Generate creation of the sub blocks.
|
1456
1830
|
self.each_statement do |stmnt|
|
@@ -1471,28 +1845,32 @@ module HDLRuby::Low
|
|
1471
1845
|
# Generates the execution of the block C text of the equivalent
|
1472
1846
|
# HDLRuby code.
|
1473
1847
|
# +level+ is the hierachical level of the object.
|
1474
|
-
def to_c(level = 0)
|
1475
|
-
|
1476
|
-
res
|
1848
|
+
# def to_c(level = 0)
|
1849
|
+
def to_c(res,level = 0)
|
1850
|
+
# res = " " * (level*3)
|
1851
|
+
res << " " * (level*3)
|
1852
|
+
res << Low2C.code_name(self) << "();\n"
|
1477
1853
|
return res
|
1478
1854
|
end
|
1479
1855
|
|
1480
1856
|
## Generates the content of the h file.
|
1481
|
-
def to_ch
|
1857
|
+
# def to_ch
|
1858
|
+
def to_ch(res)
|
1482
1859
|
# puts "to_ch for block=#{Low2C.obj_name(self)} with=#{self.each_inner.count} inners"
|
1483
|
-
res = ""
|
1860
|
+
# res = ""
|
1484
1861
|
# Declare the global variable holding the block.
|
1485
|
-
res << "extern Block
|
1862
|
+
res << "extern Block " << Low2C.obj_name(self) << ";\n\n"
|
1486
1863
|
|
1487
1864
|
# Generate the access to the function making the block. */
|
1488
|
-
res << "extern Block
|
1865
|
+
res << "extern Block " << Low2C.make_name(self) << "();\n\n"
|
1489
1866
|
|
1490
1867
|
# Generate the accesses to the ports.
|
1491
|
-
self.each_inner { |inner| res << inner.to_ch }
|
1868
|
+
# self.each_inner { |inner| res << inner.to_ch }
|
1869
|
+
self.each_inner { |inner| inner.to_ch(res) }
|
1492
1870
|
|
1493
1871
|
# Recurse on the statements.
|
1494
|
-
self.each_statement { |stmnt| res << stmnt.to_ch }
|
1495
|
-
|
1872
|
+
# self.each_statement { |stmnt| res << stmnt.to_ch }
|
1873
|
+
self.each_statement { |stmnt| stmnt.to_ch(res) }
|
1496
1874
|
|
1497
1875
|
return res
|
1498
1876
|
end
|
@@ -1516,7 +1894,8 @@ module HDLRuby::Low
|
|
1516
1894
|
|
1517
1895
|
# Generates the C text of the equivalent HDLRuby code.
|
1518
1896
|
# +level+ is the hierachical level of the object.
|
1519
|
-
def to_c(level = 0)
|
1897
|
+
# def to_c(level = 0)
|
1898
|
+
def to_c(res,level = 0)
|
1520
1899
|
# Should never be here.
|
1521
1900
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1522
1901
|
end
|
@@ -1528,25 +1907,50 @@ module HDLRuby::Low
|
|
1528
1907
|
|
1529
1908
|
## Generates the C text for an access to the value.
|
1530
1909
|
# +level+ is the hierachical level of the object.
|
1531
|
-
def to_c(level = 0)
|
1532
|
-
|
1910
|
+
def to_c(res,level = 0)
|
1911
|
+
# res << Low2C.make_name(self) << "()"
|
1912
|
+
# return res
|
1913
|
+
res << (" " * (level*3))
|
1914
|
+
# res << "d=" << Low2C.make_name(self) << "();\n"
|
1915
|
+
res << "push(" << Low2C.make_name(self) << "());\n"
|
1916
|
+
return res
|
1917
|
+
end
|
1918
|
+
|
1919
|
+
## Generates the C text for an expression access to the value.
|
1920
|
+
# +level+ is the hierachical level of the object.
|
1921
|
+
def to_c_expr(res,level = 0)
|
1922
|
+
res << Low2C.make_name(self) << "()"
|
1923
|
+
return res
|
1533
1924
|
end
|
1534
1925
|
|
1535
1926
|
## Generates the content of the h file.
|
1536
|
-
def to_ch
|
1537
|
-
|
1538
|
-
|
1927
|
+
# def to_ch
|
1928
|
+
def to_ch(res)
|
1929
|
+
# res = ""
|
1930
|
+
# return "extern Value #{Low2C.make_name(self)}();"
|
1931
|
+
res << "extern Value " << Low2C.make_name(self) << "();"
|
1932
|
+
return res
|
1539
1933
|
end
|
1540
1934
|
|
1935
|
+
@@made_values = Set.new
|
1936
|
+
|
1541
1937
|
# Generates the text of the equivalent c.
|
1542
1938
|
# +level+ is the hierachical level of the object.
|
1543
|
-
def to_c_make(level = 0)
|
1939
|
+
# def to_c_make(level = 0)
|
1940
|
+
def to_c_make(res,level = 0)
|
1941
|
+
# Check is the value maker is already present.
|
1942
|
+
maker = Low2C.make_name(self);
|
1943
|
+
# return "" if @@made_values.include?(maker)
|
1944
|
+
return res if @@made_values.include?(maker)
|
1945
|
+
@@made_values.add(maker)
|
1946
|
+
|
1544
1947
|
# The resulting string.
|
1545
|
-
res = ""
|
1948
|
+
# res = ""
|
1546
1949
|
|
1547
1950
|
# The header of the value generation.
|
1548
1951
|
res << " " * level*3
|
1549
|
-
res << "Value
|
1952
|
+
# res << "Value " << Low2C.make_name(self) << "() {\n"
|
1953
|
+
res << "Value " << maker << "() {\n"
|
1550
1954
|
|
1551
1955
|
# Declares the data.
|
1552
1956
|
# Create the bit string.
|
@@ -1584,8 +1988,11 @@ module HDLRuby::Low
|
|
1584
1988
|
# Create the value.
|
1585
1989
|
res << " " * (level+1)*3
|
1586
1990
|
# 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
|
-
|
1991
|
+
# res << "return make_set_value(#{self.type.to_c(level+1)},1," +
|
1992
|
+
# "data);\n"
|
1993
|
+
res << "return make_set_value("
|
1994
|
+
self.type.to_c(res,level+1)
|
1995
|
+
res << ",1,data);\n"
|
1589
1996
|
else
|
1590
1997
|
# No, generate a bit string value.
|
1591
1998
|
res << " " * (level+1)*3
|
@@ -1593,8 +2000,11 @@ module HDLRuby::Low
|
|
1593
2000
|
res << "static unsigned char data[] = \"#{str.reverse}\";\n"
|
1594
2001
|
# Create the value.
|
1595
2002
|
res << " " * (level+1)*3
|
1596
|
-
res << "return make_set_value(#{self.type.to_c(level+1)},0," +
|
1597
|
-
|
2003
|
+
# res << "return make_set_value(#{self.type.to_c(level+1)},0," +
|
2004
|
+
# "data);\n"
|
2005
|
+
res << "return make_set_value("
|
2006
|
+
self.type.to_c(res,level+1)
|
2007
|
+
res << ",0,data);\n"
|
1598
2008
|
end
|
1599
2009
|
|
1600
2010
|
# Close the value.
|
@@ -1608,29 +2018,54 @@ module HDLRuby::Low
|
|
1608
2018
|
## Extends the Cast class with generation of C text.
|
1609
2019
|
class Cast
|
1610
2020
|
|
2021
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2022
|
+
# # +level+ is the hierachical level of the object.
|
2023
|
+
# # def to_c(level = 0)
|
2024
|
+
# def to_c(res,level = 0)
|
2025
|
+
# # res = "({\n"
|
2026
|
+
# res << "({\n"
|
2027
|
+
# # Overrides the upper src0 and dst...
|
2028
|
+
# res << (" " * ((level+1)*3))
|
2029
|
+
# res << "Value src0, dst = get_value();\n"
|
2030
|
+
# # Save the state of the value pool.
|
2031
|
+
# res << (" " * ((level+1)*3))
|
2032
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2033
|
+
# # Compute the child.
|
2034
|
+
# res << (" " * ((level+1)*3))
|
2035
|
+
# # res << "src0 = #{self.child.to_c(level+2)};\n"
|
2036
|
+
# res << "src0 = "
|
2037
|
+
# self.child.to_c(res,level+2)
|
2038
|
+
# res << ";\n"
|
2039
|
+
# res << (" " * ((level+1)*3))
|
2040
|
+
# # res += "dst = cast_value(src0," +
|
2041
|
+
# # "#{self.type.to_c(level+1)},dst);\n"
|
2042
|
+
# res << "dst = cast_value(src0,"
|
2043
|
+
# self.type.to_c(res,level+1)
|
2044
|
+
# res << ",dst);\n"
|
2045
|
+
# # Restore the value pool state.
|
2046
|
+
# res << (" " * ((level+1)*3))
|
2047
|
+
# res << "set_value_pos(pool_state);\n"
|
2048
|
+
# # Close the computation
|
2049
|
+
# res << (" " * (level*3))
|
2050
|
+
# res << "dst; })"
|
2051
|
+
|
2052
|
+
# return res
|
2053
|
+
# end
|
1611
2054
|
# Generates the C text of the equivalent HDLRuby code.
|
1612
2055
|
# +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
|
2056
|
+
# def to_c(level = 0)
|
2057
|
+
def to_c(res,level = 0)
|
2058
|
+
# Save the value pool state.
|
2059
|
+
res << (" " * (level*3)) << "SV;\n"
|
2060
|
+
# Generate the child.
|
2061
|
+
self.child.to_c(res,level)
|
1631
2062
|
res << (" " * (level*3))
|
1632
|
-
res << "
|
1633
|
-
|
2063
|
+
# res << "d=cast(d,"
|
2064
|
+
res << "cast("
|
2065
|
+
self.type.to_c(res,level+1)
|
2066
|
+
res << ");\n"
|
2067
|
+
# Restore the value pool state.
|
2068
|
+
res << (" " * (level*3)) << "RV;\n"
|
1634
2069
|
return res
|
1635
2070
|
end
|
1636
2071
|
end
|
@@ -1641,7 +2076,8 @@ module HDLRuby::Low
|
|
1641
2076
|
|
1642
2077
|
# Generates the C text of the equivalent HDLRuby code.
|
1643
2078
|
# +level+ is the hierachical level of the object.
|
1644
|
-
def to_c(level = 0)
|
2079
|
+
# def to_c(level = 0)
|
2080
|
+
def to_c(res,level = 0)
|
1645
2081
|
# Should never be here.
|
1646
2082
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1647
2083
|
end
|
@@ -1650,42 +2086,81 @@ module HDLRuby::Low
|
|
1650
2086
|
## Extends the Unary class with generation of C text.
|
1651
2087
|
class Unary
|
1652
2088
|
|
2089
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2090
|
+
# # +level+ is the hierachical level of the object.
|
2091
|
+
# # def to_c(level = 0)
|
2092
|
+
# def to_c(res,level = 0)
|
2093
|
+
# # res = "({\n"
|
2094
|
+
# res << "({\n"
|
2095
|
+
# # Overrides the upper src0 and dst...
|
2096
|
+
# res << (" " * ((level+1)*3))
|
2097
|
+
# res << "Value src0, dst;\n"
|
2098
|
+
# if (self.operator != :+@) then
|
2099
|
+
# # And allocates a new value for dst unless the operator
|
2100
|
+
# # is +@ that does not compute anything.
|
2101
|
+
# res << (" " * ((level+1)*3))
|
2102
|
+
# res << "dst = get_value();\n"
|
2103
|
+
# end
|
2104
|
+
# # Save the state of the value pool.
|
2105
|
+
# res << (" " * ((level+1)*3))
|
2106
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2107
|
+
# # Compute the child.
|
2108
|
+
# res << (" " * ((level+1)*3))
|
2109
|
+
# # res << "src0 = #{self.child.to_c(level+2)};\n"
|
2110
|
+
# res << "src0 = "
|
2111
|
+
# self.child.to_c(res,level+2)
|
2112
|
+
# res << ";\n"
|
2113
|
+
# res << (" " * ((level+1)*3))
|
2114
|
+
# case self.operator
|
2115
|
+
# when :~ then
|
2116
|
+
# res << "dst = not_value(src0,dst);\n"
|
2117
|
+
# when :-@ then
|
2118
|
+
# res << "dst = neg_value(src0,dst);\n"
|
2119
|
+
# when :+@ then
|
2120
|
+
# # res << "dst = #{self.child.to_c(level)};\n"
|
2121
|
+
# res << "dst = "
|
2122
|
+
# self.child.to_c(res,level)
|
2123
|
+
# res << ";\n"
|
2124
|
+
# else
|
2125
|
+
# raise "Invalid unary operator: #{self.operator}."
|
2126
|
+
# end
|
2127
|
+
# # Restore the value pool state.
|
2128
|
+
# res << (" " * ((level+1)*3))
|
2129
|
+
# res << "set_value_pos(pool_state);\n"
|
2130
|
+
# # Close the computation
|
2131
|
+
# res << (" " * (level*3))
|
2132
|
+
# res << "dst; })"
|
2133
|
+
|
2134
|
+
# return res
|
2135
|
+
# end
|
1653
2136
|
# Generates the C text of the equivalent HDLRuby code.
|
1654
2137
|
# +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"
|
2138
|
+
# def to_c(level = 0)
|
2139
|
+
def to_c(res,level = 0)
|
2140
|
+
if (self.operator == :+@) then
|
2141
|
+
# No computation required.
|
2142
|
+
self.child.to_c(res,level)
|
2143
|
+
return res
|
1665
2144
|
end
|
1666
|
-
#
|
1667
|
-
|
1668
|
-
res << "
|
1669
|
-
#
|
1670
|
-
res
|
1671
|
-
res << "
|
1672
|
-
res << ("
|
2145
|
+
# Some computation required.
|
2146
|
+
# Save the value pool state.
|
2147
|
+
res << (" " * (level*3)) << "SV;\n"
|
2148
|
+
# Generate the child.
|
2149
|
+
self.child.to_c(res,level)
|
2150
|
+
res << (" " * (level*3))
|
2151
|
+
res << "unary("
|
2152
|
+
# Adds the operation
|
1673
2153
|
case self.operator
|
1674
2154
|
when :~ then
|
1675
|
-
res
|
2155
|
+
res << "¬_value"
|
1676
2156
|
when :-@ then
|
1677
|
-
res
|
1678
|
-
when :+@ then
|
1679
|
-
res += "dst = #{self.child.to_c(level)};\n"
|
2157
|
+
res << "&neg_value"
|
1680
2158
|
else
|
1681
2159
|
raise "Invalid unary operator: #{self.operator}."
|
1682
2160
|
end
|
2161
|
+
res << ");\n"
|
1683
2162
|
# 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; })"
|
2163
|
+
res << (" " * (level*3)) << "RV;\n"
|
1689
2164
|
|
1690
2165
|
return res
|
1691
2166
|
end
|
@@ -1695,78 +2170,147 @@ module HDLRuby::Low
|
|
1695
2170
|
## Extends the Binary class with generation of C text.
|
1696
2171
|
class Binary
|
1697
2172
|
|
2173
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2174
|
+
# # +level+ is the hierachical level of the object.
|
2175
|
+
# # def to_c(level = 0)
|
2176
|
+
# def to_c(res, level = 0)
|
2177
|
+
# # res = "({\n"
|
2178
|
+
# res << "({\n"
|
2179
|
+
# # Overrides the upper src0, src1 and dst...
|
2180
|
+
# # And allocates a new value for dst.
|
2181
|
+
# res << (" " * ((level+1)*3))
|
2182
|
+
# res << "Value src0,src1,dst = get_value();\n"
|
2183
|
+
# # Save the state of the value pool.
|
2184
|
+
# res << (" " * ((level+1)*3))
|
2185
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2186
|
+
# # Compute the left.
|
2187
|
+
# res << (" " * ((level+1)*3))
|
2188
|
+
# # res << "src0 = " << self.left.to_c(level+2) << ";\n"
|
2189
|
+
# res << "src0 = "
|
2190
|
+
# self.left.to_c(res,level+2)
|
2191
|
+
# res << ";\n"
|
2192
|
+
# # Compute the right.
|
2193
|
+
# res << (" " * ((level+1)*3))
|
2194
|
+
# # res << "src1 = " << self.right.to_c(level+2) << ";\n"
|
2195
|
+
# res << "src1 = "
|
2196
|
+
# self.right.to_c(res,level+2)
|
2197
|
+
# res << ";\n"
|
2198
|
+
# res << (" " * ((level+1)*3))
|
2199
|
+
|
2200
|
+
# # Compute the current binary operation.
|
2201
|
+
# case self.operator
|
2202
|
+
# when :+ then
|
2203
|
+
# res << "dst = add_value(src0,src1,dst);\n"
|
2204
|
+
# when :- then
|
2205
|
+
# res << "dst = sub_value(src0,src1,dst);\n"
|
2206
|
+
# when :* then
|
2207
|
+
# res << "dst = mul_value(src0,src1,dst);\n"
|
2208
|
+
# when :/ then
|
2209
|
+
# res << "dst = div_value(src0,src1,dst);\n"
|
2210
|
+
# when :% then
|
2211
|
+
# res << "dst = mod_value(src0,src1,dst);\n"
|
2212
|
+
# when :** then
|
2213
|
+
# res << "dst = pow_value(src0,src1,dst);\n"
|
2214
|
+
# when :& then
|
2215
|
+
# res << "dst = and_value(src0,src1,dst);\n"
|
2216
|
+
# when :| then
|
2217
|
+
# res << "dst = or_value(src0,src1,dst);\n"
|
2218
|
+
# when :^ then
|
2219
|
+
# res << "dst = xor_value(src0,src1,dst);\n"
|
2220
|
+
# when :<<,:ls then
|
2221
|
+
# res << "dst = shift_left_value(src0,src1,dst);\n"
|
2222
|
+
# when :>>,:rs then
|
2223
|
+
# res << "dst = shift_right_value(src0,src1,dst);\n"
|
2224
|
+
# when :lr then
|
2225
|
+
# res << "dst = rotate_left_value(src0,src1,dst);\n"
|
2226
|
+
# when :rr then
|
2227
|
+
# res << "dst = rotate_right_value(src0,src1,dst);\n"
|
2228
|
+
# when :== then
|
2229
|
+
# res << "dst = equal_value(src0,src1,dst);\n"
|
2230
|
+
# res << "dst = reduce_or_value(dst,dst);"
|
2231
|
+
# when :!= then
|
2232
|
+
# res << "dst = xor_value(src0,src1,dst);\n"
|
2233
|
+
# res << "dst = reduce_or_value(dst,dst);"
|
2234
|
+
# when :> then
|
2235
|
+
# res << "dst = greater_value(src0,src1,dst);\n"
|
2236
|
+
# when :< then
|
2237
|
+
# res << "dst = lesser_value(src0,src1,dst);\n"
|
2238
|
+
# when :>= then
|
2239
|
+
# res << "dst = greater_equal_value(src0,src1,dst);\n"
|
2240
|
+
# when :<= then
|
2241
|
+
# res << "dst = lesser_equal_value(src0,src1,dst);\n"
|
2242
|
+
# else
|
2243
|
+
# raise "Invalid binary operator: #{self.operator}."
|
2244
|
+
# end
|
2245
|
+
# # Restore the state of the value pool.
|
2246
|
+
# res << (" " * ((level+1)*3))
|
2247
|
+
# res << "set_value_pos(pool_state);\n"
|
2248
|
+
# # Close the computation.
|
2249
|
+
# res << (" " * (level*3))
|
2250
|
+
# res << "dst;})"
|
2251
|
+
|
2252
|
+
# return res
|
2253
|
+
# end
|
1698
2254
|
# Generates the C text of the equivalent HDLRuby code.
|
1699
2255
|
# +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.
|
2256
|
+
# def to_c(level = 0)
|
2257
|
+
def to_c(res, level = 0)
|
2258
|
+
# Save the value pool state.
|
2259
|
+
res << (" " * (level*3)) << "SV;\n"
|
2260
|
+
# Generate the left computation.
|
2261
|
+
self.left.to_c(res,level)
|
2262
|
+
# Generate the right computation.
|
2263
|
+
self.right.to_c(res,level)
|
2264
|
+
# Generate the binary.
|
2265
|
+
res << (" " * (level*3))
|
2266
|
+
res << "binary("
|
2267
|
+
# Set the operation.
|
1719
2268
|
case self.operator
|
1720
2269
|
when :+ then
|
1721
|
-
res
|
2270
|
+
res << "&add_value"
|
1722
2271
|
when :- then
|
1723
|
-
res
|
2272
|
+
res << "&sub_value"
|
1724
2273
|
when :* then
|
1725
|
-
res
|
2274
|
+
res << "&mul_value"
|
1726
2275
|
when :/ then
|
1727
|
-
res
|
2276
|
+
res << "&div_value"
|
1728
2277
|
when :% then
|
1729
|
-
res
|
2278
|
+
res << "&mod_value"
|
1730
2279
|
when :** then
|
1731
|
-
res
|
2280
|
+
res << "&pow_value"
|
1732
2281
|
when :& then
|
1733
|
-
res
|
2282
|
+
res << "&and_value"
|
1734
2283
|
when :| then
|
1735
|
-
res
|
2284
|
+
res << "&or_value"
|
1736
2285
|
when :^ then
|
1737
|
-
res
|
2286
|
+
res << "&xor_value"
|
1738
2287
|
when :<<,:ls then
|
1739
|
-
res
|
2288
|
+
res << "&shift_left_value"
|
1740
2289
|
when :>>,:rs then
|
1741
|
-
res
|
2290
|
+
res << "&shift_right_value"
|
1742
2291
|
when :lr then
|
1743
|
-
res
|
2292
|
+
res << "&rotate_left_value"
|
1744
2293
|
when :rr then
|
1745
|
-
res
|
2294
|
+
res << "&rotate_right_value"
|
1746
2295
|
when :== then
|
1747
|
-
res
|
1748
|
-
"dst = reduce_or_value(dst,dst);"
|
2296
|
+
res << "&equal_value_c"
|
1749
2297
|
when :!= then
|
1750
|
-
|
1751
|
-
res += "dst = xor_value(src0,src1,dst);\n" +
|
1752
|
-
"dst = reduce_or_value(dst,dst);"
|
2298
|
+
res << "¬_equal_value_c"
|
1753
2299
|
when :> then
|
1754
|
-
res
|
2300
|
+
res << "&greater_value"
|
1755
2301
|
when :< then
|
1756
|
-
res
|
2302
|
+
res << "&lesser_value"
|
1757
2303
|
when :>= then
|
1758
|
-
res
|
2304
|
+
res << "&greater_equal_value"
|
1759
2305
|
when :<= then
|
1760
|
-
res
|
2306
|
+
res << "&lesser_equal_value"
|
1761
2307
|
else
|
1762
2308
|
raise "Invalid binary operator: #{self.operator}."
|
1763
2309
|
end
|
1764
|
-
# Restore the state of the value pool.
|
1765
|
-
res << (" " * ((level+1)*3))
|
1766
|
-
res << "set_value_pos(pool_state);\n"
|
1767
2310
|
# Close the computation.
|
1768
|
-
res <<
|
1769
|
-
|
2311
|
+
res << ");\n"
|
2312
|
+
# Restore the value pool state.
|
2313
|
+
res << (" " * (level*3)) << "RV;\n"
|
1770
2314
|
|
1771
2315
|
return res
|
1772
2316
|
end
|
@@ -1775,103 +2319,200 @@ module HDLRuby::Low
|
|
1775
2319
|
## Extends the Select class with generation of C text.
|
1776
2320
|
class Select
|
1777
2321
|
|
2322
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2323
|
+
# # +level+ is the hierachical level of the object.
|
2324
|
+
# # def to_c(level = 0)
|
2325
|
+
# def to_c(res,level = 0)
|
2326
|
+
# # Gather the possible selection choices.
|
2327
|
+
# expressions = self.each_choice.to_a
|
2328
|
+
# # Create the resulting string.
|
2329
|
+
# # res = "({\n"
|
2330
|
+
# res << "({\n"
|
2331
|
+
# # Overrides the upper sel, src0, src1, ..., and dst...
|
2332
|
+
# # And allocates a new value for dst.
|
2333
|
+
# res << (" " * ((level+1)*3))
|
2334
|
+
# res << "Value sel;\n"
|
2335
|
+
# res << (" " * ((level+1)*3))
|
2336
|
+
# res << "Value "
|
2337
|
+
# res << expressions.size.times.map do |i|
|
2338
|
+
# "src#{i}"
|
2339
|
+
# end.join(",")
|
2340
|
+
# res << ";\n"
|
2341
|
+
# res << (" " * ((level+1)*3))
|
2342
|
+
# res << "Value dst = get_value();\n"
|
2343
|
+
# # Save the state of the value pool.
|
2344
|
+
# res << (" " * ((level+1)*3))
|
2345
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2346
|
+
# # Compute the selection.
|
2347
|
+
# res << (" " * ((level+1)*3))
|
2348
|
+
# # res << "sel = #{self.select.to_c(level+2)};\n"
|
2349
|
+
# res << "sel = "
|
2350
|
+
# self.select.to_c(res,level+2)
|
2351
|
+
# res << ";\n"
|
2352
|
+
# # Compute each choice expression.
|
2353
|
+
# expressions.each_with_index do |expr,i|
|
2354
|
+
# res << (" " * ((level+1)*3))
|
2355
|
+
# # res << "src#{i} = #{expr.to_c(level+2)};\n"
|
2356
|
+
# res << "src#{i} = "
|
2357
|
+
# expr.to_c(res,level+2)
|
2358
|
+
# res << ";\n"
|
2359
|
+
# end
|
2360
|
+
# # Compute the resulting selection.
|
2361
|
+
# res << (" " * ((level+1)*3))
|
2362
|
+
# res << "select_value(sel,dst,#{expressions.size},"
|
2363
|
+
# # res << "#{expressions.size.times.map { |i| "src#{i}" }.join(",")}"
|
2364
|
+
# res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
2365
|
+
# res << ");\n"
|
2366
|
+
# # Restore the state of the value pool.
|
2367
|
+
# res << (" " * ((level+1)*3))
|
2368
|
+
# res << "set_value_pos(pool_state);\n"
|
2369
|
+
# # Close the computation.
|
2370
|
+
# res << (" " * (level*3))
|
2371
|
+
# res << "dst; })"
|
2372
|
+
# return res
|
2373
|
+
# end
|
1778
2374
|
# Generates the C text of the equivalent HDLRuby code.
|
1779
2375
|
# +level+ is the hierachical level of the object.
|
1780
|
-
def to_c(level = 0)
|
2376
|
+
def to_c(res,level = 0)
|
2377
|
+
# Save the value pool state.
|
2378
|
+
res << (" " * (level*3)) << "SV;\n"
|
1781
2379
|
# Gather the possible selection choices.
|
1782
2380
|
expressions = self.each_choice.to_a
|
1783
2381
|
# 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
2382
|
# Compute the selection.
|
1800
|
-
res
|
1801
|
-
res << "sel = #{self.select.to_c(level+2)};\n"
|
2383
|
+
self.select.to_c(res,level)
|
1802
2384
|
# Compute each choice expression.
|
1803
2385
|
expressions.each_with_index do |expr,i|
|
1804
|
-
res
|
1805
|
-
res << "src#{i} = #{expr.to_c(level+2)};\n"
|
2386
|
+
expr.to_c(res,level)
|
1806
2387
|
end
|
1807
2388
|
# 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
2389
|
res << (" " * (level*3))
|
1817
|
-
res << "
|
2390
|
+
res << "select(#{expressions.size});\n"
|
2391
|
+
# Restore the value pool state.
|
2392
|
+
res << (" " * (level*3)) << "RV;\n"
|
2393
|
+
return res
|
1818
2394
|
end
|
1819
2395
|
end
|
1820
2396
|
|
1821
2397
|
## Extends the Concat class with generation of C text.
|
1822
2398
|
class Concat
|
1823
2399
|
|
1824
|
-
|
2400
|
+
|
2401
|
+
# # Generates the C text for the equivalent HDLRuby code.
|
2402
|
+
# # +level+ is the hierachical level of the object.
|
2403
|
+
# def to_c(res,level = 0)
|
2404
|
+
# # Gather the content to concat.
|
2405
|
+
# expressions = self.each_expression.to_a
|
2406
|
+
# # Create the resulting string.
|
2407
|
+
# res << "({\n"
|
2408
|
+
# # Overrides the upper src0, src1, ..., and dst...
|
2409
|
+
# # And allocates a new value for dst.
|
2410
|
+
# res << (" " * ((level+1)*3))
|
2411
|
+
# res << "Value "
|
2412
|
+
# res << expressions.size.times.map do |i|
|
2413
|
+
# "src#{i}"
|
2414
|
+
# end.join(",")
|
2415
|
+
# res << ";\n"
|
2416
|
+
# res << (" " * ((level+1)*3))
|
2417
|
+
# res << "Value dst = get_value();\n"
|
2418
|
+
# # Save the state of the value pool.
|
2419
|
+
# res << (" " * ((level+1)*3))
|
2420
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2421
|
+
# # Compute each sub expression.
|
2422
|
+
# expressions.each_with_index do |expr,i|
|
2423
|
+
# res << (" " * ((level+1)*3))
|
2424
|
+
# res << "src#{i} = "
|
2425
|
+
# expr.to_c_expr(res,level+2)
|
2426
|
+
# res << ";\n"
|
2427
|
+
# end
|
2428
|
+
# # Compute the direction.
|
2429
|
+
# # Compute the resulting concatenation.
|
2430
|
+
# res << (" " * ((level+1)*3))
|
2431
|
+
# res << "concat_value(#{expressions.size},"
|
2432
|
+
# res << "#{self.type.direction == :little ? 1 : 0},dst,"
|
2433
|
+
# res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
2434
|
+
# res << ");\n"
|
2435
|
+
# # Restore the state of the value pool.
|
2436
|
+
# res << (" " * ((level+1)*3))
|
2437
|
+
# res << "set_value_pos(pool_state);\n"
|
2438
|
+
# # Close the computation.
|
2439
|
+
# res << (" " * (level*3))
|
2440
|
+
# res << "dst; })"
|
2441
|
+
# return res
|
2442
|
+
# end
|
2443
|
+
# Generates the C text for the equivalent HDLRuby code.
|
1825
2444
|
# +level+ is the hierachical level of the object.
|
1826
|
-
def to_c(level = 0)
|
2445
|
+
def to_c(res,level = 0)
|
2446
|
+
# Save the value pool state.
|
2447
|
+
res << (" " * (level*3)) << "SV;\n"
|
2448
|
+
# Gather the content to concat.
|
2449
|
+
expressions = self.each_expression.to_a
|
2450
|
+
# Compute each sub expression.
|
2451
|
+
expressions.each_with_index do |expr,i|
|
2452
|
+
expr.to_c(res,level+2)
|
2453
|
+
end
|
2454
|
+
# Compute the resulting concatenation.
|
2455
|
+
res << (" " * ((level+1)*3))
|
2456
|
+
res << "sconcat(#{expressions.size},"
|
2457
|
+
res << (self.type.direction == :little ? "1" : "0")
|
2458
|
+
res << ");\n"
|
2459
|
+
# Restore the value pool state.
|
2460
|
+
res << (" " * (level*3)) << "RV;\n"
|
2461
|
+
return res
|
2462
|
+
end
|
2463
|
+
|
2464
|
+
# Generates the C text of expression for the equivalent HDLRuby code.
|
2465
|
+
# +level+ is the hierachical level of the object.
|
2466
|
+
def to_c_expr(res,level = 0)
|
1827
2467
|
# Gather the content to concat.
|
1828
2468
|
expressions = self.each_expression.to_a
|
1829
2469
|
# Create the resulting string.
|
1830
|
-
|
1831
|
-
res = "({\n"
|
2470
|
+
res << "({\n"
|
1832
2471
|
# Overrides the upper src0, src1, ..., and dst...
|
1833
2472
|
# And allocates a new value for dst.
|
1834
2473
|
res << (" " * ((level+1)*3))
|
1835
|
-
res << "Value
|
2474
|
+
res << "Value "
|
2475
|
+
res << expressions.size.times.map do |i|
|
1836
2476
|
"src#{i}"
|
1837
|
-
end.join(",")
|
2477
|
+
end.join(",")
|
2478
|
+
res << ";\n"
|
1838
2479
|
res << (" " * ((level+1)*3))
|
1839
2480
|
res << "Value dst = get_value();\n"
|
1840
|
-
# Save the
|
1841
|
-
res << (" " * (
|
1842
|
-
res << "unsigned int pool_state = get_value_pos();\n"
|
2481
|
+
# Save the value pool state.
|
2482
|
+
res << (" " * (level*3)) << "SV;\n"
|
1843
2483
|
# Compute each sub expression.
|
1844
2484
|
expressions.each_with_index do |expr,i|
|
1845
2485
|
res << (" " * ((level+1)*3))
|
1846
|
-
res << "src#{i} =
|
2486
|
+
res << "src#{i} = "
|
2487
|
+
expr.to_c_expr(res,level+2)
|
2488
|
+
res << ";\n"
|
1847
2489
|
end
|
1848
2490
|
# Compute the direction.
|
1849
2491
|
# Compute the resulting concatenation.
|
1850
2492
|
res << (" " * ((level+1)*3))
|
1851
2493
|
res << "concat_value(#{expressions.size},"
|
1852
2494
|
res << "#{self.type.direction == :little ? 1 : 0},dst,"
|
1853
|
-
res <<
|
2495
|
+
res << expressions.size.times.map { |i| "src#{i}" }.join(",")
|
1854
2496
|
res << ");\n"
|
1855
|
-
#
|
1856
|
-
res << (" " * (
|
1857
|
-
res << "set_value_pos(pool_state);\n"
|
2497
|
+
# Save the value pool state.
|
2498
|
+
res << (" " * (level*3)) << "SV;\n"
|
1858
2499
|
# Close the computation.
|
1859
2500
|
res << (" " * (level*3))
|
1860
2501
|
res << "dst; })"
|
1861
|
-
|
1862
2502
|
return res
|
1863
|
-
|
1864
2503
|
end
|
1865
2504
|
end
|
1866
2505
|
|
1867
2506
|
|
2507
|
+
|
1868
2508
|
## Extends the Ref class with generation of C text.
|
1869
2509
|
class Ref
|
1870
2510
|
|
1871
2511
|
# Generates the C text of the equivalent HDLRuby code.
|
1872
2512
|
# +level+ is the hierachical level of the object and
|
1873
2513
|
# +left+ tells if it is a left value or not.
|
1874
|
-
def to_c(level = 0, left = false)
|
2514
|
+
# def to_c(level = 0, left = false)
|
2515
|
+
def to_c(res,level = 0, left = false)
|
1875
2516
|
# Should never be here.
|
1876
2517
|
raise AnyError, "Internal error: to_c should be implemented in class :#{self.class}"
|
1877
2518
|
end
|
@@ -1884,7 +2525,8 @@ module HDLRuby::Low
|
|
1884
2525
|
# Generates the C text of the equivalent HDLRuby code.
|
1885
2526
|
# +level+ is the hierachical level of the object and
|
1886
2527
|
# +left+ tells if it is a left value or not.
|
1887
|
-
def to_c(level = 0, left = false)
|
2528
|
+
# def to_c(level = 0, left = false)
|
2529
|
+
def to_c(res,level = 0, left = false)
|
1888
2530
|
raise "RefConcat cannot be converted to C directly, please use break_concat_assign!."
|
1889
2531
|
# # The resulting string.
|
1890
2532
|
# res = "ref_concat(#{self.each_ref.to_a.size}"
|
@@ -1897,7 +2539,8 @@ module HDLRuby::Low
|
|
1897
2539
|
|
1898
2540
|
# Generates the C text for reference as left value to a signal.
|
1899
2541
|
# +level+ is the hierarchical level of the object.
|
1900
|
-
def to_c_signal(level = 0)
|
2542
|
+
# def to_c_signal(level = 0)
|
2543
|
+
def to_c_signal(res,level = 0)
|
1901
2544
|
raise "RefConcat cannot be converted to C directly, please use break_concat_assign!."
|
1902
2545
|
# # The resulting string.
|
1903
2546
|
# res = "sig_concat(#{self.each_ref.to_a.size}"
|
@@ -1913,44 +2556,109 @@ module HDLRuby::Low
|
|
1913
2556
|
## Extends the RefIndex class with generation of C text.
|
1914
2557
|
class RefIndex
|
1915
2558
|
|
2559
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2560
|
+
# # +level+ is thehierachical level of the object and
|
2561
|
+
# # +left+ tells if it is a left value or not.
|
2562
|
+
# # def to_c(level = 0, left = false)
|
2563
|
+
# def to_c(res,level = 0, left = false)
|
2564
|
+
# # res = "({\n"
|
2565
|
+
# res << "({\n"
|
2566
|
+
# # And allocates a new value for dst.
|
2567
|
+
# res << (" " * ((level+1)*3))
|
2568
|
+
# res << "Value ref,dst = get_value();\n"
|
2569
|
+
# res << (" " * ((level+1)*3))
|
2570
|
+
# res << "unsigned long long idx;\n"
|
2571
|
+
# # Save the state of the value pool.
|
2572
|
+
# res << (" " * ((level+1)*3))
|
2573
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2574
|
+
# # Compute the reference.
|
2575
|
+
# res << (" " * ((level+1)*3))
|
2576
|
+
# # res << "ref = #{self.ref.to_c(level+2)};\n"
|
2577
|
+
# res << "ref = "
|
2578
|
+
# self.ref.to_c(res,level+2)
|
2579
|
+
# res << ";\n"
|
2580
|
+
# # Compute the index.
|
2581
|
+
# res << (" " * ((level+1)*3))
|
2582
|
+
# # res << "idx = value2integer(#{self.index.to_c(level+2)});\n"
|
2583
|
+
# res << "idx = value2integer("
|
2584
|
+
# self.index.to_c(res,level+2)
|
2585
|
+
# res << ");\n"
|
2586
|
+
# # Make the access.
|
2587
|
+
# res << (" " * ((level+1)*3))
|
2588
|
+
# # puts "self.type.width=#{self.type.width}"
|
2589
|
+
# # res << "dst = read_range(ref,idx,idx,#{self.type.to_c(level)},dst);\n"
|
2590
|
+
# res << "dst = read_range(ref,idx,idx,"
|
2591
|
+
# # res << self.type.to_c(level)
|
2592
|
+
# self.type.to_c(res,level)
|
2593
|
+
# res << ",dst);\n"
|
2594
|
+
# # Restore the state of the value pool.
|
2595
|
+
# res << (" " * ((level+1)*3))
|
2596
|
+
# res << "set_value_pos(pool_state);\n"
|
2597
|
+
# # Close the computation.
|
2598
|
+
# res << (" " * (level*3))
|
2599
|
+
# res << "dst; })"
|
2600
|
+
# return res
|
2601
|
+
# end
|
1916
2602
|
# Generates the C text of the equivalent HDLRuby code.
|
1917
2603
|
# +level+ is thehierachical level of the object and
|
1918
2604
|
# +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"
|
2605
|
+
def to_c(res,level = 0, left = false)
|
2606
|
+
# Save the value pool state.
|
2607
|
+
res << (" " * (level*3)) << "SV;\n"
|
1929
2608
|
# Compute the reference.
|
1930
|
-
res
|
1931
|
-
res << "ref = #{self.ref.to_c(level+2)};\n"
|
2609
|
+
self.ref.to_c(res,level)
|
1932
2610
|
# Compute the index.
|
1933
|
-
res
|
1934
|
-
res << "
|
2611
|
+
self.index.to_c(res,level)
|
2612
|
+
res << (" " * (level*3))
|
1935
2613
|
# 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
2614
|
res << (" " * (level*3))
|
1944
|
-
|
2615
|
+
if (left) then
|
2616
|
+
res << "swriteI("
|
2617
|
+
else
|
2618
|
+
res << "sreadI("
|
2619
|
+
end
|
2620
|
+
self.type.to_c(res,level)
|
2621
|
+
res << ");\n"
|
2622
|
+
# Restore the value pool state.
|
2623
|
+
res << (" " * (level*3)) << "RV;\n"
|
2624
|
+
return res
|
1945
2625
|
end
|
1946
2626
|
|
2627
|
+
# # Generates the C text for reference as left value to a signal.
|
2628
|
+
# # +level+ is the hierarchical level of the object.
|
2629
|
+
# # def to_c_signal(level = 0)
|
2630
|
+
# def to_c_signal(res,level = 0)
|
2631
|
+
# # puts "to_c_signal for RefIndex"
|
2632
|
+
# res << "make_ref_rangeS("
|
2633
|
+
# self.ref.to_c_signal(res,level)
|
2634
|
+
# res << ","
|
2635
|
+
# self.type.to_c(res,level)
|
2636
|
+
# res << ",value2integer("
|
2637
|
+
# self.index.to_c(res,level)
|
2638
|
+
# res << "),value2integer("
|
2639
|
+
# self.index.to_c(res,level)
|
2640
|
+
# res << "))"
|
2641
|
+
# return res
|
2642
|
+
# end
|
1947
2643
|
# Generates the C text for reference as left value to a signal.
|
1948
2644
|
# +level+ is the hierarchical level of the object.
|
1949
|
-
def to_c_signal(level = 0)
|
2645
|
+
# def to_c_signal(level = 0)
|
2646
|
+
def to_c_signal(res,level = 0)
|
1950
2647
|
# puts "to_c_signal for RefIndex"
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
2648
|
+
res << "make_ref_rangeS("
|
2649
|
+
self.ref.to_c_signal(res,level)
|
2650
|
+
res << ","
|
2651
|
+
self.type.to_c(res,level)
|
2652
|
+
res << ",value2integer(({\n"
|
2653
|
+
self.index.to_c(res,level)
|
2654
|
+
res << " " * ((level+1)*3)
|
2655
|
+
res << "pop();})"
|
2656
|
+
res << "),value2integer(({\n"
|
2657
|
+
self.index.to_c(res,level)
|
2658
|
+
res << " " * ((level+1)*3)
|
2659
|
+
res << "pop();})"
|
2660
|
+
res << "))"
|
2661
|
+
return res
|
1954
2662
|
end
|
1955
2663
|
end
|
1956
2664
|
|
@@ -1958,51 +2666,112 @@ module HDLRuby::Low
|
|
1958
2666
|
## Extends the RefRange class with generation of C text.
|
1959
2667
|
class RefRange
|
1960
2668
|
|
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
|
-
|
2669
|
+
# # Generates the C text of the equivalent HDLRuby code.
|
2670
|
+
# # +level+ is the hierachical level of the object and
|
2671
|
+
# # +left+ tells if it is a left value or not.
|
2672
|
+
# # def to_c(level = 0, left = false)
|
2673
|
+
# def to_c(res,level = 0, left = false)
|
2674
|
+
# # Decide if it is a read or a write
|
2675
|
+
# command = left ? "write" : "read"
|
2676
|
+
# # res = "({\n"
|
2677
|
+
# res << "({\n"
|
2678
|
+
# # Overrides the upper ref and dst...
|
2679
|
+
# # And allocates a new value for dst.
|
2680
|
+
# res << (" " * ((level+1)*3))
|
2681
|
+
# res << "Value ref,dst = get_value();\n"
|
2682
|
+
# res << (" " * ((level+1)*3))
|
2683
|
+
# res << "unsigned long long first,last;\n"
|
2684
|
+
# # Save the state of the value pool.
|
2685
|
+
# res << (" " * ((level+1)*3))
|
2686
|
+
# res << "unsigned int pool_state = get_value_pos();\n"
|
2687
|
+
# # Compute the reference.
|
2688
|
+
# res << (" " * ((level+1)*3))
|
2689
|
+
# # res << "ref = #{self.ref.to_c(level+2)};\n"
|
2690
|
+
# res << "ref = "
|
2691
|
+
# self.ref.to_c(res,level+2)
|
2692
|
+
# res << ";\n"
|
2693
|
+
# # Compute the range.
|
2694
|
+
# res << (" " * ((level+1)*3))
|
2695
|
+
# # res << "first = value2integer(#{self.range.first.to_c(level+2)});\n"
|
2696
|
+
# res << "first = value2integer("
|
2697
|
+
# self.range.first.to_c(res,level+2)
|
2698
|
+
# res << ");\n"
|
2699
|
+
# res << (" " * ((level+1)*3))
|
2700
|
+
# # res << "last = value2integer(#{self.range.last.to_c(level+2)});\n"
|
2701
|
+
# res << "last = value2integer("
|
2702
|
+
# self.range.last.to_c(res,level+2)
|
2703
|
+
# res << ");\n"
|
2704
|
+
# # Make the access.
|
2705
|
+
# res << (" " * ((level+1)*3))
|
2706
|
+
# # puts "#{command}_range with first=#{self.range.first} and last=#{self.range.last}"
|
2707
|
+
# # res << "dst = #{command}_range(ref,first,last,#{self.type.base.to_c(level)},dst);\n"
|
2708
|
+
# res << "dst = #{command}_range(ref,first,last,"
|
2709
|
+
# self.type.base.to_c(res,level)
|
2710
|
+
# res << ",dst);\n"
|
2711
|
+
# # Restore the state of the value pool.
|
2712
|
+
# res << (" " * ((level+1)*3))
|
2713
|
+
# res << "set_value_pos(pool_state);\n"
|
2714
|
+
# # Close the computation.
|
2715
|
+
# res << (" " * (level*3))
|
2716
|
+
# res << "dst; })"
|
2717
|
+
# return res
|
2718
|
+
# end
|
2719
|
+
def to_c(res,level = 0, left = false)
|
2720
|
+
# Save the value pool state.
|
2721
|
+
res << (" " * (level*3)) << "SV;\n"
|
1977
2722
|
# Compute the reference.
|
1978
|
-
res
|
1979
|
-
res << "
|
2723
|
+
self.ref.to_c(res,level)
|
2724
|
+
# res << (" " * (level*3))
|
1980
2725
|
# 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"
|
2726
|
+
self.range.first.to_c(res,level)
|
2727
|
+
self.range.last.to_c(res,level)
|
1987
2728
|
# 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
2729
|
res << (" " * (level*3))
|
1997
|
-
|
2730
|
+
if left then
|
2731
|
+
res << "swriteR("
|
2732
|
+
else
|
2733
|
+
res << "sreadR("
|
2734
|
+
end
|
2735
|
+
self.type.base.to_c(res,level)
|
2736
|
+
res << ");\n"
|
2737
|
+
# Restore the value pool state.
|
2738
|
+
res << (" " * (level*3)) << "RV;\n"
|
2739
|
+
return res
|
1998
2740
|
end
|
1999
2741
|
|
2742
|
+
# # Generates the C text for reference as left value to a signal.
|
2743
|
+
# # +level+ is the hierarchical level of the object.
|
2744
|
+
# # def to_c_signal(level = 0)
|
2745
|
+
# def to_c_signal(res,level = 0)
|
2746
|
+
# # return "make_ref_rangeS(#{self.ref.to_c_signal(level)}," +
|
2747
|
+
# # "value2integer(#{self.range.first.to_c(level)}),value2integer(#{self.range.last.to_c(level)}))"
|
2748
|
+
# res << "make_ref_rangeS("
|
2749
|
+
# self.ref.to_c_signal(res,level)
|
2750
|
+
# res << ",value2integer("
|
2751
|
+
# self.range.first.to_c(res,level)
|
2752
|
+
# res << "),value2integer("
|
2753
|
+
# self.range.last.to_c(res,level)
|
2754
|
+
# res << "))"
|
2755
|
+
# return res
|
2756
|
+
# end
|
2000
2757
|
# Generates the C text for reference as left value to a signal.
|
2001
2758
|
# +level+ is the hierarchical level of the object.
|
2002
|
-
def to_c_signal(level = 0)
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2759
|
+
# def to_c_signal(level = 0)
|
2760
|
+
def to_c_signal(res,level = 0)
|
2761
|
+
res << "make_ref_rangeS("
|
2762
|
+
self.ref.to_c_signal(res,level)
|
2763
|
+
res << ","
|
2764
|
+
self.type.base.to_c(res,level)
|
2765
|
+
res << ",value2integer(({\n"
|
2766
|
+
self.range.first.to_c(res,level)
|
2767
|
+
res << " " * ((level+1)*3)
|
2768
|
+
res << "pop();})"
|
2769
|
+
res << "),value2integer(({\n"
|
2770
|
+
self.range.last.to_c(res,level)
|
2771
|
+
res << " " * ((level+1)*3)
|
2772
|
+
res << "pop();})"
|
2773
|
+
res << "))"
|
2774
|
+
return res
|
2006
2775
|
end
|
2007
2776
|
end
|
2008
2777
|
|
@@ -2013,17 +2782,31 @@ module HDLRuby::Low
|
|
2013
2782
|
# Generates the C text of the equivalent HDLRuby code.
|
2014
2783
|
# +level+ is the hierachical level of the object and
|
2015
2784
|
# +left+ tells if it is a left value or not.
|
2016
|
-
def to_c(level = 0, left = false)
|
2785
|
+
# def to_c(level = 0, left = false)
|
2786
|
+
def to_c(res,level = 0, left = false)
|
2787
|
+
# # puts "RefName to_c for #{self.name}"
|
2788
|
+
# self.resolve.to_c_signal(res,level+1)
|
2789
|
+
# res << "->" << (left ? "f_value" : "c_value")
|
2790
|
+
# return res
|
2017
2791
|
# puts "RefName to_c for #{self.name}"
|
2018
|
-
|
2019
|
-
|
2792
|
+
res << (" " * (level*3))
|
2793
|
+
# res << "d="
|
2794
|
+
res << "push("
|
2795
|
+
self.resolve.to_c_signal(res,level+1)
|
2796
|
+
res << "->" << (left ? "f_value" : "c_value")
|
2797
|
+
# res << ";\n"
|
2798
|
+
res << ");\n"
|
2799
|
+
return res
|
2020
2800
|
end
|
2021
2801
|
|
2022
2802
|
# Generates the C text for reference as left value to a signal.
|
2023
2803
|
# +level+ is the hierarchical level of the object.
|
2024
|
-
def to_c_signal(level = 0)
|
2804
|
+
# def to_c_signal(level = 0)
|
2805
|
+
def to_c_signal(res,level = 0)
|
2025
2806
|
# puts "to_c_signal with self=#{self.name}, resolve=#{self.resolve}"
|
2026
|
-
return "#{self.resolve.to_c_signal(level+1)}"
|
2807
|
+
# return "#{self.resolve.to_c_signal(level+1)}"
|
2808
|
+
self.resolve.to_c_signal(res,level+1)
|
2809
|
+
return res
|
2027
2810
|
end
|
2028
2811
|
end
|
2029
2812
|
|
@@ -2033,14 +2816,20 @@ module HDLRuby::Low
|
|
2033
2816
|
# Generates the C text of the equivalent HDLRuby code.
|
2034
2817
|
# +level+ is the hierachical level of the object and
|
2035
2818
|
# +left+ tells if it is a left value or not.
|
2036
|
-
def to_c(level = 0, left = false)
|
2037
|
-
|
2819
|
+
# def to_c(level = 0, left = false)
|
2820
|
+
def to_c(res,level = 0, left = false)
|
2821
|
+
# return "this()"
|
2822
|
+
res << "this()"
|
2823
|
+
return res
|
2038
2824
|
end
|
2039
2825
|
|
2040
2826
|
# Generates the C text for reference as left value to a signal.
|
2041
2827
|
# +level+ is the hierarchical level of the object.
|
2042
|
-
def to_c_signal(level = 0)
|
2043
|
-
|
2828
|
+
# def to_c_signal(level = 0)
|
2829
|
+
def to_c_signal(res,level = 0)
|
2830
|
+
# return "this()"
|
2831
|
+
res << "this()"
|
2832
|
+
return res
|
2044
2833
|
end
|
2045
2834
|
end
|
2046
2835
|
|