-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (52 loc) · 1.67 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.IO;
namespace Converter
{
class Program
{
public const string Name = "bin2vhdl";
private const int Success = 0;
private const int Failure = 1;
static int Main(string[] args)
{
Options options;
try
{
options = new Options(Name, args);
}
catch (Exception ex)
{
Console.Error.WriteLine($"{Name}: {ex.Message}");
return Failure;
}
if (options.Action == Options.Actions.ShowHelp)
{
options.Describe(Console.Error);
return Failure;
}
try
{
var binary = File.ReadAllBytes(options.SourceFileName);
string text;
switch (options.Action)
{
case Options.Actions.ConvertToVhdl:
text = VhdlConverter.Convert(binary, options.PackageName, options.Width, options.Endian);
break;
case Options.Actions.ConvertToMif:
text = MifConverter.Convert(binary, options.Width, options.Endian);
break;
default:
throw new NotImplementedException($"{options.Action} not implemented");
}
File.WriteAllText(options.OutputFileName, text);
return Success;
}
catch (Exception ex)
{
Console.Error.WriteLine($"{Name}: {ex.Message}");
return Failure;
}
}
}
}