Thursday, December 07, 2017

Bash script convert c to mif and coe

#head -n -1 $1 > $1.txt
sed '1d' $1 > $1.tst
#sed 's/\<0x\>//g' $1.tst > $1.txt
#buang ")x"
sed "s/0x//g" $1.tst > $1.txt
head -n -1 $1.txt | tr -d ,  > $1.tmp
#tr -d , $1.tmp
#tail -n +1 $1.txt > $1.tmp
mv $1.tmp $1.anu

echo "DEPTH = 1024;" > $1.mif
echo "WIDTH = 8;" >> $1.mif

echo "ADDRESS_RADIX = DEC;" >> $1.mif
echo "DATA_RADIX = HEX;" >> $1.mif
echo "CONTENT" >> $1.mif
echo "  BEGIN" >> $1.mif

let n=0
for i in `cat $1.anu`
do
   echo "$n : $i;" >> $1.mif
   let n=n+1;
done

echo "END;" >> $1.mif

#head -n -1 $1.txt | tr -d '\n'  > $1.eco
head -n -1 $1.txt > $1.eci
#membuang last comma
sed '$s/,$//' < $1.eci  > $1.eco
sed '$s/$/;/' < $1.eco  > $1.eci
echo "memory_initialization_radix=16;"  > $1.coe
echo "memory_initialization_vector="    >> $1.coe
cat $1.eci >> $1.coe

#cat $1.coe

No comments:

Post a Comment