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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
###############################################################################
# Copyright (c) 2018-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform.  As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose.  Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
#   @plugin
#       Import Synplicity Project
#   @namespace
#       ImportSynplicity
#   @section
#       Link to Other Tools
#   @description
#       Insert a Userware menu to import Synplicity project files.
#   @license
#       permit rtl
#       permit verilog
#   @files
#       importSynplicity/importSynplicity.tcl
#   @tag
#       rtl verilog fpga
###############################################################################


# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc ImportSynplicity:Init {argv} {
    global ImportSynplicity

    set ImportSynplicity(file)         {}
    set ImportSynplicity(base_dir)     {}
    set ImportSynplicity(output)       {}
    set ImportSynplicity(args)         {}
    set ImportSynplicity(run_from_gui) 1

    ##
    # Add menu entries.
    #
    gui menu command {"Userware" "Import Synplicity Project"} \
        [list ImportSynplicity:ShowDialog]

    ##
    # Immediately load project file if additional command line options
    # are present.
    #
    set argc [llength $argv]
    if {$argc == 1} {
        set ImportSynplicity(run_from_gui) 0
        set ImportSynplicity(file)   [lindex $argv 0]
    } elseif {$argc == 2} {
        set ImportSynplicity(run_from_gui) 0
        set ImportSynplicity(file)   [lindex $argv 0]
        set ImportSynplicity(output) [lindex $argv 1]
    }

    if {$ImportSynplicity(file) != {}} {
        if {[catch {ImportSynplicity:Import} msg]} {
            zmessage print ERR \
                "Error while importing Synplicity project: $msg"
        }
    }
}


# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc ImportSynplicity:Finit {} {
    ##
    # Undo modifications of the GUI.
    #
    gui menu removeEntry {"Userware" "Import Synplicity Project"}
}


# -----------------------------------------------------------------------------
# _browseFile -
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_browseFile {type w} {
    global ImportSynplicity

    switch -exact -- $type {
        "input" {
            set fname [gui window fileDialog openFile \
                -parent $w                            \
                "Select Synplicity Project File"      \
                {{"Synplicity Project" {.prj}}}       \
            ]
            if {$fname != {}} {
                set ImportSynplicity(file) $fname
            }
        }
        "output" {
            set fname [gui window fileDialog saveFile \
                -parent $w                            \
                "Select Set File"                     \
                {{"Set File" {.set}}}                 \
            ]
            if {$fname != {}} {
                set ImportSynplicity(output) $fname
            }
        }
        default {}
    }
}


# =============================================================================
# ShowDialog - create and display the 'Import Synplicity Project' dialog.
# =============================================================================
#
proc ImportSynplicity:ShowDialog {} {
    global ImportSynplicity

    set w .importSynplicityDialog
    if {[winfo exists $w]} {
        destroy $w
    }
    toplevel $w -class Dialog

    set row -1

    set infoText [list \
        "Import a Synplicity project file." \
        "" \
        "You can optionally write a 'Set' file, which can later be read via\
        the Open dialog's 'Restore Settings' function, or via the command\
        line option '-argsFromFile'." \
        "" \
        "You can directly import Synplicity projects from the command line via"\
        "    *vision -userware2 importSynplicity.tcl project.prj" \
        "    *vision -userware3 importSynplicity.tcl project.prj project.set" \
        "" \
        "Importing a Synplicity project may fail due to an incomplete\
        implementation of the Synplicity commands. If you run into problems,\
        enable 'Verbose' messages (Preferences > Misc > Report Level: Verbose)\
        in order to see detailed messages from the import process." \
    ]
    set width  80
    set height 2
    foreach line $infoText {
        incr height
        set len [string length $line]
        if {$len >= $width} {
            incr height [expr {($len - $width) / $width}]
        }
    }
    text $w.info \
        -height $height \
        -width  [expr {$width + 5}] \
        -wrap word \
        -relief flat -padx 8 -pady 8
    $w.info insert end [join $infoText \n]
    $w.info configure -state disabled
    grid $w.info -row [incr row] -column 0 -sticky news

    set space1 [incr row]

    ttk::label $w.inpLabel -text "Synplicity Project File:"
    grid $w.inpLabel -row [incr row] -column 0 -sticky news -padx 8

    ttk::frame  $w.file
    ttk::entry  $w.file.fname  -textvariable ImportSynplicity(file)
    ttk::button $w.file.browse \
        -text "..." \
        -style Browse.TButton \
        -width 3 \
        -command [list ImportSynplicity:_browseFile input $w]
    grid $w.file.fname  -row 0 -column 0 -sticky ew
    grid $w.file.browse -row 0 -column 1
    grid columnconfigure $w.file 0 -weight 1
    grid $w.file -row [incr row] -column 0 -sticky news -padx 8

    ttk::label $w.outpLabel -text "Create Set File (optional):"
    grid $w.outpLabel -row [incr row] -column 0 -sticky news -padx 8

    ttk::frame  $w.outp
    ttk::entry  $w.outp.fname  -textvariable ImportSynplicity(output)
    ttk::button $w.outp.browse \
        -text "..." \
        -style Browse.TButton \
        -width 3 \
        -command [list ImportSynplicity:_browseFile output $w]
    grid $w.outp.fname  -row 0 -column 0 -sticky ew
    grid $w.outp.browse -row 0 -column 1
    grid columnconfigure $w.outp 0 -weight 1
    grid $w.outp -row [incr row] -column 0 -sticky news -padx 8

    set space2 [incr row]

    ttk::frame  $w.btns
    ttk::button $w.btns.cancel -text "Cancel"
    ttk::button $w.btns.import -text "Import"

    grid columnconfigure $w.btns 0 -weight 1
    grid $w.btns.cancel -row 0 -column 1 -padx 5 -pady 2
    grid $w.btns.import -row 0 -column 2 -padx 5 -pady 2

    grid $w.btns -row [incr row] -column 0 -sticky news

    grid columnconfigure $w 0 -weight 1
    grid rowconfigure    $w 0 -weight 1
    grid rowconfigure    $w $space1 -minsize 8
    grid rowconfigure    $w $space2 -minsize 8

    set but [gui window dialog \
        $w \
        "Import Synplicity Project" \
        -place "CENTER" \
        -focus $w.btns.cancel \
        -buttons [list $w.btns.cancel $w.btns.import] \
    ]

    set err 0
    if {$but == 1} {
        if {$ImportSynplicity(file) == ""} {
            set err 1
            zmessage print ERR \
                "No Synplicity project file selected."
        }

        if {!$err} {
            set ImportSynplicity(run_from_gui) 1
            if {[catch {ImportSynplicity:Import} msg]} {
                zmessage print ERR \
                    "Error while importing Synplicity project: $msg"
            }
        }
    }

    destroy $w
}


# -----------------------------------------------------------------------------
# _unknown - "unknown" slave interpreter command.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_unknown {command args} {
    zmessage print WAR \
        "ImportSynplicity: ignoring unsupported command: $command $args"
}


# -----------------------------------------------------------------------------
# _puts - "puts" slave interpreter command.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_puts {args} {
    set argc [llength $args]
    if {$argc == 1} {
        zmessage print TIT \
            "ImportSynplicity: message: [lindex $args 0]"
    }
}


# -----------------------------------------------------------------------------
# _guessFileType - guess file type from file extension.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_guessFileType {fname} {
    foreach {ext type} {
        .adc  -analysis_constraint
        .edf  -edif
        .edn  -edif
        .fdc  -fpga_constraint
        .sdc  -constraint
        .sv   -verilog
        .tcl  -tcl
        .v    -verilog
        .vhd  -vhdl
        .vhdl -vhdl
    } {
        if {[string match "*$ext" $fname]} {
            return $type
        }
    }

    return "-include"
}


# -----------------------------------------------------------------------------
# _expandFileName - convert fname to absolute path relative to the project file.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_expandFileName {fname} {
    global ImportSynplicity

    return [zos convertFilename2 $fname $ImportSynplicity(base_dir)]
}


# -----------------------------------------------------------------------------
# _add_file - "add_file" slave interpreter command.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_add_file {args} {
    global ImportSynplicity

    set file_type ""
    set vhdl_lib  "work"

    ##
    # Use placeholder for vlog_std as the actual value may be set later using
    # "set_option -vlog_std ...".
    #
    set vlog_std  "PARAM_VLOG_STD"

    for {set i 0} {$i < [llength $args]} {incr i} {
        set arg [lindex $args $i]
        switch -- $arg {
            "-constraint"          -
            "-analysis_constraint" -
            "-edif"                -
            "-fpga_constraint"     -
            "-include"             -
            "-tcl"                 -
            "-verilog"             -
            "-vhdl"                {
                set file_type $arg
            }
            "-folder" {
                incr i
                zmessage print WAR \
                    "ImportSynplicity: 'add_file':\
                    ignoring unsupported option: $arg [lindex $args $i]"
            }
            "-lib" {
                incr i
                set vhdl_lib [lindex $args $i]
            }
            "-vlog_std" {
                incr i
                set vlog_std [lindex $args $i]
                switch -exact -- $vlog_std {
                    "sysv" {
                        set vlog_std "-systemVerilog"
                    }
                    "v95" {
                        set vlog_std "-verilog95"
                    }
                    "v2001" {
                        set vlog_std "-verilog2001"
                    }
                    default {
                        zmessage print ERR \
                            "ImportSynplicity: 'add_file':\
                            unknown '-vlog_std' parameter: $vlog_std"
                    }
                }
            }
            "-*" {
                zmessage print ERR \
                    "ImportSynplicity: 'add_file': unknown option: $arg"
            }
            default {
                set t $file_type
                if {$t == ""} {
                    set t [ImportSynplicity:_guessFileType $arg]
                }
                set arg [ImportSynplicity:_expandFileName $arg]
                switch -exact -- $t {
                    "-analysis_constraint" -
                    "-constraint"          -
                    "-fpga_constraint"     -
                    "-include"             -
                    "-tcl"                 {
                        zmessage print WAR \
                            "ImportSynplicity: 'add_file':\
                            ignoring file of unsupported type $t: $arg"
                    }
                    "-edif" {
                        lappend ImportSynplicity(args) [list -edif $arg]
                    }
                    "-verilog" {
                        lappend ImportSynplicity(args) [list $vlog_std $arg]
                    }
                    "-vhdl" {
                        ##
                        # Use placeholder for the vhdl type, as the actual
                        # version may be set later using
                        # "set_option -vhdl2008 0|1".
                        #
                        lappend ImportSynplicity(args) [list -library $vhdl_lib]
                        lappend ImportSynplicity(args) [list PARAM_VHDL $arg]
                    }
                    default {
                        error "unknown switch value: $t"
                    }
                }
            }
        }
    }
}


# -----------------------------------------------------------------------------
# _hdl_define - "hdl_define" slave interpreter command.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_hdl_define {args} {
    global ImportSynplicity

    set n [llength $args]
    if {$n <= 1} {
        zmessage print ERR \
            "ImportSynplicity: 'hdl_define'\
            requires at least one additional parameter"
    }

    if {[lindex $args 0] == "-list"} {
        zmessage print WAR \
            "ImportSynplicity: 'hdl_define': skipping unsupported option -list"
        return
    }

    if {[lindex $args 0] != "-set"} {
        zmessage print WAR \
            "ImportSynplicity: 'hdl_define': unknown option: [lindex $args 0]"
    }

    if {$n != 2} {
        zmessage print ERR \
            "ImportSynplicity: 'hdl_define -set'\
            requires exactly one additional parameter"
    }

    foreach p [regexp -inline -all -- {\S+} [lindex $args 1]] {
        lappend ImportSynplicity(args) [list -define $p]
    }
}


# -----------------------------------------------------------------------------
# _hdl_param - "hdl_param" slave interpreter command.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_hdl_param {args} {
    global ImportSynplicity

    set n [llength $args]
    if {$n != 3} {
        zmessage print ERR \
            "ImportSynplicity: 'hdl_param'\
            requires three additional parameters"
    }

    if {[lindex $args 0] != "-set"} {
        zmessage print WAR \
            "ImportSynplicity: 'hdl_param':\
            skipping unsupported option [lindex $args 0]"
        return
    }

    lappend ImportSynplicity(args) \
        [list -define [lindex $args 1]=[lindex $args 2]]
}


# -----------------------------------------------------------------------------
# _set_option_continue_on_error - handler for the "continue_on_error" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_continue_on_error {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    set p [lindex $params 0]
    if {$p eq "0"} {
        lappend ImportSynplicity(args) [list -breakOnError 1]
    } elseif {$p eq "1"} {
        lappend ImportSynplicity(args) [list -breakOnError 0]
    } else {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option $params':\
            bad parameter $p."
    }
}


# -----------------------------------------------------------------------------
# _set_option_hdl_define - handler for the "-hdl_define" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_hdl_define {option params} {
    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    ImportSynplicity:_hdl_define {*}$params
}


# -----------------------------------------------------------------------------
# _set_option_hdl_param - handler for the "-hdl_param" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_hdl_param {option params} {
    set n [llength $params]
    if {$n != 3} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires three additional parameters"
    }

    ImportSynplicity:_hdl_param {*}$params
}


# -----------------------------------------------------------------------------
# _set_option_include_path - handler for the "-include_path" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_include_path {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    foreach p [split [lindex $params 0] ";"] {
        lappend ImportSynplicity(args) \
            [list -incdir [ImportSynplicity:_expandFileName $p]]
    }
}


# -----------------------------------------------------------------------------
# _set_option_libext - handler for the "-libext" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_libext {option params} {
    global ImportSynplicity

    if {$params == {}} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires at least one additional parameter"
    }

    lappend ImportSynplicity(args) +libext+[join $params +]
}


# -----------------------------------------------------------------------------
# _set_option_library_path - handler for the "-library_path" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_library_path {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    foreach p [split [lindex $params 0] ";"] {
        lappend ImportSynplicity(args) \
            [list -y [ImportSynplicity:_expandFileName $p]]
    }
}


# -----------------------------------------------------------------------------
# _set_option_multi_file_compilation_unit - handler for the
#                                           "-multi_file_compilation_unit"
#                                           option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_multi_file_compilation_unit {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    set p [lindex $params 0]
    if {$p eq "0"} {
        lappend ImportSynplicity(args) [list -compileMode mfcu]
    } elseif {$p eq "1"} {
        lappend ImportSynplicity(args) [list -compileMode sfcu]
    } else {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option $params':\
            bad parameter $p."
    }
}


# -----------------------------------------------------------------------------
# _set_option_synthesis_onoff_pragma - handler for the "-synthesis_onoff_pragma"
#                                      option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_synthesis_onoff_pragma {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
           requires one additional parameter"
    }

    set p [lindex $params 0]
    if {($p eq "0") || ($p eq "1")} {
        lappend ImportSynplicity(args) [list -ignoreTranslate $p]
    } else {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option $params':\
            bad parameter $p."
    }
}


# -----------------------------------------------------------------------------
# _set_option_top_module - handler for the "-top_module" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_top_module {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    set p [lindex $params 0]
    lappend ImportSynplicity(args) [list -top $p]
}


# -----------------------------------------------------------------------------
# _set_option_vhdl2008 - handler for the "-vhdl2008" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_vhdl2008 {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    set p [lindex $params 0]
    if {($p eq "0") || ($p eq "1")} {
        set ImportSynplicity(vhdl2008) $p
    } else {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option $params':\
            bad parameter $p."
    }
}


# -----------------------------------------------------------------------------
# _set_option_vlog_std - handler for the "-vlog_std" option.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option_vlog_std {option params} {
    global ImportSynplicity

    set n [llength $params]
    if {$n != 1} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option $option'\
            requires one additional parameter"
    }

    set p [lindex $params 0]
    switch -exact -- $p {
        "sysv" {
            set ImportSynplicity(vlog_std) "-systemVerilog"
        }
        "v95" {
            set ImportSynplicity(vlog_std) "-verilog95"
        }
        "v2001" {
            set ImportSynplicity(vlog_std) "-verilog2001"
        }
        default {
            zmessage print ERR \
                "ImportSynplicity: 'set_option $option $params':\
                bad parameter $p."
        }
    }
}


# -----------------------------------------------------------------------------
# _set_option - "set_option" slave interpreter command.
# -----------------------------------------------------------------------------
#
proc ImportSynplicity:_set_option {args} {
    if {$args == {}} {
        zmessage print ERR \
            "ImportSynplicity: 'set_option' without parameters."
        return
    }

    set option [lindex $args 0]
    set args   [lrange $args 1 end]
    set argc   [llength $args]

    foreach {candidate proc} {
        "continue_on_error"            _set_option_continue_on_error
        "-hdl_define"                  _set_option_hdl_define
        "-hdl_param"                   _set_option_hdl_param
        "-include_path"                _set_option_include_path
        "-libext"                      _set_option_libext
        "-library_path"                _set_option_library_path
        "-multi_file_compilation_unit" _set_option_multi_file_compilation_unit
        "-synthesis_onoff_pragma"      _set_option_synthesis_onoff_pragma
        "-top_module"                  _set_option_top_module
        "-vhdl2008"                    _set_option_vhdl2008
        "-vlog_std"                    _set_option_vlog_std
    } {
        if {$candidate == $option} {
            ImportSynplicity:$proc $option $args
            return
        }
    }

    zmessage print WAR \
        "ImportSynplicity: 'set_option': ignoring unsupported option: $option"
}


# =============================================================================
# Import - actually import a Synplicity file.
# =============================================================================
#
proc ImportSynplicity:Import {} {
    global ImportSynplicity

    set ImportSynplicity(args)     {}
    set ImportSynplicity(vhdl2008) 0
    set ImportSynplicity(vlog_std) "-systemVerilog"

    set file_abs [zos convertFilename $ImportSynplicity(file) absolute]
    set ImportSynplicity(base_dir) [zos dirname $file_abs]

    set i [interp create -safe]
    $i alias unknown    ImportSynplicity:_unknown
    $i alias puts       ImportSynplicity:_puts
    $i alias add_file   ImportSynplicity:_add_file
    $i alias hdl_define ImportSynplicity:_hdl_define
    $i alias hdl_param  ImportSynplicity:_hdl_param
    $i alias set_option ImportSynplicity:_set_option

    interp invokehidden $i source $ImportSynplicity(file)
    interp delete $i

    set f {}
    if {$ImportSynplicity(output) != ""} {
        set f [open $ImportSynplicity(output) w]
        chan configure $f -translation binary
    }

    ##
    # Prepare collected arguments. Replace placeholders.
    #
    set args {}
    foreach arg $ImportSynplicity(args) {
        set arg2 {}
        foreach a $arg {
            switch -exact -- $a {
                "PARAM_VHDL" {
                    if {$ImportSynplicity(vhdl2008)} {
                        lappend arg2 -vhdl2008
                    } else {
                        lappend arg2 -vhdl93
                    }
                }
                "PARAM_VLOG_STD" {
                    lappend arg2 $ImportSynplicity(vlog_std)
                }
                default {
                    lappend arg2 $a
                }
            }
        }
        lappend args {*}$arg2
        if {$f != {}} {
            puts $f $arg2
        }
    }

    if {$f != {}} {
        close $f
    }

    gui parser setArgs rtl $args

    if {$ImportSynplicity(run_from_gui)} {
        gui parser showReadDialog rtl
    }
}


# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
ImportSynplicity:Init $argv