#Convert Xilinx Mif to Altera MIF #Ex of How to run Script for a 16x8 (16 bit wide, 8 deep) Xilinx Block RAM: #python X_altera_mif_conversion.py -d 8 -w 16 -i Xilinx_mif.mif -o intel_mif.mif #If your Xilinx MIF (Xilinx_mif.mif) is a 8x16 (dxw) MIF generated in Vivado/ISE, the command above will generate a intel MIF file intel_mif.mif in the correct format that will pass Quartus synthesis. import sys, getopt, struct def convert_mif(ifile, ofile, depth, width): fp_out=open(ofile, "w") fp_out.write("DEPTH = " + str(depth) + ";" + "\n" + "\n") fp_out.write("WIDTH = " + str(width) + ";" + "\n" + "\n" + "\n") fp_out.write("ADDRESS_RADIX = DEC;\n") fp_out.write("DATA_RADIX = BIN;\n\n\n") fp_out.write("CONTENT\n") fp_out.write("BEGIN\n") fp_in=open(ifile, "r") lines = fp_in.readlines() i=0 for line in lines: fp_out.write(str(i) + " : " + line.rstrip() + ";" + "\n") i = i+1 fp_out.write("END;") fp_in.close() fp_out.close() print("Converted Xilinx MIF: " + ifile + " To Intel PSG MIF: " + ofile) def main(argv): inputfile = '' outputfile = '' depth = 0 width = 0 try: opts, args = getopt.getopt(argv,"hd:w:i:o:") except getopt.GetoptError: print 'X_altera_mif_conversion.py -d -w -i -o ' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'X_altera_mif_conversion.py -d -w -i -o ' sys.exit() elif opt == '-d': depth = arg elif opt == '-w': width = arg elif opt == "-i": inputfile = arg elif opt == "-o": outputfile = arg print 'Input file is ', inputfile print 'Output file is ', outputfile print 'depth is ', depth print 'width is ', width convert_mif(inputfile, outputfile, depth, width) if __name__ == "__main__": main(sys.argv[1:])