| [11] | 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 | subckt_counter = 0 |
|---|
| 42 | while (my_getline()){ |
|---|
| 43 | main() |
|---|
| 44 | } |
|---|
| 45 | if (flag){ |
|---|
| 46 | print ".end" |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | function main(){ |
|---|
| 51 | while (1) { |
|---|
| 52 | if ($1 == ".model"){ |
|---|
| 53 | print |
|---|
| 54 | while (last_char("\\")==1){ |
|---|
| 55 | getline |
|---|
| 56 | print |
|---|
| 57 | } |
|---|
| 58 | flag = 1; |
|---|
| 59 | break |
|---|
| 60 | } |
|---|
| 61 | if ($1 == ".end"){ |
|---|
| 62 | print |
|---|
| 63 | flag = 0; |
|---|
| 64 | break |
|---|
| 65 | } |
|---|
| 66 | if ($1 == ".inputs" || $1 == ".outputs"){ |
|---|
| 67 | print |
|---|
| 68 | while (last_char("\\")==1){ |
|---|
| 69 | getline |
|---|
| 70 | print |
|---|
| 71 | } |
|---|
| 72 | break |
|---|
| 73 | } |
|---|
| 74 | if ($1 == ".subckt"){ |
|---|
| 75 | fieldCounter = 0; |
|---|
| 76 | do{ |
|---|
| 77 | last_char_back_slash = last_char("\\") |
|---|
| 78 | gsub("\\\\","") |
|---|
| 79 | for (i=1; i<=NF; i++){ |
|---|
| 80 | fieldArray[fieldCounter] = $i; |
|---|
| 81 | fieldCounter++; |
|---|
| 82 | } |
|---|
| 83 | if (last_char_back_slash) getline |
|---|
| 84 | } while (last_char_back_slash) |
|---|
| 85 | |
|---|
| 86 | printf("%s %s %d ", fieldArray[0], fieldArray[1], subckt_counter) |
|---|
| 87 | subckt_counter++; |
|---|
| 88 | for (i=2; i<fieldCounter-1; i++){ |
|---|
| 89 | printf("%s ", fieldArray[i]) |
|---|
| 90 | } |
|---|
| 91 | printf("%s\n", fieldArray[fieldCounter-1]); |
|---|
| 92 | } |
|---|
| 93 | if ($1 == ".latch"){ |
|---|
| 94 | fieldCounter = 0; |
|---|
| 95 | do{ |
|---|
| 96 | last_char_back_slash = last_char("\\") |
|---|
| 97 | gsub("\\\\","") |
|---|
| 98 | for (i=1; i<=NF; i++){ |
|---|
| 99 | fieldArray[fieldCounter] = $i; |
|---|
| 100 | fieldCounter++; |
|---|
| 101 | } |
|---|
| 102 | if (last_char_back_slash) getline |
|---|
| 103 | } while (last_char_back_slash) |
|---|
| 104 | |
|---|
| 105 | print fieldArray[0], " ", fieldArray[1], " ", fieldArray[2] |
|---|
| 106 | print ".reset ", fieldArray[2] |
|---|
| 107 | if ((fieldCounter == 4) || (fieldCounter == 6)){ |
|---|
| 108 | resetValue = fieldArray[fieldCounter-1]; |
|---|
| 109 | if (resetValue == "0" || resetValue == "1") |
|---|
| 110 | print resetValue |
|---|
| 111 | else |
|---|
| 112 | print "-" |
|---|
| 113 | } |
|---|
| 114 | else { |
|---|
| 115 | print "0" |
|---|
| 116 | } |
|---|
| 117 | break |
|---|
| 118 | } |
|---|
| 119 | if ($1 == ".names"){ |
|---|
| 120 | print |
|---|
| 121 | while (last_char("\\")==1){ |
|---|
| 122 | getline |
|---|
| 123 | print |
|---|
| 124 | } |
|---|
| 125 | if (my_getline() == 0) break |
|---|
| 126 | if (row_of_table()){ |
|---|
| 127 | if (last_char("0")) |
|---|
| 128 | print ".def 1" |
|---|
| 129 | else |
|---|
| 130 | print ".def 0" |
|---|
| 131 | while (1){ |
|---|
| 132 | gsub("1","1 ") |
|---|
| 133 | gsub("0","0 ") |
|---|
| 134 | gsub("-","- ") |
|---|
| 135 | for(i = 1; i< NF; i++) |
|---|
| 136 | printf("%s ",$i) |
|---|
| 137 | printf("%s",$NF) |
|---|
| 138 | printf("\n") |
|---|
| 139 | if (my_getline() == 0) break |
|---|
| 140 | if (row_of_table()) |
|---|
| 141 | continue |
|---|
| 142 | else |
|---|
| 143 | break |
|---|
| 144 | } |
|---|
| 145 | continue |
|---|
| 146 | } |
|---|
| 147 | else { |
|---|
| 148 | print ".def 0" |
|---|
| 149 | continue |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | if ($1 == ".exdc"){ # ignore the rest of the file |
|---|
| 153 | while (getline){ |
|---|
| 154 | } |
|---|
| 155 | break |
|---|
| 156 | } |
|---|
| 157 | while (last_char("\\")==1) |
|---|
| 158 | getline |
|---|
| 159 | break |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | function last_char(char, linelength, lastchar){ |
|---|
| 164 | linelength = length |
|---|
| 165 | lastchar = substr($0, linelength) |
|---|
| 166 | if (lastchar == char) |
|---|
| 167 | return 1 |
|---|
| 168 | else |
|---|
| 169 | return 0 |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | function first_char(char, firstchar){ |
|---|
| 173 | firstchar = substr($1,1,1) |
|---|
| 174 | if (firstchar == char) |
|---|
| 175 | return 1 |
|---|
| 176 | else |
|---|
| 177 | return 0 |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | function row_of_table(){ |
|---|
| 181 | if (first_char("1") || first_char("0") || first_char("-")) |
|---|
| 182 | return 1 |
|---|
| 183 | else |
|---|
| 184 | return 0 |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | function my_getline(){ |
|---|
| 189 | while (getline){ |
|---|
| 190 | if ((NF == 0) || first_char("#")) |
|---|
| 191 | continue |
|---|
| 192 | return 1 |
|---|
| 193 | } |
|---|
| 194 | return 0 |
|---|
| 195 | } |
|---|