1;;; gEDA - GPL Electronic Design Automation 2;;; gnetlist - gEDA Netlist 3;;; Copyright (C) 1998-2010 Ales Hvezda 4;;; Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details) 5;;; 6;;; This program is free software; you can redistribute it and/or modify 7;;; it under the terms of the GNU General Public License as published by 8;;; the Free Software Foundation; either version 2 of the License, or 9;;; (at your option) any later version. 10;;; 11;;; This program is distributed in the hope that it will be useful, 12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14;;; GNU General Public License for more details. 15;;; 16;;; You should have received a copy of the GNU General Public License 17;;; along with this program; if not, write to the Free Software 18;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19;;; MA 02111-1301 USA. 20 21 22;; get all packages for a particular schematic page 23;; eventually placeholder will be either the hierarchical level or something 24;; of the sort 25(define packages 26 (gnetlist:get-packages "placeholder")) 27 28;; return a list of all unique the nets in the design 29(define all-unique-nets 30 (gnetlist:get-all-unique-nets "placeholder")) 31 32;; return a list of all the nets in the design 33;; Might return duplicates 34(define all-nets 35 (gnetlist:get-all-nets "placeholder")) 36 37 38;; not very useful, but amusing 39(define all-pins 40 (map gnetlist:get-pins packages)) 41 42 43;; 44;; Functions for dealing with naming requirements for different 45;; output netlist formats which may be more restrictive than 46;; gEDA's internals. 47;; 48 49;; These will become hash tables which provide the mapping 50;; from gEDA net name to netlist net name and from netlist 51;; net name to gEDA net name. 52(define gnetlist:net-hash-forward (make-hash-table (length all-nets))) 53(define gnetlist:net-hash-reverse (make-hash-table (length all-nets))) 54 55;; These will become hash tables which provide the mapping 56;; from gEDA refdes to netlist refdes and from netlist 57;; refdes to gEDA refdes. 58(define gnetlist:refdes-hash-forward (make-hash-table (length packages))) 59(define gnetlist:refdes-hash-reverse (make-hash-table (length packages))) 60 61;; build the hash tables with the net name mappings and 62;; while doing so, check for any shorts which are created 63;; by modifying the netnames. If a short occurs, error out 64;; with a descriptive message. 65;; 66;; This function should be called as one of the first steps 67;; in a netlister which needs to alias nets. 68(define gnetlist:build-net-aliases 69 (lambda (mapfn nets) 70 (if (not (null? nets)) 71 (begin 72 (let ( (net (car nets)) 73 (alias (mapfn (car nets))) 74 ) 75 76 (if (hash-ref gnetlist:net-hash-reverse alias) 77 (begin 78 (display "***** ERROR *****\n") 79 (display "There is a net name collision!\n") 80 (display "The net called \"") 81 (display net) 82 (display "\" will be remapped\nto \"") 83 (display alias) 84 (display "\" which is already used\n") 85 (display "by the net called \"") 86 (display (hash-ref gnetlist:net-hash-reverse alias)) 87 (display "\".\n") 88 (display "This may be caused by netname attributes colliding with other netnames\n") 89 (display "due to truncation of the name, case insensitivity, or\n") 90 (display "other limitations imposed by this netlist format.\n") 91 (error) 92 ) 93 ) 94 (hash-create-handle! gnetlist:net-hash-forward net alias) 95 (hash-create-handle! gnetlist:net-hash-reverse alias net ) 96 (gnetlist:build-net-aliases mapfn (cdr nets)) 97 ) 98 ) 99 ) 100 ) 101 ) 102 103;; build the hash tables with the refdes mappings and 104;; while doing so, check for any name clashes which are created 105;; by modifying the refdes's. If a name clash occurs, error out 106;; with a descriptive message. 107;; 108;; This function should be called as one of the first steps 109;; in a netlister which needs to alias refdes's. 110(define gnetlist:build-refdes-aliases 111 (lambda (mapfn refdeses) 112 (if (not (null? refdeses)) 113 (begin 114 (let ( (refdes (car refdeses)) 115 (alias (mapfn (car refdeses))) 116 ) 117 118 (if (hash-ref gnetlist:refdes-hash-reverse alias) 119 (begin 120 (display "***** ERROR *****\n") 121 (display "There is a refdes name collision!\n") 122 (display "The refdes \"") 123 (display refdes) 124 (display "\" will be mapped\nto \"") 125 (display alias) 126 (display "\" which is already used\n") 127 (display "by \"") 128 (display (hash-ref gnetlist:refdes-hash-reverse alias)) 129 (display "\".\n") 130 (display "This may be caused by refdes attributes colliding with others\n") 131 (display "due to truncation of the refdes, case insensitivity, or\n") 132 (display "other limitations imposed by this netlist format.\n") 133 (error) 134 ) 135 ) 136 (hash-create-handle! gnetlist:refdes-hash-forward refdes alias) 137 (hash-create-handle! gnetlist:refdes-hash-reverse alias refdes ) 138 (gnetlist:build-refdes-aliases mapfn (cdr refdeses)) 139 ) 140 ) 141 ) 142 ) 143 ) 144 145;; convert a gEDA netname into an output netlist net name 146(define gnetlist:alias-net 147 (lambda (net) 148 (hash-ref gnetlist:net-hash-forward net) 149 ) 150 ) 151 152;; convert a gEDA refdes into an output netlist refdes 153(define gnetlist:alias-refdes 154 (lambda (refdes) 155 (hash-ref gnetlist:refdes-hash-forward refdes) 156 ) 157 ) 158 159;; convert an output netlist net name into a gEDA netname 160(define gnetlist:unalias-net 161 (lambda (net) 162 (hash-ref gnetlist:net-hash-reverse net) 163 ) 164 ) 165 166;; convert an output netlist refdes into a gEDA refdes 167(define gnetlist:unalias-refdes 168 (lambda (refdes) 169 (hash-ref gnetlist:refdes-hash-reverse refdes) 170 ) 171 ) 172 173