-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsyfala.tcl
executable file
·654 lines (631 loc) · 20.7 KB
/
syfala.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
#!/usr/bin/tclsh
# -------------------------------------------------------------------------------------------------
# configuration
# -------------------------------------------------------------------------------------------------
set tstart [clock seconds]
set spath [file normalize [info script]]
set sroot [file dirname $spath]
# If user executes a symlink, set spath to symlink's target
set sym [exec ls -l $spath]
if {[string match "l*" $sym]} {
set spath [file normalize [exec readlink -f $spath]]
set sroot [file dirname $spath]
}
source $sroot/scripts/sylib.tcl
namespace import Syfala::*
# gets command line argument value at next '::argv' index
proc get_argument_value {index} {
upvar $index idx
return [lindex $::argv [incr idx]]
}
namespace eval runtime {
# runtime makefile variable & targets
variable targets [list]
variable make_debug 0
variable faust2vhdl 0
variable reset_check 1
variable force 0
set mkenv_parameters [list]
set cli_parameters [list]
variable mode "command"
set root $sroot
}
namespace eval p {
set fpga_parameters [list \
"TARGET_TYPE" \
"FAUST_DSP_TARGET" \
"FAUST_FIXED_POINT" \
"FAUST_MCD" \
"FAUST_FPGA_MEM" \
"FAUST_VEC" \
"HLS_SOURCE_MAIN" \
"HLS_CSIM_SOURCE" \
"HLS_CSIM_NUM_ITER" \
"HLS_CSIM_INPUTS_DIR" \
"XILINX_ROOT" \
"XILINX_VERSION" \
"HLS_DIRECTIVES_UNSAFE_MATH_OPTIMIZATIONS" \
"HLS_ROUTING_AND_PLACEMENT" \
"CONFIG_EXPERIMENTAL_ETHERNET" \
"CONFIG_EXPERIMENTAL_ETHERNET_NO_OUTPUT" \
"CONFIG_EXPERIMENTAL_SIGMA_DELTA" \
"CONFIG_EXPERIMENTAL_TDM" \
"SIGMA_DELTA_ORDER" \
"INPUTS" \
"OUTPUTS" \
"MULTISAMPLE" \
"BOARD" \
"MEMORY_TARGET" \
"SAMPLE_RATE" \
"SAMPLE_WIDTH" \
"DEBUG_AUDIO" \
]
set arm_parameters [list \
"CTRL_MIDI" \
"CTRL_OSC" \
"CTRL_HTTP" \
"ADAU_EXTERN" \
"ADAU_MOTHERBOARD" \
"SSM_VOLUME" \
"SSM_SPEED" \
"CONTROLLER_TYPE" \
"VERBOSE" \
]
set cmd_parameters [list \
"SCP_TARGET_ADDR" \
"SCP_TARGET_USER" \
"SD_DEVICE" \
"IMPORT_TARGET" \
"EXPORT_TARGET" \
]
}
if [file exists "$::runtime::root/makefile.env"] {
# Parse parameters
set f [open $::runtime::root/makefile.env r]
set d [read $f]
foreach l [split $d "\n"] {
if [regexp {.*:=.*} $l] {
set s [split $l ":="]
set p [string trimright [lindex $s 0]]
set v [string trimleft [lindex $s 2]]
lappend ::runtime::mkenv_parameters [list $p $v]
# print_info "Retrieved parameter $p with value $v"
}
}
} else {
# Otherwise, don't ask for a reset when adding parameters
set ::runtime::reset_check 0
}
proc add_target {target} {
lappend ::runtime::targets $target
}
proc set_parameter {parameter value} {
lappend ::runtime::cli_parameters [list $parameter $value]
}
proc parameter_type {p} {
if [lcontains $p $::p::fpga_parameters] {
return "fpga"
} elseif [lcontains $p $::p::arm_parameters] {
return "arm"
} elseif [lcontains $p $::p::cmd_parameters] {
return "cmd"
} else {
return "err"
}
}
proc reset_yn {p} {
if $::runtime::force {
set confirm "y"
} else {
print_info "[emph Warning], adding/removing or re-setting parameter [emph $p] would require
re-setting the project, would you like to continue? \[y/[emph N]\]"
set confirm [gets stdin]
}
switch $confirm {
y - Y - yes - Yes - YES {
file delete -force "build"
exec rm -rf "syfala_log.txt"
}
default {
exit 0
}
}
}
proc handle_value_change {p} {
# If value is different, two possibilities:
switch [parameter_type $p] {
fpga {
# For an FPGA-dependent parameter, ask for a build reset
# print_info "Parameter $p: value changed!"
if $::runtime::reset_check {
reset_yn $p
set ::runtime::reset_check 0
}
}
arm {
# For an ARM-dependent parameter, re-build host control application.
exec touch $::Syfala::INCLUDE_DIR/syfala/config_arm.hpp
}
cmd {}
err {}
}
}
proc write_mkenv {mkenv} {
# Write 'makefile.env'
set f [open "$::runtime::root/makefile.env" w]
foreach p $mkenv {
set n [lindex $p 0]
set v [lindex $p 1]
set l "$n := $v"
puts $f $l
}
close $f
}
proc process_mkenv {} {
switch $::runtime::mode {
command {
# If we're in 'command mode':
# - we should keep 'makefile.env' as is, not to mess with the current build.
set mkenv [list]
foreach mkenv_p $::runtime::mkenv_parameters {
set mkenv_pn [lindex $mkenv_p 0]
set mkenv_pv [lindex $mkenv_p 1]
# - the only thing we can remove/replace are the command-related
# options & variables.
switch [parameter_type $mkenv_pn] {
fpga - arm {
lappend mkenv $mkenv_p
}
cmd {
foreach p $::runtime::cli_parameters {
set pn [lindex $p 0]
set pv [lindex $p 1]
if {$pn == $mkenv_pn} {
# 1. if also in cli, re-set it with newest value
lappend mkenv $p
break
}
}
}
}
}
# Now, check if new cmd_parameters have been added
foreach p $::runtime::cli_parameters {
set pn [lindex $p 0]
switch [parameter_type $pn] {
cmd {
set found 0
foreach mkenv_p $::runtime::mkenv_parameters {
set mkenv_pn [lindex $mkenv_p 0]
if {$pn == $mkenv_pn} {
set found 1
}
}
# Parameter not already found in 'makefile.env'
# Add it to the list.
if !$found {
lappend mkenv $p
}
}
}
}
write_mkenv $mkenv
}
build {
# Otherwise, check all command-line-entered parameters.
foreach p $::runtime::cli_parameters {
# Retrieve parameter name 'pn' & value 'pv'
set pn [lindex $p 0]
set pv [lindex $p 1]
set found 0
# Check if parameters is not already registered in 'makefile.env'
foreach mkenv_p $::runtime::mkenv_parameters {
set mkenv_pn [lindex $mkenv_p 0]
set mkenv_pv [lindex $mkenv_p 1]
if {$pn == $mkenv_pn} {
# If already registered, compare their values
set found 1
if {$pv != $mkenv_pv} {
handle_value_change $pn
}
}
}
# Now if the parameter has not been registered in previous 'makefile.env':
if !$found {
handle_value_change $pn
}
}
# Finally, check for 'removed' parameters
foreach mkenv_p $::runtime::mkenv_parameters {
set mkenv_pn [lindex $mkenv_p 0]
set found 0
foreach p $::runtime::cli_parameters {
set pn [lindex $p 0]
if {$mkenv_pn == $pn} {
set found 1
}
}
if !$found {
handle_value_change $mkenv_pn
}
}
write_mkenv $::runtime::cli_parameters
}
}
}
proc make {} {
# Write 'makefile.env' with cli parameters
cd $::runtime::root
process_mkenv
if [is_empty $::runtime::targets] {
lappend ::runtime::targets "all"
}
if $::runtime::make_debug {
exec make -dn {*}$::runtime::targets reports >&@stdout
} else {
if [contains "log" $::runtime::targets] {
exec make {*}$::runtime::targets >&@stdout
} elseif [contains "help" $::runtime::targets] {
exec make {*}$::runtime::targets >&@stdout
} else {
if {[set err [catch "exec make {*}$::runtime::targets reports >&@stdout | tee -a syfala_log.txt"]]} {
print_error "Command failed with error code: $err"
if [contains "hls" $::runtime::targets] {
exec make reports >&@stdout
}
exit
}
}
}
}
# -----------------------------------------------------------------------------------------
# PARSING COMMAND-LINE ARGUMENTS
# -----------------------------------------------------------------------------------------
for {set index 0} {$index < [llength $::argv]} {incr index} {
set argument [lindex $::argv $index]
switch $argument {
COMMENT {
# tcl doesn't allow comments outside of switch blocks...
# we actually have to do this...
# -----------------------------------------------------------------------------------------
# BASICS
# -----------------------------------------------------------------------------------------
}
-h - --help - help {
add_target "help"
}
-v - --version - version {
add_target "version"
}
COMMENT {
# -----------------------------------------------------------------------------------------
# COMMANDS
# -----------------------------------------------------------------------------------------
}
install {
add_target "install"
}
tidy {
add_target "tidy"
}
clean {
add_target "clean"
}
reset {
set target [get_argument_value index]
switch $target {
linux {
set part [get_argument_value index]
switch $part {
boot {add_target "reset-linux-boot"}
root {add_target "reset-linux-root"}
default {add_target "reset-linux"}
}
}
default {
add_target "reset"
}
}
}
open-project {
set target [get_argument_value index]
switch $target {
hls - HLS {
add_target "open-project-hls"
}
default {
add_target "open-project"
}
}
}
report - rpt - --report - --rpt {
set target [get_argument_value index]
switch $target {
HLS - hls {
add_target "report-hls"
}
default {
add_target "report"
}
}
}
import {
set target [get_argument_value index]
set_parameter "IMPORT_TARGET" $target
add_target "import"
}
export {
set target [get_argument_value index]
set_parameter "EXPORT_TARGET" $target
add_target "export"
}
--export-hls {
add_target "hls-export"
}
flash - --flash {
set platform [get_argument_value index]
switch $platform {
linux {
set target [get_argument_value index]
add_target "linux"
switch $target {
boot {add_target "flash-linux-boot"}
root {add_target "flash-linux-root"}
dsp {add_target "flash-linux-dsp"}
default {
incr index -1
add_target "flash-linux"
}
}
}
boot {
add_target "flash-boot"
}
default {
add_target "flash"
}
}
}
scp {
set addr [get_argument_value index]
set host [get_argument_value index]
set_parameter "SCP_TARGET_ADDR" $addr
if [not_empty $host] {
set_parameter "SCP_TARGET_USER" $host
}
add_target "scp"
}
test {
add_target "tests"
}
log {
add_target "log"
}
COMMENT {
# -----------------------------------------------------------------------------------------
# OPTIONS
# -----------------------------------------------------------------------------------------
}
-x - --xilinx-root {
set_parameter "XILINX_ROOT" [get_argument_value index]
}
--xversion {
set_parameter "XILINX_VERSION" [get_argument_value index]
}
--flatpak {
set_parameter "XILINX_FLATPAK" TRUE
}
--unsafe-math-optimizations - --umo {
set_parameter "HLS_DIRECTIVES_UNSAFE_MATH_OPTIMIZATIONS" TRUE
}
--accurate-use {
set_parameter "HLS_ROUTING_AND_PLACEMENT" TRUE
}
--csim {
add_target "hls-csim"
set_parameter "HLS_CSIM_SOURCE" [get_argument_value index]
}
--csim-iter {
set_parameter "HLS_CSIM_NUM_ITER" [get_argument_value index]
}
--csim-inputs {
set_parameter "HLS_CSIM_INPUTS_DIR" [file normalize [get_argument_value index]]
}
--arm-target {
set_parameter "HOST_MAIN_SOURCE" [file normalize [get_argument_value index]]
}
--benchmark {
set_parameter "ARM_BENCHMARK" 1
}
--verbose {
set level [get_argument_value index]
if [is_empty $level] {
set level 1
}
set_parameter "VERBOSE" $level
}
--sigma-delta {
set order [get_argument_value index]
set_parameter "CONFIG_EXPERIMENTAL_SIGMA_DELTA" TRUE
set_parameter "SIGMA_DELTA_ORDER" $order
}
--tdm {
set_parameter "CONFIG_EXPERIMENTAL_TDM" TRUE
}
--linux {
add_target "linux"
}
--linux-dsp {
set_parameter "LINUX" TRUE
add_target "linux-dsp"
}
--vhdl - --faust2vhdl {
set_parameter "TARGET_TYPE" faust2vhdl
set ::runtime::faust2vhdl 1
}
--fixed-point {
set_parameter "FAUST_FIXED_POINT" TRUE
}
--inputs {
set_parameter "INPUTS" [get_argument_value index]
}
--outputs {
set_parameter "OUTPUTS" [get_argument_value index]
}
--mcd {
set_parameter "FAUST_MCD" [get_argument_value index]
}
--fvec {
set_parameter "FAUST_VEC" 1
}
--multisample {
set_parameter "MULTISAMPLE" [get_argument_value index]
}
--no-ctrl-block - --ncb {
set_parameter "CONTROL_BLOCK" 0
}
--block-design - --bd {
set_parameter "BD_TARGET" [get_argument_value index]
}
--transceiver - --i2s {
set_parameter "I2S_SOURCE" [get_argument_value index]
}
--shield {
set target [get_argument_value index]
switch $target {
adau {
set_parameter "ADAU_EXTERN" 1
}
motherboard {
set_parameter "ADAU_EXTERN" 1
set_parameter "ADAU_MOTHERBOARD" 1
}
}
}
--ethernet - --eth {
set_parameter "CONFIG_EXPERIMENTAL_ETHERNET" TRUE
}
--no-ethernet-output {
set_parameter "CONFIG_EXPERIMENTAL_ETHERNET_NO_OUTPUT" 1
}
--midi {
set_parameter "CTRL_MIDI" 1
}
--osc {
set_parameter "CTRL_OSC" 1
}
--http {
set_parameter "CTRL_HTTP" 1
}
--sd {
set target [get_argument_value index]
set_parameter "SD_DEVICE" $target
}
--debug {
set target [get_argument_value index]
switch $target {
audio {
set_parameter "DEBUG_AUDIO" 1
}
make {
set ::runtime::make_debug 1
}
default {
# TODO
}
}
}
-y {
set ::runtime::force 1
}
COMMENT {
# -----------------------------------------------------------------------------------------
# BUILD STEPS
# -----------------------------------------------------------------------------------------
}
--faust {
# This is used by multiN, in order to make a copy of the dsp file and
# replace the patterns there instead of doing so in the original file.
add_target "build-faust-target"
}
arch - --arch - sources - --sources {
add_target "sources"
}
hls - --hls - ip - --ip {
add_target "hls"
}
project - --project {
add_target "project"
}
syn - synth - --syn - --synth {
add_target "hw"
}
app - --app - host - --host {
add_target "sw"
}
gui - --gui {
add_target "gui"
}
start-gui {
add_target "start-gui"
}
boot - --boot {
add_target "boot"
}
COMMENT {
# -----------------------------------------------------------------------------------------
# RUNTIME PARAMETERS
# -----------------------------------------------------------------------------------------
}
-b - --board {
set_parameter "BOARD" [get_argument_value index]
}
-m - --memory {
set_parameter "MEMORY_TARGET" [get_argument_value index]
}
--faust-mem {
set_parameter "FAUST_FPGA_MEM" [get_argument_value index]
}
--sample-rate {
set_parameter "SAMPLE_RATE" [get_argument_value index]
}
--sample-width {
set_parameter "SAMPLE_WIDTH" [get_argument_value index]
}
--controller-type {
set_parameter "CONTROLLER_TYPE" [get_argument_value index]
}
--ssm-volume {
set_parameter "SSM_VOLUME" [get_argument_value index]
}
--ssm-speed {
set_parameter "SSM_SPEED" [get_argument_value index]
}
COMMENT {
# -----------------------------------------------------------------------------------------
# DSP FILE / INVALID ARGUMENT
# -----------------------------------------------------------------------------------------
}
default {
# check DSP target file
if [string match "*.dsp" $argument] {
set_parameter "FAUST_DSP_TARGET" [file normalize $argument]
set ::runtime::mode "build"
if !$::runtime::faust2vhdl {
set_parameter "TARGET_TYPE" faust
}
} elseif [string match "*.cpp" $argument] {
set_parameter "HLS_SOURCE_MAIN" [file normalize $argument]
set_parameter "TARGET_TYPE" cpp
set ::runtime::mode "build"
} else {
print_error "Invalid argument ($argument), aborting"
exit 1
}
}
}
}
make
print_elapsed_time $tstart
print_ok "Successful run!"
print_ok "To see the build's full log: open 'syfala_log.txt' in the repository's root directory"