Скачиваний:
21
Добавлен:
09.05.2014
Размер:
176.36 Кб
Скачать

Утилитаmcd2mif

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

namespace mcd2mif

{

class Program

{

class InputFile

{

string[] Input;

int CurrentLine;

public InputFile(string FName)

{

Input = File.ReadAllLines(FName);

CurrentLine = 0;

}

public string GetStr()

{

try

{

while (Input[CurrentLine] == "" || Input[CurrentLine][0] == '#') CurrentLine++;

}

catch (Exception e)

{

return null;

}

return Input[CurrentLine++];

}

}

class MifFile

{

static string MifHead = "WIDTH={0};\nDEPTH={1};\nADDRESS_RADIX=HEX;\nDATA_RADIX=HEX;\nCONTENT BEGIN\n";

static string MifEnd = "END;";

static string MifEnt = "{0:X}:{1:X};\n";

string fName;

int fDepth;

int fWidth;

public MifFile(string FName, int Width, int Depth)

{

fName = FName;

fDepth = Depth;

fWidth = Width;

File.CreateText(fName).Close();

File.AppendAllText(fName, String.Format(MifHead, fWidth, fDepth), Encoding.ASCII);

}

public void AddNum(int Addr, int Num)

{

File.AppendAllText(fName, String.Format(MifEnt, Addr, Num), Encoding.ASCII);

}

public void Done()

{

File.AppendAllText(fName, MifEnd, Encoding.ASCII);

}

}

static void Main(string[] args)

{

try

{

Console.WriteLine("mcd2mif utility by C.c (c) 2011");

if (args.Length < 1) throw new Exception("Illegal arguments! No input file specified");

Console.WriteLine("Processing file \"{0}\" ...", args[0]);

InputFile Input = new InputFile(args[0]);

List<MifFile> Outputs = new List<MifFile>();

int OutCount = Convert.ToInt32(Input.GetStr());

for (int i = 0; i < OutCount; i++)

{

string[] Format = Input.GetStr().Split(' ');

Outputs.Add(new MifFile(Format[2]+".mif", Convert.ToInt32(Format[1])*8, 1024));

}

string s;

int Addr = 0;

List<string> Unique = new List<string>();

while ((s = Input.GetStr()) != null)

{

string[] Bytes = s.Split('|');

for (int i = 0; i < OutCount; i++)

{

Outputs[i].AddNum(Addr, int.Parse(Bytes[i], System.Globalization.NumberStyles.HexNumber));

}

Addr++;

if (!Unique.Contains(s)) Unique.Add(s);

}

for (int i = 0; i < OutCount; i++) Outputs[i].Done();

Console.WriteLine("Done. {0} microoperations total, {1} unique.\n", Addr, Unique.Count);

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

}

}

Соседние файлы в папке Отчет