1 ;;; ---------------------------------------------------------------------
2 ;;; Written by Martin Lehmann
3 ;;; ---------------------------------------------------------------------
5 ;;; This file contents two functions to the hot-keys
6 ;;; g-n and g-e, which stand for (g)enerate (n)etlist and - (e)ntity.
9 ;; The generate-mode will be gave to the gnetlist environment, with help
10 ;; of the -c parameter of gEDA gnetlist.
11 ;; The same is doing with all toplevel attributes of a component (or schematic).
12 ;; they are defined in the variable top-attribs.
14 ;; generate-mode sets :
15 ;; 1 - generate netlist of current schematic
16 ;; 2 - generate entity of selected component, or of toplevel, when non selected
18 ;; get-selected-filename: - returns the whole filename of
19 ;; the current-gschem-schematic
21 ;; get-selected-component-attributes: - returns all toplevel attributes
22 ;; of the current entity
24 ;; This function only put together the gnetlist command for the
25 ;; generating-netlist-call.
27 (define generate-netlist
30 (source-file (get-selected-filename))
31 (source-file-length (string-length source-file))
33 ;;generate a sensible output-filename (<old-path>/<old-basefilename>.vhdl)
34 (target-file (string-append
35 (substring source-file
36 (+ (string-rindex source-file #\/ 0
37 (string-length source-file)) 1)
38 (- (string-length source-file) 4))
41 ;;generating the complex gnetlist command
42 (display (getenv 'PWD))
43 (set! command "gnetlist")
44 (set! command (string-append command " -o " vhdl-path "/" target-file))
45 (set! command (string-append command " -g vams " source-file))
46 (display "\ngenerating netlist from current schematic\n")
51 ;; this part is not really important
52 ;;(set! command (string-append "dtpad " vhdl-path "/"
53 ;; (string-append (substring target-file 0
55 ;; target-file #\. 0))
61 ;; Makes the same like generate-netlist, but its activate a
62 ;; generating-entity-call.
64 (define generate-entity
68 (top-attribs (get-selected-component-attributes))
70 ;; search the right schematic-file for gnetlist call
71 ;; Is necessary, when the selected component contents a
72 ;; underlying schematic (hierachical schematic)
73 (source-file (which-source-file top-attribs))
75 ;; generates the target-file, like <source-filebasename>.vhdl
76 (target-file (string-append
77 (substring source-file
78 (if (string-rindex source-file #\/ 0
79 (string-length source-file))
80 (+ (string-rindex source-file #\/ 0
81 (string-length source-file)) 1)
83 (- (string-length source-file) 4))
87 ;; put the whole gnetlist command together
89 (string-append guile-comm "\"(define top-attribs " "'"
90 (list2string top-attribs) ") (define generate-mode '2)\""))
91 (set! command (string-append "gnetlist -c " guile-comm
92 " -o " vhdl-path "/" target-file
93 " -g vams " (get-selected-filename)))
99 ;;(set! command (string-append "dtpad " vhdl-path "/" target-file " &"))
100 ;;(if (null? top-attribs)
108 ;; generates a string from a list.
112 (for-each (lambda (element)
113 (set! string (string-append string element " ")))
115 (set! string (string-append string ")"))
119 ;; search the right source-file, when selected component contents a
120 ;; underlying schematic. which is saved in the source-attribute of
122 (define which-source-file
123 (lambda (top-attribs)
124 (if (not (null? top-attribs))
125 (if (string-prefix=? "source=" (car top-attribs))
127 (append (substring (car top-attribs) 7
128 (string-length (car top-attribs)))))
129 (which-source-file (cdr top-attribs)))
130 (append (get-selected-filename)))))
133 ;; define the default vhdl-path, where netlist- and entity-files are
135 (define vhdl-path ".")
137 (display "loaded generate-netlist.scm\n")