[14] | 1 | #!nawk -f |
---|
| 2 | |
---|
| 3 | #**CFile*********************************************************************** |
---|
| 4 | # |
---|
| 5 | # FileName [ioBlifToMv.nawk] |
---|
| 6 | # |
---|
| 7 | # PackageName [io] |
---|
| 8 | # |
---|
| 9 | # Synopsis [A nawk script to convert a blif file into a blif-mv file.] |
---|
| 10 | # |
---|
| 11 | # Description [A nawk script to convert a blif file into a blif-mv file. |
---|
| 12 | # The blif file should be free of errors. The script ignores synthesis related |
---|
| 13 | # information.] |
---|
| 14 | # |
---|
| 15 | # SeeAlso [] |
---|
| 16 | # |
---|
| 17 | # Author [Rajeev K. Ranjan, Yuji Kukimoto] |
---|
| 18 | # |
---|
| 19 | # Copyright [Copyright (c) 1994-1996 The Regents of the Univ. of California. |
---|
| 20 | # All rights reserved. |
---|
| 21 | # |
---|
| 22 | # Permission is hereby granted, without written agreement and without license |
---|
| 23 | # or royalty fees, to use, copy, modify, and distribute this software and its |
---|
| 24 | # documentation for any purpose, provided that the above copyright notice and |
---|
| 25 | # the following two paragraphs appear in all copies of this software. |
---|
| 26 | # |
---|
| 27 | # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR |
---|
| 28 | # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
---|
| 29 | # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |
---|
| 30 | # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 31 | # |
---|
| 32 | # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
---|
| 33 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
---|
| 34 | # FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN |
---|
| 35 | # "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE |
---|
| 36 | # MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.] |
---|
| 37 | # |
---|
| 38 | #*****************************************************************************/ |
---|
| 39 | |
---|
| 40 | BEGIN { |
---|
| 41 | while (my_getline()){ |
---|
| 42 | main() |
---|
| 43 | } |
---|
| 44 | print ".end" |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | function main(){ |
---|
| 48 | while (1) { |
---|
| 49 | if (match($1,"\\.latch|\\.model|\\.inputs|\\.outputs")){ |
---|
| 50 | while (last_char("\\") == 1){ |
---|
| 51 | getline |
---|
| 52 | } |
---|
| 53 | break |
---|
| 54 | } |
---|
| 55 | if ($1 == ".names"){ |
---|
| 56 | print |
---|
| 57 | while (last_char("\\")==1){ |
---|
| 58 | getline |
---|
| 59 | print |
---|
| 60 | } |
---|
| 61 | if (my_getline() == 0) break |
---|
| 62 | if (row_of_table()){ |
---|
| 63 | if (last_char("0")) |
---|
| 64 | print ".def 1" |
---|
| 65 | else |
---|
| 66 | print ".def 0" |
---|
| 67 | while (1){ |
---|
| 68 | gsub("1","1 ") |
---|
| 69 | gsub("0","0 ") |
---|
| 70 | gsub("-","- ") |
---|
| 71 | for(i = 1; i< NF; i++) |
---|
| 72 | printf("%s ",$i) |
---|
| 73 | printf("%s",$NF) |
---|
| 74 | printf("\n") |
---|
| 75 | if (my_getline() == 0) break |
---|
| 76 | if (row_of_table()) |
---|
| 77 | continue |
---|
| 78 | else |
---|
| 79 | break |
---|
| 80 | } |
---|
| 81 | continue |
---|
| 82 | } |
---|
| 83 | else { |
---|
| 84 | print ".def 0" |
---|
| 85 | continue |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | if ($1 == ".subckt"){ |
---|
| 89 | fieldCounter = 0; |
---|
| 90 | do{ |
---|
| 91 | last_char_back_slash = last_char("\\") |
---|
| 92 | gsub("\\\\","") |
---|
| 93 | for (i=1; i<=NF; i++){ |
---|
| 94 | fieldArray[fieldCounter] = $i; |
---|
| 95 | fieldCounter++; |
---|
| 96 | } |
---|
| 97 | if (last_char_back_slash) getline |
---|
| 98 | } while (last_char_back_slash) |
---|
| 99 | |
---|
| 100 | printf("%s %s %d ", fieldArray[0], fieldArray[1], subckt_counter) |
---|
| 101 | subckt_counter++; |
---|
| 102 | for (i=2; i<fieldCounter-1; i++){ |
---|
| 103 | printf("%s ", fieldArray[i]) |
---|
| 104 | } |
---|
| 105 | printf("%s\n", fieldArray[fieldCounter-1]); |
---|
| 106 | } |
---|
| 107 | if ($1 == ".exdc"){ # ignore the rest of the file |
---|
| 108 | while (getline){ |
---|
| 109 | } |
---|
| 110 | break |
---|
| 111 | } |
---|
| 112 | while (last_char("\\")==1) |
---|
| 113 | getline |
---|
| 114 | break |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | function last_char(char, linelength, lastchar){ |
---|
| 119 | linelength = length |
---|
| 120 | lastchar = substr($0, linelength) |
---|
| 121 | if (lastchar == char) |
---|
| 122 | return 1 |
---|
| 123 | else |
---|
| 124 | return 0 |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | function first_char(char, firstchar){ |
---|
| 128 | firstchar = substr($1,1,1) |
---|
| 129 | if (firstchar == char) |
---|
| 130 | return 1 |
---|
| 131 | else |
---|
| 132 | return 0 |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | function row_of_table(){ |
---|
| 136 | if (first_char("1") || first_char("0") || first_char("-")) |
---|
| 137 | return 1 |
---|
| 138 | else |
---|
| 139 | return 0 |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | function my_getline(){ |
---|
| 144 | while (getline){ |
---|
| 145 | if ((NF == 0) || first_char("#")) |
---|
| 146 | continue |
---|
| 147 | return 1 |
---|
| 148 | } |
---|
| 149 | return 0 |
---|
| 150 | } |
---|